Skip to content

Commit

Permalink
tests/positive: remove enablement symlink(s) before disabling a unit
Browse files Browse the repository at this point in the history
  • Loading branch information
sohankunkerkar committed May 2, 2022
1 parent ddb7113 commit d54bda3
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/positive/files/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func init() {
register.Register(register.PositiveTest, CreateEmptyDropinsUnit())
register.Register(register.PositiveTest, TestUnmaskUnit())
register.Register(register.PositiveTest, TestMaskUnit())
register.Register(register.PositiveTest, RemoveEnablementSymLinksforUnit())
}

func CreateInstantiatedService() types.Test {
Expand Down Expand Up @@ -259,3 +260,66 @@ func TestMaskUnit() types.Test {
ConfigMinVersion: configMinVersion,
}
}

// RemoveEnablementSymLinksforUnit checks if Ignition
// removes the enablement symlink for a given systemd
// unit before disbling it. Also, verifies that the code
// doesn't error out while disabling a non-existent unit.
func RemoveEnablementSymLinksforUnit() types.Test {
name := "unit.remove.symlinks"
in := types.GetBaseDisk()
out := types.GetBaseDisk()
config := `{
"ignition": { "version": "$version" },
"systemd": {
"units": [
{
"enabled": false,
"name": "foo.service"
},
{
"enabled": false,
"name": "foo2.service"
}
]
}
}`
in[0].Partitions.AddLinks("ROOT", []types.Link{
{
Node: types.Node{
Directory: "etc/systemd/system",
Name: "foo.service",
},
Target: "/usr/lib/systemd/system/foo.service",
Hard: false,
},
})
in[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "foo.service",
Directory: "usr/lib/systemd/system",
},
Contents: "[Unit]\nDescription=f\n[Service]\nType=oneshot\nExecStart=/usr/bin/true\n[Install]\nWantedBy=multi-user.target\n",
},
})
out[0].Partitions.AddRemovedNodes("ROOT", []types.Node{
{
Directory: "etc/systemd/system",
Name: "foo.service",
},
{
Directory: "etc/systemd/system",
Name: "foo2.service",
},
})
configMinVersion := "3.3.0"

return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}

0 comments on commit d54bda3

Please sign in to comment.