summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSushilG96 <guptarahul201010@gmail.com>2019-12-16 14:40:51 +0530
committerSushilG96 <guptarahul201010@gmail.com>2020-01-07 18:11:19 +0530
commite354751fe37492e2c7f0053bb2aabe1f5e071d49 (patch)
tree18f6ac23767da86db510e736ae817fd36e42bea3
parent5ae45abc159a37af04c43acf45dd4b0a21f323a2 (diff)
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
-rw-r--r--tests/functional/heketi/test_heketi_create_volume.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/functional/heketi/test_heketi_create_volume.py b/tests/functional/heketi/test_heketi_create_volume.py
index 6e25895..79d54f4 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)