def test_get_fails_for_unstored_item(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource.copy(), subarch) resource["content_id"] = factory.make_name("other") self.assertRaises(KeyError, product_dict.get, resource)
def test_get_ignores_extraneous_keys(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) resource["other_item"] = factory.make_name("other") self.assertEqual([subarch], product_dict.get(resource))
def test_only_creates_links_for_its_own_subarch(self): # Regression test for LP:1656425 product_name = factory.make_name("product_name") version_name = factory.make_name("version_name") product_mapping = ProductMapping() for subarch in [ "hwe-p", "hwe-q", "hwe-r", "hwe-s", "hwe-t", "hwe-u", "hwe-v", "hwe-w", "ga-16.04", ]: product = self.make_product( product_name=product_name, version_name=version_name, subarch=subarch, ) product_mapping.add(product, subarch) repo_writer = download_resources.RepoWriter(None, None, product_mapping) self.patch(download_resources, "products_exdata").return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, "insert_file") mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={"ga-16.04"}, bootloader_type=None, ), )
def test_calls_download_boot_resources(self): self.patch(download_resources, "datetime", MockDateTime) storage_path = self.make_dir() snapshot_path = download_resources.compose_snapshot_path(storage_path) cache_path = os.path.join(storage_path, "cache") file_store = FileStore(cache_path) source = { "url": "http://example.com", "keyring": self.make_file("keyring"), } product_mapping = ProductMapping() fake = self.patch(download_resources, "download_boot_resources") download_resources.download_all_boot_resources( sources=[source], storage_path=storage_path, product_mapping=product_mapping, store=file_store, ) self.assertThat( fake, MockCalledWith( source["url"], file_store, snapshot_path, product_mapping, keyring_file=source["keyring"], ), )
def test_make_key_extracts_identifying_items(self): resource = make_boot_resource() content_id = resource['content_id'] product_name = resource['product_name'] version_name = resource['version_name'] self.assertEqual( (content_id, product_name, version_name), ProductMapping.make_key(resource))
def test_inserts_generic_link_for_generic_kflavor_old_hwe_style_ga(self): # Regression test for LP:1768323 product_mapping = ProductMapping() product = self.make_product( subarch="hwe-p", kflavor="generic", release="precise" ) product_mapping.add(product, "hwe-p") repo_writer = download_resources.RepoWriter( None, None, product_mapping ) self.patch( download_resources, "products_exdata" ).return_value = product # Prevent MAAS from trying to actually write the file. mock_insert_file = self.patch(download_resources, "insert_file") mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_insert_file, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={"hwe-p", "generic"}, bootloader_type=None, ), )
def test_inserts_archive(self): product_mapping = ProductMapping() subarch = factory.make_name("subarch") product = self.make_product(ftype="archive.tar.xz", subarch=subarch) product_mapping.add(product, subarch) repo_writer = download_resources.RepoWriter( None, None, product_mapping ) self.patch( download_resources, "products_exdata" ).return_value = product # Prevent MAAS from trying to actually write the file. mock_extract_archive_tar = self.patch( download_resources, "extract_archive_tar" ) mock_link_resources = self.patch(download_resources, "link_resources") # We only need to provide the product as the other fields are only used # when writing the actual files to disk. repo_writer.insert_item(product, None, None, None, None) # None is used for the store and the content source as we're not # writing anything to disk. self.assertThat( mock_extract_archive_tar, MockCalledOnceWith( None, os.path.basename(product["path"]), product["sha256"], {"sha256": product["sha256"]}, product["size"], None, ), ) # links are mocked out by the mock_insert_file above. self.assertThat( mock_link_resources, MockCalledOnceWith( snapshot_path=None, links=mock.ANY, osystem=product["os"], arch=product["arch"], release=product["release"], label=product["label"], subarches={subarch}, bootloader_type=None, ), )
def test_make_key_ignores_other_items(self): resource = make_boot_resource() resource['other_item'] = factory.make_name('other') self.assertEqual( ( resource['content_id'], resource['product_name'], resource['version_name'], ), ProductMapping.make_key(resource))
def test_get_returns_stored_item(self): product_dict = ProductMapping() resource = make_boot_resource() subarch = factory.make_name("subarch") product_dict.add(resource, subarch) self.assertEqual([subarch], product_dict.get(resource))