def make_kernel_parameters(testcase=None, **parms): """Make a randomly populated `KernelParameters` instance. If testcase is passed, we poke the generated arch/subarch into the ArchitectureRegistry and call addCleanup on the testcase to make sure it is removed after the test completes. """ # fs_host needs to be an IP address, set it if it was not passed. if 'fs_host' not in parms: parms.update({'fs_host': factory.make_ip_address()}) parms.update({ field: factory.make_name(field) for field in KernelParameters._fields if field not in parms }) if not isinstance(parms['http_boot'], bool): parms['http_boot'] = True params = KernelParameters(**parms) if testcase is not None: name = "%s/%s" % (params.arch, params.subarch) if name in ArchitectureRegistry: # It's already there, no need to patch and risk overwriting # preset kernel options. return params resource = Architecture(name, name) ArchitectureRegistry.register_item(name, resource) testcase.addCleanup(ArchitectureRegistry.unregister_item, name) return params
def test_get_by_pxealias_returns_None_if_none_matching(self): arch1 = Architecture( name="arch1", description="arch1", pxealiases=["archibald", "reginald"]) arch2 = Architecture(name="arch2", description="arch2") ArchitectureRegistry.register_item("arch1", arch1) ArchitectureRegistry.register_item("arch2", arch2) self.assertEqual( None, ArchitectureRegistry.get_by_pxealias("stinkywinky"))
def test_get_by_pxealias_returns_valid_arch(self): arch1 = Architecture( name="arch1", description="arch1", pxealiases=["archibald", "reginald"]) arch2 = Architecture( name="arch2", description="arch2", pxealiases=["fake", "foo"]) ArchitectureRegistry.register_item("arch1", arch1) ArchitectureRegistry.register_item("arch2", arch2) self.assertEqual( arch1, ArchitectureRegistry.get_by_pxealias("archibald"))
def compose_arch_opts(params): """Return any architecture-specific options required""" arch_subarch = '%s/%s' % (params.arch, params.subarch) resource = ArchitectureRegistry.get_item(arch_subarch) if resource is not None and resource.kernel_options is not None: return resource.kernel_options else: return []
def handle_boot_method(self, file_name: TFTPPath, result): boot_method, params = result if boot_method is None: return super().get_reader(file_name) # Map pxe namespace architecture names to MAAS's. arch = params.get("arch") if arch is not None: maasarch = ArchitectureRegistry.get_by_pxealias(arch) if maasarch is not None: params["arch"] = maasarch.name.split("/")[0] # Send the local and remote endpoint addresses. local_host, local_port = tftp.get_local_address() params["local_ip"] = local_host remote_host, remote_port = tftp.get_remote_address() params["remote_ip"] = remote_host d = self.get_boot_method_reader(boot_method, params) return d
def test_architecture_registry(self): self.assertItemsEqual([], ArchitectureRegistry) ArchitectureRegistry.register_item("resource", sentinel.resource) self.assertIn(sentinel.resource, (item for name, item in ArchitectureRegistry))