Lint: E722 do not use bare 'except' (2)
This commit is contained in:
		| @@ -50,15 +50,15 @@ def install(**kwargs): | |||||||
|     # failures of these gracefully, should administrators forget to specify them. |     # failures of these gracefully, should administrators forget to specify them. | ||||||
|     try: |     try: | ||||||
|         deb_release = kwargs['deb_release'] |         deb_release = kwargs['deb_release'] | ||||||
|     except: |     except Exception: | ||||||
|         deb_release = "stable" |         deb_release = "stable" | ||||||
|     try: |     try: | ||||||
|         deb_mirror = kwargs['deb_mirror'] |         deb_mirror = kwargs['deb_mirror'] | ||||||
|     except: |     except Exception: | ||||||
|         deb_mirror = "http://ftp.debian.org/debian" |         deb_mirror = "http://ftp.debian.org/debian" | ||||||
|     try: |     try: | ||||||
|         deb_packages = kwargs['deb_packages'].split(',') |         deb_packages = kwargs['deb_packages'].split(',') | ||||||
|     except: |     except Exception: | ||||||
|         deb_packages = ["linux-image-amd64", "grub-pc", "cloud-init", "python3-cffi-backend", "wget"] |         deb_packages = ["linux-image-amd64", "grub-pc", "cloud-init", "python3-cffi-backend", "wget"] | ||||||
|  |  | ||||||
|     # We need to know our root disk |     # We need to know our root disk | ||||||
|   | |||||||
| @@ -238,7 +238,7 @@ def add_osd(zk_conn, node, device, weight): | |||||||
|             else: |             else: | ||||||
|                 message = 'ERROR: Failed to create new OSD; check node logs for details.' |                 message = 'ERROR: Failed to create new OSD; check node logs for details.' | ||||||
|                 success = False |                 success = False | ||||||
|         except: |         except Exception: | ||||||
|             message = 'ERROR: Command ignored by node.' |             message = 'ERROR: Command ignored by node.' | ||||||
|             success = False |             success = False | ||||||
|  |  | ||||||
| @@ -270,7 +270,7 @@ def remove_osd(zk_conn, osd_id): | |||||||
|             else: |             else: | ||||||
|                 message = 'ERROR: Failed to remove OSD; check node logs for details.' |                 message = 'ERROR: Failed to remove OSD; check node logs for details.' | ||||||
|                 success = False |                 success = False | ||||||
|         except: |         except Exception: | ||||||
|             success = False |             success = False | ||||||
|             message = 'ERROR Command ignored by node.' |             message = 'ERROR Command ignored by node.' | ||||||
|  |  | ||||||
| @@ -593,7 +593,7 @@ def add_pool(zk_conn, name, pgs, replcfg): | |||||||
|         copies, mincopies = replcfg.split(',') |         copies, mincopies = replcfg.split(',') | ||||||
|         copies = int(copies.replace('copies=', '')) |         copies = int(copies.replace('copies=', '')) | ||||||
|         mincopies = int(mincopies.replace('mincopies=', '')) |         mincopies = int(mincopies.replace('mincopies=', '')) | ||||||
|     except: |     except Exception: | ||||||
|         copies = None |         copies = None | ||||||
|         mincopies = None |         mincopies = None | ||||||
|     if not copies or not mincopies: |     if not copies or not mincopies: | ||||||
| @@ -962,7 +962,7 @@ def resize_volume(zk_conn, pool, name, size): | |||||||
|             if target_vm_conn: |             if target_vm_conn: | ||||||
|                 target_vm_conn.blockResize(volume_id, int(format_bytes_fromhuman(size)[:-1]), libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES) |                 target_vm_conn.blockResize(volume_id, int(format_bytes_fromhuman(size)[:-1]), libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES) | ||||||
|             target_lv_conn.close() |             target_lv_conn.close() | ||||||
|         except: |         except Exception: | ||||||
|             pass |             pass | ||||||
|  |  | ||||||
|     # 2. Get volume stats |     # 2. Get volume stats | ||||||
|   | |||||||
| @@ -37,14 +37,14 @@ def set_maintenance(zk_conn, maint_state): | |||||||
|         else: |         else: | ||||||
|             zkhandler.writedata(zk_conn, {'/maintenance': 'false'}) |             zkhandler.writedata(zk_conn, {'/maintenance': 'false'}) | ||||||
|             return True, 'Successfully set cluster in normal mode' |             return True, 'Successfully set cluster in normal mode' | ||||||
|     except: |     except Exception: | ||||||
|         return False, 'Failed to set cluster maintenance state' |         return False, 'Failed to set cluster maintenance state' | ||||||
|  |  | ||||||
| def getClusterInformation(zk_conn): | def getClusterInformation(zk_conn): | ||||||
|     # Get cluster maintenance state |     # Get cluster maintenance state | ||||||
|     try: |     try: | ||||||
|         maint_state = zkhandler.readdata(zk_conn, '/maintenance') |         maint_state = zkhandler.readdata(zk_conn, '/maintenance') | ||||||
|     except: |     except Exception: | ||||||
|         maint_state = 'false' |         maint_state = 'false' | ||||||
|  |  | ||||||
|     # List of messages to display to the clients |     # List of messages to display to the clients | ||||||
|   | |||||||
| @@ -55,11 +55,11 @@ def run_os_command(command_string, background=False, environment=None, timeout=N | |||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         stdout = command_output.stdout.decode('ascii') |         stdout = command_output.stdout.decode('ascii') | ||||||
|     except: |     except Exception: | ||||||
|         stdout = '' |         stdout = '' | ||||||
|     try: |     try: | ||||||
|         stderr = command_output.stderr.decode('ascii') |         stderr = command_output.stderr.decode('ascii') | ||||||
|     except: |     except Exception: | ||||||
|         stderr = '' |         stderr = '' | ||||||
|     return retcode, stdout, stderr |     return retcode, stdout, stderr | ||||||
|  |  | ||||||
| @@ -70,7 +70,7 @@ def validateUUID(dom_uuid): | |||||||
|     try: |     try: | ||||||
|         uuid.UUID(dom_uuid) |         uuid.UUID(dom_uuid) | ||||||
|         return True |         return True | ||||||
|     except: |     except Exception: | ||||||
|         return False |         return False | ||||||
|  |  | ||||||
| # | # | ||||||
| @@ -98,7 +98,7 @@ def stopZKConnection(zk_conn): | |||||||
| def getDomainXML(zk_conn, dom_uuid): | def getDomainXML(zk_conn, dom_uuid): | ||||||
|     try: |     try: | ||||||
|         xml = zkhandler.readdata(zk_conn, '/domains/{}/xml'.format(dom_uuid)) |         xml = zkhandler.readdata(zk_conn, '/domains/{}/xml'.format(dom_uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         return None |         return None | ||||||
|  |  | ||||||
|     # Parse XML using lxml.objectify |     # Parse XML using lxml.objectify | ||||||
| @@ -125,7 +125,7 @@ def getDomainMainDetails(parsed_xml): | |||||||
|     dvcpu = str(parsed_xml.vcpu) |     dvcpu = str(parsed_xml.vcpu) | ||||||
|     try: |     try: | ||||||
|         dvcputopo = '{}/{}/{}'.format(parsed_xml.cpu.topology.attrib.get('sockets'), parsed_xml.cpu.topology.attrib.get('cores'), parsed_xml.cpu.topology.attrib.get('threads')) |         dvcputopo = '{}/{}/{}'.format(parsed_xml.cpu.topology.attrib.get('sockets'), parsed_xml.cpu.topology.attrib.get('cores'), parsed_xml.cpu.topology.attrib.get('threads')) | ||||||
|     except: |     except Exception: | ||||||
|         dvcputopo = 'N/A' |         dvcputopo = 'N/A' | ||||||
|  |  | ||||||
|     return duuid, dname, ddescription, dmemory, dvcpu, dvcputopo |     return duuid, dname, ddescription, dmemory, dvcpu, dvcputopo | ||||||
| @@ -150,7 +150,7 @@ def getDomainCPUFeatures(parsed_xml): | |||||||
|     try: |     try: | ||||||
|         for feature in parsed_xml.features.getchildren(): |         for feature in parsed_xml.features.getchildren(): | ||||||
|             dfeatures.append(feature.tag) |             dfeatures.append(feature.tag) | ||||||
|     except: |     except Exception: | ||||||
|         pass |         pass | ||||||
|  |  | ||||||
|     return dfeatures |     return dfeatures | ||||||
| @@ -168,7 +168,7 @@ def getDomainDisks(parsed_xml, stats_data): | |||||||
|             disk_stats_list = [x for x in stats_data.get('disk_stats', []) if x.get('name') == disk_attrib.get('name')] |             disk_stats_list = [x for x in stats_data.get('disk_stats', []) if x.get('name') == disk_attrib.get('name')] | ||||||
|             try: |             try: | ||||||
|                 disk_stats = disk_stats_list[0] |                 disk_stats = disk_stats_list[0] | ||||||
|             except: |             except Exception: | ||||||
|                 disk_stats = {} |                 disk_stats = {} | ||||||
|  |  | ||||||
|             if disk_type == 'network': |             if disk_type == 'network': | ||||||
| @@ -225,19 +225,19 @@ def getInformationFromXML(zk_conn, uuid): | |||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         domain_node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(uuid)) |         domain_node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         domain_node_limit = None |         domain_node_limit = None | ||||||
|     try: |     try: | ||||||
|         domain_node_selector = zkhandler.readdata(zk_conn, '/domains/{}/node_selector'.format(uuid)) |         domain_node_selector = zkhandler.readdata(zk_conn, '/domains/{}/node_selector'.format(uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         domain_node_selector = None |         domain_node_selector = None | ||||||
|     try: |     try: | ||||||
|         domain_node_autostart = zkhandler.readdata(zk_conn, '/domains/{}/node_autostart'.format(uuid)) |         domain_node_autostart = zkhandler.readdata(zk_conn, '/domains/{}/node_autostart'.format(uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         domain_node_autostart = None |         domain_node_autostart = None | ||||||
|     try: |     try: | ||||||
|         domain_migration_method = zkhandler.readdata(zk_conn, '/domains/{}/migration_method'.format(uuid)) |         domain_migration_method = zkhandler.readdata(zk_conn, '/domains/{}/migration_method'.format(uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         domain_migration_method = None |         domain_migration_method = None | ||||||
|  |  | ||||||
|     if not domain_node_limit: |     if not domain_node_limit: | ||||||
| @@ -250,14 +250,14 @@ def getInformationFromXML(zk_conn, uuid): | |||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         domain_profile = zkhandler.readdata(zk_conn, '/domains/{}/profile'.format(uuid)) |         domain_profile = zkhandler.readdata(zk_conn, '/domains/{}/profile'.format(uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         domain_profile = None |         domain_profile = None | ||||||
|  |  | ||||||
|     parsed_xml = getDomainXML(zk_conn, uuid) |     parsed_xml = getDomainXML(zk_conn, uuid) | ||||||
|  |  | ||||||
|     try: |     try: | ||||||
|         stats_data = loads(zkhandler.readdata(zk_conn, '/domains/{}/stats'.format(uuid))) |         stats_data = loads(zkhandler.readdata(zk_conn, '/domains/{}/stats'.format(uuid))) | ||||||
|     except: |     except Exception: | ||||||
|         stats_data = {} |         stats_data = {} | ||||||
|  |  | ||||||
|     domain_uuid, domain_name, domain_description, domain_memory, domain_vcpu, domain_vcputopo = getDomainMainDetails(parsed_xml) |     domain_uuid, domain_name, domain_description, domain_memory, domain_vcpu, domain_vcputopo = getDomainMainDetails(parsed_xml) | ||||||
| @@ -316,24 +316,24 @@ def getDomainNetworks(parsed_xml, stats_data): | |||||||
|         if device.tag == 'interface': |         if device.tag == 'interface': | ||||||
|             try: |             try: | ||||||
|                 net_type = device.attrib.get('type') |                 net_type = device.attrib.get('type') | ||||||
|             except: |             except Exception: | ||||||
|                 net_type = None |                 net_type = None | ||||||
|             try: |             try: | ||||||
|                 net_mac = device.mac.attrib.get('address') |                 net_mac = device.mac.attrib.get('address') | ||||||
|             except: |             except Exception: | ||||||
|                 net_mac = None |                 net_mac = None | ||||||
|             try: |             try: | ||||||
|                 net_bridge = device.source.attrib.get(net_type) |                 net_bridge = device.source.attrib.get(net_type) | ||||||
|             except: |             except Exception: | ||||||
|                 net_bridge = None |                 net_bridge = None | ||||||
|             try: |             try: | ||||||
|                 net_model = device.model.attrib.get('type') |                 net_model = device.model.attrib.get('type') | ||||||
|             except: |             except Exception: | ||||||
|                 net_model = None |                 net_model = None | ||||||
|             try: |             try: | ||||||
|                 net_stats_list = [x for x in stats_data.get('net_stats', []) if x.get('bridge') == net_bridge] |                 net_stats_list = [x for x in stats_data.get('net_stats', []) if x.get('bridge') == net_bridge] | ||||||
|                 net_stats = net_stats_list[0] |                 net_stats = net_stats_list[0] | ||||||
|             except: |             except Exception: | ||||||
|                 net_stats = {} |                 net_stats = {} | ||||||
|             net_rd_bytes = net_stats.get('rd_bytes', 0) |             net_rd_bytes = net_stats.get('rd_bytes', 0) | ||||||
|             net_rd_packets = net_stats.get('rd_packets', 0) |             net_rd_packets = net_stats.get('rd_packets', 0) | ||||||
| @@ -395,7 +395,7 @@ def getPrimaryNode(zk_conn): | |||||||
|     while True: |     while True: | ||||||
|         try: |         try: | ||||||
|             primary_node = zkhandler.readdata(zk_conn, '/primary_node') |             primary_node = zkhandler.readdata(zk_conn, '/primary_node') | ||||||
|         except: |         except Exception: | ||||||
|             primary_node == 'none' |             primary_node == 'none' | ||||||
|  |  | ||||||
|         if primary_node == 'none': |         if primary_node == 'none': | ||||||
| @@ -420,13 +420,13 @@ def findTargetNode(zk_conn, dom_uuid): | |||||||
|         node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(dom_uuid)).split(',') |         node_limit = zkhandler.readdata(zk_conn, '/domains/{}/node_limit'.format(dom_uuid)).split(',') | ||||||
|         if not any(node_limit): |         if not any(node_limit): | ||||||
|             node_limit = None |             node_limit = None | ||||||
|     except: |     except Exception: | ||||||
|         node_limit = None |         node_limit = None | ||||||
|  |  | ||||||
|     # Determine VM search field or use default; set config value if read fails |     # Determine VM search field or use default; set config value if read fails | ||||||
|     try: |     try: | ||||||
|         search_field = zkhandler.readdata(zk_conn, '/domains/{}/node_selector'.format(dom_uuid)) |         search_field = zkhandler.readdata(zk_conn, '/domains/{}/node_selector'.format(dom_uuid)) | ||||||
|     except: |     except Exception: | ||||||
|         search_field = 'mem' |         search_field = 'mem' | ||||||
|  |  | ||||||
|     # Execute the search |     # Execute the search | ||||||
|   | |||||||
| @@ -392,7 +392,7 @@ def remove_dhcp_reservation(zk_conn, network, reservation): | |||||||
|     # Remove the entry from zookeeper |     # Remove the entry from zookeeper | ||||||
|     try: |     try: | ||||||
|         zkhandler.deletekey(zk_conn, '/networks/{}/dhcp4_{}/{}'.format(net_vni, lease_type_zk, match_description)) |         zkhandler.deletekey(zk_conn, '/networks/{}/dhcp4_{}/{}'.format(net_vni, lease_type_zk, match_description)) | ||||||
|     except: |     except Exception: | ||||||
|         return False, 'ERROR: Failed to write to Zookeeper!' |         return False, 'ERROR: Failed to write to Zookeeper!' | ||||||
|  |  | ||||||
|     return True, 'DHCP {} "{}" removed successfully!'.format(lease_type_human, match_description) |     return True, 'DHCP {} "{}" removed successfully!'.format(lease_type_human, match_description) | ||||||
|   | |||||||
| @@ -135,7 +135,7 @@ def flush_locks(zk_conn, domain): | |||||||
|             else: |             else: | ||||||
|                 message = 'ERROR: Failed to flush locks on VM "{}"; check node logs for details.'.format(domain) |                 message = 'ERROR: Failed to flush locks on VM "{}"; check node logs for details.'.format(domain) | ||||||
|                 success = False |                 success = False | ||||||
|         except: |         except Exception: | ||||||
|             message = 'ERROR: Command ignored by node.' |             message = 'ERROR: Command ignored by node.' | ||||||
|             success = False |             success = False | ||||||
|  |  | ||||||
| @@ -151,7 +151,7 @@ def define_vm(zk_conn, config_data, target_node, node_limit, node_selector, node | |||||||
|     # Parse the XML data |     # Parse the XML data | ||||||
|     try: |     try: | ||||||
|         parsed_xml = lxml.objectify.fromstring(config_data) |         parsed_xml = lxml.objectify.fromstring(config_data) | ||||||
|     except: |     except Exception: | ||||||
|         return False, 'ERROR: Failed to parse XML data.' |         return False, 'ERROR: Failed to parse XML data.' | ||||||
|     dom_uuid = parsed_xml.uuid.text |     dom_uuid = parsed_xml.uuid.text | ||||||
|     dom_name = parsed_xml.name.text |     dom_name = parsed_xml.name.text | ||||||
| @@ -247,7 +247,7 @@ def modify_vm(zk_conn, domain, restart, new_vm_config): | |||||||
|     # Parse and valiate the XML |     # Parse and valiate the XML | ||||||
|     try: |     try: | ||||||
|         parsed_xml = lxml.objectify.fromstring(new_vm_config) |         parsed_xml = lxml.objectify.fromstring(new_vm_config) | ||||||
|     except: |     except Exception: | ||||||
|         return False, 'ERROR: Failed to parse XML data.' |         return False, 'ERROR: Failed to parse XML data.' | ||||||
|  |  | ||||||
|     # Obtain the RBD disk list using the common functions |     # Obtain the RBD disk list using the common functions | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user