def handle(self, *args, **options): with RegionConfiguration.open_for_update() as config: for name, option in gen_configuration_options(): value = options.get(name) if value is not None: try: setattr(config, name, value) except formencode.Invalid as error: message = str(error).rstrip(".") raise CommandError("%s: %s." % (name.replace("_", "-"), message))
def test__options_are_reset(self): self.useFixture(RegionConfigurationFixture()) with RegionConfiguration.open_for_update() as configuration: # Give the option a random value. if isinstance(getattr(configuration, self.option), str): value = factory.make_name("foobar") else: value = factory.pick_port() setattr(configuration, self.option, value) stdio = call_reset(**{self.option: True}) # Nothing is echoed back to the user. self.assertThat(stdio.getOutput(), Equals("")) self.assertThat(stdio.getError(), Equals("")) # There is no custom value in the configuration file. with open(RegionConfiguration.DEFAULT_FILENAME, "rb") as fd: settings = yaml.safe_load(fd) self.assertThat(settings, Equals({}))
def test_dns_config_has_NS_record(self): self.patch(settings, "DNS_CONNECT", True) ip = factory.make_ipv4_address() with RegionConfiguration.open_for_update() as config: config.maas_url = "http://%s/" % ip domain = factory.make_Domain() node, static = self.create_node_with_static_ip(domain=domain) dns_update_all_zones() # Creating the domain triggered writing the zone file and updating the # DNS. self.dns_wait_soa(domain.name) # Get the NS record for the zone 'domain.name'. ns_record = dig_call(port=self.bind.config.port, commands=[domain.name, "NS", "+short"]) self.assertGreater(len(ns_record), 0, "No NS record for domain.name.") # Resolve that hostname. self.dns_wait_soa(ns_record) ip_of_ns_record = dig_call(port=self.bind.config.port, commands=[ns_record, "+short"]) self.assertEqual(ip, ip_of_ns_record)
def handle(self, *args, **options): with RegionConfiguration.open_for_update() as config: for name, option in gen_configuration_options(): if options.get(name): delattr(config, name)