Example #1
0
 def test_execute_rndc_command_executes_command(self):
     recorder = FakeMethod()
     fake_dir = patch_dns_config_path(self)
     self.patch(config, 'call_and_check', recorder)
     command = factory.make_string()
     execute_rndc_command([command])
     rndc_conf_path = os.path.join(fake_dir, MAAS_RNDC_CONF_NAME)
     expected_command = ['rndc', '-c', rndc_conf_path, command]
     self.assertEqual((expected_command, ), recorder.calls[0][0])
Example #2
0
 def test_execute_rndc_command_executes_command(self):
     recorder = FakeMethod()
     fake_dir = patch_dns_config_path(self)
     self.patch(config, "call_and_check", recorder)
     command = factory.make_string()
     execute_rndc_command([command], timeout=sentinel.timeout)
     rndc_conf_path = os.path.join(fake_dir, MAAS_RNDC_CONF_NAME)
     expected_command = ["rndc", "-c", rndc_conf_path, command]
     self.assertEqual((expected_command, ), recorder.calls[0][0])
     self.assertEqual({"timeout": sentinel.timeout}, recorder.calls[0][1])
Example #3
0
 def test_execute_rndc_command_executes_command(self):
     recorder = FakeMethod()
     fake_dir = factory.getRandomString()
     self.patch(config, 'call_and_check', recorder)
     self.patch(conf, 'DNS_CONFIG_DIR', fake_dir)
     command = factory.getRandomString()
     execute_rndc_command([command])
     rndc_conf_path = os.path.join(fake_dir, MAAS_RNDC_CONF_NAME)
     expected_command = ['rndc', '-c', rndc_conf_path, command]
     self.assertEqual((expected_command,), recorder.calls[0][0])
Example #4
0
def bind_reload():
    """Ask BIND to reload its configuration and all zone files.  This operation
    is 'best effort' (with logging) as the server may not be running, and there
    is often no context for reporting.

    :return: True if success, False otherwise.
    """
    try:
        execute_rndc_command(("reload", ))
        return True
    except CalledProcessError as exc:
        maaslog.error("Reloading BIND failed (is it running?): %s", exc)
        return False
Example #5
0
def rndc_command(arguments, retry=False, callback=None):
    """Use rndc to execute a command.
    :param arguments: Argument list passed down to the rndc command.
    :type arguments : list
    :param retry: Should this task be retried in case of failure?
    :type retry: bool
    :param callback: Callback subtask.
    :type callback: callable
    """
    try:
        execute_rndc_command(arguments)
    except CalledProcessError, exc:
        if retry:
            return rndc_command.retry(
                exc=exc, countdown=RNDC_COMMAND_RETRY_DELAY)
        else:
            raise
Example #6
0
def bind_reload_zones(zone_list):
    """Ask BIND to reload the zone file for the given zone.

    :param zone_list: A list of zone names to reload, or a single name as a
        string.
    :return: True if success, False otherwise.
    """
    ret = True
    if not isinstance(zone_list, list):
        zone_list = [zone_list]
    for name in zone_list:
        try:
            execute_rndc_command(("reload", name))
        except CalledProcessError as exc:
            maaslog.error("Reloading BIND zone %r failed (is it running?): %s",
                          name, exc)
            ret = False
    return ret
Example #7
0
def bind_reconfigure():
    """Ask BIND to reload its configuration and *new* zone files.

    From rndc(8):

      Reload the configuration file and load new zones, but do not reload
      existing zone files even if they have changed. This is faster than a
      full reload when there is a large number of zones because it avoids the
      need to examine the modification times of the zones files.

    """
    try:
        execute_rndc_command(("reconfig", ))
    except CalledProcessError as exc:
        maaslog.error("Reloading BIND configuration failed: %s", exc)
        # Log before upgrade so that the output does not go to maaslog.
        ExternalProcessError.upgrade(exc)
        raise