diff options
author | vamahaja <vamahaja@redhat.com> | 2019-09-11 14:46:59 +0530 |
---|---|---|
committer | vponomar <vponomar@redhat.com> | 2019-09-19 11:45:44 +0000 |
commit | a214cf6781d48594afc84d08e865d59bdcbe8fe1 (patch) | |
tree | 484092c4cc0f318871ed4c4299e663edf0b0489e /tests/functional/heketi/test_heketi_node_operations.py | |
parent | 764d7bd68ec0b4ea9229c381b3b4195367b44b83 (diff) |
Merge heketi node operation tests in one class and fix library
Fix consists of -
- Use "**kwargs" approach in the "heketi_node_list"
function as it is done in lots of other functions.
- Parse the CLI output in the "heketi_node_list" function
using regex instead of the splitting and stripping strings.
- Combine test cases related to the same feature into one
module - test_heketi_node_operations.py
- Remove redundant checks which already exist in common
libraries.
- Remove unnecessary logging.
Change-Id: I815ddfbbacb765140229e7630ec87a6bbaa6255b
Signed-off-by: vamahaja <vamahaja@redhat.com>
Diffstat (limited to 'tests/functional/heketi/test_heketi_node_operations.py')
-rw-r--r-- | tests/functional/heketi/test_heketi_node_operations.py | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/functional/heketi/test_heketi_node_operations.py b/tests/functional/heketi/test_heketi_node_operations.py new file mode 100644 index 00000000..6386be6f --- /dev/null +++ b/tests/functional/heketi/test_heketi_node_operations.py @@ -0,0 +1,108 @@ +from glustolibs.gluster import peer_ops + +from openshiftstoragelibs import baseclass +from openshiftstoragelibs import heketi_ops +from openshiftstoragelibs import podcmd + + +class TestHeketiNodeOperations(baseclass.BaseClass): + """Class to test heketi node operations + """ + + @podcmd.GlustoPod() + def test_heketi_node_list(self): + """Test node list operation + """ + h_client, h_server = self.heketi_client_node, self.heketi_server_url + + # List heketi nodes + node_ips = [] + heketi_node_id_list = heketi_ops.heketi_node_list(h_client, h_server) + + for node_id in heketi_node_id_list: + node_info = heketi_ops.heketi_node_info( + h_client, h_server, node_id, json=True) + node_ips.append(node_info["hostnames"]["storage"]) + + # Compare the node listed in previous step + hostnames = [] + list_of_pools = peer_ops.get_pool_list('auto_get_gluster_endpoint') + self.assertTrue( + list_of_pools, + "Failed to get the pool list from gluster pods/nodes") + for pool in list_of_pools: + hostnames.append(pool["hostname"]) + self.assertEqual( + len(heketi_node_id_list), len(list_of_pools), + "Heketi volume list %s is not equal to gluster volume list %s" + % (node_ips, hostnames)) + + def test_heketi_node_info(self): + """Test heketi node info operation + """ + h_client, h_server = self.heketi_client_node, self.heketi_server_url + + # List heketi node + heketi_node_id_list = heketi_ops.heketi_node_list(h_client, h_server) + self.assertTrue(heketi_node_id_list, "Node Id list is empty.") + + for node_id in heketi_node_id_list: + node_info = heketi_ops.heketi_node_info( + h_client, h_server, node_id, json=True) + self.assertTrue(node_info, "Failed to retrieve the node info") + self.assertEqual( + node_info["id"], node_id, + "Failed to match node ID. Exp: %s, Act: %s" % ( + node_id, node_info["id"])) + + def test_heketi_node_states_enable_disable(self): + """Test node enable and disable functionality + """ + h_client, h_server = self.heketi_client_node, self.heketi_server_url + + node_list = heketi_ops.heketi_node_list(h_client, h_server) + online_hosts = [] + for node_id in node_list: + node_info = heketi_ops.heketi_node_info( + h_client, h_server, node_id, json=True) + if node_info["state"] == "online": + online_hosts.append(node_info) + + if len(online_hosts) < 3: + raise self.skipTest( + "This test can run only if online hosts are more than 2") + + # Disable n-3 nodes, in case we have n nodes + for node_info in online_hosts[3:]: + node_id = node_info["id"] + heketi_ops.heketi_node_disable(h_client, h_server, node_id) + self.addCleanup( + heketi_ops.heketi_node_enable, h_client, h_server, node_id) + + # Create volume when 3 nodes are online + vol_size = 1 + vol_info = heketi_ops.heketi_volume_create( + h_client, h_server, vol_size, json=True) + self.addCleanup( + heketi_ops.heketi_volume_delete, + h_client, h_server, vol_info['id']) + + node_id = online_hosts[0]['id'] + try: + heketi_ops.heketi_node_disable(h_client, h_server, node_id) + + # Try to create a volume, volume creation should fail + with self.assertRaises(AssertionError): + heketi_volume = heketi_ops.heketi_volume_create( + h_client, h_server, vol_size) + self.addCleanup( + heketi_ops.heketi_volume_delete, + h_client, h_server, heketi_volume["id"]) + finally: + # Enable heketi node + heketi_ops.heketi_node_enable(h_client, h_server, node_id) + + # Create volume when heketi node is enabled + vol_info = heketi_ops.heketi_volume_create( + h_client, h_server, vol_size, json=True) + heketi_ops.heketi_volume_delete(h_client, h_server, vol_info['id']) |