def test_get_reader_install(self): # Given the right configuration options, the PXE configuration is # correctly rendered. method = S390XBootMethod() params = make_kernel_parameters( self, arch="s390x", purpose="xinstall") output = method.get_reader(backend=None, kernel_params=params) # The output is a BytesReader. self.assertThat(output, IsInstance(BytesReader)) output = output.read(10000).decode("utf-8") # The template has rendered without error. PXELINUX configurations # typically start with a DEFAULT line. self.assertThat(output, StartsWith("DEFAULT ")) # The PXE parameters are all set according to the options. image_dir = compose_image_path( osystem=params.osystem, arch=params.arch, subarch=params.subarch, release=params.release, label=params.label) self.assertThat( output, MatchesAll( MatchesRegex( r'.*^\s+KERNEL %s/%s$' % ( re.escape(image_dir), params.kernel), re.MULTILINE | re.DOTALL), MatchesRegex( r'.*^\s+INITRD %s/%s$' % ( re.escape(image_dir), params.initrd), re.MULTILINE | re.DOTALL), MatchesRegex( r'.*^\s+APPEND .+?$', re.MULTILINE | re.DOTALL)))
def test_match_path_pxe_config_without_mac(self): method = S390XBootMethod() fake_mac = factory.make_mac_address("-") self.patch(s390x_module, "get_remote_mac").return_value = fake_mac config_path = b"s390x/pxelinux.cfg/default" params = method.match_path(None, config_path) expected = {"arch": "s390x", "mac": fake_mac} self.assertEqual(expected, params)
def test_get_reader_with_local_purpose(self): # If purpose is "local", output should be empty string. method = S390XBootMethod() options = { "backend": None, "kernel_params": make_kernel_parameters(arch="amd64", purpose="local"), } output = method.get_reader(**options).read(10000).decode("utf-8") self.assertIn("", output)
def test_get_reader_appends_bootif(self): method = S390XBootMethod() fake_mac = factory.make_mac_address("-") params = make_kernel_parameters(self, arch="amd64", purpose="install") output = method.get_reader( backend=None, kernel_params=params, arch='s390x', mac=fake_mac) output = output.read(10000).decode("utf-8") config = parse_pxe_config(output) expected = 'BOOTIF=%s' % format_bootif(fake_mac) self.assertIn(expected, config['execute']['APPEND'])
def test_match_path_pxe_config_without_mac(self): method = S390XBootMethod() fake_mac = factory.make_mac_address("-") self.patch(s390x_module, 'get_remote_mac').return_value = fake_mac config_path = b's390x/pxelinux.cfg/default' params = method.match_path(None, config_path) expected = { 'arch': 's390x', 'mac': fake_mac, } self.assertEqual(expected, params)
def test_match_path_pxe_prefix_request(self): method = S390XBootMethod() fake_mac = factory.make_mac_address("-") self.patch(s390x_module, "get_remote_mac").return_value = fake_mac file_path = b"s390x/file" params = method.match_path(None, file_path) expected = { "arch": "s390x", "mac": fake_mac, # The "s390x/" prefix has been removed from the path. "path": file_path.decode("utf-8")[6:], } self.assertEqual(expected, params)
def test_path_prefix_removed(self): temp_dir = FilePath(self.make_dir()) backend = Mock(base=temp_dir) # A `TFTPBackend`. # Create a file in the backend's base directory. data = factory.make_string().encode("ascii") temp_file = temp_dir.child("example") temp_file.setContent(data) method = S390XBootMethod() params = method.get_params(backend, b"s390x/example") self.assertEqual({"path": "example"}, params) reader = method.get_reader(backend, make_kernel_parameters(), **params) self.addCleanup(reader.finish) self.assertEqual(len(data), reader.size) self.assertEqual(data, reader.read(len(data))) self.assertEqual(b"", reader.read(1))
def test_get_reader_with_extra_arguments_does_not_affect_output(self): # get_reader() allows any keyword arguments as a safety valve. method = S390XBootMethod() options = { "backend": None, "kernel_params": make_kernel_parameters(self, arch="s390x", purpose="install"), } # Capture the output before sprinking in some random options. output_before = method.get_reader(**options).read(10000) # Sprinkle some magic in. options.update((factory.make_name("name"), factory.make_name("value")) for _ in range(10)) # Capture the output after sprinking in some random options. output_after = method.get_reader(**options).read(10000) # The generated template is the same. self.assertEqual(output_before, output_after)
PowerNVBootMethod, ) from provisioningserver.boot.pxe import PXEBootMethod # noqa:E402 isort:skip from provisioningserver.boot.s390x import ( # noqa:E402 isort:skip S390XBootMethod, ) from provisioningserver.boot.uefi_amd64 import ( # noqa:E402 isort:skip UEFIAMD64BootMethod, UEFIAMD64HTTPBootMethod, ) from provisioningserver.boot.uefi_arm64 import ( # noqa:E402 isort:skip UEFIARM64BootMethod, ) from provisioningserver.boot.windows import ( # noqa:E402 isort:skip WindowsPXEBootMethod, ) builtin_boot_methods = [ IPXEBootMethod(), PXEBootMethod(), UEFIAMD64BootMethod(), UEFIAMD64HTTPBootMethod(), UEFIARM64BootMethod(), OpenFirmwarePPC64ELBootMethod(), PowerNVBootMethod(), WindowsPXEBootMethod(), S390XBootMethod(), ] for method in builtin_boot_methods: BootMethodRegistry.register_item(method.name, method)
def test_template_subdir(self): method = S390XBootMethod() self.assertEqual("pxe", method.template_subdir)
def test_name(self): method = S390XBootMethod() self.assertEqual("s390x", method.name)
def test_bootloader_path_does_not_include_tftp_root(self): tftproot = self.make_tftp_root() method = S390XBootMethod() self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path)))
def test_bootloader_path(self): method = S390XBootMethod() self.assertEqual("boots390x.bin", method.bootloader_path)
def test_match_path_pxe_config_with_mac(self): method = S390XBootMethod() config_path, args = get_example_path_and_components() params = method.match_path(None, config_path) expected = {"arch": "s390x", "mac": args["mac"].decode("ascii")} self.assertEqual(expected, params)
def test_path_prefix(self): method = S390XBootMethod() self.assertEqual("s390x/", method.path_prefix)
def test_arch_octet(self): method = S390XBootMethod() self.assertEqual("00:1F", method.arch_octet)