コード例 #1
0
ファイル: test_merge_rd.py プロジェクト: vzhestkov/uyuni
    def test_should_create_a_new_initrd_starting_from_a_xz_compressed_one(
            self):
        self.ensure_package_is_installed("tar", "xz")
        self.ensure_package_is_installed("xz")

        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, self.initrd_xz, self.final_initrd,
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        # ensure the new initrd has been created
        errors = b"".join(stderr.readlines()).decode()
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))
        self.assertTrue(os.path.exists(self.final_initrd))

        # ensure the new initrd is compressed using gzip
        (status, stdout, stderr) = my_popen([
            "file",
            self.final_initrd,
        ])
        errors = b"".join(stderr.readlines()).decode()
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))
        self.assertTrue(
            "gzip compressed data" in b"".join(stdout.readlines()).decode())

        # uncompress the initrd
        (status, stdout, stderr) = my_popen(["gzip", "-d", self.final_initrd])
        errors = b"".join(stderr.readlines()).decode()
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))

        # extract the contents of the initrd
        uncomp_dir = os.path.join(self.data_dir, "uncompressed")
        os.mkdir(uncomp_dir)

        os.chdir(uncomp_dir)
        (status, stdout, stderr) = my_popen(
            ["cpio", "-idF",
             self.final_initrd.replace(".gz", "")])
        errors = b"".join(stderr.readlines()).decode()
        self.assertEqual(0, status,
                         "Something wrong happened: {0}".format(errors))

        test_file = os.path.join(uncomp_dir, "susemanager", "test_file")
        self.assertTrue(os.path.exists(test_file))

        expected_data = helper.read_data_from_fixture(
            "ks-tree-shadow/susemanager/test_file")
        with open(test_file) as file:
            self.assertEqual(file.read(), expected_data)

        # the "uncomp_dir" is going to be removed at the end of the tests
        os.chdir("/")
コード例 #2
0
ファイル: test_merge_rd.py プロジェクト: vzhestkov/uyuni
    def test_should_fail_when_the_initrd_is_not_a_valid_file(self):
        (status, stdout, stderr) = my_popen(["touch", "/etc/fstab"])
        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, "/etc/fstab", self.final_initrd,
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        errors = b"".join(stderr.readlines()).decode()

        self.assertNotEqual(0, status)
        if not "Error uncompressing" in errors:
            self.fail(
                "Command failed for a different reason: {0}".format(errors))
コード例 #3
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def ensure_package_is_not_installed(self, *pkgs):
        cmd = ["zypper", "rm", "-y"]
        for pkg in pkgs:
            cmd.append(pkg)

        (status, stdout, stderr) = my_popen(cmd)

        if status != 0:
            self.fail("Something went wrong while ensuring {0} was not "
                      "installed: {1}".format(pkg,
                                              "".join(stderr.readlines())))
コード例 #4
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def test_should_fail_when_the_initrd_is_not_found(self):
        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, "/fake_initrd", self.final_initrd,
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        errors = "".join(stderr.readlines())

        self.assertNotEqual(0, status)
        if not "Cannot find initrd" in errors:
            self.fail(
                "Command failed for a different reason: {0}".format(errors))
コード例 #5
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def test_should_fail_when_xz_is_not_installed(self):
        self.ensure_package_is_not_installed("xz")
        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, self.initrd_xz, self.final_initrd,
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        errors = "".join(stderr.readlines())

        self.assertNotEqual(0, status)
        if not "Error uncompressing" in errors:
            self.fail(
                "Command failed for a different reason: {0}".format(errors))
コード例 #6
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def test_should_fail_when_the_user_tree_directory_is_missing(self):
        self.ensure_package_is_installed("tar", "xz")
        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, self.initrd_xz, self.final_initrd,
            "/does/not/exist/ks-tree-shadow/"
        ])

        errors = "".join(stderr.readlines())

        self.assertNotEqual(0, status)
        if not "Cannot find user tree" in errors:
            self.fail(
                "Command failed for a different reason: {0}".format(errors))
コード例 #7
0
ファイル: test_merge_rd.py プロジェクト: renner/uyuni
    def test_should_fail_when_directory_containing_final_initrd_does_not_exist(
            self):
        self.ensure_package_is_installed("tar", "xz")
        (status, stdout, stderr) = my_popen([
            "/bin/sh", MERGE_RD_CMD, self.initrd_xz, "/new_dir/initrd.out",
            helper.path_to_fixture("ks-tree-shadow/")
        ])

        errors = "".join(stderr.readlines())

        self.assertNotEqual(0, status)
        if not "Cannot find final destination dir" in errors:
            self.fail(
                "Command failed for a different reason: {0}".format(errors))