Exemplo n.º 1
0
    def test_snapshot_using_mender_artifact(self, terminal, bitbake_path,
                                            bitbake_variables, connection):
        try:
            (active,
             _) = determine_active_passive_part(bitbake_variables, connection)

            common_args = get_ssh_common_args(connection)
            # mender-artifact prefixes each ssh argument with "-S"
            common_args = common_args.replace(" ", " -S ")

            try:
                subprocess.check_call(
                    "%s mender-artifact write rootfs-image -S %s -n test -t test -o test_snapshot_using_mender_artifact.mender -f ssh://%s@%s:%s"
                    % (
                        terminal,
                        common_args,
                        connection.user,
                        connection.host,
                        connection.port,
                    ),
                    shell=True,
                )
            finally:
                subprocess.call("cat screen.log.tmp ; rm -f screen.log.tmp",
                                shell=True)

            output = subprocess.check_output(
                "mender-artifact read test_snapshot_using_mender_artifact.mender",
                shell=True,
            ).decode()

            partsize = connection.run("blockdev --getsize64 %s" %
                                      active).stdout.strip()

            # Ensure that the payload size of the produced artifact matches the
            # partition.
            assert re.search("size: *%s" % partsize, output) is not None

        finally:
            try:
                os.remove("test_snapshot_using_mender_artifact.mender")
            except:
                pass
Exemplo n.º 2
0
    def test_basic_snapshot(self, compression, bitbake_variables, connection):
        try:
            (_,
             passive) = determine_active_passive_part(bitbake_variables,
                                                      connection)

            # Wipe the inactive partition first.
            connection.run("dd if=/dev/zero of=%s bs=1M count=100" % passive)

            # Dump what we currently have to the inactive partition.
            connection.run("mender snapshot dump %s %s %s" %
                           (compression[0], compression[1], passive))

            # Make sure this looks like a sane filesystem.
            connection.run("fsck.ext4 -p %s" % passive)

            # And that it can be mounted with actual content.
            connection.run("mount %s /mnt" % passive)
            connection.run("test -f /mnt/etc/passwd")

        finally:
            connection.run("umount /mnt || true")
Exemplo n.º 3
0
    def test_snapshot_inactive(self, bitbake_variables, connection):
        try:
            (_,
             passive) = determine_active_passive_part(bitbake_variables,
                                                      connection)

            test_str = "TeSt StrIng!#"

            # Seed the initial part of the inactive partition with a test string
            connection.run("echo '%s' | dd of=%s" % (test_str, passive))

            # Try to snapshot inactive partition, keeping the initial part, and
            # dumping the rest.
            connection.run(
                "mender snapshot dump --source %s | ( dd of=/data/snapshot-test bs=%d count=1; cat > /dev/null )"
                % (passive, len(test_str)))

            output = connection.run("cat /data/snapshot-test").stdout.strip()

            assert output == test_str

        finally:
            connection.run("rm -f /data/snapshot-test")
Exemplo n.º 4
0
    def test_snapshot_device_file(self, bitbake_variables, connection):
        try:
            (active,
             passive) = determine_active_passive_part(bitbake_variables,
                                                      connection)

            # Wipe the inactive partition first.
            connection.run("dd if=/dev/zero of=%s bs=1M count=100" % passive)

            # Dump what we currently have to the inactive partition, using
            # device file reference.
            connection.run("mender snapshot dump --source %s > %s" %
                           (active, passive))

            # Make sure this looks like a sane filesystem.
            connection.run("fsck.ext4 -p %s" % passive)

            # And that it can be mounted with actual content.
            connection.run("mount %s /mnt" % passive)
            connection.run("test -f /mnt/etc/passwd")

        finally:
            connection.run("umount /mnt || true")
Exemplo n.º 5
0
    def test_snapshot_using_mender_artifact_no_sudo(  # see MEN-3987
            self, terminal, bitbake_path, bitbake_variables, connection):
        try:
            (active,
             passive) = determine_active_passive_part(bitbake_variables,
                                                      connection)

            common_args = get_ssh_common_args(connection)
            # mender-artifact prefixes each ssh argument with "-S"
            common_args = common_args.replace(" ", " -S ")

            # /usr/bin/sudo is a link to /data/usr/bin/sudo see
            #  meta-mender-qemu/recipes-extended/sudo/sudo_%.bbappend
            sudo_path = "/data/usr/bin/sudo"
            # let's move the sudo away
            result = connection.run("mv %s %s-off" % (sudo_path, sudo_path),
                                    warn=True,
                                    echo=True)
            assert result.return_code == 0

            # lets be sure it does not work
            result = connection.run("sudo --help", echo=True, warn=True)
            assert result.return_code != 0

            try:
                # mender-artifact as of mender-artifact/pull/305 does not use sudo
                #  when user is root or when uid is 0
                subprocess.check_call(
                    "%s mender-artifact write rootfs-image -S %s -n test -t test -o test_snapshot_using_mender_artifact.mender -f ssh://%s@%s:%s"
                    % (
                        terminal,
                        common_args,
                        connection.user,
                        connection.host,
                        connection.port,
                    ),
                    shell=True,
                )
            finally:
                subprocess.call("cat screen.log.tmp ; rm -f screen.log.tmp",
                                shell=True)
                # let's put the sudo back in place and verify that it works
                result = connection.run("mv %s-off %s" %
                                        (sudo_path, sudo_path),
                                        warn=True,
                                        echo=True)
                result = connection.run("sudo --help", echo=True, warn=True)
                assert result.return_code == 0

            output = subprocess.check_output(
                "mender-artifact read test_snapshot_using_mender_artifact.mender",
                shell=True,
            ).decode()

            partsize = connection.run("blockdev --getsize64 %s" %
                                      active).stdout.strip()

            # Ensure that the payload size of the produced artifact matches the
            # partition.
            assert re.search("size: *%s" % partsize, output) is not None

        finally:
            try:
                os.remove("test_snapshot_using_mender_artifact.mender")
            except:
                pass