From c6814acfc8e6db87e4b0be2a09f50b71a37a48aa Mon Sep 17 00:00:00 2001 From: sayaleeraut Date: Thu, 9 Jul 2020 11:45:21 +0530 Subject: [TestFix] Fix failures in test_dht_create_dir.py Added following changes: 1) The test script consists of 2 test cases. Hence changed the setUpClass(cls) to setUp(self). 2) Changed the code that checks if the symlink is pointing to correct location in the test_create_link_for_directory(self), as earlier it was failing with "AssertionError: sym link does not point to correct location" as the output of command 'stat' for symlink file varies as per the platform. Change-Id: I43f98a0d60b3ebf30236ff7e702667373a39a0e1 Signed-off-by: sayaleeraut --- tests/functional/dht/test_dht_create_dir.py | 124 ++++++++++------------------ 1 file changed, 44 insertions(+), 80 deletions(-) diff --git a/tests/functional/dht/test_dht_create_dir.py b/tests/functional/dht/test_dht_create_dir.py index f39e0d473..d3604dcbc 100644 --- a/tests/functional/dht/test_dht_create_dir.py +++ b/tests/functional/dht/test_dht_create_dir.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2020 Red Hat, Inc. +# Copyright (C) 2017-2020 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,6 +17,7 @@ # pylint: disable=too-many-statements, undefined-loop-variable # pylint: disable=too-many-branches,too-many-locals,pointless-string-statement +from re import search from glusto.core import Glusto as g from glustolibs.gluster.exceptions import ExecutionError from glustolibs.gluster.gluster_base_class import GlusterBaseClass, runs_on @@ -33,10 +34,9 @@ Description: tests to check the dht layouts of files and directories, """ -@runs_on([['replicated', - 'distributed', - 'distributed-replicated', - 'dispersed', 'distributed-dispersed'], +@runs_on([['distributed', 'distributed-replicated', + 'dispersed', 'distributed-dispersed', 'replicated', + 'arbiter', 'distributed-arbiter'], ['glusterfs']]) class TestDhtClass(GlusterBaseClass): @@ -44,15 +44,13 @@ class TestDhtClass(GlusterBaseClass): Description: tests to check the dht layouts of files and directories, along with their symlinks. """ - @classmethod - def setUpClass(cls): + def setUp(self): - # Calling GlusterBaseClass setUpClass - cls.get_super_method(cls, 'setUpClass')() + # Calling GlusterBaseClass setUp + self.get_super_method(self, 'setUp')() # Setup Volume and Mount Volume - g.log.info("Starting to Setup Volume and Mount Volume") - ret = cls.setup_volume_and_mount_volume(cls.mounts) + ret = self.setup_volume_and_mount_volume(self.mounts) if not ret: raise ExecutionError("Failed to Setup_Volume and Mount_Volume") g.log.info("Successful in Setup Volume and Mount Volume") @@ -60,7 +58,6 @@ class TestDhtClass(GlusterBaseClass): def tearDown(self): # Unmount and cleanup original volume - g.log.info("Starting to Unmount Volume and Cleanup Volume") ret = self.unmount_volume_and_cleanup_volume(mounts=self.mounts) if not ret: raise ExecutionError("Failed to umount the vol & cleanup Volume") @@ -71,7 +68,6 @@ class TestDhtClass(GlusterBaseClass): def test_create_directory(self): - g.log.info("creating multiple,multilevel directories") m_point = self.mounts[0].mountpoint command = 'mkdir -p ' + m_point + '/root_dir/test_dir{1..3}' ret, _, _ = g.run(self.mounts[0].client_system, command) @@ -82,8 +78,6 @@ class TestDhtClass(GlusterBaseClass): self.assertEqual(ret, 0, "ls failed on parent directory:root_dir") g.log.info("ls on parent directory: successful") - g.log.info("creating files at different directory levels inside %s", - self.mounts[0].mountpoint) command = 'touch ' + m_point + \ '/root_dir/test_file{1..5} ' + m_point + \ '/root_dir/test_dir{1..3}/test_file{1..5}' @@ -91,7 +85,7 @@ class TestDhtClass(GlusterBaseClass): self.assertEqual(ret, 0, "File creation: failed") command = 'ls ' + m_point + '/root_dir' ret, out, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "can't list the created directories") + self.assertEqual(ret, 0, "Failed to list the created directories") list_of_files_and_dirs = out.split('\n') flag = True for x_count in range(3): @@ -104,25 +98,20 @@ class TestDhtClass(GlusterBaseClass): flag = False self.assertTrue(flag, "ls command didn't list all the " "directories and files") - g.log.info("creation of files at multiple levels successful") + g.log.info("Creation of files at multiple levels successful") - g.log.info("creating a list of all directories") command = 'cd ' + m_point + ';find root_dir -type d -print' ret, out, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "creation of directory list failed") + self.assertEqual(ret, 0, "Creation of directory list failed") list_of_all_dirs = out.split('\n') del list_of_all_dirs[-1] - g.log.info("verifying that all the directories are present on " - "every brick and the layout ranges are correct") flag = validate_files_in_dir(self.clients[0], m_point + '/root_dir', test_type=k.TEST_LAYOUT_IS_COMPLETE) self.assertTrue(flag, "Layout has some holes or overlaps") g.log.info("Layout is completely set") - g.log.info("Checking if gfid xattr of directories is displayed and" - "is same on all the bricks on the server node") brick_list = get_all_bricks(self.mnode, self.volname) for direc in list_of_all_dirs: list_of_gfid = [] @@ -139,13 +128,11 @@ class TestDhtClass(GlusterBaseClass): for x_count in range(len(list_of_gfid) - 1): if list_of_gfid[x_count] != list_of_gfid[x_count + 1]: flag = False - self.assertTrue(flag, ("the gfid for the directory %s is not " + self.assertTrue(flag, ("The gfid for the directory %s is not " "same on all the bricks", direc)) - g.log.info("the gfid for each directory is the same on all the " + g.log.info("The gfid for each directory is the same on all the " "bricks") - g.log.info("Verify that for all directories mount point " - "should not display xattr") for direc in list_of_all_dirs: list_of_xattrs = get_fattr_list(self.mounts[0].client_system, self.mounts[0].mountpoint @@ -157,13 +144,11 @@ class TestDhtClass(GlusterBaseClass): g.log.info("Verified : mount point not displaying important " "xattrs") - g.log.info("Verifying that for all directories only mount point " - "shows pathinfo xattr") for direc in list_of_all_dirs: fattr = get_fattr(self.mounts[0].client_system, self.mounts[0].mountpoint+'/'+direc, 'trusted.glusterfs.pathinfo') - self.assertTrue(fattr, ("pathinfo not displayed for the " + self.assertTrue(fattr, ("Pathinfo not displayed for the " "directory %s on mount point", direc)) brick_list = get_all_bricks(self.mnode, self.volname) for direc in list_of_all_dirs: @@ -178,118 +163,97 @@ class TestDhtClass(GlusterBaseClass): def test_create_link_for_directory(self): - g.log.info("creating a directory at mount point") m_point = self.mounts[0].mountpoint - test_dir_path = 'test_dir' - fqpath = m_point + '/' + test_dir_path + fqpath_for_test_dir = m_point + '/test_dir' + flag = mkdir(self.clients[0], fqpath_for_test_dir, True) + self.assertTrue(flag, "Failed to create a directory") + fqpath = m_point + '/test_dir/dir{1..3}' flag = mkdir(self.clients[0], fqpath, True) - self.assertTrue(flag, "failed to create a directory") - fqpath = m_point + '/' + test_dir_path + '/dir{1..3}' - flag = mkdir(self.clients[0], fqpath, True) - self.assertTrue(flag, "failed to create sub directories") + self.assertTrue(flag, "Failed to create sub directories") flag = validate_files_in_dir(self.clients[0], - m_point + '/test_dir', + fqpath_for_test_dir, test_type=k.TEST_LAYOUT_IS_COMPLETE) - self.assertTrue(flag, "layout of test directory is complete") - g.log.info("directory created successfully") + self.assertTrue(flag, "Layout of test directory is not complete") + g.log.info("Layout for directory is complete") - g.log.info("creating a symlink for test_dir") sym_link_path = m_point + '/' + 'test_sym_link' - command = 'ln -s ' + m_point + '/test_dir ' + sym_link_path + command = 'ln -s ' + fqpath_for_test_dir + ' ' + sym_link_path ret, _, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "failed to create symlink for test_dir") + self.assertEqual(ret, 0, "Failed to create symlink for test_dir") command = 'stat ' + sym_link_path ret, out, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "stat command didn't return the details " + self.assertEqual(ret, 0, "Stat command didn't return the details " "correctly") flag = False - g.log.info("checking if the link is symbolic") if 'symbolic link' in out: flag = True - self.assertTrue(flag, "the type of the link is not symbolic") - g.log.info("the link is symbolic") - g.log.info("checking if the sym link points to right directory") - index_start = out.find('->') + 6 - index_end = out.find("\n") - 3 - dir_pointed = out[index_start:index_end] + self.assertTrue(flag, "The type of the link is not symbolic") + g.log.info("The link is symbolic") flag = False - if dir_pointed == m_point + '/' + test_dir_path: + if search(fqpath_for_test_dir, out): flag = True self.assertTrue(flag, "sym link does not point to correct " "location") g.log.info("sym link points to right directory") g.log.info("The details of the symlink are correct") - g.log.info("verifying that inode number of the test_dir " - "and its sym link are different") - command = 'ls -id ' + m_point + '/' + \ - test_dir_path + ' ' + sym_link_path + command = 'ls -id ' + fqpath_for_test_dir + ' ' + sym_link_path ret, out, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "inode numbers not retrieved by the " + self.assertEqual(ret, 0, "Inode numbers not retrieved by the " "ls command") list_of_inode_numbers = out.split('\n') - flag = True if (list_of_inode_numbers[0].split(' ')[0] == list_of_inode_numbers[1].split(' ')[0]): flag = False - self.assertTrue(flag, "the inode numbers of the dir and sym link " + self.assertTrue(flag, "The inode numbers of the dir and sym link " "are same") - g.log.info("verified: inode numbers of the test_dir " + g.log.info("Verified: inode numbers of the test_dir " "and its sym link are different") - g.log.info("listing the contents of the test_dir from its sym " - "link") command = 'ls ' + sym_link_path ret, out1, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "failed to list the contents using the " + self.assertEqual(ret, 0, "Failed to list the contents using the " "sym link") - command = 'ls ' + m_point + '/' + test_dir_path + command = 'ls ' + fqpath_for_test_dir ret, out2, _ = g.run(self.mounts[0].client_system, command) - self.assertEqual(ret, 0, "failed to list the contents of the " + self.assertEqual(ret, 0, "Failed to list the contents of the " "test_dir using ls command") flag = False if out1 == out2: flag = True - self.assertTrue(flag, "the contents listed using the sym link " + self.assertTrue(flag, "The contents listed using the sym link " "are not the same") - g.log.info("the contents listed using the symlink are" + g.log.info("The contents listed using the symlink are" " the same as that of the test_dir") - g.log.info("verifying that mount point doesn't display important " - "xattrs using the symlink") command = 'getfattr -d -m . -e hex ' + sym_link_path ret, out, _ = g.run(self.mounts[0].client_system, command) self.assertEqual(ret, 0, "failed to retrieve xattrs") list_xattrs = ['trusted.gfid', 'trusted.glusterfs.dht'] - flag = True for xattr in list_xattrs: if xattr in out: flag = False - self.assertTrue(flag, "important xattrs are being compromised" + self.assertTrue(flag, "Important xattrs are being compromised" " using the symlink at the mount point") - g.log.info("verified: mount point doesn't display important " + g.log.info("Verified: mount point doesn't display important " "xattrs using the symlink") - g.log.info("verifying that mount point shows path info xattr for the" - " test_dir and sym link and is same for both") path_info_1 = get_pathinfo(self.mounts[0].client_system, - m_point + '/' + test_dir_path) + fqpath_for_test_dir) path_info_2 = get_pathinfo(self.mounts[0].client_system, sym_link_path) if path_info_1 == path_info_2: flag = True - self.assertTrue(flag, "pathinfos for test_dir and its sym link " + self.assertTrue(flag, "Pathinfos for test_dir and its sym link " "are not same") - g.log.info("pathinfos for test_dir and its sym link are same") + g.log.info("Pathinfos for test_dir and its sym link are same") - g.log.info("verifying readlink on sym link at mount point returns " - "the name of the directory") command = 'readlink ' + sym_link_path ret, out, _ = g.run(self.mounts[0].client_system, command) self.assertEqual(ret, 0, "readlink command returned an error") flag = False - if out.rstrip() == m_point + '/' + test_dir_path: + if out.rstrip() == fqpath_for_test_dir: flag = True self.assertTrue(flag, "readlink did not return the path of the " "test_dir") -- cgit