From 3070312c13e02cace3041d3429b0c31fc10b73ee Mon Sep 17 00:00:00 2001 From: Nigel Babu Date: Wed, 16 Nov 2016 17:36:15 +0530 Subject: Clean up pyflakes and pep8 errors Change-Id: Ibdd092118d3bb912716c46fd278ef3c680a6e742 Signed-off-by: Nigel Babu --- .../glustolibs/gluster/bitrot_ops.py | 11 ++-- .../glustolibs/gluster/brick_libs.py | 4 +- glustolibs-gluster/glustolibs/gluster/brick_ops.py | 1 + .../glustolibs/gluster/gluster_base_class.py | 10 ++-- .../glustolibs/gluster/gluster_init.py | 10 ++-- glustolibs-gluster/glustolibs/gluster/heal_libs.py | 3 +- glustolibs-gluster/glustolibs/gluster/heal_ops.py | 3 -- glustolibs-gluster/glustolibs/gluster/lib_utils.py | 61 +++++++++++----------- glustolibs-gluster/glustolibs/gluster/peer_ops.py | 1 - glustolibs-gluster/glustolibs/gluster/quota_ops.py | 2 - .../glustolibs/gluster/rebalance_ops.py | 1 - glustolibs-gluster/glustolibs/gluster/samba_ops.py | 3 -- glustolibs-gluster/glustolibs/gluster/snap_ops.py | 2 - .../glustolibs/gluster/tiering_ops.py | 1 + glustolibs-gluster/glustolibs/gluster/uss_ops.py | 1 + .../glustolibs/gluster/volume_libs.py | 28 ++++------ .../glustolibs/gluster/volume_ops.py | 12 ++--- 17 files changed, 66 insertions(+), 88 deletions(-) (limited to 'glustolibs-gluster/glustolibs/gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/bitrot_ops.py b/glustolibs-gluster/glustolibs/gluster/bitrot_ops.py index 6eed10e19..cab205cbb 100644 --- a/glustolibs-gluster/glustolibs/gluster/bitrot_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/bitrot_ops.py @@ -27,11 +27,6 @@ from glustolibs.gluster.lib_utils import (get_pathinfo, import time import re -try: - import xml.etree.cElementTree as etree -except ImportError: - import xml.etree.ElementTree as etree - # Global variables SCRUBBER_TIMEOUT = 100 @@ -174,7 +169,7 @@ def is_file_signed(mnode, filename, volname, expected_file_version=None): g.log.error("File version mismatch in signature.Filename: %s ." "Expected file version: %s.Actual file version: %s" % (filename, expected_file_version, - actual_signature_file_version)) + actual_signature_file_version)) return False actual_file_signature = ''.join(re.findall('.{16}', @@ -185,7 +180,7 @@ def is_file_signed(mnode, filename, volname, expected_file_version=None): g.log.error("File signature mismatch. File name: %s . Expected " "file signature: %s. Actual file signature: %s" % (filename, expected_file_signature, - actual_file_signature)) + actual_file_signature)) return False return True @@ -572,7 +567,7 @@ def get_scrub_status(mnode, volname): corrupt_list = [] for node in temp_list: tmp_reg = ('Node: (\S+)\n.*Error count.*' - + 'Corrupted object.*?:(.*)\n=.*') + 'Corrupted object.*?:(.*)\n=.*') m = re.search(tmp_reg, node, re.S) if m is None: g.log.error("Mismatch in cli output when bad file" diff --git a/glustolibs-gluster/glustolibs/gluster/brick_libs.py b/glustolibs-gluster/glustolibs/gluster/brick_libs.py index 617419d9e..508eae6a9 100644 --- a/glustolibs-gluster/glustolibs/gluster/brick_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/brick_libs.py @@ -22,7 +22,6 @@ import random from glusto.core import Glusto as g from glustolibs.gluster.volume_ops import (get_volume_info, get_volume_status) -from glustolibs.gluster.volume_libs import get_subvols def get_all_bricks(mnode, volname): @@ -232,7 +231,7 @@ def bring_bricks_online(mnode, volname, bricks_list, False otherwise """ rc = True - failed_to_brick_online_list = [] + failed_to_bring_online_list = [] for brick in bricks_list: bring_brick_online_method = random.choice(bring_bricks_online_methods) if bring_brick_online_method == 'glusterd_restart': @@ -337,6 +336,7 @@ def are_bricks_online(mnode, volname, bricks_list): g.log.info("All the bricks %s are online" % bricks_list) return True + def get_offline_bricks_list(mnode, volname): """Get list of bricks which are offline. diff --git a/glustolibs-gluster/glustolibs/gluster/brick_ops.py b/glustolibs-gluster/glustolibs/gluster/brick_ops.py index ae55b6851..61c86fa75 100644 --- a/glustolibs-gluster/glustolibs/gluster/brick_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/brick_ops.py @@ -21,6 +21,7 @@ from glusto.core import Glusto as g + def add_brick(mnode, volname, bricks_list, replica=None): """Add Bricks specified in the bricks_list to the volume. diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py index 276e51db7..c17946249 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_base_class.py @@ -297,7 +297,7 @@ class GlusterVolumeBaseClass(GlusterBaseClass): # Validate if peer is connected from all the servers for server in cls.servers: ret = is_peer_connected(server, cls.servers) - assert (ret == True), "Validating Peers to be in Cluster Failed" + assert (ret is True), "Validating Peers to be in Cluster Failed" # Print Peer Status from mnode _, _, _ = peer_status(cls.mnode) @@ -306,7 +306,7 @@ class GlusterVolumeBaseClass(GlusterBaseClass): ret = setup_volume(mnode=cls.mnode, all_servers_info=cls.all_servers_info, volume_config=cls.volume, force=True) - assert (ret == True), "Setup volume %s failed" % cls.volname + assert (ret is True), "Setup volume %s failed" % cls.volname time.sleep(10) # Print Volume Info and Status @@ -342,7 +342,7 @@ class GlusterVolumeBaseClass(GlusterBaseClass): (mount_obj.server_system, mount_obj.volname, mount_obj.client_system, mount_obj.mountpoint)) rc = False - assert (rc == True), ("Mounting volume %s on few clients failed" % + assert (rc is True), ("Mounting volume %s on few clients failed" % cls.volname) @classmethod @@ -359,9 +359,9 @@ class GlusterVolumeBaseClass(GlusterBaseClass): mount_obj.client_system, mount_obj.mountpoint) ) rc = False - assert (rc == True), ("Unmount of all mounts are not successful") + assert (rc is True), ("Unmount of all mounts are not successful") # Cleanup volume if cleanup_vol: ret = cleanup_volume(mnode=cls.mnode, volname=cls.volname) - assert (ret == True), ("cleanup volume %s failed" % cls.volname) + assert (ret is True), ("cleanup volume %s failed" % cls.volname) diff --git a/glustolibs-gluster/glustolibs/gluster/gluster_init.py b/glustolibs-gluster/glustolibs/gluster/gluster_init.py index 182080717..371e187ea 100644 --- a/glustolibs-gluster/glustolibs/gluster/gluster_init.py +++ b/glustolibs-gluster/glustolibs/gluster/gluster_init.py @@ -21,6 +21,7 @@ """ from glusto.core import Glusto as g + def start_glusterd(servers): """Starts glusterd on specified servers if they are not running. @@ -46,6 +47,7 @@ def start_glusterd(servers): return True + def stop_glusterd(servers): """Stops the glusterd on specified servers. @@ -97,6 +99,7 @@ def restart_glusterd(servers): return True + def is_glusterd_running(servers): """Checks the glusterd status on specified servers. @@ -122,13 +125,14 @@ def is_glusterd_running(servers): g.log.error("glusterd is not running on the server %s", server) rc = 1 if cmd2_results[server][0] == 0: - g.log.error("PID of glusterd is alive and status is not running") + g.log.error("PID of glusterd is alive and status is not " + "running") rc = -1 return rc -#TODO: THIS IS NOT IMPLEMENTED YET. PLEASE DO THIS MANUALLY -# TILL WE IMPLEMENT THIS PART +# TODO: THIS IS NOT IMPLEMENTED YET. PLEASE DO THIS MANUALLY +# TILL WE IMPLEMENT THIS def env_setup_servers(servers): """Set up environment on all the specified servers. diff --git a/glustolibs-gluster/glustolibs/gluster/heal_libs.py b/glustolibs-gluster/glustolibs/gluster/heal_libs.py index 2ad408c57..4d5594a11 100644 --- a/glustolibs-gluster/glustolibs/gluster/heal_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/heal_libs.py @@ -20,10 +20,9 @@ Description: Module for gluster heal related helper functions. """ -import os import time from glusto.core import Glusto as g -from glustolibs.gluster.volume_ops import (get_volume_info, get_volume_status) +from glustolibs.gluster.volume_ops import get_volume_status try: import xml.etree.cElementTree as etree except ImportError: diff --git a/glustolibs-gluster/glustolibs/gluster/heal_ops.py b/glustolibs-gluster/glustolibs/gluster/heal_ops.py index 1bf8d2f87..8c0b6c820 100644 --- a/glustolibs-gluster/glustolibs/gluster/heal_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/heal_ops.py @@ -19,10 +19,7 @@ Description: Module for gluster heal operations. """ -import os -import time from glusto.core import Glusto as g -from glustolibs.gluster.volume_ops import (get_volume_info, get_volume_status) try: import xml.etree.cElementTree as etree except ImportError: diff --git a/glustolibs-gluster/glustolibs/gluster/lib_utils.py b/glustolibs-gluster/glustolibs/gluster/lib_utils.py index 19587894f..d1329d688 100644 --- a/glustolibs-gluster/glustolibs/gluster/lib_utils.py +++ b/glustolibs-gluster/glustolibs/gluster/lib_utils.py @@ -31,11 +31,6 @@ import random ONE_GB_BYTES = 1073741824.0 -try: - import xml.etree.cElementTree as etree -except ImportError: - import xml.etree.ElementTree as etree - def append_string_to_file(mnode, filename, str_to_add_in_file, user="root"): @@ -364,7 +359,7 @@ def get_servers_used_bricks_dict(mnode, servers): for item in list1: x = re.search(':(.*)/(.*)', item) list2 = x.group(1).strip().split(':') - if servers_used_bricks_dict.has_key(list2[0]): + if list2[0] in servers_used_bricks_dict: value = servers_used_bricks_dict[list2[0]] value.append(list2[1]) else: @@ -400,7 +395,7 @@ def get_servers_unused_bricks_dict(mnode, servers, servers_info): dict2 = get_servers_used_bricks_dict(mnode, servers) servers_unused_bricks_dict = OrderedDict() for key, value in dict1.items(): - if dict2.has_key(key): + if key in dict2: unused_bricks = list(set(value) - set(dict2[key])) servers_unused_bricks_dict[key] = unused_bricks else: @@ -457,8 +452,9 @@ def form_bricks_list(mnode, volname, number_of_bricks, servers, servers_info): for num in range(brick_index, brick_index + number_of_bricks): # current_server is the server from which brick path will be created current_server = servers_unused_bricks_dict.keys()[dict_index] - current_server_unused_bricks_list = (servers_unused_bricks_dict.values() - [dict_index]) + current_server_unused_bricks_list = ( + servers_unused_bricks_dict.values()[dict_index] + ) brick_path = '' if current_server_unused_bricks_list: brick_path = ("%s:%s/%s_brick%s" % @@ -476,6 +472,7 @@ def form_bricks_list(mnode, volname, number_of_bricks, servers, servers_info): return bricks_list + def is_rhel6(servers): """Function to get whether the server is RHEL-6 @@ -491,10 +488,11 @@ def is_rhel6(servers): for server, ret_values in results.iteritems(): retcode, out, err = ret_values if retcode != 0: - g.log.error("Unable to get the RHEL version on server %s" %(server,)) + g.log.error("Unable to get the RHEL version on server %s" % + (server)) rc = False - if retcode == 0 and not "release 6" in out: - g.log.error("Server %s is not RHEL-6" %(server,)) + if retcode == 0 and "release 6" not in out: + g.log.error("Server %s is not RHEL-6" % (server)) rc = False return rc @@ -514,10 +512,11 @@ def is_rhel7(servers): for server, ret_values in results.iteritems(): retcode, out, err = ret_values if retcode != 0: - g.log.error("Unable to get the RHEL version on server %s" %(server,)) + g.log.error("Unable to get the RHEL version on server %s" % + (server)) rc = False - if retcode == 0 and not "release 7" in out: - g.log.error("Server %s is not RHEL-7" %(server,)) + if retcode == 0 and "release 7" not in out: + g.log.error("Server %s is not RHEL-7" % (server)) rc = False return rc @@ -541,12 +540,12 @@ def get_disk_usage(mnode, path, user="root"): get_disk_usage("abc.com", "/mnt/glusterfs") """ - inst = random.randint(10,100) + inst = random.randint(10, 100) conn = g.rpyc_get_connection(mnode, user=user, instance=inst) if conn is None: g.log.error("Failed to get rpyc connection") return None - cmd = 'stat -f '+ path + cmd = 'stat -f ' + path p = conn.modules.subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() @@ -568,19 +567,20 @@ def get_disk_usage(mnode, path, user="root"): keys = ['b_size', 'b_total', 'b_free', 'b_avail', 'i_total', 'i_free'] val = list(match.groups()) info = dict(zip(keys, val)) - usage_info['total'] = ((int(info['b_total']) * int(info['b_size'])) - / ONE_GB_BYTES) - usage_info['free'] = ((int(info['b_free']) * int(info['b_size'])) - / ONE_GB_BYTES) - usage_info['used_percent'] = (100 - (100.0 * usage_info['free'] - / usage_info['total'])) + usage_info['total'] = ((int(info['b_total']) * int(info['b_size'])) / + ONE_GB_BYTES) + usage_info['free'] = ((int(info['b_free']) * int(info['b_size'])) / + ONE_GB_BYTES) + usage_info['used_percent'] = (100 - (100.0 * usage_info['free'] / + usage_info['total'])) usage_info['total_inode'] = int(info['i_total']) usage_info['free_inode'] = int(info['i_free']) - usage_info['used_percent_inode'] = (100 - (100.0 * usage_info['free_inode'] - / usage_info['total_inode'])) + usage_info['used_percent_inode'] = (100 - (100.0 * + usage_info['free_inode'] / + usage_info['total_inode'])) usage_info['used'] = usage_info['total'] - usage_info['free'] usage_info['used_inode'] = (usage_info['total_inode'] - - usage_info['free_inode']) + usage_info['free_inode']) return usage_info @@ -636,11 +636,9 @@ def check_if_dir_is_filled(mnode, dirname, percent_to_fill, used = output['used_percent'] if int(percent_to_fill) > int(used): - remaining_to_fill = int(percent_to_fill) - int(used) - g.log.info("Directory %s used percent: %s" - %(dirname, used)) - if int(percent_to_fill) <= int(used): + % (dirname, used)) + if int(percent_to_fill) <= int(used): flag = 1 g.rpyc_close_connection(host=mnode) break @@ -657,6 +655,7 @@ def check_if_dir_is_filled(mnode, dirname, percent_to_fill, g.log.info("Directory is filled with given percentage") return True else: - g.log.info("Timeout reached before filling directory with given percentage") + g.log.info("Timeout reached before filling directory with given" + " percentage") return True return False diff --git a/glustolibs-gluster/glustolibs/gluster/peer_ops.py b/glustolibs-gluster/glustolibs/gluster/peer_ops.py index 9f74bb7c7..e4d3e6ec3 100644 --- a/glustolibs-gluster/glustolibs/gluster/peer_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/peer_ops.py @@ -375,7 +375,6 @@ def is_peer_connected(mnode, servers): if mnode in servers: servers.remove(mnode) - peer_connected = True peer_status_list = get_peer_status(mnode) if peer_status_list is None: g.log.error("Failed to parse the peer status. Hence failed to " diff --git a/glustolibs-gluster/glustolibs/gluster/quota_ops.py b/glustolibs-gluster/glustolibs/gluster/quota_ops.py index f7121b05f..5a7f50fcb 100644 --- a/glustolibs-gluster/glustolibs/gluster/quota_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/quota_ops.py @@ -20,8 +20,6 @@ """ from glusto.core import Glusto as g -import re -import time try: import xml.etree.cElementTree as etree diff --git a/glustolibs-gluster/glustolibs/gluster/rebalance_ops.py b/glustolibs-gluster/glustolibs/gluster/rebalance_ops.py index 108a246af..a4cd57e99 100644 --- a/glustolibs-gluster/glustolibs/gluster/rebalance_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/rebalance_ops.py @@ -20,7 +20,6 @@ """ from glusto.core import Glusto as g -import re import time try: diff --git a/glustolibs-gluster/glustolibs/gluster/samba_ops.py b/glustolibs-gluster/glustolibs/gluster/samba_ops.py index e4f5b0154..ec158b04b 100644 --- a/glustolibs-gluster/glustolibs/gluster/samba_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/samba_ops.py @@ -133,9 +133,6 @@ def create_smb_users(servers, smb_users_info, start_uid=50000): for smb_user in smb_users_info.keys(): if smb_user == 'root': continue - user_add_command = ("getent passwd %d | grep %s &> /dev/null || " - "useradd -u %d %s" % (uid, smb_user, - uid, smb_user)) for server in servers: # Check if user already exist with same uid cmd = ("getent passwd %d" % uid) diff --git a/glustolibs-gluster/glustolibs/gluster/snap_ops.py b/glustolibs-gluster/glustolibs/gluster/snap_ops.py index 5d58f23be..2ca5688b5 100644 --- a/glustolibs-gluster/glustolibs/gluster/snap_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/snap_ops.py @@ -21,8 +21,6 @@ from glusto.core import Glusto as g from glustolibs.gluster.volume_ops import volume_start, volume_stop -import re -import time try: import xml.etree.cElementTree as etree diff --git a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py index 38890f5ca..755ca276a 100644 --- a/glustolibs-gluster/glustolibs/gluster/tiering_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/tiering_ops.py @@ -20,6 +20,7 @@ """ import re +import time from glusto.core import Glusto as g from glustolibs.gluster.peer_ops import peer_probe_servers from glustolibs.gluster.gluster_init import start_glusterd diff --git a/glustolibs-gluster/glustolibs/gluster/uss_ops.py b/glustolibs-gluster/glustolibs/gluster/uss_ops.py index 3275a6e61..4a48a2cb0 100644 --- a/glustolibs-gluster/glustolibs/gluster/uss_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/uss_ops.py @@ -43,6 +43,7 @@ def enable_uss(mnode, volname): cmd = "gluster volume set %s features.uss enable" % volname return g.run(mnode, cmd) + def disable_uss(mnode, volname): """Disables uss on the specified volume diff --git a/glustolibs-gluster/glustolibs/gluster/volume_libs.py b/glustolibs-gluster/glustolibs/gluster/volume_libs.py index 24aac821d..520e8afcd 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_libs.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_libs.py @@ -192,12 +192,6 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False): g.log.error("Invalid volume type defined in config") return False - # Get transport type - if 'transport' in volume_config['voltype']: - transpor_type = volume_config['voltype']['transport'] - else: - transport_type = 'tcp' - # get bricks_list bricks_list = form_bricks_list(mnode=mnode, volname=volname, number_of_bricks=number_of_bricks, @@ -335,14 +329,14 @@ def setup_volume(mnode, all_servers_info, volume_config, force=False): return False # Enable Ganesha -## if ('nfs_ganesha' in volume_config and -## 'enable' in volume_config['nfs_ganesha'] and -## volume_config['nfs_ganesha']['enable']): -## from glustolibs.gluster.ganesha import vol_set_ganesha -## ret = vol_set_ganesha(mnode=mnode, volname=volname, option=True) -## if not ret: -## g.log.error("failed to set the ganesha option for %s" % volname) -## return False +# if ('nfs_ganesha' in volume_config and +# 'enable' in volume_config['nfs_ganesha'] and +# volume_config['nfs_ganesha']['enable']): +# from glustolibs.gluster.ganesha import vol_set_ganesha +# ret = vol_set_ganesha(mnode=mnode, volname=volname, option=True) +# if not ret: +# g.log.error("failed to set the ganesha option for %s" % volname) +# return False # Enable Samba if ('smb' in volume_config and 'enable' in volume_config['smb'] and @@ -479,7 +473,7 @@ def get_subvols(mnode, volname): # Disperse or Distribute-Disperse volume elif (cold_tier_type == 'Disperse' or - cold_tier_type == 'Distributed-Disperse'): + cold_tier_type == 'Distributed-Disperse'): disp_count = sum([int(nums) for nums in ((volinfo[volname]["bricks"]['coldBricks'] ['numberOfBricks']).split("x", 1)[1]. @@ -641,8 +635,8 @@ def get_volume_type_info(mnode, volname): if key in volinfo[volname]: non_tiered_volume_type_info[key] = volinfo[volname][key] else: - g.log.error("Unable to find key '%s' in the volume info for the " - "volume %s" % (key, volname)) + g.log.error("Unable to find key '%s' in the volume info for " + "the volume %s" % (key, volname)) non_tiered_volume_type_info[key] = None volume_type_info['volume_type_info'] = non_tiered_volume_type_info diff --git a/glustolibs-gluster/glustolibs/gluster/volume_ops.py b/glustolibs-gluster/glustolibs/gluster/volume_ops.py index f7a9473cb..6770b1d3e 100644 --- a/glustolibs-gluster/glustolibs/gluster/volume_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/volume_ops.py @@ -17,17 +17,12 @@ import re -import time from glusto.core import Glusto as g from pprint import pformat try: import xml.etree.cElementTree as etree except ImportError: import xml.etree.ElementTree as etree -from glustolibs.gluster.mount_ops import mount_volume -from glustolibs.gluster.gluster_init import env_setup_servers, start_glusterd -from glustolibs.gluster.peer_ops import (peer_probe_servers, - nodes_from_pool_list) """ This file contains the gluster volume operations like create volume, @@ -80,7 +75,7 @@ def volume_create(mnode, volname, bricks_list, force=False, **kwargs): volume_create(mnode, volname, bricks_list) """ replica_count = arbiter_count = stripe_count = None - disperse_count = disperse_data_count = redundancy_count = None + disperse_count = disperse_data_count = redundancy_count = None transport_type = None if 'replica_count' in kwargs: @@ -137,6 +132,7 @@ def volume_create(mnode, volname, bricks_list, force=False, **kwargs): return g.run(mnode, cmd) + def volume_start(mnode, volname, force=False): """Starts the gluster volume @@ -235,7 +231,7 @@ def volume_delete(mnode, volname): bricks = [x["name"] for x in volinfo[volname]["bricks"]["brick"] if "name" in x] ret, _, _ = g.run(mnode, "gluster volume delete %s --mode=script" - % volname) + % volname) if ret != 0: return False @@ -658,7 +654,7 @@ def get_volume_info(mnode, volname='all'): (volinfo[volname]["bricks"][el.tag]["brick"]. append(brick_info_dict)) else: - volinfo[volname]["bricks"][el.tag][elmt.tag] = elmt.text + volinfo[volname]["bricks"][el.tag][elmt.tag] = elmt.text # noqa: E501 elif elem.tag == "options": volinfo[volname]["options"] = {} for option in elem.findall("option"): -- cgit