summaryrefslogtreecommitdiffstats
path: root/openshift-storage-libs/openshiftstoragelibs/baseclass.py
diff options
context:
space:
mode:
authorvamahaja <vamahaja@redhat.com>2019-09-03 18:40:23 +0530
committervamahaja <vamahaja@redhat.com>2019-09-13 17:28:10 +0530
commitc5c02f6402ebe010e8db71eda738857d73f7e83d (patch)
treeec11367a5a2d2282ba9e1fb1b48fe2d56562fba4 /openshift-storage-libs/openshiftstoragelibs/baseclass.py
parent610c21c8a73329a13167f47bf6de0cf66e57cd05 (diff)
Fix test cases which are failing to delete volume after test completion
In test case when we use large disk size, heketi takes time to create volume and due to timeout it gives error. Add fix in such test cases to check if volume created after getting an exception, get details of such volumes or raise exception in case it fails to create volume. Change-Id: I1c23a8c6558c23edf8947771e4f41a4bd3ffd66a Signed-off-by: vamahaja <vamahaja@redhat.com>
Diffstat (limited to 'openshift-storage-libs/openshiftstoragelibs/baseclass.py')
-rw-r--r--openshift-storage-libs/openshiftstoragelibs/baseclass.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/openshift-storage-libs/openshiftstoragelibs/baseclass.py b/openshift-storage-libs/openshiftstoragelibs/baseclass.py
index 554863ee..ae433872 100644
--- a/openshift-storage-libs/openshiftstoragelibs/baseclass.py
+++ b/openshift-storage-libs/openshiftstoragelibs/baseclass.py
@@ -1,7 +1,9 @@
import datetime
+import re
import unittest
from glusto.core import Glusto as g
+import six
from openshiftstoragelibs import command
from openshiftstoragelibs.exceptions import (
@@ -15,7 +17,10 @@ from openshiftstoragelibs.heketi_ops import (
hello_heketi,
heketi_blockvolume_delete,
heketi_blockvolume_info,
+ heketi_volume_create,
heketi_volume_delete,
+ heketi_volume_info,
+ heketi_volume_list,
)
from openshiftstoragelibs.openshift_ops import (
get_pod_name_from_dc,
@@ -41,6 +46,8 @@ from openshiftstoragelibs.openshift_storage_libs import (
from openshiftstoragelibs.openshift_version import get_openshift_version
from openshiftstoragelibs.waiter import Waiter
+HEKETI_VOLUME_REGEX = "Id:(.*).Cluster:(.*).Name:%s"
+
class BaseClass(unittest.TestCase):
"""Base class for test classes."""
@@ -308,6 +315,41 @@ class BaseClass(unittest.TestCase):
def create_dc_with_pvc(self, pvc_name, timeout=300, wait_step=10):
return self.create_dcs_with_pvc(pvc_name, timeout, wait_step)[pvc_name]
+ def create_heketi_volume_with_name_and_wait(
+ self, name, size, timeout=600, wait_step=10, **kwargs):
+ json = kwargs.get("json", False)
+
+ try:
+ h_volume_info = heketi_volume_create(
+ self.heketi_client_node, self.heketi_server_url,
+ size, name=name, **kwargs)
+ except Exception as e:
+ if ('more required' in six.text_type(e)
+ or ('Failed to allocate new volume' in six.text_type(e))):
+ raise
+
+ for w in Waiter(timeout, wait_step):
+ h_volumes = heketi_volume_list(
+ self.heketi_client_node, self.heketi_server_url)
+ h_volume_match = re.search(
+ HEKETI_VOLUME_REGEX % name, h_volumes)
+ if h_volume_match:
+ h_volume_info = heketi_volume_info(
+ self.heketi_client_node, self.heketi_server_url,
+ h_volume_match.group(1), json=json)
+ break
+
+ if w.expired:
+ g.log.info(
+ "Heketi volume with name %s not created in 600 sec" % name)
+ raise
+
+ self.addCleanup(
+ heketi_volume_delete, self.heketi_client_node,
+ self.heketi_server_url, h_volume_info["id"])
+
+ return h_volume_info
+
def is_containerized_gluster(self):
cmd = ("oc get pods --no-headers -l glusterfs-node=pod "
"-o=custom-columns=:.spec.nodeName")