Skip to content

Commit

Permalink
Merge pull request coreos#1009 from miabbott/systemd_checks
Browse files Browse the repository at this point in the history
kola/tests/coretest/core: add RHCOS checks for disabled services
  • Loading branch information
Stephen Lowrie authored Jun 12, 2019
2 parents 7ec5264 + d2bdf71 commit eb6c08f
Showing 1 changed file with 68 additions and 6 deletions.
74 changes: 68 additions & 6 deletions kola/tests/coretest/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ const (
UpdateEnginePubKeyV2 = "a76a22e6afcdfbc55dd2953aa950c7ec93b254774fca02d13ec52c59672e5982"
)

// RHCOS services we expect disabled/inactive
var offServices = []string{
"dnsmasq.service",
"iscsid.service",
"iscsid.socket",
"iscsiuio.service",
"nfs-blkmap.service",
"nfs-idmapd.service",
"nfs-mountd.service",
"nfs-server.service",
"nis-domainname.service",
"rbdmap.service",
"rdisc.service",
"rpc-statd.service",
"rpcbind.service",
"rpcbind.socket",
"sssd.service",
"tcsd.service",
}

func init() {
register.Register(&register.Test{
Name: "cl.basic",
Expand All @@ -48,12 +68,13 @@ func init() {
Run: LocalTests,
ClusterSize: 1,
NativeFuncs: map[string]func() error{
"PortSSH": TestPortSsh,
"DbusPerms": TestDbusPerms,
"ServicesActive": TestServicesActiveRHCOS,
"ReadOnly": TestReadOnlyFs,
"Useradd": TestUseradd,
"MachineID": TestMachineID,
"PortSSH": TestPortSsh,
"DbusPerms": TestDbusPerms,
"ServicesActive": TestServicesActiveRHCOS,
"ServicesDisabled": TestServicesDisabledRHCOS,
"ReadOnly": TestReadOnlyFs,
"Useradd": TestUseradd,
"MachineID": TestMachineID,
},
Distros: []string{"rhcos"},
})
Expand Down Expand Up @@ -275,6 +296,47 @@ func servicesActive(units []string) error {
return nil
}

func TestServicesDisabledRHCOS() error {
err := servicesInactive(offServices)
if err != nil {
return err
}

err = servicesDisabled(offServices)
if err != nil {
return err
}
return nil
}

func servicesInactive(units []string) error {
for _, unit := range units {
c := exec.Command("systemctl", "is-active", unit)
err := c.Run()
if err == nil {
return fmt.Errorf("Service Incorrectly Active: %q", unit)
}
}
return nil
}

func servicesDisabled(units []string) error {
for _, unit := range units {
c := exec.Command("systemctl", "is-enabled", unit)
out, err := c.Output()
if err == nil {
// "is-enabled" can return 0 in some cases when the output is not
// explicitly "disabled". In the case of the RHCOS services
// that are checked, we expect some to report "static"
outString := strings.TrimSuffix(string(out), "\n")
if (outString != "disabled") && (outString != "static") {
return fmt.Errorf("Service Incorrectly Enabled: %q", unit)
}
}
}
return nil
}

func TestReadOnlyFs() error {
mountModes := make(map[string]bool)
mounts, err := GetMountTable()
Expand Down

0 comments on commit eb6c08f

Please sign in to comment.