From: tierno Date: Wed, 28 Sep 2016 14:57:25 +0000 (+0000) Subject: Capture and logging general exceptios at http X-Git-Tag: v1.0.0~16 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=65a9b0cb9f8eafc84ed12d6279442763005969da;p=osm%2FRO.git Capture and logging general exceptios at http Signed-off-by: tierno --- diff --git a/httpserver.py b/httpserver.py index 046584e3..43f57242 100644 --- a/httpserver.py +++ b/httpserver.py @@ -321,6 +321,10 @@ def http_get_tenants(): except db_base_Exception as e: logger.error("http_get_tenants error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '/tenants/', method='GET') def http_get_tenant_id(tenant_id): @@ -336,6 +340,10 @@ def http_get_tenant_id(tenant_id): except db_base_Exception as e: logger.error("http_get_tenant_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '/tenants', method='POST') def http_post_tenants(): @@ -352,6 +360,10 @@ def http_post_tenants(): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_tenants error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '/tenants/', method='PUT') def http_edit_tenant_id(tenant_id): @@ -374,6 +386,10 @@ def http_edit_tenant_id(tenant_id): except db_base_Exception as e: logger.error("http_edit_tenant_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '/tenants/', method='DELETE') def http_delete_tenant_id(tenant_id): @@ -385,7 +401,10 @@ def http_delete_tenant_id(tenant_id): except db_base_Exception as e: logger.error("http_delete_tenant_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) - + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '//datacenters', method='GET') def http_get_datacenters(tenant_id): @@ -414,6 +433,10 @@ def http_get_datacenters(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_datacenters error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '//datacenters/', method='GET') def http_get_datacenter_id(tenant_id, datacenter_id): @@ -467,6 +490,9 @@ def http_get_datacenter_id(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '/datacenters', method='POST') def http_post_datacenters(): @@ -483,6 +509,9 @@ def http_post_datacenters(): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_datacenters error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '/datacenters/', method='PUT') def http_edit_datacenter_id(datacenter_id_name): @@ -500,6 +529,9 @@ def http_edit_datacenter_id(datacenter_id_name): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_edit_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//networks', method='GET') #deprecated @bottle.route(url_base + '//datacenters//netmaps', method='GET') @@ -532,6 +564,9 @@ def http_getnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_getnetwork_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//netmaps', method='DELETE') @bottle.route(url_base + '//datacenters//netmaps/', method='DELETE') @@ -558,6 +593,9 @@ def http_delnetmap_datacenter_id(tenant_id, datacenter_id, netmap_id=None): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_delnetmap_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//netmaps/upload', method='POST') @@ -572,6 +610,9 @@ def http_uploadnetmap_datacenter_id(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_uploadnetmap_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//netmaps', method='POST') def http_postnetmap_datacenter_id(tenant_id, datacenter_id): @@ -592,6 +633,9 @@ def http_postnetmap_datacenter_id(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_postnetmap_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//netmaps/', method='PUT') def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id): @@ -610,6 +654,9 @@ def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_putnettmap_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters//action', method='POST') @@ -631,6 +678,9 @@ def http_action_datacenter_id(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_action_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '/datacenters/', method='DELETE') @@ -644,6 +694,9 @@ def http_delete_datacenter_id( datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_delete_datacenter_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters/', method='POST') def http_associate_datacenters(tenant_id, datacenter_id): @@ -665,6 +718,9 @@ def http_associate_datacenters(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_associate_datacenters error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//datacenters/', method='DELETE') def http_deassociate_datacenters(tenant_id, datacenter_id): @@ -676,6 +732,9 @@ def http_deassociate_datacenters(tenant_id, datacenter_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_deassociate_datacenters error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vim//', method='GET') @bottle.route(url_base + '//vim///', method='GET') @@ -687,6 +746,9 @@ def http_get_vim_items(tenant_id, datacenter_id, item, name=None): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_vim_items error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vim///', method='DELETE') def http_del_vim_items(tenant_id, datacenter_id, item, name): @@ -697,6 +759,10 @@ def http_del_vim_items(tenant_id, datacenter_id, item, name): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_del_vim_items error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) + @bottle.route(url_base + '//vim//', method='POST') def http_post_vim_items(tenant_id, datacenter_id, item): logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) @@ -707,6 +773,9 @@ def http_post_vim_items(tenant_id, datacenter_id, item): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_vim_items error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vnfs', method='GET') def http_get_vnfs(tenant_id): @@ -730,6 +799,9 @@ def http_get_vnfs(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_vnfs error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vnfs/', method='GET') def http_get_vnf_id(tenant_id,vnf_id): @@ -743,6 +815,9 @@ def http_get_vnf_id(tenant_id,vnf_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_vnf_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vnfs', method='POST') def http_post_vnfs(tenant_id): @@ -766,6 +841,9 @@ def http_post_vnfs(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_vnfs error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//vnfs/', method='DELETE') def http_delete_vnf_id(tenant_id,vnf_id): @@ -779,6 +857,9 @@ def http_delete_vnf_id(tenant_id,vnf_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_delete_vnf_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) #@bottle.route(url_base + '//hosts/topology', method='GET') #@bottle.route(url_base + '//physicalview/Madrid-Alcantara', method='GET') @@ -804,6 +885,9 @@ def http_get_hosts(tenant_id, datacenter): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_hosts error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '/', method='OPTIONS') @@ -836,6 +920,9 @@ def http_post_deploy(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_deploy error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//topology/verify', method='POST') def http_post_verify(tenant_id): @@ -873,6 +960,9 @@ def http_post_scenarios(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_scenarios error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//scenarios//action', method='POST') def http_post_scenario_action(tenant_id, scenario_id): @@ -911,6 +1001,9 @@ def http_post_scenario_action(tenant_id, scenario_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_scenario_action error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//scenarios', method='GET') def http_get_scenarios(tenant_id): @@ -935,6 +1028,9 @@ def http_get_scenarios(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_scenarios error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//scenarios/', method='GET') def http_get_scenario_id(tenant_id, scenario_id): @@ -952,6 +1048,9 @@ def http_get_scenario_id(tenant_id, scenario_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_scenarios error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//scenarios/', method='DELETE') def http_delete_scenario_id(tenant_id, scenario_id): @@ -967,6 +1066,9 @@ def http_delete_scenario_id(tenant_id, scenario_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_delete_scenario_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//scenarios/', method='PUT') @@ -985,6 +1087,9 @@ def http_put_scenario_id(tenant_id, scenario_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_put_scenario_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//instances', method='POST') def http_post_instances(tenant_id): @@ -1004,6 +1109,9 @@ def http_post_instances(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_instances error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) # # INSTANCES @@ -1027,6 +1135,9 @@ def http_get_instances(tenant_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_instances error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//instances/', method='GET') def http_get_instance_id(tenant_id, instance_id): @@ -1053,7 +1164,7 @@ def http_get_instance_id(tenant_id, instance_id): logger.error("http_get_instance_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) except Exception as e: - logger.error("http_get_instance_id error {}".format(str(e))) + logger.error("Unexpected exception %s", str(e)) bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//instances/', method='DELETE') @@ -1072,6 +1183,9 @@ def http_delete_instance_id(tenant_id, instance_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_delete_instance_id error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.route(url_base + '//instances//action', method='POST') def http_post_instance_scenario_action(tenant_id, instance_id): @@ -1097,6 +1211,9 @@ def http_post_instance_scenario_action(tenant_id, instance_id): except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_post_instance_scenario_action error {}: {}".format(e.http_code, str(e))) bottle.abort(e.http_code, str(e)) + except Exception as e: + logger.error("Unexpected exception %s", str(e)) + bottle.abort(HTTP_Internal_Server_Error, str(e)) @bottle.error(400)