Example #1
0
def ubimg_without_uboot_env(request, latest_ubimg, prepared_test_build,
                            bitbake_image):
    """The ubireader_utils_info tool and friends don't support our UBI volumes
    that contain the U-Boot environment and hence not valid UBIFS structures.
    Therefore, make a new temporary image that doesn't contain U-Boot."""

    # The tests are marked with "only_with_image('ubimg')", but that is checked
    # using a function fixture, and this is a session fixture, which cannot
    # depend on that. So we need this check here to bail out if we don't find a
    # ubimg.
    if not latest_ubimg:
        pytest.skip("No ubimg found")

    reset_build_conf(prepared_test_build["build_dir"])
    build_image(
        prepared_test_build["build_dir"],
        prepared_test_build["bitbake_corebase"],
        bitbake_image,
        ['MENDER_FEATURES_DISABLE_append = " mender-uboot"'],
    )

    ubimg = latest_build_artifact(prepared_test_build["build_dir"],
                                  "core-image*.ubimg")
    imgdir = tempfile.mkdtemp()
    tmpimg = os.path.join(imgdir, os.path.basename(ubimg))
    shutil.copyfile(ubimg, tmpimg)

    def remove_ubimg():
        os.unlink(tmpimg)

    request.addfinalizer(remove_ubimg)

    return tmpimg
Example #2
0
    def test_dataimg_creation(self, bitbake_variables, prepared_test_build,
                              bitbake_image):
        """Test that we can build a dataimg successfully."""

        build_image(
            prepared_test_build["build_dir"],
            prepared_test_build["bitbake_corebase"],
            bitbake_image,
            ['IMAGE_FSTYPES = "dataimg"'],
        )

        built_img = latest_build_artifact(prepared_test_build["build_dir"],
                                          "core-image*.dataimg")

        # Check that it contains the device_type file, as we expect.
        with make_tempdir() as tmpdir:
            menderdir = os.path.join(tmpdir, "mender")
            if ("ARTIFACTIMG_FSTYPE" in bitbake_variables
                    and bitbake_variables["ARTIFACTIMG_FSTYPE"] == "ubifs"):
                subprocess.check_call(
                    ["ubireader_extract_files", "-o", tmpdir, built_img])
            else:
                os.mkdir(menderdir)
                subprocess.check_call([
                    "debugfs",
                    "-R",
                    "dump -p /mender/device_type %s" %
                    os.path.join(menderdir, "device_type"),
                    built_img,
                ])
            with open(os.path.join(menderdir, "device_type")) as fd:
                content = fd.read()
            assert (content == "device_type=%s\n" %
                    bitbake_variables["MENDER_DEVICE_TYPE"])
Example #3
0
    def test_mender_inventory_network_scripts(self, prepared_test_build, bitbake_image):
        """
        Test the 'inventory-network-scripts' build feature configuration through
        'PACKAGECONFIG' is working as expected.

        This verifies that the 'inventory-network-scripts' option is a part
        build, and also that the inventory scripts are not included when
        removed.


        The test only runs for sdimg, as the build image should not really matter here.
        """

        #
        # Feature enabled
        #
        reset_build_conf(prepared_test_build["build_dir"])
        build_image(
            prepared_test_build["build_dir"],
            prepared_test_build["bitbake_corebase"],
            bitbake_image,
            ['PACKAGECONFIG_append_pn-mender-client = " inventory-network-scripts"'],
        )
        rootfs = latest_build_artifact(
            prepared_test_build["build_dir"], "core-image*.ext4"
        )
        assert len(rootfs) > 0, "rootfs not generated"

        output = subprocess.check_output(
            ["debugfs", "-R", "ls /usr/share/mender/inventory", rootfs]
        )
        assert (
            b"mender-inventory-geo" in output,
        ), "mender-inventory-network-scripts seems not to be a part of the image, like they should"

        #
        # Feature disabled
        #
        reset_build_conf(prepared_test_build["build_dir"])
        build_image(
            prepared_test_build["build_dir"],
            prepared_test_build["bitbake_corebase"],
            bitbake_image,
            ['PACKAGECONFIG_remove_pn-mender-client = " inventory-network-scripts"'],
        )
        rootfs = latest_build_artifact(
            prepared_test_build["build_dir"], "core-image*.ext4"
        )
        assert len(rootfs) > 0, "ext4 not generated"
        output = subprocess.check_output(
            ["debugfs", "-R", "ls /usr/share/mender/inventory", rootfs]
        )
        assert (
            b"mender-inventory-geo" not in output,
        ), "mender-inventory-network-scripts unexpectedly a part of the image"
Example #4
0
    def test_equal_checksum_ubimg_and_artifact(self, prepared_test_build,
                                               bitbake_image):

        # See ubimg_without_uboot_env() for why this is needed. We need to do it
        # explicitly here because we need both the artifact and the ubimg.

        build_image(
            prepared_test_build["build_dir"],
            prepared_test_build["bitbake_corebase"],
            bitbake_image,
            ['MENDER_FEATURES_DISABLE_append = " mender-uboot"'],
        )

        bufsize = 1048576  # 1MiB
        with tempfile.NamedTemporaryFile() as tmp_artifact:
            latest_mender_image = latest_build_artifact(
                prepared_test_build["build_dir"], "*.mender")
            subprocess.check_call(
                "tar xOf %s data/0000.tar.gz | tar xzO > %s" %
                (latest_mender_image, tmp_artifact.name),
                shell=True,
            )
            size = os.stat(tmp_artifact.name).st_size
            hash = hashlib.md5()
            while True:
                buf = tmp_artifact.read(bufsize)
                if len(buf) == 0:
                    break
                hash.update(buf)
            artifact_hash = hash.hexdigest()
            artifact_info = subprocess.check_output(
                ["ubireader_display_info", tmp_artifact.name])
            artifact_ls = subprocess.check_output(
                ["ls", "-l", tmp_artifact.name])

        tmpdir = tempfile.mkdtemp()
        try:
            ubifsdir = extract_ubimg_images(
                latest_build_artifact(prepared_test_build["build_dir"],
                                      "*.ubimg"),
                tmpdir,
            )
            rootfsa = os.path.join(ubifsdir, [
                img for img in os.listdir(ubifsdir) if "rootfsa" in img
            ][0])
            bytes_read = 0
            hash = hashlib.md5()
            with open(rootfsa, "rb") as fd:
                while bytes_read < size:
                    buf = fd.read(min(size - bytes_read, bufsize))
                    if len(buf) == 0:
                        break
                    bytes_read += len(buf)
                    hash.update(buf)
                image_hash = hash.hexdigest()
            image_info = subprocess.check_output(
                ["ubireader_display_info", rootfsa])
            image_ls = subprocess.check_output(["ls", "-l", rootfsa])
        finally:
            shutil.rmtree(tmpdir)

        assert artifact_info == image_info
        assert artifact_hash == image_hash, "Artifact:\n%s\nImage:\n%s" % (
            artifact_ls,
            image_ls,
        )