From e354751fe37492e2c7f0053bb2aabe1f5e071d49 Mon Sep 17 00:00:00 2001 From: SushilG96 Date: Mon, 16 Dec 2019 14:40:51 +0530 Subject: Add TC for checking pending operations in heketidb Create volume and see the pending operations of volume and bricks in heketidb and verify that after creation count is changed. Change-Id: I2d73f82bde422fdffc1fbbdc14564a0c8ffa99aa --- .../functional/heketi/test_heketi_create_volume.py | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'tests/functional/heketi/test_heketi_create_volume.py') diff --git a/tests/functional/heketi/test_heketi_create_volume.py b/tests/functional/heketi/test_heketi_create_volume.py index 6e25895e..79d54f48 100644 --- a/tests/functional/heketi/test_heketi_create_volume.py +++ b/tests/functional/heketi/test_heketi_create_volume.py @@ -1,14 +1,24 @@ +try: + # py2/3 + import simplejson as json +except ImportError: + # py2 + import json + from glusto.core import Glusto as g from glustolibs.gluster.volume_ops import get_volume_list, get_volume_info +import mock import six from openshiftstoragelibs.baseclass import BaseClass +from openshiftstoragelibs import command from openshiftstoragelibs.heketi_ops import ( get_heketi_volume_and_brick_count_list, heketi_blockvolume_create, heketi_blockvolume_delete, heketi_cluster_delete, heketi_cluster_list, + heketi_db_check, heketi_node_delete, heketi_node_info, heketi_node_list, @@ -19,7 +29,9 @@ from openshiftstoragelibs.heketi_ops import ( heketi_volume_list, ) from openshiftstoragelibs.openshift_ops import cmd_run_on_gluster_pod_or_node +from openshiftstoragelibs import exceptions from openshiftstoragelibs import podcmd +from openshiftstoragelibs import waiter class TestHeketiVolume(BaseClass): @@ -358,3 +370,65 @@ class TestHeketiVolume(BaseClass): msg = "volume: %s not found in the volume list: %s" % ( volume_name, g_vol_list) self.assertIn(volume_name, g_vol_list, msg) + + def test_verify_pending_entries_in_db(self): + """Verify pending entries of volumes and bricks in db during + volume creation from heketi side + """ + h_volume_size = 100 + h_db_chk_bfr_v_creation = heketi_db_check( + self.heketi_client_node, self.heketi_server_url) + + if (h_db_chk_bfr_v_creation["bricks"]["pending"] != 0 + or h_db_chk_bfr_v_creation["volumes"]["pending"] != 0): + self.skipTest( + "Skip TC due to unexpected bricks/volumes pending operations") + + # Verify bricks and volume pending operation before creation + self.assertEqual(h_db_chk_bfr_v_creation["bricks"]["pending"], 0) + self.assertEqual(h_db_chk_bfr_v_creation["volumes"]["pending"], 0) + + # Temporary replace g.run with g.async_run in heketi_volume_create func + # to be able to run it in background.Also, avoid parsing the output as + # it won't be json at that moment. Parse it after reading the async + # operation results. + + def run_async(cmd, hostname, raise_on_error=True): + return g.run_async(host=hostname, command=cmd) + + with mock.patch.object( + json, 'loads', side_effect=(lambda j: j)): + with mock.patch.object(command, 'cmd_run', side_effect=run_async): + h_vol_creation_async_op = heketi_volume_create( + self.heketi_client_node, + self.heketi_server_url, h_volume_size, json=True) + + for w in waiter.Waiter(timeout=5, interval=1): + h_db_chk_during_v_creation = heketi_db_check( + self.heketi_client_node, self.heketi_server_url) + if h_db_chk_during_v_creation["bricks"]["pending"] != 0: + break + if w.expired: + err_msg = "No pending operation in Heketi db" + g.log.error(err_msg) + raise exceptions.ExecutionError(err_msg) + + retcode, stdout, stderr = h_vol_creation_async_op.async_communicate() + heketi_vol = json.loads(stdout) + volume_id = heketi_vol["id"] + self.addCleanup( + heketi_volume_delete, self.heketi_client_node, + self.heketi_server_url, volume_id, raise_on_error=True) + + # Verify volume pending operation during creation + self.assertFalse(h_db_chk_during_v_creation["bricks"]["pending"] % 3) + self.assertEqual( + h_db_chk_bfr_v_creation["volumes"]["pending"] + 1, + h_db_chk_during_v_creation["volumes"]["pending"]) + + h_db_chk_after_v_creation = heketi_db_check( + self.heketi_client_node, self.heketi_server_url) + + # Verify bricks and volume pending operation after creation + self.assertEqual(h_db_chk_after_v_creation["bricks"]["pending"], 0) + self.assertEqual(h_db_chk_after_v_creation["volumes"]["pending"], 0) -- cgit