From 86d16d2a98af540ba458721edc2ac8a530c01635 Mon Sep 17 00:00:00 2001 From: kshithijiyer Date: Wed, 8 Jan 2020 15:53:31 +0530 Subject: [py2to3] Change str to list in isinstance() Use 'list' object type in comparisons instead of 'str' Because it is differently treated in py2 and py3. Example: In py2 isinstance(u'foo', str) is False In py3 isinstance(u'foo', str) is True Change-Id: I7663d42494bf59d74550ff4897379d35cc357db4 Signed-off-by: kshithijiyer --- glustolibs-gluster/glustolibs/gluster/block_ops.py | 2 +- .../glustolibs/gluster/brick_libs.py | 6 +++--- .../glustolibs/gluster/gluster_base_class.py | 2 +- glustolibs-gluster/glustolibs/gluster/heal_libs.py | 6 +++--- glustolibs-gluster/glustolibs/gluster/lib_utils.py | 24 +++++++++++----------- glustolibs-gluster/glustolibs/gluster/peer_ops.py | 6 +++--- .../glustolibs/gluster/quota_libs.py | 2 +- .../glustolibs/gluster/snap_scheduler.py | 2 +- .../glustolibs/gluster/tiering_ops.py | 4 ++-- .../glustolibs/gluster/volume_libs.py | 6 +++--- .../glustolibs/gluster/volume_ops.py | 2 +- 11 files changed, 31 insertions(+), 31 deletions(-) diff --git a/glustolibs-gluster/glustolibs/gluster/block_ops.py b/glustolibs-gluster/glustolibs/gluster/block_ops.py index 8e6ff25fe..f51c3e4b2 100644 --- a/glustolibs-gluster/glustolibs/gluster/block_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/block_ops.py @@ -56,7 +56,7 @@ def block_create(mnode, volname, blockname, servers, size=None, block_create(mnode, volname, blockname, servers, size, **block_args_info) """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] ha = auth = prealloc = storage = ring_buffer = '' diff --git a/glustolibs-gluster/glustolibs/gluster/brick_libs.py b/glustolibs-gluster/glustolibs/gluster/brick_libs.py index f84085969..0ec9e879f 100644 --- a/glustolibs-gluster/glustolibs/gluster/brick_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/brick_libs.py @@ -179,10 +179,10 @@ def bring_bricks_offline(volname, bricks_list, """ if bring_bricks_offline_methods is None: bring_bricks_offline_methods = ['service_kill'] - elif isinstance(bring_bricks_offline_methods, str): + elif not isinstance(bring_bricks_offline_methods, list): bring_bricks_offline_methods = [bring_bricks_offline_methods] - if isinstance(bricks_list, str): + if not isinstance(bricks_list, list): bricks_list = [bricks_list] node_list = [] @@ -281,7 +281,7 @@ def bring_bricks_online(mnode, volname, bricks_list, if bring_bricks_online_methods is None: bring_bricks_online_methods = ['glusterd_restart', 'volume_start_force'] - elif isinstance(bring_bricks_online_methods, str): + elif not isinstance(bring_bricks_online_methods, list): bring_bricks_online_methods = [bring_bricks_online_methods] g.log.info("Bringing bricks '%s' online with '%s'", diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py index 858741abd..a8b737f04 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py @@ -161,7 +161,7 @@ class GlusterBaseClass(TestCase): list: List of IP's corresponding to the hostnames of nodes. """ nodes_ips = [] - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] for node in nodes: try: diff --git a/glustolibs-gluster/glustolibs/gluster/heal_libs.py b/glustolibs-gluster/glustolibs/gluster/heal_libs.py index 8b7c3b437..2b0e9ed33 100755 --- a/glustolibs-gluster/glustolibs/gluster/heal_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/heal_libs.py @@ -341,7 +341,7 @@ def get_self_heal_daemon_pid(nodes): """ glustershd_pids = {} _rc = True - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] cmd = r"pgrep -f glustershd | grep -v ^$$\$" g.log.info("Executing cmd: %s on node %s" % (cmd, nodes)) @@ -447,7 +447,7 @@ def is_shd_daemonized(nodes, timeout=120): """ counter = 0 flag = 0 - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] while counter < timeout: ret, pids = get_self_heal_daemon_pid(nodes) @@ -483,7 +483,7 @@ def bring_self_heal_daemon_process_offline(nodes): bool : True on successfully bringing self-heal daemon process offline. False otherwise """ - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] failed_nodes = [] diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py index f8b6cc720..e1a9182aa 100755 --- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py +++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py @@ -308,7 +308,7 @@ def get_servers_bricks_dict(servers, servers_info): get_servers_bricks_dict(g.config['servers'], g.config['servers_info']) """ servers_bricks_dict = OrderedDict() - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] for server in servers: server_info = servers_info[server] @@ -342,7 +342,7 @@ def get_servers_used_bricks_dict(mnode, servers): get_servers_used_bricks_dict(g.config['servers'][0]['host'], g.config['servers']) """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] servers_used_bricks_dict = OrderedDict() @@ -389,7 +389,7 @@ def get_servers_unused_bricks_dict(mnode, servers, servers_info): g.config['servers'], g.config['servers_info']) """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] dict1 = get_servers_bricks_dict(servers, servers_info) dict2 = get_servers_used_bricks_dict(mnode, servers) @@ -429,7 +429,7 @@ def form_bricks_list(mnode, volname, number_of_bricks, servers, servers_info): form_bricks_path(g.config['servers'](0), "testvol", 6, g.config['servers'], g.config['servers_info']) """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] dict_index = 0 bricks_list = [] @@ -483,7 +483,7 @@ def is_rhel6(servers): Returns: bool:Returns True, if its RHEL-6 else returns false """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] results = g.run_parallel(servers, "cat /etc/redhat-release") @@ -509,7 +509,7 @@ def is_rhel7(servers): Returns: bool:Returns True, if its RHEL-7 else returns false """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] results = g.run_parallel(servers, "cat /etc/redhat-release") @@ -680,7 +680,7 @@ def install_epel(servers): Example: install_epel(["abc.com", "def.com"]) """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] rt = True @@ -734,7 +734,7 @@ def inject_msg_in_logs(nodes, log_msg, list_of_dirs=None, list_of_files=None): Returns: bool: True if successfully injected msg on all log files. """ - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] if list_of_dirs is None: @@ -858,10 +858,10 @@ def remove_service_from_firewall(nodes, firewall_service, permanent=False): bool: True|False(Firewall removed or Failed) """ - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] - if isinstance(firewall_service, str): + if not isinstance(firewall_service, list): firewall_service = [firewall_service] _rc = True @@ -902,10 +902,10 @@ def add_services_to_firewall(nodes, firewall_service, permanent=False): bool: True|False(Firewall Enabled or Failed) """ - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] - if isinstance(firewall_service, str): + if not isinstance(firewall_service, list): firewall_service = [firewall_service] _rc = True diff --git a/glustolibs-gluster/glustolibs/gluster/peer_ops.py b/glustolibs-gluster/glustolibs/gluster/peer_ops.py index 55385e8a7..988a13cb7 100644 --- a/glustolibs-gluster/glustolibs/gluster/peer_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/peer_ops.py @@ -139,7 +139,7 @@ def peer_probe_servers(mnode, servers, validate=True, time_delay=10): Returns: bool: True on success and False on failure. """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] else: servers = servers[:] @@ -195,7 +195,7 @@ def peer_detach_servers(mnode, servers, force=False, validate=True, Returns: bool: True on success and False on failure. """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] else: servers = servers[:] @@ -367,7 +367,7 @@ def is_peer_connected(mnode, servers): bool : True on success (peer in cluster and connected), False on failure. """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] else: servers = servers[:] diff --git a/glustolibs-gluster/glustolibs/gluster/quota_libs.py b/glustolibs-gluster/glustolibs/gluster/quota_libs.py index 279b90203..7462b69c3 100755 --- a/glustolibs-gluster/glustolibs/gluster/quota_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/quota_libs.py @@ -97,7 +97,7 @@ def quota_fetch_daemon_pid(nodes): """ quotad_pids = {} _rc = True - if isinstance(nodes, str): + if not isinstance(nodes, list): nodes = [nodes] cmd = r"pgrep -f quotad | grep -v ^$$\$" g.log.info("Executing cmd: %s on node %s" % (cmd, nodes)) diff --git a/glustolibs-gluster/glustolibs/gluster/snap_scheduler.py b/glustolibs-gluster/glustolibs/gluster/snap_scheduler.py index 4493cf40f..f0ccbf547 100644 --- a/glustolibs-gluster/glustolibs/gluster/snap_scheduler.py +++ b/glustolibs-gluster/glustolibs/gluster/snap_scheduler.py @@ -36,7 +36,7 @@ def scheduler_init(servers): scheduler_init("abc.com") """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] cmd = "snap_scheduler.py init" diff --git a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py index 7e48a48c7..357b3d471 100644 --- a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py @@ -48,7 +48,7 @@ def add_extra_servers_to_cluster(mnode, extra_servers): add_extra_servers_to_cluster("abc.com", ['peer_node1','peer_node2']) """ - if isinstance(extra_servers, str): + if not isinstance(extra_servers, list): extra_servers = [extra_servers] ret = start_glusterd(servers=extra_servers) @@ -97,7 +97,7 @@ def tier_attach(mnode, volname, num_bricks_to_add, extra_servers, tier_attach("abc.com", testvol, '2', ['extra_server1','extra_server2'], extra_server_info) """ - if isinstance(extra_servers, str): + if not isinstance(extra_servers, list): extra_servers = [extra_servers] replica = int(replica) diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py index 36e1fc10c..e5a4f4f1c 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py @@ -1143,7 +1143,7 @@ def enable_and_validate_volume_options(mnode, volname, volume_options_list, bool: True when enabling and validating all volume options is successful. False otherwise """ - if isinstance(volume_options_list, str): + if not isinstance(volume_options_list, list): volume_options_list = [volume_options_list] for option in volume_options_list: @@ -1864,7 +1864,7 @@ def replace_brick_from_volume(mnode, volname, servers, all_servers_info, bool: True if replacing brick from the volume is successful. False otherwise. """ - if isinstance(servers, str): + if not isinstance(servers, list): servers = [servers] # Check if volume exists @@ -2190,7 +2190,7 @@ def get_files_and_dirs_from_brick(brick_node, brick_path, raise RuntimeError("Not specified object type to find dir/files") skip_items = ["'.glusterfs'", "'.trashcan'"] - if isinstance(skip, str): + if not isinstance(skip, list): skip_items.append("'%s'" % skip) exclude_pattern = ' '.join([' | grep -ve {}'.format(item) diff --git a/glustolibs-gluster/glustolibs/gluster/volume_ops.py b/glustolibs-gluster/glustolibs/gluster/volume_ops.py index 0b3c94b07..9bc86498c 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_ops.py @@ -573,7 +573,7 @@ def set_volume_options(mnode, volname, options): # Check if group options are specified. if 'group' in volume_options: group_options = volume_options.pop('group') - if isinstance(group_options, str): + if not isinstance(group_options, list): group_options = [group_options] for group_option in group_options: cmd = ("gluster volume set %s group %s --mode=script" % -- cgit