kola/tests/coretest/core: add RHCOS checks for disabled services
In RHCOS, we are explicitly disabling certain services.  These
additional tests will verify that we don't regress.
@@ -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",
@@ -51,6 +71,7 @@ func init() {
"PortSSH": TestPortSsh,
"DbusPerms": TestDbusPerms,
"ServicesActive": TestServicesActiveRHCOS,
+ "ServicesDisabled": TestServicesDisabledRHCOS,
"ReadOnly": TestReadOnlyFs,
"Useradd": TestUseradd,
"MachineID": TestMachineID,
@@ -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()
