コード例 #1
0
ファイル: utils_test.py プロジェクト: openSUSE/cobbler
def test_dhcp_service_name():
    # Arrange

    # Act
    result = utils.dhcp_service_name()

    # Assert
    assert result == "dhcpd"
コード例 #2
0
def run(api, args, logger) -> int:
    """
    Run the trigger via this method, meaning in this case that depending on the settings dns and/or dhcp services are
    restarted.

    :param api: The api to resolve settings.
    :param args: This parameter is not used currently.
    :param logger: The logger to audit the action with.
    :return: The return code of the service restarts.
    """
    settings = api.settings()

    which_dhcp_module = module_loader.get_module_name("dhcp", "module").strip()
    which_dns_module = module_loader.get_module_name("dns", "module").strip()

    # special handling as we don't want to restart it twice
    has_restarted_dnsmasq = False

    rc = 0
    if settings.manage_dhcp:
        if which_dhcp_module == "managers.isc":
            if settings.restart_dhcp:
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name()
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger,
                                           dhcp_restart_command,
                                           shell=True)
        elif which_dhcp_module == "managers.dnsmasq":
            if settings.restart_dhcp:
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if settings.manage_dns and settings.restart_dns:
        if which_dns_module == "managers.bind":
            named_service_name = utils.named_service_name()
            dns_restart_command = "service %s restart" % named_service_name
            rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
        elif which_dns_module == "managers.dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger,
                                       "service dnsmasq restart",
                                       shell=True)
        elif which_dns_module == "managers.dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        elif which_dns_module == "managers.ndjbdns":
            # N-DJBDNS picks up configuration changes automatically and does not need to be restarted.
            pass
        else:
            logger.error("unknown DNS engine: %s" % which_dns_module)
            rc = 412

    return rc
コード例 #3
0
def run(api, args, logger):

    settings = api.settings()

    manage_dhcp = str(settings.manage_dhcp).lower()
    manage_dns = str(settings.manage_dns).lower()
    restart_dhcp = str(settings.restart_dhcp).lower()
    restart_dns = str(settings.restart_dns).lower()

    which_dhcp_module = module_loader.get_module_name("dhcp", "module").strip()
    which_dns_module = module_loader.get_module_name("dns", "module").strip()

    # special handling as we don't want to restart it twice
    has_restarted_dnsmasq = False

    rc = 0
    if manage_dhcp != "0":
        if which_dhcp_module == "manage_isc":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name(api)
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger,
                                           dhcp_restart_command,
                                           shell=True)
        elif which_dhcp_module == "manage_dnsmasq":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "manage_bind":
            named_service_name = utils.named_service_name(api)
            dns_restart_command = "service %s restart" % named_service_name
            rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
        elif which_dns_module == "manage_dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger,
                                       "service dnsmasq restart",
                                       shell=True)
        elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        elif which_dns_module == "manage_ndjbdns":
            # N-DJBDNS picks up configuration changes automatically and does not need to be restarted.
            pass
        else:
            logger.error("unknown DNS engine: %s" % which_dns_module)
            rc = 412

    return rc
コード例 #4
0
    def restart_service(self):
        if self.settings.restart_dhcp == "0":
            return 0
        service_v4 = utils.dhcp_service_name()

        # Even if one fails, try both and return an error
        ret = 0
        if self.settings.manage_dhcp_v4 != "0":
            ret |= self.restart_dhcp(service_v4)
        if self.settings.manage_dhcp_v6 != "0":
            # TODO: Fix hard coded string
            ret |= self.restart_dhcp("dhcpd6")
        return ret
コード例 #5
0
def run(api, args, logger):

    settings = api.settings()

    manage_dhcp = str(settings.manage_dhcp).lower()
    manage_dns = str(settings.manage_dns).lower()
    restart_dhcp = str(settings.restart_dhcp).lower()
    restart_dns = str(settings.restart_dns).lower()

    which_dhcp_module = module_loader.get_module_name("dhcp", "module").strip()
    which_dns_module = module_loader.get_module_name("dns", "module").strip()

    # special handling as we don't want to restart it twice
    has_restarted_dnsmasq = False

    rc = 0
    if manage_dhcp != "0":
        if which_dhcp_module == "manage_isc":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "dhcpd -t -q", shell=True)
                if rc != 0:
                    logger.error("dhcpd -t failed")
                    return 1
                dhcp_service_name = utils.dhcp_service_name(api)
                dhcp_restart_command = "service %s restart" % dhcp_service_name
                rc = utils.subprocess_call(logger, dhcp_restart_command, shell=True)
        elif which_dhcp_module == "manage_dnsmasq":
            if restart_dhcp != "0":
                rc = utils.subprocess_call(logger, "service dnsmasq restart")
                has_restarted_dnsmasq = True
        else:
            logger.error("unknown DHCP engine: %s" % which_dhcp_module)
            rc = 411

    if manage_dns != "0" and restart_dns != "0":
        if which_dns_module == "manage_bind":
            named_service_name = utils.named_service_name(api)
            dns_restart_command = "service %s restart" % named_service_name
            rc = utils.subprocess_call(logger, dns_restart_command, shell=True)
        elif which_dns_module == "manage_dnsmasq" and not has_restarted_dnsmasq:
            rc = utils.subprocess_call(logger, "service dnsmasq restart", shell=True)
        elif which_dns_module == "manage_dnsmasq" and has_restarted_dnsmasq:
            rc = 0
        elif which_dns_module == "manage_ndjbdns":
            # N-DJBDNS picks up configuration changes automatically and does not need to be restarted.
            pass
        else:
            logger.error("unknown DNS engine: %s" % which_dns_module)
            rc = 412

    return rc
コード例 #6
0
ファイル: manage_isc.py プロジェクト: andrewwyatt/cobbler
 def sync_dhcp(self):
     restart_dhcp = str(self.settings.restart_dhcp).lower()
     service_name = utils.dhcp_service_name(self.api)
     if restart_dhcp != "0":
         rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
         if rc != 0:
             error_msg = "dhcpd -t failed"
             self.logger.error(error_msg)
             raise CX(error_msg)
         service_restart = "service %s restart" % service_name
         rc = utils.subprocess_call(self.logger, service_restart, shell=True)
         if rc != 0:
             error_msg = "%s failed" % service_name
             self.logger.error(error_msg)
             raise CX(error_msg)
コード例 #7
0
 def sync_dhcp(self):
     restart_dhcp = str(self.settings.restart_dhcp).lower()
     service_name = utils.dhcp_service_name(self.api)
     if restart_dhcp != "0":
         rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
         if rc != 0:
             error_msg = "dhcpd -t failed"
             self.logger.error(error_msg)
             raise CX(error_msg)
         service_restart = "service %s restart" % service_name
         rc = utils.subprocess_call(self.logger, service_restart, shell=True)
         if rc != 0:
             error_msg = "%s failed" % service_name
             self.logger.error(error_msg)
             raise CX(error_msg)
コード例 #8
0
ファイル: isc.py プロジェクト: vzhestkov/cobbler
 def restart_service(self):
     """
     This syncs the dhcp server with it's new config files.
     Basically this restarts the service to apply the changes.
     """
     service_name = utils.dhcp_service_name()
     ret = 0
     if self.settings.restart_dhcp:
         ret = utils.subprocess_call("dhcpd -t -q", shell=True)
         if ret != 0:
             self.logger.error("dhcpd -t failed")
         service_restart = "service %s restart" % service_name
         ret = utils.subprocess_call(service_restart, shell=True)
         if ret != 0:
             self.logger.error("%s service failed", service_name)
     return ret
コード例 #9
0
ファイル: isc.py プロジェクト: peikai01/cobbler
 def sync_dhcp(self):
     """
     This syncs the dhcp server with it's new config files. Basically this restarts the service to apply the changes.
     """
     service_name = utils.dhcp_service_name()
     if self.settings.restart_dhcp:
         rc = utils.subprocess_call(self.logger, "dhcpd -t -q", shell=True)
         if rc != 0:
             error_msg = "dhcpd -t failed"
             self.logger.error(error_msg)
             raise CX(error_msg)
         service_restart = "service %s restart" % service_name
         rc = utils.subprocess_call(self.logger, service_restart, shell=True)
         if rc != 0:
             error_msg = "%s failed" % service_name
             self.logger.error(error_msg)
             raise CX(error_msg)