From 0a86502c92a4be3818b8b6abe3601af02b949cc6 Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Thu, 28 Nov 2019 17:57:44 +0530 Subject: Fix str/list/tuple distinguishing in library functions to support py3 We try to distinguish strings from other iterable object types in several our library functions and now it is not compatible with py3. The problem is that in py2 strings don't have "__iter__" method, but it exists in case of py3. So, fix it by using py2/3 compatible check for string types. Change-Id: I3f833b5e79f1563a3ae6a2bb9ae43d8919d82c30 --- .../openshiftstoragelibs/openshift_ops.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'openshift-storage-libs/openshiftstoragelibs/openshift_ops.py') diff --git a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py index 4e668d68..249a1b50 100644 --- a/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py +++ b/openshift-storage-libs/openshiftstoragelibs/openshift_ops.py @@ -712,7 +712,8 @@ def scale_dcs_pod_amount_and_wait(hostname, dc_names, pod_amount=1, "dc_name_n": ["pod_name_n_1", "pod_name_n_2", ..., "pod_name_n_n"], } """ - dc_names = dc_names if hasattr(dc_names, '__iter__') else [dc_names] + dc_names = ( + [dc_names] if isinstance(dc_names, six.string_types) else dc_names) dc_and_pod_names = {} namespace_arg = "--namespace=%s" % namespace if namespace else "" scale_cmd = "oc scale %s --replicas=%d dc/%s" % ( @@ -1827,8 +1828,10 @@ def oc_annotate(hostname, rtype, rname, annotations): Raises: AssertionError: In case adding annotations to resource fails. """ - annotations = annotations if hasattr( - annotations, '__iter__') else [annotations] + annotations = ( + [annotations] + if isinstance(annotations, six.string_types) + else annotations) for annotation in annotations: cmd = 'oc annotate %s %s %s --overwrite' % (rtype, rname, annotation) command.cmd_run(cmd, hostname=hostname) @@ -1885,9 +1888,9 @@ def oc_create_service_monitor(hostname, sm_name="heketi", ep_namespace_selector_matchnames if ep_namespace_selector_matchnames else ['glusterfs']) ep_namespace_selector_matchnames = ( - ep_namespace_selector_matchnames - if hasattr(ep_namespace_selector_matchnames, '__iter__') - else [ep_namespace_selector_matchnames]) + [ep_namespace_selector_matchnames] + if isinstance(ep_namespace_selector_matchnames, six.string_types) + else ep_namespace_selector_matchnames) ep_matchlabels = ( ep_matchlabels if ep_matchlabels else {"heketi": "storage-service"}) sm_data = json.dumps({ -- cgit