diff options
-rw-r--r-- | openshift-storage-libs/openshiftstoragelibs/heketi_ops.py | 33 | ||||
-rw-r--r-- | tests/functional/heketi/test_server_state_examine_gluster.py | 22 |
2 files changed, 55 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py index d2fa6569..fb872370 100644 --- a/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py +++ b/openshift-storage-libs/openshiftstoragelibs/heketi_ops.py @@ -1591,3 +1591,36 @@ def heketi_server_operation_cleanup( "after %s second" % timeout) g.log.error(err_msg) raise exceptions.ExecutionError(err_msg) + + +def heketi_db_check(heketi_client_node, heketi_server_url, **kwargs): + """Execute 'heketi db check' command. + + Args: + - heketi_client_node (str): Node where we want to run our commands. + - heketi_server_url (str): This is a heketi server url. + + Raises: + NotImplementedError: if heketi version is not expected + exceptions.AssertionError: if command fails. + + Returns: + dictionary: if successful + """ + + version = heketi_version.get_heketi_version(heketi_client_node) + if version < '8.0.0-7': + msg = "heketi-client package %s does not support db check" % ( + version.v_str) + g.log.error(msg) + raise NotImplementedError(msg) + + heketi_server_url, json_arg, secret, user = _set_heketi_global_flags( + heketi_server_url, **kwargs) + + # output is always json-like and we do not need to provide "--json" CLI arg + cmd = "heketi-cli db check %s %s %s" % ( + heketi_server_url, user, secret) + cmd = TIMEOUT_PREFIX + cmd + out = heketi_cmd_run(heketi_client_node, cmd) + return json.loads(out) diff --git a/tests/functional/heketi/test_server_state_examine_gluster.py b/tests/functional/heketi/test_server_state_examine_gluster.py index 22352024..31859bd0 100644 --- a/tests/functional/heketi/test_server_state_examine_gluster.py +++ b/tests/functional/heketi/test_server_state_examine_gluster.py @@ -43,3 +43,25 @@ class TestHeketiServerStateExamineGluster(BaseClass): self.assertNotIn( "heketi volume list matches with volume list of all nodes", out['report']) + + def test_compare_real_vol_count_with_db_check_info(self): + """Validate volumes using heketi db check""" + + # Create volume + vol = heketi_ops.heketi_volume_create( + self.heketi_client_node, self.heketi_server_url, 1, json=True) + self.addCleanup( + heketi_ops.heketi_volume_delete, self.heketi_client_node, + self.heketi_server_url, vol['id']) + + # Check heketi db + db_result = heketi_ops.heketi_db_check( + self.heketi_client_node, self.heketi_server_url) + vol_count = db_result["volumes"]["total"] + vol_list = heketi_ops.heketi_volume_list( + self.heketi_client_node, self.heketi_server_url, json=True) + count = len(vol_list["volumes"]) + self.assertEqual( + count, vol_count, "Volume count doesn't match expected" + " result %s, actual result is %s" % ( + count, vol_count)) |