From 169bcbdea5b7e6cf7ba6135627a0ecd45fb7613e Mon Sep 17 00:00:00 2001 From: mandaltapesh Date: Mon, 15 Jan 2018 15:48:10 +0530 Subject: Adding delete volumes function Change-Id: I36dfea0d9c1715a015fc14183f1dce39cbc20eb2 Signed-off-by: mandaltapesh --- cns-libs/cnslibs/common/heketi_libs.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/cns-libs/cnslibs/common/heketi_libs.py b/cns-libs/cnslibs/common/heketi_libs.py index 0e913c29..79fcd69a 100644 --- a/cns-libs/cnslibs/common/heketi_libs.py +++ b/cns-libs/cnslibs/common/heketi_libs.py @@ -11,7 +11,9 @@ from collections import OrderedDict from cnslibs.common.exceptions import ExecutionError, ConfigError from cnslibs.common.heketi_ops import (setup_heketi_ssh_key, modify_heketi_executor, - export_heketi_cli_server, hello_heketi) + export_heketi_cli_server, + hello_heketi, + heketi_volume_delete) from cnslibs.common.openshift_ops import (oc_login, switch_oc_project, get_ocp_gluster_pod_names) @@ -102,6 +104,29 @@ class HeketiBaseClass(unittest.TestCase): msg = "Starting Test : %s : %s" % (self.id(), self.glustotest_run_id) g.log.info(msg) + def delete_volumes(self, volume_ids): + """ + Delete volumes by their IDs and raise error with list of failures + Input: (volume_ids) It can be a single volume ID + or a list of volume IDs + """ + errored_ids = [] + + if not isinstance(volume_ids, (list, set, tuple)): + volume_ids = [volume_ids] + + for volume_id in volume_ids: + out = heketi_volume_delete( + self.heketi_client_node, self.heketi_server_url, volume_id) + output_str = 'Volume %s deleted' % volume_id + if output_str not in out: + errored_ids.append(volume_id) + + if errored_ids: + raise ExecutionError( + "Failed to delete following heketi volumes: " + "%s" % ',\n'.join(errored_ids)) + def tearDown(self): super(HeketiBaseClass, self).tearDown() msg = "Ending Test: %s : %s" % (self.id(), self.glustotest_run_id) -- cgit