Beispiel #1
0
 def test_set_up_options_conf_handles_no_upstream_dns(self):
     dns_conf_dir = self.make_dir()
     self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
     set_up_options_conf()
     target_file = os.path.join(
         dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     self.assertThat(target_file, FileExists())
Beispiel #2
0
 def handle(self, *args, **options):
     no_clobber = options.get('no_clobber')
     set_up_rndc()
     set_up_options_conf(overwrite=not no_clobber)
     config = DNSConfig()
     config.write_config(overwrite=not no_clobber,
                         zone_names=(),
                         reverse_zone_names=())
Beispiel #3
0
 def handle(self, *args, **options):
     no_clobber = options.get('no_clobber')
     setup_rndc()
     upstream_dns = Config.objects.get_config("upstream_dns")
     set_up_options_conf(
         overwrite=not no_clobber, upstream_dns=upstream_dns)
     config = DNSConfig()
     config.write_config(
         overwrite=not no_clobber, zone_names=(), reverse_zone_names=())
Beispiel #4
0
 def test_set_up_options_conf_writes_configuration(self):
     dns_conf_dir = patch_dns_config_path(self)
     fake_dns = [factory.make_ipv4_address(), factory.make_ipv4_address()]
     set_up_options_conf(upstream_dns=fake_dns)
     target_file = os.path.join(dns_conf_dir,
                                MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     self.assertThat(
         target_file,
         MatchesAll(*(FileContains(matcher=Contains(address))
                      for address in fake_dns)))
Beispiel #5
0
 def test_set_up_options_conf_write_config_allows_single_override(self):
     dns_conf_dir = patch_dns_config_path(self)
     factory.make_file(
         location=dns_conf_dir, name=NAMED_CONF_OPTIONS,
         contents=NAMED_CONF_OPTIONS_WITH_ALLOW_QUERY_CONTENTS)
     set_up_options_conf()
     target_file = os.path.join(
         dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     target = read_isc_file(target_file)
     self.assertIsNone(target.get('allow-query'))
Beispiel #6
0
 def test_set_up_options_conf_writes_configuration(self):
     dns_conf_dir = self.make_dir()
     self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
     fake_dns = factory.getRandomIPAddress()
     set_up_options_conf(upstream_dns=fake_dns)
     target_file = os.path.join(
         dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     self.assertThat(
         target_file,
         FileContains(matcher=Contains(fake_dns)))
Beispiel #7
0
 def test_set_up_options_conf_write_config_assumes_no_overrides(self):
     dns_conf_dir = patch_dns_config_path(self)
     set_up_options_conf()
     target_file = os.path.join(dns_conf_dir,
                                MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     target = read_isc_file(target_file)
     self.assertThat([
         target['allow-query']['any'],
         target['allow-recursion']['trusted'],
         target['allow-query-cache']['trusted'],
     ], AllMatch(Equals(True)))
Beispiel #8
0
def bind_write_options(upstream_dns, dnssec_validation):
    """Write BIND options.

    :param upstream_dns: A sequence of upstream DNS servers.
    """
    # upstream_dns was formerly specified as a single IP address. These
    # assertions are here to prevent code that assumes that slipping through.
    assert not isinstance(upstream_dns, (bytes, str))
    assert isinstance(upstream_dns, collections.Sequence)

    set_up_options_conf(upstream_dns=upstream_dns,
                        dnssec_validation=dnssec_validation)
Beispiel #9
0
def run(args, stdout=sys.stdout, stderr=sys.stderr):
    """Setup MAAS DNS configuration.

    :param args: Parsed output of the arguments added in `add_arguments()`.
    :param stdout: Standard output stream to write to.
    :param stderr: Standard error stream to write to.
    """
    set_up_rndc()
    set_up_options_conf(overwrite=not args.no_clobber)
    config = DNSConfig()
    config.write_config(overwrite=not args.no_clobber,
                        zone_names=(),
                        reverse_zone_names=())
Beispiel #10
0
 def test_set_up_options_conf_write_config_allows_zero_overrides(self):
     dns_conf_dir = patch_dns_config_path(self)
     factory.make_file(location=dns_conf_dir,
                       name=NAMED_CONF_OPTIONS,
                       contents=NAMED_CONF_OPTIONS_NO_ALLOW_CONTENTS)
     set_up_options_conf()
     target_file = os.path.join(dns_conf_dir,
                                MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     target = read_isc_file(target_file)
     self.assertThat([
         target['allow-query']['any'],
         target['allow-recursion']['trusted'],
         target['allow-query-cache']['trusted'],
     ], AllMatch(Equals(True)))
Beispiel #11
0
 def test_set_up_options_conf_write_config_allows_overrides(self):
     dns_conf_dir = patch_dns_config_path(self)
     factory.make_file(location=dns_conf_dir,
                       name=NAMED_CONF_OPTIONS,
                       contents=NAMED_CONF_OPTIONS_CONTENTS)
     set_up_options_conf()
     target_file = os.path.join(dns_conf_dir,
                                MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     target = read_isc_file(target_file)
     self.assertThat([
         target.get('allow-query'),
         target.get('allow-recursion'),
         target.get('allow-query-cache'),
     ], AllMatch(Is(None)))
Beispiel #12
0
def write_full_dns_config(zones=None, callback=None, **kwargs):
    """Write out the DNS configuration files: the main configuration
    file and the zone files.
    :param zones: List of zones to write.
    :type zones: list of :class:`DNSZoneData`
    :param callback: Callback subtask.
    :type callback: callable
    :param **kwargs: Keyword args passed to DNSConfig.write_config()
    """
    if zones is not None:
        for zone in zones:
            zone.write_config()
    # Write main config file.
    dns_config = DNSConfig(zones=zones)
    dns_config.write_config(**kwargs)
    # Write the included options file.
    set_up_options_conf(**kwargs)
    if callback is not None:
        callback.delay()
Beispiel #13
0
 def test_set_up_options_conf_handles_no_upstream_dns(self):
     dns_conf_dir = patch_dns_config_path(self)
     set_up_options_conf()
     target_file = os.path.join(dns_conf_dir,
                                MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
     self.assertThat(target_file, FileExists())