def test_parse_channels(self): with open(path_to_fixture("expected_channels.json"), "r") as file: expected_channels = json.load(file) with open(path_to_fixture("expected_hierarchy.json"), "r") as file: expected_hierarchy = json.load(file) channels = parse_channels( read_data_from_fixture("list_channels.data"), self.mgr_sync.log) self.assertEqual(sorted(channels.keys()), sorted(expected_hierarchy.keys())) for label, bc in channels.items(): self.assertEqual(label, bc.label) self.assertEqual( bc.status, expected_channels[bc.label]) if bc.children and bc.status == Channel.Status.INSTALLED: children = sorted([c.label for c in bc.children]) self.assertEqual(children, sorted(expected_hierarchy[bc.label])) else: self.assertEqual(0, len(expected_hierarchy[bc.label]))
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 = "".join(stderr.readlines()) 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 = "".join(stderr.readlines()) self.assertEqual(0, status, "Something wrong happened: {0}".format(errors)) self.assertTrue("gzip compressed data" in "".join(stdout.readlines())) # uncompress the initrd (status, stdout, stderr) = my_popen(["gzip", "-d", self.final_initrd]) errors = "".join(stderr.readlines()) 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 = "".join(stderr.readlines()) 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("/")
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))
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))
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))