From 8b6107b62dacf5edc264f4f0206771d8fa07f7bf Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Thu, 20 Dec 2018 23:04:22 +0530 Subject: Add abstraction between deployment types and gluster commands Now, it is possible to run glustolibs commands on both deployment types: containerized and standalone. It is possible using 'auto_get_gluster_endpoint' as target for lib function in addition to the '@podcmd.GlustoPod()' decorator. Example: """ from glustolibs.gluster.volume_ops import get_volume_list from cnslibs.common import heketi_libs from cnslibs.common import podcmd class TestExample(heketi_libs.HeketiBaseClass): @podcmd.GlustoPod() def test_get_vol_list_either_on_node_or_on_pod(self): volumes = get_volume_list('auto_get_gluster_endpoint') """ Also, delete all the current usages of 'deployment_type' config option, and delete the option as unneeded anymore. Change-Id: I281f287c432a5a9efefda588be436ee285188697 --- tests/cns_tests_sample_config.yml | 3 - .../heketi/heketi_tests/test_disabling_device.py | 11 +-- .../heketi_tests/test_heketi_create_volume.py | 28 ++---- .../common/heketi/heketi_tests/test_node_info.py | 9 +- ...est_create_distributed_replica_heketi_volume.py | 17 +--- .../common/heketi/test_volume_creation.py | 26 ++--- .../heketi/test_volume_expansion_and_devices.py | 108 ++++++--------------- 7 files changed, 50 insertions(+), 152 deletions(-) (limited to 'tests') diff --git a/tests/cns_tests_sample_config.yml b/tests/cns_tests_sample_config.yml index 89f0f162..07ed23eb 100644 --- a/tests/cns_tests_sample_config.yml +++ b/tests/cns_tests_sample_config.yml @@ -41,9 +41,6 @@ cns: cns_project_name: "storage-project" cns_username: "test-admin" cns_password: - - # 'deployment_type' can be cns|crs - deployment_type: 'cns' trusted_storage_pool_list: - [gluster_server1, gluster_server2] heketi_config: diff --git a/tests/functional/common/heketi/heketi_tests/test_disabling_device.py b/tests/functional/common/heketi/heketi_tests/test_disabling_device.py index 43d222a2..5d5e867c 100644 --- a/tests/functional/common/heketi/heketi_tests/test_disabling_device.py +++ b/tests/functional/common/heketi/heketi_tests/test_disabling_device.py @@ -4,7 +4,6 @@ from glustolibs.gluster.volume_ops import get_volume_info from cnslibs.common import exceptions from cnslibs.common import heketi_libs from cnslibs.common import heketi_ops -from cnslibs.common import openshift_ops from cnslibs.common import podcmd @@ -122,12 +121,6 @@ class TestDisableHeketiDevice(heketi_libs.HeketiBaseClass): name = out["name"] # Get gluster volume info - if self.deployment_type == "cns": - gluster_pod = openshift_ops.get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - out = get_volume_info(p, volname=name) - else: - out = get_volume_info(self.heketi_client_node, volname=name) - self.assertTrue(out, "Failed to get '%s' volume info." % name) + vol_info = get_volume_info('auto_get_gluster_endpoint', volname=name) + self.assertTrue(vol_info, "Failed to get '%s' volume info." % name) g.log.info("Successfully got the '%s' volume info." % name) diff --git a/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py index 7f2a61da..7963413b 100644 --- a/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py +++ b/tests/functional/common/heketi/heketi_tests/test_heketi_create_volume.py @@ -16,7 +16,6 @@ from cnslibs.common.heketi_ops import (heketi_volume_create, heketi_node_info, heketi_node_list, heketi_node_delete) -from cnslibs.common.openshift_ops import get_ocp_gluster_pod_names from cnslibs.common import podcmd @@ -53,24 +52,18 @@ class TestHeketiVolume(HeketiBaseClass): g.log.info("Heketi volumes successfully listed") g.log.info("List gluster volumes") - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - out = get_volume_list(p) - else: - out = get_volume_list(self.heketi_client_node) - self.assertTrue(out, ("Unable to get volumes list")) + vol_list = get_volume_list('auto_get_gluster_endpoint') + self.assertTrue(vol_list, ("Unable to get volumes list")) g.log.info("Successfully got the volumes list") # Check the volume count are equal self.assertEqual( - len(volumes["volumes"]), len(out), + len(volumes["volumes"]), len(vol_list), "Lengths of gluster '%s' and heketi '%s' volume lists are " - "not equal." % (out, volumes) + "not equal." % (vol_list, volumes) ) g.log.info("Heketi volumes list %s and" - " gluster volumes list %s" % ((volumes), (out))) + " gluster volumes list %s" % (volumes, vol_list)) @podcmd.GlustoPod() def test_create_vol_and_retrieve_vol_info(self): @@ -97,15 +90,8 @@ class TestHeketiVolume(HeketiBaseClass): g.log.info("Successfully got the heketi volume info") name = out["name"] - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - out = get_volume_info(p, volname=name) - else: - out = get_volume_info(self.heketi_client_node, - volname=name) - self.assertTrue(out, ("Failed to get volume info %s" % name)) + vol_info = get_volume_info('auto_get_gluster_endpoint', volname=name) + self.assertTrue(vol_info, "Failed to get volume info %s" % name) g.log.info("Successfully got the volume info %s" % name) def test_to_check_deletion_of_cluster(self): diff --git a/tests/functional/common/heketi/heketi_tests/test_node_info.py b/tests/functional/common/heketi/heketi_tests/test_node_info.py index 016b3ec4..3f956d62 100644 --- a/tests/functional/common/heketi/heketi_tests/test_node_info.py +++ b/tests/functional/common/heketi/heketi_tests/test_node_info.py @@ -4,7 +4,6 @@ from glustolibs.gluster.peer_ops import get_pool_list from cnslibs.common.heketi_libs import HeketiBaseClass from cnslibs.common import heketi_ops, podcmd -from cnslibs.common.openshift_ops import get_ocp_gluster_pod_names class TestHeketiVolume(HeketiBaseClass): @@ -44,13 +43,7 @@ class TestHeketiVolume(HeketiBaseClass): hostname = [] g.log.info("Get the pool list") - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - list_of_pools = get_pool_list(p) - else: - list_of_pools = get_pool_list(self.heketi_client_node) + list_of_pools = get_pool_list('auto_get_gluster_endpoint') self.assertTrue(list_of_pools, ("Failed to get the " "pool list from gluster pods/nodes")) g.log.info("Successfully got the pool list from gluster pods/nodes") diff --git a/tests/functional/common/heketi/test_create_distributed_replica_heketi_volume.py b/tests/functional/common/heketi/test_create_distributed_replica_heketi_volume.py index 3dd4230b..561e1342 100644 --- a/tests/functional/common/heketi/test_create_distributed_replica_heketi_volume.py +++ b/tests/functional/common/heketi/test_create_distributed_replica_heketi_volume.py @@ -14,7 +14,6 @@ from cnslibs.common.heketi_ops import (heketi_node_list, 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 @@ -107,12 +106,8 @@ class TestHeketiVolume(HeketiBaseClass): # Get gluster volume info g.log.info("Get gluster volume '%s' info" % vol_name) - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names(self.master_node)[0] - p = podcmd.Pod(self.master_node, gluster_pod) - gluster_vol = get_volume_info(p, volname=vol_name) - else: - gluster_vol = get_volume_info(self.gluster_node, volname=vol_name) + gluster_vol = get_volume_info( + 'auto_get_gluster_endpoint', volname=vol_name) self.assertTrue( gluster_vol, "Failed to get volume '%s' info" % vol_name) g.log.info("Successfully got volume '%s' info" % vol_name) @@ -157,13 +152,9 @@ class TestHeketiVolume(HeketiBaseClass): # Check the gluster volume list g.log.info("Get the gluster volume list") - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names(self.master_node)[0] - p = podcmd.Pod(self.master_node, gluster_pod) - gluster_volumes = get_volume_list(p) - else: - gluster_volumes = get_volume_list(self.gluster_node) + gluster_volumes = get_volume_list('auto_get_gluster_endpoint') self.assertTrue(gluster_volumes, "Unable to get Gluster volume list") + g.log.info("Successfully got Gluster volume list" % gluster_volumes) self.assertNotIn(vol_id, gluster_volumes) self.assertNotIn(vol_name, gluster_volumes) diff --git a/tests/functional/common/heketi/test_volume_creation.py b/tests/functional/common/heketi/test_volume_creation.py index 07dba094..b9f2a680 100644 --- a/tests/functional/common/heketi/test_volume_creation.py +++ b/tests/functional/common/heketi/test_volume_creation.py @@ -4,7 +4,6 @@ from glustolibs.gluster import volume_ops from cnslibs.common import exceptions from cnslibs.common import heketi_libs from cnslibs.common import heketi_ops -from cnslibs.common import openshift_ops from cnslibs.common import podcmd @@ -60,25 +59,14 @@ class TestVolumeCreationTestCases(heketi_libs.HeketiBaseClass): "Hosts and gluster servers not matching for %s" % volume_id) - if self.deployment_type == "cns": - gluster_pod = openshift_ops.get_ocp_gluster_pod_names( - self.heketi_client_node)[1] + volume_info = volume_ops.get_volume_info( + 'auto_get_gluster_endpoint', volume_name) + self.assertIsNotNone(volume_info, "get_volume_info returned None") - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - - volume_info = volume_ops.get_volume_info(p, volume_name) - volume_status = volume_ops.get_volume_status(p, volume_name) - - elif self.deployment_type == "crs": - volume_info = volume_ops.get_volume_info( - self.heketi_client_node, volume_name) - volume_status = volume_ops.get_volume_status( - self.heketi_client_node, volume_name) - - self.assertNotEqual(volume_info, None, - "get_volume_info returned None") - self.assertNotEqual(volume_status, None, - "get_volume_status returned None") + volume_status = volume_ops.get_volume_status( + 'auto_get_gluster_endpoint', volume_name) + self.assertIsNotNone( + volume_status, "get_volume_status returned None") self.assertEqual(int(volume_info[volume_name]["status"]), 1, "Volume %s status down" % volume_id) diff --git a/tests/functional/common/heketi/test_volume_expansion_and_devices.py b/tests/functional/common/heketi/test_volume_expansion_and_devices.py index 8d590fb6..262e3d6b 100644 --- a/tests/functional/common/heketi/test_volume_expansion_and_devices.py +++ b/tests/functional/common/heketi/test_volume_expansion_and_devices.py @@ -8,7 +8,6 @@ from glustolibs.gluster import volume_ops, rebalance_ops from cnslibs.common.exceptions import ExecutionError from cnslibs.common.heketi_libs import HeketiBaseClass -from cnslibs.common.openshift_ops import get_ocp_gluster_pod_names from cnslibs.common import heketi_ops, podcmd @@ -19,101 +18,52 @@ class TestVolumeExpansionAndDevicesTestCases(HeketiBaseClass): @podcmd.GlustoPod() def get_num_of_bricks(self, volume_name): - """ - Method to determine number of - bricks at present in the volume - """ - brick_info = [] - - if self.deployment_type == "cns": - - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - - volume_info_before_expansion = volume_ops.get_volume_info( - p, volume_name) - - elif self.deployment_type == "crs": - volume_info_before_expansion = volume_ops.get_volume_info( - self.heketi_client_node, volume_name) + """Method to determine number of bricks at present in the volume.""" + volume_info = volume_ops.get_volume_info( + 'auto_get_gluster_endpoint', volume_name) self.assertIsNotNone( - volume_info_before_expansion, - "Volume info is None") + volume_info, "'%s' volume info is None" % volume_name) - for brick_details in (volume_info_before_expansion - [volume_name]["bricks"]["brick"]): - - brick_info.append(brick_details["name"]) - - num_of_bricks = len(brick_info) - - return num_of_bricks + return len([b for b in volume_info[volume_name]["bricks"]["brick"]]) @podcmd.GlustoPod() def get_rebalance_status(self, volume_name): - """ - Rebalance status after expansion - """ - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] - - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - - wait_reb = rebalance_ops.wait_for_rebalance_to_complete( - p, volume_name) - self.assertTrue(wait_reb, "Rebalance not complete") - - reb_status = rebalance_ops.get_rebalance_status( - p, volume_name) - - elif self.deployment_type == "crs": - wait_reb = rebalance_ops.wait_for_rebalance_to_complete( - self.heketi_client_node, volume_name) - self.assertTrue(wait_reb, "Rebalance not complete") - - reb_status = rebalance_ops.get_rebalance_status( - self.heketi_client_node, volume_name) + """Rebalance status after expansion.""" + wait_reb = rebalance_ops.wait_for_rebalance_to_complete( + 'auto_get_gluster_endpoint', volume_name) + self.assertTrue( + wait_reb, + "Rebalance for '%s' volume was not completed." % volume_name) - self.assertEqual(reb_status["aggregate"]["statusStr"], - "completed", "Rebalance not yet completed") + reb_status = rebalance_ops.get_rebalance_status( + 'auto_get_gluster_endpoint', volume_name) + self.assertEqual( + reb_status["aggregate"]["statusStr"], "completed", + "Failed to get rebalance status for '%s' volume." % volume_name) @podcmd.GlustoPod() def get_brick_and_volume_status(self, volume_name): - """ - Status of each brick in a volume - for background validation - """ - brick_info = [] - - if self.deployment_type == "cns": - gluster_pod = get_ocp_gluster_pod_names( - self.heketi_client_node)[1] + """Status of each brick in a volume for background validation.""" - p = podcmd.Pod(self.heketi_client_node, gluster_pod) - - volume_info = volume_ops.get_volume_info(p, volume_name) - volume_status = volume_ops.get_volume_status(p, volume_name) - - elif self.deployment_type == "crs": - volume_info = volume_ops.get_volume_info( - self.heketi_client_node, volume_name) - volume_status = volume_ops.get_volume_status( - self.heketi_client_node, volume_name) + volume_info = volume_ops.get_volume_info( + 'auto_get_gluster_endpoint', volume_name) + self.assertIsNotNone( + volume_info, "'%s' volume info is empty" % volume_name) - self.assertIsNotNone(volume_info, "Volume info is empty") - self.assertIsNotNone(volume_status, "Volume status is empty") + volume_status = volume_ops.get_volume_status( + 'auto_get_gluster_endpoint', volume_name) + self.assertIsNotNone( + volume_status, "'%s' volume status is empty" % volume_name) self.assertEqual(int(volume_info[volume_name]["status"]), 1, "Volume not up") + + brick_info = [] for brick_details in volume_info[volume_name]["bricks"]["brick"]: brick_info.append(brick_details["name"]) - - if brick_info == []: - raise ExecutionError("Brick details empty for %s" % volume_name) + self.assertTrue( + brick_info, "Brick details are empty for %s" % volume_name) for brick in brick_info: brick_data = brick.strip().split(":") -- cgit