Пример #1
0
    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"))
Пример #2
0
    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"))
Пример #3
0
 def test_includes_local_debs(self):
     package_name = "foo"
     maker = PackageMaker()
     self.useFixture(ContextManagerFixture(maker))
     local_path = maker.make_package(package_name, "1.2", {})
     available_package = FetchedPackage.from_deb(local_path)
     sources_dict = self.sourcesDictForPackages([])
     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, [available_package],
                        sources_dict,
                        package_spec=package_name))
Пример #4
0
 def test_includes_local_debs(self):
     package_name = "foo"
     maker = PackageMaker()
     self.useFixture(ContextManagerFixture(maker))
     local_path = maker.make_package(package_name, "1.2", {})
     available_package = FetchedPackage.from_deb(local_path)
     sources_dict = self.sourcesDictForPackages([])
     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, [available_package],
             sources_dict,
             package_spec=package_name))
Пример #5
0
 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))
Пример #6
0
 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))
Пример #7
0
    def add_dependency_package(self, packages_spec):
        """Add a packge that depends on packages_spec to the hardware pack.

        :param packages_spec: A list of apt package specifications,
            e.g. ``['foo', 'bar (>= 1.2)']``.
        """
        with PackageMaker() as maker:
            dep_package_name = 'hwpack-' + self.metadata.name
            relationships = {}
            if packages_spec:
                relationships = {'Depends': ', '.join(packages_spec)}
            deb_file_path = maker.make_package(
                dep_package_name, self.metadata.version,
                relationships, self.metadata.architecture)
            self.packages.append(FetchedPackage.from_deb(deb_file_path))
Пример #8
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))
Пример #9
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))