def test_dump_json_combines_similar_entries(self): image = make_image_spec() other_release = factory.make_name("other-release") resource1 = factory.make_name("resource") resource2 = factory.make_name("other-resource") image_dict = BootImageMapping() set_resource(image_dict, image, resource1) set_resource( image_dict, image._replace(release=other_release), resource2 ) self.assertEqual( { image.os: { image.arch: { image.subarch: { image.kflavor: { image.release: {image.label: resource1}, other_release: {image.label: resource2}, } } } } }, json.loads(image_dict.dump_json()), )
def make_meta_file(self, image_params, image_resource, tftproot): image = ImageSpec(os=image_params["osystem"], arch=image_params["architecture"], subarch=image_params["subarchitecture"], kflavor="generic", release=image_params["release"], label=image_params["label"]) mapping = BootImageMapping() mapping.setdefault(image, image_resource) maas_meta = mapping.dump_json() filepath = os.path.join(tftproot, "maas.meta") with open(filepath, "w", encoding="utf-8") as f: f.write(maas_meta)
def test_extract_ephemeral_image_params_with_metadata(self): path, osystem, arch, subarch, release, label = self._make_path() # Patch OperatingSystemRegistry to return a fixed list of # values. purpose1 = factory.make_name("purpose") purpose2 = factory.make_name("purpose") xi_purpose = "ephemeral" xi_path = factory.make_name("xi_path") xi_type = factory.make_name("xi_type") purposes = [purpose1, purpose2, xi_purpose] self._patch_osystem_registry(purposes, xinstall_params=(xi_path, xi_type)) # Create some maas.meta content. image = ImageSpec(os=osystem, arch=arch, subarch=subarch, kflavor='generic', release=release, label=label) image_resource = dict(subarches=factory.make_name("subarches")) mapping = BootImageMapping() mapping.setdefault(image, image_resource) maas_meta = mapping.dump_json() params = extract_image_params(path, maas_meta) self.assertItemsEqual([ { "osystem": osystem, "architecture": arch, "subarchitecture": subarch, "release": release, "label": label, "purpose": purpose1, "xinstall_path": '', "xinstall_type": '', "supported_subarches": image_resource["subarches"], }, { "osystem": osystem, "architecture": arch, "subarchitecture": subarch, "release": release, "label": label, "purpose": purpose2, "xinstall_path": '', "xinstall_type": '', "supported_subarches": image_resource["subarches"], }, { "osystem": osystem, "architecture": arch, "subarchitecture": subarch, "release": release, "label": label, "purpose": xi_purpose, "xinstall_path": xi_path, "xinstall_type": xi_type, "supported_subarches": image_resource["subarches"], }, ], params)