Exemplo n.º 1
0
def test_is_systemd():
    # Arrange

    # Act
    result = utils.is_systemd()

    # Assert
    assert result
Exemplo n.º 2
0
    def check_service(self, status, which, notes=""):
        """
        Check if the service command is available or the old init.d system has to be used.

        :param status: The status list with possible problems.
        :param which: The service to check for.
        :param notes: A manual not to attach.
        """
        if notes != "":
            notes = " (NOTE: %s)" % notes
        return_code = 0
        if utils.is_supervisord():
            with ServerProxy('http://localhost:9001/RPC2') as server:
                process_info = server.supervisor.getProcessInfo(which)
                if process_info['statename'] != "RUNNING":
                    status.append("service %s is not running%s" %
                                  (which, notes))
                    return
        elif utils.is_systemd():
            return_code = utils.subprocess_call(
                "systemctl status %s > /dev/null 2>/dev/null" % which,
                shell=True)
            if return_code != 0:
                status.append("service %s is not running%s" % (which, notes))
                return
        elif self.checked_family in ("redhat", "suse"):
            if os.path.exists("/etc/rc.d/init.d/%s" % which):
                return_code = utils.subprocess_call(
                    "/sbin/service %s status > /dev/null 2>/dev/null" % which,
                    shell=True)
            if return_code != 0:
                status.append("service %s is not running%s" % (which, notes))
                return
        elif self.checked_family == "debian":
            # we still use /etc/init.d
            if os.path.exists("/etc/init.d/%s" % which):
                return_code = utils.subprocess_call(
                    "/etc/init.d/%s status /dev/null 2>/dev/null" % which,
                    shell=True)
            if return_code != 0:
                status.append("service %s is not running%s" % (which, notes))
                return
        else:
            status.append(
                "Unknown distribution type, cannot check for running service %s"
                % which)
            return