Minor exception changes in files 41/1041/2
authorvenkatamahesh <venkatamaheshkotha@gmail.com>
Fri, 27 Jan 2017 17:34:40 +0000 (23:04 +0530)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 30 Jan 2017 16:30:25 +0000 (17:30 +0100)
Signed-off-by: venkatamahesh <venkatamaheshkotha@gmail.com>
httpserver.py
test/test_osconnector.py
utils.py
vimconn_openvim.py

index 789e022..9dd537f 100644 (file)
@@ -483,14 +483,14 @@ def http_get_datacenter_id(tenant_id, datacenter_id):
                     try:
                         config_dict = yaml.load(vim_tenant['config'])
                         vim_tenant['config'] = config_dict
-                    except Exception, e:
+                    except Exception as e:
                         logger.error("Exception '%s' while trying to load config information", str(e))
 
         if datacenter['config'] != None:
             try:
                 config_dict = yaml.load(datacenter['config'])
                 datacenter['config'] = config_dict
-            except Exception, e:
+            except Exception as e:
                 logger.error("Exception '%s' while trying to load config information", str(e))
         #change_keys_http2db(content, http2db_datacenter, reverse=True)
         convert_datetime2str(datacenter)
index 152155b..ac3bf77 100755 (executable)
@@ -87,7 +87,7 @@ def delete_items():
             try:
                 myvim[name]=id_
                 result=1
-            except Exception, e:
+            except Exception as e:
                 result=-1
                 message= "  " + str(type(e))[6:-1] + ": "+  str(e)
         else:
@@ -108,7 +108,7 @@ if __name__=="__main__":
     try:
         opts, args = getopt.getopt(sys.argv[1:], "hv:u:U:p:t:i:",
                  ["username=", "help", "version=", "password=", "tenant=", "url=","skip-admin-tests",'image='])
-    except getopt.GetoptError, err:
+    except getopt.GetoptError as err:
         # print help information and exit:
         print "Error:", err # will print something like "option -a not recognized"
         usage()
@@ -158,7 +158,7 @@ if __name__=="__main__":
                 user=creds['username'], passwd=creds['password'],
                 debug = False, config={'network_vlan_ranges':'physnet_sriov'} )
             print " Ok"
-        except Exception, e:
+        except Exception as e:
             print " Fail"
             print str(type(e))[6:-1] + ": "+  str(e) 
             exit(-1)
@@ -229,7 +229,7 @@ if __name__=="__main__":
                 rollback_list.append(("creds", "tenant", creds["tenant_name"]))
                 rollback_list.append(("creds", "user",   creds["username"]))
                 rollback_list.append(("creds", "passwd", creds["password"]))
-            except Exception, e:
+            except Exception as e:
                 print " Fail"
                 print " Error setting osconnector to new tenant:", str(type(e))[6:-1] + ": "+  str(e)
                 exit(-1)
index a5a7858..00f6f2d 100644 (file)
--- a/utils.py
+++ b/utils.py
@@ -39,7 +39,7 @@ def read_file(file_to_read):
         f = open(file_to_read, 'r')
         read_data = f.read()
         f.close()
-    except Exception,e:
+    except Exception as e:
         return (False, str(e))
       
     return (True, read_data)
@@ -50,7 +50,7 @@ def write_file(file_to_write, text):
         f = open(file_to_write, 'w')
         f.write(text)
         f.close()
-    except Exception,e:
+    except Exception as e:
         return (False, str(e))
       
     return (True, None)
@@ -61,7 +61,7 @@ def format_in(http_response, schema):
         js_v(client_data, schema)
         #print "Input data: ", str(client_data)
         return True, client_data
-    except js_e.ValidationError, exc:
+    except js_e.ValidationError as exc:
         print "validate_in error, jsonschema exception ", exc.message, "at", exc.path
         return False, ("validate_in error, jsonschema exception ", exc.message, "at", exc.path)
 
index 62c1677..bd963c7 100644 (file)
@@ -377,7 +377,7 @@ class vimconnector(vimconn.vimconnector):
             js_v(client_data, schema)
             #print "Input data: ", str(client_data)
             return True, client_data
-        except js_e.ValidationError, exc:
+        except js_e.ValidationError as exc:
             print "validate_in error, jsonschema exception ", exc.message, "at", exc.path
             return False, ("validate_in error, jsonschema exception ", exc.message, "at", exc.path)
     
@@ -753,7 +753,7 @@ class vimconnector(vimconn.vimconnector):
         payload_req = vm_data
         try:
             vim_response = requests.post(self.url+'/'+self.tenant+'/servers', headers = self.headers_req, data=payload_req)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             print "new_vminstancefromJSON Exception: ", e.args
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print vim_response
@@ -1079,7 +1079,7 @@ class vimconnector(vimconn.vimconnector):
         url=self.url+'/hosts'
         try:
             vim_response = requests.get(url)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             print "get_hosts_info Exception: ", e.args
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
@@ -1101,7 +1101,7 @@ class vimconnector(vimconn.vimconnector):
             url=self.url+'/hosts/'+host['id']
             try:
                 vim_response = requests.get(url)
-            except requests.exceptions.RequestException, e:
+            except requests.exceptions.RequestException as e:
                 print "get_hosts_info Exception: ", e.args
                 return -vimconn.HTTP_Not_Found, str(e.args[0])
             print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
@@ -1123,7 +1123,7 @@ class vimconnector(vimconn.vimconnector):
         url=self.url+'/hosts'
         try:
             vim_response = requests.get(url)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             print "get_hosts Exception: ", e.args
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
@@ -1144,7 +1144,7 @@ class vimconnector(vimconn.vimconnector):
             url=self.url+'/' + vim_tenant + '/servers?hostId='+host['id']
             try:
                 vim_response = requests.get(url)
-            except requests.exceptions.RequestException, e:
+            except requests.exceptions.RequestException as e:
                 print "get_hosts Exception: ", e.args
                 return -vimconn.HTTP_Not_Found, str(e.args[0])
             print "vim get", url, "response:",  vim_response.status_code, vim_response.json()
@@ -1164,7 +1164,7 @@ class vimconnector(vimconn.vimconnector):
         url=self.url+'/processor_ranking'
         try:
             vim_response = requests.get(url)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             print "get_processor_rankings Exception: ", e.args
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print "vim get", url, "response:", vim_response.status_code, vim_response.json()
@@ -1207,7 +1207,7 @@ class vimconnector(vimconn.vimconnector):
         payload_req = port_data
         try:
             vim_response = requests.post(self.url_admin+'/ports', headers = self.headers_req, data=payload_req)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             self.logger.error("new_external_port Exception: ", str(e))
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print vim_response
@@ -1241,7 +1241,7 @@ class vimconnector(vimconn.vimconnector):
         payload_req = '{"network":{"name": "' + net_name + '","shared":true,"type": "' + net_type + '"}}'
         try:
             vim_response = requests.post(self.url+'/networks', headers = self.headers_req, data=payload_req)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             self.logger.error( "new_external_network Exception: ", e.args)
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print vim_response
@@ -1281,7 +1281,7 @@ class vimconnector(vimconn.vimconnector):
             url= self.url
         try:
             vim_response = requests.put(url +'/ports/'+port_id, headers = self.headers_req, data=payload_req)
-        except requests.exceptions.RequestException, e:
+        except requests.exceptions.RequestException as e:
             print "connect_port_network Exception: ", e.args
             return -vimconn.HTTP_Not_Found, str(e.args[0])
         print vim_response