Skip to content

Commit

Permalink
kola/tests/coretest/core: add RHCOS checks for disabled services
Browse files Browse the repository at this point in the history
In RHCOS, we are explicitly disabling certain services.  These
additional tests will verify that we don't regress.
  • Loading branch information
miabbott committed Jun 12, 2019
1 parent 4332de0 commit d2bdf71
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 d2bdf71

Please sign in to comment.