Lint: E722 do not use bare 'except'
This commit is contained in:
@ -47,7 +47,7 @@ def strtobool(stringv):
|
||||
return bool(stringv)
|
||||
try:
|
||||
return bool(dustrtobool(stringv))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
#
|
||||
@ -134,13 +134,13 @@ def run_benchmark(self, pool):
|
||||
# Phase 0 - connect to databases
|
||||
try:
|
||||
db_conn, db_cur = open_database(config)
|
||||
except:
|
||||
except Exception:
|
||||
print('FATAL - failed to connect to Postgres')
|
||||
raise Exception
|
||||
|
||||
try:
|
||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||
except:
|
||||
except Exception:
|
||||
print('FATAL - failed to connect to Zookeeper')
|
||||
raise Exception
|
||||
|
||||
|
@ -53,13 +53,13 @@ def strtobool(stringv):
|
||||
return bool(stringv)
|
||||
try:
|
||||
return bool(dustrtobool(stringv))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
# Parse the configuration file
|
||||
try:
|
||||
pvc_config_file = os.environ['PVC_CONFIG_FILE']
|
||||
except:
|
||||
except Exception:
|
||||
print('Error: The "PVC_CONFIG_FILE" environment variable must be set before starting pvcapid.')
|
||||
exit(1)
|
||||
|
||||
@ -4205,11 +4205,11 @@ class API_Provisioner_Template_System_Root(Resource):
|
||||
# Validate arguments
|
||||
try:
|
||||
vcpus = int(reqargs.get('vcpus'))
|
||||
except:
|
||||
except Exception:
|
||||
return { "message": "A vcpus value must be an integer" }, 400
|
||||
try:
|
||||
vram = int(reqargs.get('vram'))
|
||||
except:
|
||||
except Exception:
|
||||
return { "message": "A vram value must be an integer" }, 400
|
||||
# Cast boolean arguments
|
||||
if bool(strtobool(reqargs.get('serial', 'false'))):
|
||||
@ -4345,11 +4345,11 @@ class API_Provisioner_Template_System_Element(Resource):
|
||||
# Validate arguments
|
||||
try:
|
||||
vcpus = int(reqargs.get('vcpus'))
|
||||
except:
|
||||
except Exception:
|
||||
return { "message": "A vcpus value must be an integer" }, 400
|
||||
try:
|
||||
vram = int(reqargs.get('vram'))
|
||||
except:
|
||||
except Exception:
|
||||
return { "message": "A vram value must be an integer" }, 400
|
||||
# Cast boolean arguments
|
||||
if bool(strtobool(reqargs.get('serial', False))):
|
||||
|
@ -42,7 +42,7 @@ def strtobool(stringv):
|
||||
return bool(stringv)
|
||||
try:
|
||||
return bool(dustrtobool(stringv))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
#
|
||||
@ -499,7 +499,7 @@ def update_vm_meta(vm, limit, selector, autostart, provisioner_profile, migratio
|
||||
if autostart is not None:
|
||||
try:
|
||||
autostart = bool(strtobool(autostart))
|
||||
except:
|
||||
except Exception:
|
||||
autostart = False
|
||||
retflag, retdata = pvc_vm.modify_vm_metadata(zk_conn, vm, limit, selector, autostart, provisioner_profile, migration_method)
|
||||
pvc_common.stopZKConnection(zk_conn)
|
||||
@ -1393,7 +1393,7 @@ def ceph_volume_upload(pool, volume, img_type):
|
||||
# Save the data to the blockdev directly
|
||||
try:
|
||||
data.save(dest_blockdev)
|
||||
except:
|
||||
except Exception:
|
||||
output = {
|
||||
'message': "Failed to write image file to volume."
|
||||
}
|
||||
@ -1457,7 +1457,7 @@ def ceph_volume_upload(pool, volume, img_type):
|
||||
def ova_stream_factory(total_content_length, filename, content_type, content_length=None):
|
||||
return open(temp_blockdev, 'wb')
|
||||
parse_form_data(flask.request.environ, stream_factory=ova_stream_factory)
|
||||
except:
|
||||
except Exception:
|
||||
output = {
|
||||
'message': "Failed to upload or write image file to temporary volume."
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ def upload_ova(pool, name, ova_size):
|
||||
def ova_stream_factory(total_content_length, filename, content_type, content_length=None):
|
||||
return open(ova_blockdev, 'wb')
|
||||
parse_form_data(flask.request.environ, stream_factory=ova_stream_factory)
|
||||
except:
|
||||
except Exception:
|
||||
output = {
|
||||
'message': "Failed to upload or write OVA file to temporary volume."
|
||||
}
|
||||
@ -329,7 +329,7 @@ def upload_ova(pool, name, ova_size):
|
||||
vmdk_file.close()
|
||||
# Perform an OS-level sync
|
||||
pvc_common.run_os_command('sync')
|
||||
except:
|
||||
except Exception:
|
||||
output = {
|
||||
'message': "Failed to write image file '{}' to temporary volume.".format(disk.get('src'))
|
||||
}
|
||||
@ -493,7 +493,7 @@ class OVFParser(object):
|
||||
for item in hardware_list:
|
||||
try:
|
||||
item_type = self.RASD_TYPE[item.find("{{{rasd}}}ResourceType".format(rasd=self.RASD_SCHEMA)).text]
|
||||
except:
|
||||
except Exception:
|
||||
continue
|
||||
quantity = item.find("{{{rasd}}}VirtualQuantity".format(rasd=self.RASD_SCHEMA))
|
||||
if quantity is None:
|
||||
|
@ -49,7 +49,7 @@ def strtobool(stringv):
|
||||
return bool(stringv)
|
||||
try:
|
||||
return bool(dustrtobool(stringv))
|
||||
except:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
#
|
||||
@ -370,7 +370,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
if vcpu_count is not None:
|
||||
try:
|
||||
vcpu_count = int(vcpu_count)
|
||||
except:
|
||||
except Exception:
|
||||
retmsg = { 'message': 'The vcpus value must be an integer.' }
|
||||
retcode = 400
|
||||
return retmsg, retcode
|
||||
@ -379,7 +379,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
if vram_mb is not None:
|
||||
try:
|
||||
vram_mb = int(vram_mb)
|
||||
except:
|
||||
except Exception:
|
||||
retmsg = { 'message': 'The vram value must be an integer.' }
|
||||
retcode = 400
|
||||
return retmsg, retcode
|
||||
@ -388,7 +388,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
if serial is not None:
|
||||
try:
|
||||
serial = bool(strtobool(serial))
|
||||
except:
|
||||
except Exception:
|
||||
retmsg = { 'message': 'The serial value must be a boolean.' }
|
||||
retcode = 400
|
||||
return retmsg, retcode
|
||||
@ -397,7 +397,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
if vnc is not None:
|
||||
try:
|
||||
vnc = bool(strtobool(vnc))
|
||||
except:
|
||||
except Exception:
|
||||
retmsg = { 'message': 'The vnc value must be a boolean.' }
|
||||
retcode = 400
|
||||
return retmsg, retcode
|
||||
@ -415,7 +415,7 @@ def modify_template_system(name, vcpu_count=None, vram_mb=None, serial=None, vnc
|
||||
if node_autostart is not None:
|
||||
try:
|
||||
node_autostart = bool(strtobool(node_autostart))
|
||||
except:
|
||||
except Exception:
|
||||
retmsg = { 'message': 'The node_autostart value must be a boolean.' }
|
||||
retcode = 400
|
||||
fields.append({'field': 'node_autostart', 'data': node_autostart})
|
||||
@ -1044,13 +1044,13 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True, script_r
|
||||
# Phase 0 - connect to databases
|
||||
try:
|
||||
db_conn, db_cur = open_database(config)
|
||||
except:
|
||||
except Exception:
|
||||
print('FATAL - failed to connect to Postgres')
|
||||
raise Exception
|
||||
|
||||
try:
|
||||
zk_conn = pvc_common.startZKConnection(config['coordinators'])
|
||||
except:
|
||||
except Exception:
|
||||
print('FATAL - failed to connect to Zookeeper')
|
||||
raise Exception
|
||||
|
||||
@ -1212,7 +1212,7 @@ def create_vm(self, vm_name, vm_profile, define_vm=True, start_vm=True, script_r
|
||||
pool_information = pvc_ceph.getPoolInformation(zk_conn, pool)
|
||||
if not pool_information:
|
||||
raise
|
||||
except:
|
||||
except Exception:
|
||||
raise ClusterError('Pool "{}" is not present on the cluster.'.format(pool))
|
||||
pool_free_space_gb = int(pool_information['stats']['free_bytes'] / 1024 / 1024 / 1024)
|
||||
pool_vm_usage_gb = int(pools[pool])
|
||||
|
Reference in New Issue
Block a user