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") fs_host = "http://%s:5248/images" % (convert_host_to_uri_str( params.fs_host)) 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/%s$" % ( re.escape(fs_host), re.escape(image_dir), params.kernel, ), re.MULTILINE | re.DOTALL, ), MatchesRegex( r".*^\s+INITRD %s/%s/%s$" % ( re.escape(fs_host), re.escape(image_dir), params.initrd, ), re.MULTILINE | re.DOTALL, ), MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), ), )
def test_path_prefix_only_first_occurrence_removed(self): temp_dir = FilePath(self.make_dir()) backend = Mock(base=temp_dir) # A `TFTPBackend`. # Create a file nested within a "ppc64el" directory. data = factory.make_string().encode("ascii") temp_subdir = temp_dir.child("ppc64el") temp_subdir.createDirectory() temp_file = temp_subdir.child("example") temp_file.setContent(data) method = PowerNVBootMethod() params = method.get_params(backend, b"ppc64el/ppc64el/example") self.assertEqual({"path": "ppc64el/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))