Exemplo n.º 1
0
def versioned_mender_image(request, prepared_test_build, latest_mender_image,
                           bitbake_variables, bitbake_image):
    """Gets the correct version of the artifact, whether it's the one we
    build by default, or one we have to produce ourselves.
    Returns a tuple of version and built image."""

    global LAST_BUILD_VERSION

    version = request.param

    if version == 1:
        pytest.fail()

    if (version >= 2 and not version_is_minimum(
            bitbake_variables, "mender-artifact", "2.0.0")) or (
                version >= 3 and not version_is_minimum(
                    bitbake_variables, "mender-artifact", "3.0.0")):
        pytest.skip("Requires version %d of mender-artifact format." % version)

    if version_is_minimum(bitbake_variables, "mender-artifact", "3.0.0"):
        default_version = 3
    elif version_is_minimum(bitbake_variables, "mender-artifact", "2.0.0"):
        default_version = 2
    else:
        default_version = 2

    if LAST_BUILD_VERSION != version:
        # Run a separate build for this artifact. This doesn't conflict with the
        # above version because the non-default version ends up in a different
        # directory.
        if version != default_version:
            build_image(
                prepared_test_build["build_dir"],
                prepared_test_build["bitbake_corebase"],
                bitbake_image,
                ['MENDER_ARTIFACT_EXTRA_ARGS = "-v %d"' % version],
            )
        else:
            build_image(
                prepared_test_build["build_dir"],
                prepared_test_build["bitbake_corebase"],
                bitbake_image,
            )

        LAST_BUILD_VERSION = version
    return (
        version,
        latest_build_artifact(request, prepared_test_build["build_dir"],
                              "core-image*.mender"),
    )
Exemplo n.º 2
0
    def test_multiple_device_types_compatible(
        self,
        request,
        prepared_test_build,
        bitbake_path,
        bitbake_variables,
        bitbake_image,
    ):
        """Tests that we can include multiple device_types in the artifact."""

        build_image(
            prepared_test_build["build_dir"],
            prepared_test_build["bitbake_corebase"],
            bitbake_image,
            ['MENDER_DEVICE_TYPES_COMPATIBLE = "machine1 machine2"'],
        )

        image = latest_build_artifact(request,
                                      prepared_test_build["build_dir"],
                                      "core-image*.mender")

        output = run_verbose("mender-artifact read %s" % image, capture=True)
        assert b"Compatible devices: '[machine1 machine2]'" in output

        output = subprocess.check_output(
            "tar xOf %s header.tar.gz | tar xOz header-info" % image,
            shell=True).decode()
        data = json.loads(output)
        if version_is_minimum(bitbake_variables, "mender-artifact", "3.0.0"):
            assert data["artifact_depends"]["device_type"] == [
                "machine1", "machine2"
            ]
        else:
            assert data["device_types_compatible"] == ["machine1", "machine2"]
Exemplo n.º 3
0
    def test_dbus_get_jwt_token(self, bitbake_variables, connection, setup_mock_server):
        """Test the JWT token can be retrieved using D-Bus."""

        try:
            # bootstrap the client
            result = connection.run("mender bootstrap --forcebootstrap")
            assert result.exited == 0

            # start the mender-client service
            result = connection.run("systemctl start mender-client")
            assert result.exited == 0

            # get the JWT token via D-Bus
            output = ""
            for i in range(12):
                result = connection.run(
                    "dbus-send --system --dest=io.mender.AuthenticationManager --print-reply /io/mender/AuthenticationManager io.mender.Authentication1.GetJwtToken || true"
                )
                if self.JWT_TOKEN in result.stdout:
                    output = result.stdout
                    break
                time.sleep(5)

            assert f'string "{self.JWT_TOKEN}' in output
            if version_is_minimum(bitbake_variables, "mender-client", "3.2.0"):
                assert 'string "http://localhost:' in output
            else:
                assert 'string "https://docker.mender.io' in output

        finally:
            connection.run("systemctl stop mender-client")
            cleanup_mender_state(connection)
Exemplo n.º 4
0
    def test_expected_files_ext234(self, bitbake_path, bitbake_variables,
                                   latest_rootfs):
        """Test mender client expected files"""

        with make_tempdir() as tmpdir:
            subprocess.check_call(
                ["debugfs", "-R", "dump -p /etc/fstab fstab", latest_rootfs],
                cwd=tmpdir,
            )
            with open(os.path.join(tmpdir, "fstab")) as fd:
                data = fd.read()
            TestRootfs.verify_fstab(data)

            output = subprocess.check_output(
                ["debugfs", "-R", "ls -l -p /data", latest_rootfs],
                cwd=tmpdir).decode()
            for line in output.split("\n"):
                splitted = line.split("/")
                if len(splitted) <= 1:
                    continue
                # Should only contain "." and "..". In addition, debugfs
                # sometimes, but not always, returns a strange 0 entry, with
                # no name, but a "0" in the sixth column. It is not present
                # when mounting the filesystem.
                assert splitted[5] == "." or splitted[5] == ".." or splitted[
                    6] == "0"

            # Check whether mender exists in /usr/bin
            self.verify_file_exists(tmpdir, latest_rootfs, "/usr/bin",
                                    "mender", True)

            # Check whether mender exists in /var/lib
            self.verify_file_exists(
                tmpdir,
                latest_rootfs,
                "/var/lib",
                "mender",
                True,
            )

            # Check contents of /var/lib/mender
            output = subprocess.check_output(
                ["debugfs", "-R", "stat /var/lib/mender", latest_rootfs],
                cwd=tmpdir,
            ).decode()
            assert "Type: symlink" in output
            assert 'Fast link dest: "/data/mender"' in output

            # Check whether D-Bus policy files exist
            self.verify_file_exists(
                tmpdir,
                latest_rootfs,
                "/usr/share/dbus-1/system.d",
                "io.mender.AuthenticationManager.conf",
                True,
            )
            if version_is_minimum(bitbake_variables, "mender-client", "3.0.0"):
                self.verify_file_exists(
                    tmpdir,
                    latest_rootfs,
                    "/usr/share/dbus-1/system.d",
                    "io.mender.UpdateManager.conf",
                    True,
                )
Exemplo n.º 5
0
    def test_dbus_fetch_jwt_token(
        self, bitbake_variables, connection, second_connection, setup_mock_server
    ):
        """Test the JWT token can be fetched using D-Bus."""

        # bootstrap the client
        result = connection.run("mender bootstrap --forcebootstrap")
        assert result.exited == 0

        try:
            # start monitoring the D-Bus
            def dbus_monitor():
                second_connection.run(
                    "dbus-monitor --system \"type='signal',interface='io.mender.Authentication1'\" > /tmp/dbus-monitor.log"
                )

            p = Process(target=dbus_monitor, daemon=True)
            p.start()

            # get the JWT token via D-Bus
            try:
                # start the mender-client service
                result = connection.run("systemctl start mender-client")
                assert result.exited == 0

                # fetch the JWT token
                fetched = False
                for i in range(12):
                    result = connection.run(
                        "dbus-send --system --dest=io.mender.AuthenticationManager --print-reply /io/mender/AuthenticationManager io.mender.Authentication1.FetchJwtToken || true"
                    )
                    if "true" in result.stdout:
                        fetched = True
                        break
                    time.sleep(5)

                # fetch was successful
                assert fetched

                # verify we received the D-Bus signal JwtTokenStateChange and that it contains the JWT token
                found = False
                output = ""
                for i in range(12):
                    output = connection.run("cat /tmp/dbus-monitor.log").stdout.strip()
                    if (
                        "path=/io/mender/AuthenticationManager; interface=io.mender.Authentication1; member=JwtTokenStateChange"
                        in output
                    ):
                        found = True
                        break
                    time.sleep(5)
                assert found, output

                # token is now available
                result = connection.run(
                    "dbus-send --system --dest=io.mender.AuthenticationManager --print-reply /io/mender/AuthenticationManager io.mender.Authentication1.GetJwtToken"
                )
                assert result.exited == 0

                output = result.stdout.strip()
                assert f'string "{self.JWT_TOKEN}' in output
                if version_is_minimum(bitbake_variables, "mender-client", "3.2.0"):
                    assert 'string "http://localhost:' in output
                else:
                    assert 'string "https://docker.mender.io' in output

            finally:
                p.terminate()
                connection.run("systemctl stop mender-client")
                connection.run("rm -f /tmp/dbus-monitor.log")

        finally:
            cleanup_mender_state(connection)