def test_get_reader_ephemeral_no_mac(self): s390x_partition = S390XPartitionBootMethod() params = make_kernel_parameters( self, arch="s390x", purpose=random.choice( ["commissioning", "enlist", "install", "xinstall"]), ) output = s390x_partition.get_reader(None, params) output = output.read(output.size).decode() 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_get_reader_install(self): # Given the right configuration options, the PXE configuration is # correctly rendered. method = PXEBootMethod() params = make_kernel_parameters(self, 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_compose_template_namespace(self): kernel_params = make_kernel_parameters() method = FakeBootMethod() image_dir = compose_image_path( kernel_params.osystem, kernel_params.arch, kernel_params.subarch, kernel_params.release, kernel_params.label, ) template_namespace = method.compose_template_namespace(kernel_params) self.assertEqual( "%s/%s" % (image_dir, kernel_params.initrd), template_namespace["initrd_path"](kernel_params), ) self.assertEqual( compose_kernel_command_line(kernel_params), template_namespace["kernel_command"](kernel_params), ) self.assertEqual(kernel_params, template_namespace["kernel_params"]) self.assertEqual( "%s/%s" % (image_dir, kernel_params.kernel), template_namespace["kernel_path"](kernel_params), ) self.assertIsNone(template_namespace["dtb_path"](kernel_params))
def test_compose_template_namespace_returns_filetype_when_missing(self): kernel_params = make_kernel_parameters( subarch="xgene-uboot-mustang", kernel=None, initrd=None, boot_dtb=None, ) method = FakeBootMethod() image_dir = compose_image_path( kernel_params.osystem, kernel_params.arch, kernel_params.subarch, kernel_params.release, kernel_params.label, ) template_namespace = method.compose_template_namespace(kernel_params) self.assertEqual( "%s/boot-initrd" % image_dir, template_namespace["initrd_path"](kernel_params), ) self.assertEqual( compose_kernel_command_line(kernel_params), template_namespace["kernel_command"](kernel_params), ) self.assertEqual(kernel_params, template_namespace["kernel_params"]) self.assertEqual( "%s/boot-kernel" % image_dir, template_namespace["kernel_path"](kernel_params), ) self.assertEqual( "%s/boot-dtb" % image_dir, template_namespace["dtb_path"](kernel_params), )
def test_get_reader(self): # Given the right configuration options, the UEFI configuration is # correctly rendered. method = UEFIAMD64BootMethod() params = make_kernel_parameters(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. UEFI configurations # typically start with a DEFAULT line. self.assertThat(output, StartsWith("set default=\"0\"")) # The UEFI 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+lin.*cc:\\{\'datasource_list\':" r" \[\'MAAS\'\]\\}end_cc.*", re.MULTILINE | re.DOTALL), MatchesRegex( r'.*^\s+linux %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)))
def test_compose_template_namespace_returns_dtb_file_when_arm(self): kernel_params = make_kernel_parameters(subarch="xgene-uboot-mustang") method = FakeBootMethod() image_dir = compose_image_path( kernel_params.osystem, kernel_params.arch, kernel_params.subarch, kernel_params.release, kernel_params.label, ) template_namespace = method.compose_template_namespace(kernel_params) self.assertEqual( "%s/%s" % (image_dir, kernel_params.initrd), template_namespace["initrd_path"](kernel_params), ) self.assertEqual( compose_kernel_command_line(kernel_params), template_namespace["kernel_command"](kernel_params), ) self.assertEqual(kernel_params, template_namespace["kernel_params"]) self.assertEqual( "%s/%s" % (image_dir, kernel_params.kernel), template_namespace["kernel_path"](kernel_params), ) self.assertEqual( "%s/%s" % (image_dir, kernel_params.boot_dtb), template_namespace["dtb_path"](kernel_params), )
def image_dir(params): return compose_image_path( params.osystem, params.arch, params.subarch, params.release, params.label, )
def test_compose_image_path_follows_storage_directory_layout(self): osystem = factory.make_name('osystem') arch = factory.make_name('arch') subarch = factory.make_name('subarch') release = factory.make_name('release') label = factory.make_name('label') self.assertEqual( '%s/%s/%s/%s/%s' % (osystem, arch, subarch, release, label), compose_image_path(osystem, arch, subarch, release, label))
def test_compose_image_path_does_not_include_tftp_root(self): osystem = factory.make_name('osystem') arch = factory.make_name('arch') subarch = factory.make_name('subarch') release = factory.make_name('release') label = factory.make_name('label') self.assertThat( compose_image_path(osystem, arch, subarch, release, label), Not(StartsWith(self.tftproot)))
def test_get_reader_ephemeral(self): # Given the right configuration options, the iPXE configuration is # correctly rendered. method = IPXEBootMethod() xtra = ("custom_xtra_cfg=http://{{ kernel_params.fs_host }}/" "my_extra_config?mac={{ kernel_params.mac }}") params = make_kernel_parameters( self, arch="amd64", subarch="generic", purpose="ephemeral", extra_opts=xtra, ) 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. iPXE configurations # start with #ipxe. self.assertThat(output, StartsWith("#!ipxe")) # The iPXE 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\s+" % ( re.escape(fs_host), re.escape(image_dir), params.initrd, ), re.MULTILINE | re.DOTALL, ), MatchesRegex( r".*\s+custom_xtra_cfg=http://%s/my_extra_config.*?\s+" % (params.fs_host), re.MULTILINE | re.DOTALL, ), MatchesRegex(r".*\s+maas_url=.+?$", re.MULTILINE | re.DOTALL), ), )
def test_compose_image_path_follows_storage_directory_layout(self): osystem = factory.make_name("osystem") arch = factory.make_name("arch") subarch = factory.make_name("subarch") release = factory.make_name("release") label = factory.make_name("label") self.assertEqual( "%s/%s/%s/%s/%s" % (osystem, arch, subarch, release, label), compose_image_path(osystem, arch, subarch, release, label), )
def test_compose_image_path_does_not_include_tftp_root(self): osystem = factory.make_name("osystem") arch = factory.make_name("arch") subarch = factory.make_name("subarch") release = factory.make_name("release") label = factory.make_name("label") self.assertThat( compose_image_path(osystem, arch, subarch, release, label), Not(StartsWith(self.tftproot)), )
def make_image_dir(self, image_params, tftproot): """Fake a boot image matching `image_params` under `tftproot`.""" image_dir = os.path.join( tftproot, compose_image_path(osystem=image_params['osystem'], arch=image_params['architecture'], subarch=image_params['subarchitecture'], release=image_params['release'], label=image_params['label'])) os.makedirs(image_dir) factory.make_file(image_dir, 'linux') factory.make_file(image_dir, 'initrd.gz')
def test_get_reader_tftp(self): # Given the right configuration options, the UEFI configuration is # correctly rendered. method = UEFIAMD64BootMethod() params = make_kernel_parameters(arch="amd64", 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, protocol="tftp") # The output is a BytesReader. self.assertThat(output, IsInstance(BytesReader)) output = output.read(10000).decode("utf-8") # The template has rendered without error. UEFI configurations # typically start with a DEFAULT line. self.assertThat(output, StartsWith('set default="0"')) # The UEFI 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+lin.*cc:\\{\'datasource_list\':" r" \[\'MAAS\'\]\\}end_cc.*", re.MULTILINE | re.DOTALL, ), MatchesRegex( r".*^\s+linux %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, ), ), )
def make_image_dir(image_params, tftp_root): """Fake a boot image matching `image_params` under `tftp_root`.""" image_dir = os.path.join( tftp_root, compose_image_path( osystem=image_params["osystem"], arch=image_params["architecture"], subarch=image_params["subarchitecture"], release=image_params["release"], label=image_params["label"], ), ) os.makedirs(image_dir) factory.make_file(image_dir, "linux") factory.make_file(image_dir, "initrd.gz")
def test_get_reader_xinstall_mustang_dtb(self): # Architecture specific test. # Given the right configuration options, the PXE configuration is # correctly rendered for Mustang. method = PXEBootMethod() params = make_kernel_parameters( testcase=self, osystem="ubuntu", arch="arm64", subarch="xgene-uboot-mustang", 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+FDT %s/%s$" % (re.escape(image_dir), params.boot_dtb), re.MULTILINE | re.DOTALL, ), MatchesRegex(r".*^\s+APPEND .+?$", re.MULTILINE | re.DOTALL), ), )
def test_get_reader_install(self): # Given the right configuration options, the PXE configuration is # correctly rendered. method = IPXEBootMethod() params = make_kernel_parameters(self, 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. iPXE configurations # start with #ipxe. self.assertThat(output, StartsWith("#!ipxe")) # The iPXE 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*imgargs .+?$", re.MULTILINE | re.DOTALL), ), )
def test_get_reader_ephemeral(self): # Given the right configuration options, the PXE configuration is # correctly rendered. method = PXEBootMethod() xtra = "custom_xtra_cfg=http://{{ kernel_params.fs_host }}/" \ "my_extra_config?mac={{ kernel_params.mac }}" params = make_kernel_parameters(self, arch="amd64", subarch="generic", purpose="ephemeral", extra_opts=xtra) 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) print(output) print(params.fs_host) self.assertThat( output, MatchesAll( MatchesRegex( r'.*^\s+KERNEL %s/%s$' % (re.escape(image_dir), params.kernel), re.MULTILINE | re.DOTALL), MatchesRegex( r'.*^\s+APPEND initrd=%s/%s\s+' % (re.escape(image_dir), params.initrd), re.MULTILINE | re.DOTALL), MatchesRegex( r'.*\s+custom_xtra_cfg=http://%s/my_extra_config.*?\s+' % (params.fs_host), re.MULTILINE | re.DOTALL), MatchesRegex(r'.*\s+maas_url=.+?$', re.MULTILINE | re.DOTALL)))