def test_builds_correct_contents_multiple_packages(self): package_name1 = "foo" package_name2 = "goo" available_package1 = DummyFetchedPackage(package_name1, "1.1") available_package2 = DummyFetchedPackage(package_name2, "1.2") sources_dict = self.sourcesDictForPackages( [available_package1, available_package2]) metadata, config = self.makeMetaDataAndConfigFixture( [package_name1, package_name2], sources_dict) builder = HardwarePackBuilder(config.filename, metadata.version, []) builder.build() hwpack_filename = "hwpack_%s_%s_%s.tar.gz" % ( metadata.name, metadata.version, metadata.architecture) self.assertThat( hwpack_filename, IsHardwarePack(metadata, [available_package1, available_package2], sources_dict, package_spec='%s, %s' % (package_name1, package_name2))) self.assertThat( hwpack_filename, IsHardwarePack(metadata, [available_package2, available_package1], sources_dict, package_spec='%s, %s' % (package_name1, package_name2)))
def test_Packages_file_empty_with_no_deb_content(self): package1 = DummyFetchedPackage("foo", "1.1", no_content=True) package2 = DummyFetchedPackage("bar", "1.1", no_content=True) hwpack = HardwarePack(self.metadata) hwpack.add_packages([package1, package2]) tf = self.get_tarfile(hwpack) self.assertThat(tf, HardwarePackHasFile("pkgs/Packages", content=""))
def test_obeys_assume_installed(self): package_name = "foo" assume_installed = "bar" available_package = DummyFetchedPackage(package_name, "1.1", depends=assume_installed) dependency_package = DummyFetchedPackage(assume_installed, "1.1") sources_dict = self.sourcesDictForPackages( [available_package, dependency_package]) metadata, config = self.makeMetaDataAndConfigFixture( [package_name], sources_dict, extra_config={'assume-installed': assume_installed}) builder = HardwarePackBuilder(config.filename, metadata.version, []) builder.build() filename = "hwpack_%s_%s_%s.tar.gz" % (metadata.name, metadata.version, metadata.architecture) self.assertThat( filename, IsHardwarePack(metadata, [available_package], sources_dict, package_spec=package_name)) tf = tarfile.open(filename, mode="r:gz") try: self.assertThat( tf, Not(TarfileHasFile("pkgs/%s" % dependency_package.filename))) finally: tf.close()
def test_manifest_contains_package_info(self): package1 = DummyFetchedPackage("foo", "1.1") package2 = DummyFetchedPackage("bar", "1.2") hwpack = HardwarePack(self.metadata) hwpack.add_packages([package1, package2]) tf = self.get_tarfile(hwpack) self.assertThat( tf, HardwarePackHasFile("manifest", content="foo=1.1\nbar=1.2\n"))
def test_Packages_file_correct_contents_with_packages(self): package1 = DummyFetchedPackage("foo", "1.1") package2 = DummyFetchedPackage("bar", "1.1") hwpack = HardwarePack(self.metadata) hwpack.add_packages([package1, package2]) tf = self.get_tarfile(hwpack) self.assertThat( tf, HardwarePackHasFile("pkgs/Packages", content=get_packages_file([package1, package2])))
def test_several(self): observed1 = DummyFetchedPackage("foo", "1.1") observed2 = DummyFetchedPackage("bar", "1.2") observed3 = DummyFetchedPackage("baz", "1.5") packages_content = get_packages_file([observed1, observed2, observed3]) parsed = parse_packages_file_content(packages_content) self.assertThat( parsed, MatchesSetwise(MatchesPackage(observed3), MatchesPackage(observed2), MatchesPackage(observed1)))
def test_adds_multiple_packages_at_once(self): package1 = DummyFetchedPackage("foo", "1.1") package2 = DummyFetchedPackage("bar", "1.1") hwpack = HardwarePack(self.metadata) hwpack.add_packages([package1, package2]) tf = self.get_tarfile(hwpack) self.assertThat( tf, HardwarePackHasFile("pkgs/%s" % package1.filename, content=package1.content.read())) self.assertThat( tf, HardwarePackHasFile("pkgs/%s" % package2.filename, content=package2.content.read()))
def test_ignore_one_md5(self): # This is what I actually care about: being able to specify that a # packages file matches a set of packages, ignoring just a few # details on just one package. observed1 = DummyFetchedPackage("foo", "1.1") observed2 = DummyFetchedPackage("bar", "1.2") observed3 = DummyFetchedPackage("baz", "1.5") packages_content = get_packages_file([observed1, observed2, observed3]) oldmd5 = observed3.md5 observed3._content = ''.join(reversed(observed3._content_str())) self.assertNotEqual(oldmd5, observed3.md5) self.assertThat( packages_content, MatchesAsPackagesFile(MatchesPackage(observed1), MatchesPackage(observed2), MatchesPackage(observed3).update(md5=None)))
def test_add_packages_without_content_leaves_out_debs(self): package1 = DummyFetchedPackage("foo", "1.1", no_content=True) hwpack = HardwarePack(self.metadata) hwpack.add_packages([package1]) tf = self.get_tarfile(hwpack) self.assertThat( tf, Not(HardwarePackHasFile("pkgs/%s" % package1.filename)))
def test_log_output(self): package_name = 'foo' architecture = 'armel' available_package = DummyFetchedPackage(package_name, "1.1", architecture=architecture) source = self.useFixture(AptSourceFixture([available_package])) config = self.useFixture( ConfigFileFixture( '[hwpack]\nname=ahwpack\npackages=%s\narchitectures=armel\n' '\n[ubuntu]\nsources-entry=%s\n' % (package_name, source.sources_entry))) stdout, stderr = self.run_script([config.filename, "1.0"]) # XXX Adding in the format deprecation message below is just a hack # until the test can be fixed up to test a new format hwpack. self.assertThat( stderr, DocTestMatches( "Building for %(arch)s\nFetching packages\n" "The format '1.0' is deprecated, please update your hardware " "pack configuration.\n" "Wrote hwpack_ahwpack_1.0_%(arch)s.tar.gz" "\n" % dict(arch=architecture)))
def test_find_fetched_package_finds(self): package_name = "dummy-package" wanted_package_name = "wanted-package" available_package = DummyFetchedPackage(package_name, "1.1") wanted_package = DummyFetchedPackage(wanted_package_name, "1.1") sources_dict = self.sourcesDictForPackages( [available_package, wanted_package]) _, config = self.makeMetaDataAndConfigFixture( [package_name, wanted_package_name], sources_dict, extra_config=self.extra_config) builder = HardwarePackBuilder(config.filename, "1.0", []) found_package = builder.find_fetched_package( [available_package, wanted_package], wanted_package_name) self.assertEquals(wanted_package, found_package)
def test_warn_if_not_including_local_deb(self): package_name = "foo" local_name = "bar" maker = PackageMaker() self.useFixture(ContextManagerFixture(maker)) remote_package = DummyFetchedPackage(package_name, "1.1") local_path = maker.make_package(local_name, "1.0", {}) sources_dict = self.sourcesDictForPackages([remote_package]) metadata, config = self.makeMetaDataAndConfigFixture( [package_name], sources_dict, extra_config={'assume-installed': local_name}) builder = HardwarePackBuilder(config.filename, metadata.version, [local_path]) handler = AppendingHandler() builder_logger.addHandler(handler) self.addCleanup(builder_logger.removeHandler, handler) builder.build() self.assertThat( "hwpack_%s_%s_%s.tar.gz" % (metadata.name, metadata.version, metadata.architecture), IsHardwarePack(metadata, [remote_package], sources_dict, package_spec=package_name)) self.assertThat( handler.messages, EachOf([MatchesStructure(levelname=Equals('WARNING'))])) self.assertThat(handler.messages[0].getMessage(), Equals("Local package 'bar' not included"))
def test_builds_one_pack_per_arch(self): available_package = DummyFetchedPackage("foo", "1.1") sources_dict = self.sourcesDictForPackages([available_package]) metadata, config = self.makeMetaDataAndConfigFixture( ["foo"], sources_dict, architecture="i386 armel") builder = HardwarePackBuilder(config.filename, "1.0", []) builder.build() self.assertTrue(os.path.isfile("hwpack_ahwpack_1.0_i386.tar.gz")) self.assertTrue(os.path.isfile("hwpack_ahwpack_1.0_armel.tar.gz"))
def test_creates_external_manifest(self): available_package = DummyFetchedPackage("foo", "1.1") sources_dict = self.sourcesDictForPackages([available_package]) metadata, config = self.makeMetaDataAndConfigFixture(["foo"], sources_dict) builder = HardwarePackBuilder(config.filename, "1.0", []) builder.build() self.assertTrue( os.path.isfile("hwpack_ahwpack_1.0_armel.manifest.txt"))
def test_adds_packages(self): package = DummyFetchedPackage("foo", "1.1") hwpack = HardwarePack(self.metadata) hwpack.add_packages([package]) tf = self.get_tarfile(hwpack) self.assertThat( tf, HardwarePackHasFile("pkgs/%s" % package.filename, content=package.content.read()))
def test_find_fetched_package_raises(self): package_name = "dummy-package" wanted_package_name = "wanted-package" available_package = DummyFetchedPackage(package_name, "1.1") sources_dict = self.sourcesDictForPackages([available_package]) _, config = self.makeMetaDataAndConfigFixture( [package_name], sources_dict, extra_config=self.extra_config) builder = HardwarePackBuilder(config.filename, "1.0", []) packages = [available_package] self.assertRaises(AssertionError, builder.find_fetched_package, packages, wanted_package_name)
def test_builds_correct_contents(self): package_name = "foo" available_package = DummyFetchedPackage(package_name, "1.1") sources_dict = self.sourcesDictForPackages([available_package]) metadata, config = self.makeMetaDataAndConfigFixture([package_name], sources_dict) builder = HardwarePackBuilder(config.filename, metadata.version, []) builder.build() self.assertThat( "hwpack_%s_%s_%s.tar.gz" % (metadata.name, metadata.version, metadata.architecture), IsHardwarePack(metadata, [available_package], sources_dict, package_spec=package_name))
def test_builds_a_hwpack(self): package_name = 'foo' available_package = DummyFetchedPackage(package_name, "1.1", architecture="armel") source = self.useFixture(AptSourceFixture([available_package])) config = self.useFixture( ConfigFileFixture( '[hwpack]\nname=ahwpack\npackages=%s\narchitectures=armel\n' '\n[ubuntu]\nsources-entry=%s\n' % (package_name, source.sources_entry))) stdout, stderr = self.run_script([config.filename, "1.0"]) metadata = Metadata("ahwpack", "1.0", "armel") self.assertThat( "hwpack_ahwpack_1.0_armel.tar.gz", IsHardwarePack(metadata, [available_package], {"ubuntu": source.sources_entry}, package_spec=package_name))
def test_includes_local_debs_even_if_not_in_config(self): package_name = "foo" local_name = "bar" maker = PackageMaker() self.useFixture(ContextManagerFixture(maker)) remote_package = DummyFetchedPackage(package_name, "1.1") local_path = maker.make_package(local_name, "1.0", {}) local_package = FetchedPackage.from_deb(local_path) sources_dict = self.sourcesDictForPackages([remote_package]) metadata, config = self.makeMetaDataAndConfigFixture([package_name], sources_dict) builder = HardwarePackBuilder(config.filename, metadata.version, [local_path]) builder.build() self.assertThat( "hwpack_%s_%s_%s.tar.gz" % (metadata.name, metadata.version, metadata.architecture), IsHardwarePack(metadata, [remote_package, local_package], sources_dict, package_spec=package_name))
def test_prefers_local_debs(self): package_name = "foo" maker = PackageMaker() self.useFixture(ContextManagerFixture(maker)) # The point here is that remote_package has a later version than # local_package, but local_package is still preferred. remote_package = DummyFetchedPackage(package_name, "1.1") local_path = maker.make_package(package_name, "1.0", {}) local_package = FetchedPackage.from_deb(local_path) sources_dict = self.sourcesDictForPackages([remote_package]) metadata, config = self.makeMetaDataAndConfigFixture([package_name], sources_dict) builder = HardwarePackBuilder(config.filename, metadata.version, [local_path]) builder.build() self.assertThat( "hwpack_%s_%s_%s.tar.gz" % (metadata.name, metadata.version, metadata.architecture), IsHardwarePack(metadata, [local_package], sources_dict, package_spec=package_name))
def test_one(self): observed = DummyFetchedPackage("foo", "1.1") packages_content = get_packages_file([observed]) parsed = parse_packages_file_content(packages_content) self.assertThat(len(parsed), Equals(1)) self.assertThat(parsed[0], MatchesPackage(observed))
def test_skip_one_attribute(self): observed = DummyFetchedPackage("foo", "1.1", depends="bar") expected = DummyFetchedPackage("foo", "1.1", depends="baz") self.assertThat(observed, MatchesPackage(expected).update(depends=None))
def test_mismatch(self): observed = DummyFetchedPackage("foo", "1.1", depends="bar") expected = DummyFetchedPackage("foo", "1.1", depends="baz") self.assertRaises(AssertionError, self.assertThat, observed, MatchesPackage(expected))
def test_simple(self): observed = DummyFetchedPackage("foo", "1.1", architecture="armel") expected = DummyFetchedPackage("foo", "1.1", architecture="armel") self.assertThat(observed, MatchesPackage(expected))
def test_builds_a_v3_hwpack_from_config_with_2_bootloaders(self): config_v3 = ("format: 3.0\n" "name: ahwpack\n" "architectures: armel\n" "serial_tty: ttySAC1\n" "partition_layout:\n" " - bootfs_rootfs\n" "boot_script: boot.scr\n" "extra_serial_options:\n" " - console=tty0\n" " - console=ttyO2,115200n8\n" "mmc_id: 0:1\n" "kernel_file: boot/vmlinuz-*-linaro-omap\n" "initrd_file: boot/initrd.img-*-linaro-omap\n" "dtb_file: boot/dt-*-linaro-omap/omap4-panda.dtb\n" "packages:\n" " - %s\n" " - %s\n") bootloader_config = (" package: %s\n" " in_boot_part: %s\n" " extra_boot_options:\n" " - earlyprintk\n" " - fixrtc\n" " - nocompcache\n" " - vram=48M\n" " - omapfb.vram=0:24M\n" " - mem=456M@0x80000000\n" " - mem=512M@0xA0000000\n") config_v3 += ("bootloaders:\n" " u_boot:\n" + bootloader_config + " u_boot_2:\n" + bootloader_config) config_v3 += ("sources:\n" " ubuntu: %s\n") package_names = ['foo', 'bar'] available_packages = [] for package_name in package_names: available_packages.append( DummyFetchedPackage(package_name, "1.1", architecture="armel")) source = self.useFixture(AptSourceFixture(available_packages)) config_v3 = config_v3 % (package_names[0], package_names[1], package_names[0], "True", package_names[1], "False", source.sources_entry) config_file_fixture = self.useFixture(ConfigFileFixture(config_v3)) self.run_script([config_file_fixture.filename, "1.0"]) # We now need a real config object to test against the configuration # in the hardware pack we have created. config = Config(StringIO(config_v3)) config.bootloader = "u_boot" metadata = Metadata.from_config(config, "1.0", "armel") self.assertThat( "hwpack_ahwpack_1.0_armel.tar.gz", IsHardwarePack(metadata, available_packages, {"ubuntu": source.sources_entry}, package_spec=",".join(package_names), format="3.0"))
def test_global_and_board_bootloader(self): package_names = ['package0', 'package1', 'package2', 'package3'] files = { package_names[0]: [ "usr/lib/u-boot/omap4_panda/u-boot.img", "usr/share/doc/u-boot-linaro-omap4-panda/copyright" ], package_names[1]: ["usr/lib/u-boot/omap4_panda/u-boot.img", "some/path/file"], package_names[2]: [], package_names[3]: [], } config_v3 = self.config_v3 + "\n".join([ "bootloaders:", " u_boot:", self.bootloader_config, " file: " + files[package_names[0]][0], " copy_files:", " " + package_names[2] + ":", " - some_file", "boards:", " board1:", " bootloaders:", " u_boot:", " package: %s", " file: " + files[package_names[1]][0], " copy_files:", " " + package_names[3] + ":", " - some_file", " in_boot_part: true", "sources:", " ubuntu: %s" ]) # Generate some test packages available_packages = [] maker = PackageMaker() self.useFixture(ContextManagerFixture(maker)) for package_name in package_names: # The files parameter to make_package is a list of files to create. # These files are text files containing package_name and their # path. Since package_name is different for each package, this # gives each file a unique content. deb_file_path = maker.make_package(package_name, '1.0', {}, files=files[package_name]) dummy_package = DummyFetchedPackage( package_name, "1.0", content=open(deb_file_path).read()) available_packages.append(dummy_package) source = self.useFixture(AptSourceFixture(available_packages)) # Generate a V3 config config_v3 = config_v3 % (package_names[0], package_names[1], package_names[0], "True", package_names[1], source.sources_entry) config_file_fixture = self.useFixture(ConfigFileFixture(config_v3)) # Build a hardware pack builder = HardwarePackBuilder(config_file_fixture.filename, "1.0", [ os.path.join(source.rootdir, package.filepath) for package in available_packages ]) builder.build() stored_package_names = [p.name for p in builder.packages] for package_name in package_names: self.assertIn(package_name, stored_package_names) # Read the contents of the hardware pack, making sure it is as expected tf = tarfile.open("hwpack_ahwpack_1.0_armel.tar.gz", mode="r:gz") # We check the content of each file when content != None. For our test # files this is "<package_name> <originating path>" so they can be # uniquely identified. expected_files = [ ("u_boot/" + files[package_names[0]][0], package_names[0] + " " + files[package_names[0]][0]), ("board1/u_boot/" + files[package_names[1]][0], package_names[1] + " " + files[package_names[1]][0]) ] for expected_file, contents in expected_files: self.assertThat(tf, TarfileHasFile(expected_file, content=contents))
def test_one(self): observed = DummyFetchedPackage("foo", "1.1") packages_content = get_packages_file([observed]) self.assertThat(packages_content, MatchesAsPackagesFile(MatchesPackage(observed)))