From 0c8f9389732a35682b5da03a1d86352e3fdcdb68 Mon Sep 17 00:00:00 2001 From: vamahaja Date: Thu, 31 Oct 2019 18:14:29 +0530 Subject: Add test case to automate heketi add node into valid cluster Change-Id: I4a2ac7b819929c2de6c8ea5520257800d2e134cc Signed-off-by: vamahaja --- .../openshiftstoragelibs/baseclass.py | 6 ++ .../heketi/test_heketi_cluster_operations.py | 110 +++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/openshift-storage-libs/openshiftstoragelibs/baseclass.py b/openshift-storage-libs/openshiftstoragelibs/baseclass.py index ad9c45ae..dd57a131 100644 --- a/openshift-storage-libs/openshiftstoragelibs/baseclass.py +++ b/openshift-storage-libs/openshiftstoragelibs/baseclass.py @@ -489,6 +489,12 @@ class BaseClass(unittest.TestCase): g_nodes = g_nodes.split('\n') if g_nodes else g_nodes return not not g_nodes + def configure_node_to_run_gluster(self, storage_host_manage): + if self.is_containerized_gluster(): + self.configure_node_to_run_gluster_pod(storage_host_manage) + else: + self.configure_node_to_run_gluster_node(storage_host_manage) + def _is_error_or_failure_exists(self): if hasattr(self, '_outcome'): # Python 3.4+ diff --git a/tests/functional/heketi/test_heketi_cluster_operations.py b/tests/functional/heketi/test_heketi_cluster_operations.py index b8ce8822..87e8b350 100644 --- a/tests/functional/heketi/test_heketi_cluster_operations.py +++ b/tests/functional/heketi/test_heketi_cluster_operations.py @@ -1,6 +1,8 @@ import ddt +from glusto.core import Glusto as g from openshiftstoragelibs import baseclass +from openshiftstoragelibs import exceptions from openshiftstoragelibs import heketi_ops @@ -94,3 +96,111 @@ class TestClusterOperationsTestCases(baseclass.BaseClass): "Cluster id %s was not expected in cluster list %s" % (cluster_info["id"], cluster_list["clusters"])) self.assertNotIn(cluster_info["id"], cluster_list["clusters"], err_msg) + + def test_create_heketi_cluster_and_add_node(self): + """Test heketi node add to a newly created cluster""" + storage_host_info = g.config.get("additional_gluster_servers") + if not storage_host_info: + self.skipTest( + "Skip test case as 'additional_gluster_servers' option is " + "not provided in config file") + + storage_host_info = list(storage_host_info.values())[0] + try: + storage_hostname = storage_host_info["manage"] + storage_ip = storage_host_info["storage"] + storage_device = storage_host_info["additional_devices"][0] + except KeyError: + msg = ("Config options 'additional_gluster_servers.manage' " + "'additional_gluster_servers.storage' and " + "'additional_gluster_servers.additional_devices' " + "must be set.") + g.log.error(msg) + raise exceptions.ConfigError(msg) + + h_client, h_server = self.heketi_client_node, self.heketi_server_url + storage_zone = 1 + + cluster_id = heketi_ops.heketi_cluster_create( + self.heketi_client_node, self.heketi_server_url, json=True)["id"] + self.addCleanup( + heketi_ops.heketi_cluster_delete, self.heketi_client_node, + self.heketi_server_url, cluster_id) + + self.configure_node_to_run_gluster(storage_hostname) + + heketi_node_info = heketi_ops.heketi_node_add( + h_client, h_server, storage_zone, cluster_id, + storage_hostname, storage_ip, json=True) + heketi_node_id = heketi_node_info["id"] + self.addCleanup( + heketi_ops.heketi_node_delete, h_client, h_server, heketi_node_id) + self.addCleanup( + heketi_ops.heketi_node_remove, h_client, h_server, heketi_node_id) + self.addCleanup( + heketi_ops.heketi_node_disable, h_client, h_server, heketi_node_id) + self.assertEqual( + heketi_node_info["cluster"], cluster_id, + "Node got added in unexpected cluster exp: %s, act: %s" % ( + cluster_id, heketi_node_info["cluster"])) + + heketi_ops.heketi_device_add( + h_client, h_server, storage_device, heketi_node_id) + heketi_node_info = heketi_ops.heketi_node_info( + h_client, h_server, heketi_node_id, json=True) + device_id = None + for device in heketi_node_info["devices"]: + if device["name"] == storage_device: + device_id = device["id"] + break + err_msg = ("Failed to add device %s on node %s" % ( + storage_device, heketi_node_id)) + self.assertTrue(device_id, err_msg) + + self.addCleanup( + heketi_ops.heketi_device_delete, h_client, h_server, device_id) + self.addCleanup( + heketi_ops.heketi_device_remove, h_client, h_server, device_id) + self.addCleanup( + heketi_ops.heketi_device_disable, h_client, h_server, device_id) + + cluster_info = heketi_ops.heketi_cluster_info( + h_client, h_server, cluster_id, json=True) + self.assertIn( + heketi_node_info["id"], cluster_info["nodes"], + "Newly added node %s not found in cluster %s, cluster info %s" % ( + heketi_node_info["id"], cluster_id, cluster_info)) + + topology_info = heketi_ops.heketi_topology_info( + h_client, h_server, json=True) + + cluster_details = [ + cluster for cluster in topology_info["clusters"] + if cluster["id"] == cluster_id] + err_msg = "Cluster details for id '%s' not found" % cluster_id + self.assertTrue(cluster_details, err_msg) + err_msg = ("Multiple clusters with same id '%s' found %s" % ( + cluster_id, cluster_details)) + self.assertEqual(len(cluster_details), 1, err_msg) + + node_details = [ + node for node in cluster_details[0]["nodes"] + if node["id"] == heketi_node_id] + err_msg = "Node details for id '%s' not found" % heketi_node_id + self.assertTrue(node_details, err_msg) + err_msg = ("Multiple nodes with same id '%s' found %s" % ( + heketi_node_id, node_details)) + self.assertEqual(len(node_details), 1, err_msg) + + err_msg = "Unexpected %s found '%s', expected '%s'" + exp_storage_hostname = node_details[0]["hostnames"]["manage"][0] + self.assertEqual( + exp_storage_hostname, storage_hostname, + err_msg % ("hostname", exp_storage_hostname, storage_hostname,)) + exp_storage_ip = node_details[0]["hostnames"]["storage"][0] + self.assertEqual( + exp_storage_ip, storage_ip, + err_msg % ("IP address", exp_storage_ip, storage_ip)) + zone = node_details[0]["zone"] + self.assertEqual( + zone, storage_zone, err_msg % ("zone", zone, storage_zone)) -- cgit