def test__purpose_local_uses_maas_syslog_port(self): syslog_port = factory.pick_port() Config.objects.set_config('maas_syslog_port', syslog_port) rack_controller = factory.make_RackController() local_ip = factory.make_ip_address() remote_ip = factory.make_ip_address() node = self.make_node_with_extra( status=NODE_STATUS.DEPLOYED, netboot=False) node.boot_cluster_ip = local_ip node.osystem = factory.make_name('osystem') node.distro_series = factory.make_name('distro_series') node.save() mac = node.get_boot_interface().mac_address config = get_config( rack_controller.system_id, local_ip, remote_ip, mac=mac, query_count=8) self.assertEquals({ "system_id": node.system_id, "arch": node.split_arch()[0], "subarch": node.split_arch()[1], "osystem": node.osystem, "release": node.distro_series, "kernel": '', "initrd": '', "boot_dtb": '', "purpose": 'local', "hostname": node.hostname, "domain": node.domain.name, "preseed_url": ANY, "fs_host": local_ip, "log_host": local_ip, "log_port": syslog_port, "extra_opts": '', "http_boot": True, }, config)
def test__options_are_saved(self): self.useFixture(RegionConfigurationFixture()) # Set the option to a random value. if self.option == "database_port": value = factory.pick_port() elif self.option == "database_conn_max_age": value = random.randint(0, 60) elif self.option == "num_workers": value = random.randint(1, 16) elif self.option in ["debug", "debug_queries"]: value = random.choice(['true', 'false']) else: value = factory.make_name("foobar") # Values are coming from the command-line so stringify. stdio = call_set(**{self.option: str(value)}) # Nothing is echoed back to the user. self.assertThat(stdio.getOutput(), Equals("")) self.assertThat(stdio.getError(), Equals("")) # Some validators alter the given option, like adding an HTTP scheme # to a "bare" URL, so we merely check that the value contains the # given value, not that it exactly matches. Values are converted to a # str so Contains works with int values. with RegionConfiguration.open() as configuration: self.assertThat(str(getattr(configuration, self.option)), Contains(str(value)))
def make_example_configuration(self): # Set the syslog port. port = factory.pick_port() Config.objects.set_config("maas_syslog_port", port) # Populate the database with example peers. space = factory.make_Space() region, addr4, addr6 = make_region_rack_with_address(space) self.useFixture(MAASIDFixture(region.system_id)) peer1, addr1_4, addr1_6 = make_region_rack_with_address(space) peer2, addr2_4, addr2_6 = make_region_rack_with_address(space) # Return the servers and all possible peer IP addresses. return ( port, [ ( peer1, sorted([IPAddress(addr1_4.ip), IPAddress(addr1_6.ip)])[0], ), ( peer2, sorted([IPAddress(addr2_4.ip), IPAddress(addr2_6.ip)])[0], ), ], )
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_compose_preseed_uses_maas_syslog_port(self): syslog_port = factory.pick_port() Config.objects.set_config('maas_syslog_port', syslog_port) rack_controller = factory.make_RackController(url='') node = factory.make_Node(interface=True, status=NODE_STATUS.COMMISSIONING) nic = node.get_boot_interface() nic.vlan.dhcp_on = True nic.vlan.primary_rack = rack_controller nic.vlan.save() ip_address = factory.make_ipv4_address() node.boot_cluster_ip = ip_address node.save() request = make_HttpRequest() preseed = yaml.safe_load( compose_preseed(request, PRESEED_TYPE.COMMISSIONING, node)) self.assertEqual('%s:%d' % (ip_address, syslog_port), preseed['rsyslog']['remotes']['maas'])