def test_get_reader_install(self): # Given the right configuration options, the PXE configuration is # correctly rendered. method = PowerNVBootMethod() params = make_kernel_parameters(self, arch="ppc64el", 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 = PowerNVBootMethod() fake_mac = factory.make_mac_address("-") self.patch(powernv_module, "get_remote_mac").return_value = fake_mac config_path = b"ppc64el/pxelinux.cfg/default" params = method.match_path(None, config_path) expected = {"arch": "ppc64el", "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 = PowerNVBootMethod() options = { "backend": None, "kernel_params": make_kernel_parameters(purpose="local"), } output = method.get_reader(**options).read(10000).decode("utf-8") self.assertIn("", output)
def test_match_path_pxe_config_without_mac(self): method = PowerNVBootMethod() fake_mac = factory.make_mac_address("-") self.patch(powernv_module, 'get_remote_mac').return_value = fake_mac config_path = b'ppc64el/pxelinux.cfg/default' params = method.match_path(None, config_path) expected = { 'arch': 'ppc64el', 'mac': fake_mac, } self.assertEqual(expected, params)
def test_get_reader_appends_bootif(self): method = PowerNVBootMethod() fake_mac = factory.make_mac_address("-") params = make_kernel_parameters(self, purpose="install") output = method.get_reader(backend=None, kernel_params=params, arch="ppc64el", 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_prefix_request(self): method = PowerNVBootMethod() fake_mac = factory.make_mac_address("-") self.patch(powernv_module, "get_remote_mac").return_value = fake_mac file_path = b"ppc64el/file" params = method.match_path(None, file_path) expected = { "arch": "ppc64el", "mac": fake_mac, # The "ppc64el/" prefix has been removed from the path. "path": file_path.decode("utf-8")[8:], } self.assertEqual(expected, params)
def test_get_reader_with_extra_arguments_does_not_affect_output(self): # get_reader() allows any keyword arguments as a safety valve. method = PowerNVBootMethod() options = { "backend": None, "kernel_params": make_kernel_parameters(self, 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)
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 = PowerNVBootMethod() params = method.get_params(backend, b"ppc64el/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))
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 = PowerNVBootMethod() self.assertEqual("pxe", method.template_subdir)
def test_name(self): method = PowerNVBootMethod() self.assertEqual("powernv", method.name)
def test_bootloader_path_does_not_include_tftp_root(self): tftproot = self.make_tftp_root() method = PowerNVBootMethod() self.assertThat(method.bootloader_path, Not(StartsWith(tftproot.path)))
def test_bootloader_path(self): method = PowerNVBootMethod() self.assertEqual("pxelinux.0", method.bootloader_path)
def test_match_path_pxe_config_with_mac(self): method = PowerNVBootMethod() config_path, args = get_example_path_and_components() params = method.match_path(None, config_path) expected = {"arch": "ppc64el", "mac": args["mac"].decode("ascii")} self.assertEqual(expected, params)
def test_path_prefix(self): method = PowerNVBootMethod() self.assertEqual("ppc64el/", method.path_prefix)
def test_arch_octet(self): method = PowerNVBootMethod() self.assertEqual("00:0E", method.arch_octet)