diff options
author | Valerii Ponomarov <vponomar@redhat.com> | 2018-12-03 11:31:41 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.host.prod.eng.bos.redhat.com> | 2018-12-03 11:31:41 +0000 |
commit | 25e084d6c9406a9bd3b05e1498825f201121ed6b (patch) | |
tree | d1ffc0c56308e3c2701a9b5c74d67d6e018060f8 /tests | |
parent | 18a5901e5be6ed505a9416a9c29ae4573248d104 (diff) | |
parent | 80e6057a8cc3d851b685c3afce1bc7a757b5a12c (diff) |
Merge "[CNS-778] Refactor and fix 'test_to_check_entry_in_fstab_file' TC"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/common/heketi/heketi_tests/test_check_entry.py | 132 | ||||
-rw-r--r-- | tests/functional/common/heketi/test_check_entries.py | 54 |
2 files changed, 54 insertions, 132 deletions
diff --git a/tests/functional/common/heketi/heketi_tests/test_check_entry.py b/tests/functional/common/heketi/heketi_tests/test_check_entry.py deleted file mode 100644 index 47a0b3f2..00000000 --- a/tests/functional/common/heketi/heketi_tests/test_check_entry.py +++ /dev/null @@ -1,132 +0,0 @@ -from glusto.core import Glusto as g -from glustolibs.gluster.exceptions import ConfigError - -from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass -from cnslibs.common.heketi_ops import (heketi_volume_create, - heketi_volume_list, - heketi_volume_delete) -from cnslibs.common.openshift_ops import get_ocp_gluster_pod_names -from cnslibs.common import podcmd - - -class TestHeketiVolume(HeketiClientSetupBaseClass): - """ - Check /etc/fstab entry - """ - @classmethod - def setUpClass(cls): - super(TestHeketiVolume, cls).setUpClass() - cls.volume_size = cls.heketi_volume['size'] - - @podcmd.GlustoPod() - def test_to_check_entry_in_fstab_file(self): - """ - Create a heketi volume and check entry - in /etc/fstab and delete heketi volume - and check corresponding brick entry must - be removed - """ - - # Create heketi volume - g.log.info("Creating a heketi volume") - out = heketi_volume_create(self.heketi_client_node, - self.heketi_server_url, - self.volume_size, json=True) - self.assertTrue(out, ("Failed to create heketi volume " - "of size %s" % str(self.volume_size))) - g.log.info("Heketi volume successfully created" % out) - self.volume_id = out["bricks"][0]["volume"] - path = [] - for i in out["bricks"]: - path.append(i["path"].rstrip("/brick")) - - # Listing heketi volumes - g.log.info("List heketi volumes") - out = heketi_volume_list(self.heketi_client_node, - self.heketi_server_url) - self.assertTrue(out, ("Failed to list heketi volumes")) - g.log.info("Heketi volume successfully listed") - - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - - cmd = "oc rsync " + gluster_pod + ":/var/lib/heketi/fstab /tmp" - out = g.run(self.heketi_client_node, cmd) - self.assertTrue(out, ("Failed to copy the file")) - g.log.info("Copied the file") - out = g.run_local( - "scp -r root@%s:/tmp/fstab " - "/tmp/file.txt" % self.heketi_client_node) - self.assertTrue(out, ("Failed to copy a file to /tmp/file.txt")) - g.log.info("Successfully copied to /tmp/file.txt") - out = g.run_local("ls /tmp") - self.assertTrue(out, ("Failed to list")) - g.log.info("Successfully listed") - - # open /tmp/fstab file - datafile = open("/tmp/file.txt") - # Check if the brick is mounted - for i in path: - string_to_search = i - rcode, rout, rerr = g.run_local( - 'grep %s %s' % (string_to_search, "/tmp/file.txt")) - if rcode == 0: - g.log.info("Brick %s is mounted" % i) - datafile.close() - - out = g.run(self.heketi_client_node, "rm -rf /tmp/fstab") - self.assertTrue(out, ("Failed to delete a file /tmp/fstab")) - g.log.info("Successfully removed /tmp/fstab") - out = g.run_local("rm -rf /tmp/file.txt") - self.assertTrue(out, ("Failed to delete a file /tmp/file.txt")) - g.log.info("Successfully removed /tmp/file.txt") - - # Delete heketi volume - g.log.info("Deleting heketi volumes") - out = heketi_volume_delete(self.heketi_client_node, - self.heketi_server_url, - self.volume_id) - self.assertTrue(out, ("Failed to delete " - "heketi volume %s" % self.volume_id)) - g.log.info("Heketi volume successfully deleted %s" % self.volume_id) - - # Listing heketi volumes - g.log.info("List heketi volumes") - out = heketi_volume_list(self.heketi_client_node, - self.heketi_server_url) - self.assertTrue(out, ("Failed to list or No volumes to list")) - g.log.info("Heketi volume successfully listed") - - # Check entry /etc/fstab - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[0] - - cmd = "oc rsync " + gluster_pod + ":/var/lib/heketi/fstab /" - out = g.run(self.heketi_client_node, cmd) - self.assertTrue(out, ("Failed to copy the file")) - g.log.info("Copied the file") - out = g.run_local( - "scp -r root@%s:/fstab /tmp/newfile.txt" % self.heketi_client_node) - self.assertTrue(out, ("Failed to copy to the file newfile.txt")) - g.log.info("Successfully copied to the file newfile.txt") - out = g.run_local("ls /tmp") - self.assertTrue(out, ("Failed to list")) - g.log.info("Successfully listed") - - # open /tmp/newfile.txt file - datafile = open("/tmp/newfile.txt") - # Check if the brick is mounted - for i in path: - string_to_search = i - rcode, rout, rerr = g.run_local( - 'grep %s %s' % (string_to_search, "/tmp/newfile.txt")) - if rcode == 0: - raise ConfigError("Particular %s brick entry is found" % i) - datafile.close() - - out = g.run(self.heketi_client_node, "rm -rf /fstab") - self.assertTrue(out, ("Failed to delete a file /fstab")) - g.log.info("Successfully removed /fstab") - out = g.run_local("rm -rf /tmp/newfile.txt") - self.assertTrue(out, ("Failed to delete a file /tmp/newfile.txt")) - g.log.info("Successfully removed /tmp/file.txt") diff --git a/tests/functional/common/heketi/test_check_entries.py b/tests/functional/common/heketi/test_check_entries.py new file mode 100644 index 00000000..be7add9e --- /dev/null +++ b/tests/functional/common/heketi/test_check_entries.py @@ -0,0 +1,54 @@ +from glusto.core import Glusto as g + +from cnslibs.common.heketi_libs import HeketiClientSetupBaseClass +from cnslibs.common.heketi_ops import (heketi_volume_create, + heketi_volume_delete) +from cnslibs.common.openshift_ops import get_ocp_gluster_pod_names + + +class TestHeketiVolume(HeketiClientSetupBaseClass): + """Check volume bricks presence in fstab files on Gluster PODs.""" + + def _find_bricks_in_fstab_files(self, brick_paths, present): + """Make sure that vol brick paths either exist or not in fstab file.""" + oc_node = self.ocp_master_nodes[0] + gluster_pods = get_ocp_gluster_pod_names(oc_node) + get_fstab_entries_cmd = "oc exec %s -- cat /var/lib/heketi/fstab" + fstab_files_data = '' + for gluster_pod in gluster_pods: + ret, out, err = g.run(oc_node, get_fstab_entries_cmd % gluster_pod) + self.assertEqual( + ret, 0, + "Failed to read fstab file on '%s' gluster POD. " + "\nOut: %s \nError: %s" % (gluster_pod, out, err)) + fstab_files_data += '%s\n' % out + assertion_method = self.assertIn if present else self.assertNotIn + for brick_path in brick_paths: + assertion_method(brick_path, fstab_files_data) + + def test_to_check_entry_in_fstab_file(self): + """Test case CNS-778""" + + # Create heketi volume + vol = heketi_volume_create( + self.heketi_client_node, self.heketi_server_url, size=1, json=True) + self.assertTrue(vol, "Failed to create 1Gb heketi volume") + vol_id = vol["bricks"][0]["volume"] + self.addCleanup( + heketi_volume_delete, + self.heketi_client_node, self.heketi_server_url, vol_id, + raise_on_error=False) + + # Gather brick paths + brick_paths = [p['path'].rstrip("/brick") for p in vol["bricks"]] + + # Make sure that volume's brick paths exist in the fstab files + self._find_bricks_in_fstab_files(brick_paths, present=True) + + # Delete heketi volume + out = heketi_volume_delete( + self.heketi_client_node, self.heketi_server_url, vol_id) + self.assertTrue(out, "Failed to delete heketi volume %s" % vol_id) + + # Make sure that volume's brick paths are absent in the fstab file + self._find_bricks_in_fstab_files(brick_paths, present=False) |