From 6060dd65260d576fcb67731544debbe87c3a8782 Mon Sep 17 00:00:00 2001 From: lombardofr Date: Sun, 19 May 2019 12:31:07 +0200 Subject: [PATCH] fix error propagation Change-Id: I3bfa092c9f7f67fd237edb5c770d4fe4f47a1ccd Signed-off-by: lombardofr --- .../template/modal/instance_create_nsi.html | 2 +- instancehandler/views.py | 19 ++- lib/osm/osm_util.py | 2 +- lib/osm/osmclient/clientv2.py | 126 +++++++++--------- netslicehandler/template/nst_list.html | 3 + static/src/instancehandler/instance_create.js | 1 + static/src/instancehandler/instance_list.js | 35 ++++- static/src/netslicehandler/templates_list.js | 29 ++++ static/src/packagehandler/packages_list.js | 35 ++++- 9 files changed, 176 insertions(+), 76 deletions(-) diff --git a/instancehandler/template/modal/instance_create_nsi.html b/instancehandler/template/modal/instance_create_nsi.html index 21b410a..35e11e1 100644 --- a/instancehandler/template/modal/instance_create_nsi.html +++ b/instancehandler/template/modal/instance_create_nsi.html @@ -6,7 +6,7 @@ -
{% csrf_token %} diff --git a/instancehandler/views.py b/instancehandler/views.py index bdc85a7..edf0da1 100644 --- a/instancehandler/views.py +++ b/instancehandler/views.py @@ -165,10 +165,14 @@ def create(request, type=None): ns_data['wimAccountId'] = get_wim_account_id(wim_account) except Exception as e: - request.session["OSM_ERROR"] = "Error creating the NS; Invalid parameters provided." - return __response_handler(request, {}, 'instances:list', to_redirect=True, type='ns', ) + return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message} , url=None, status=400) result = client.ns_create(user.get_token(), ns_data) - return __response_handler(request, result, 'instances:list', to_redirect=True, type='ns') + print result + if result['error']: + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) elif type == 'nsi': try: @@ -245,11 +249,14 @@ def create(request, type=None): raise ValueError("Error 'additionalParamsForSubnet' items must contain " "'additionalParamsForNs' and/or 'additionalParamsForVnf'") except Exception as e: - request.session["OSM_ERROR"] = "Error creating the NSI; Invalid parameters provided." - return __response_handler(request, {}, 'instances:list', to_redirect=True, type=type) + return __response_handler(request, {'status': 400, 'code': 'BAD_REQUEST', 'detail': e.message} , url=None, status=400) result = client.nsi_create(user.get_token(), nsi_data) - return __response_handler(request, result, 'instances:list', to_redirect=True, type=type) + if result['error']: + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) elif type == 'pdu': interface_param_name = request.POST.getlist('interfaces_name') diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index 6296d78..acc4726 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -155,7 +155,7 @@ class OsmUtil(): "monitoring-param": [], "internal-connection-point": [], "image": "ubuntu", - "cloud-init-file": "", + #"cloud-init-file": "", "vm-flavor": {}, "interface": [], "id": element_id, diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 2025277..52e20b7 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -49,7 +49,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -66,7 +66,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -85,7 +85,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -104,7 +104,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -121,7 +121,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -139,7 +139,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -156,7 +156,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -173,7 +173,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -190,7 +190,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -209,7 +209,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -228,7 +228,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -245,7 +245,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = Util.json_loads_byteified(r.text) @@ -262,7 +262,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -279,7 +279,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json2yaml(yaml.load(str(r.text))) @@ -297,7 +297,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -317,7 +317,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -337,7 +337,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -354,7 +354,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -371,7 +371,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -388,7 +388,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -405,7 +405,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -423,7 +423,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False return result @@ -480,7 +480,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -500,7 +500,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -520,7 +520,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -540,7 +540,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['data'] = r.json() result['error'] = False if r.status_code == requests.codes.conflict: @@ -561,7 +561,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['data'] = r.json() result['error'] = False if r.status_code == requests.codes.conflict: @@ -588,7 +588,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False if r.status_code == requests.codes.conflict: result['data'] = "Invalid ID." @@ -616,7 +616,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False if r.status_code == requests.codes.conflict: result['data'] = "Invalid ID." @@ -634,7 +634,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False return result @@ -659,7 +659,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: try: @@ -690,7 +690,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.no_content: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: try: @@ -712,7 +712,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False tarf = StringIO.StringIO(r.content) return tarf @@ -729,7 +729,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False tarf = StringIO.StringIO(r.content) return tarf @@ -851,7 +851,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False return yaml.load(r.text) else: @@ -872,7 +872,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False return yaml.load(r.text) else: @@ -893,7 +893,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = r.text else: @@ -915,7 +915,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = r.text else: @@ -939,7 +939,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -957,7 +957,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -975,7 +975,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -992,7 +992,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1010,7 +1010,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1028,7 +1028,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1047,7 +1047,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1121,7 +1121,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1138,7 +1138,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1155,7 +1155,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1172,7 +1172,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1188,7 +1188,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False # result['data'] = Util.json_loads_byteified(r.text) result['data'] = r.text @@ -1205,7 +1205,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False # result['data'] = Util.json_loads_byteified(r.text) result['data'] = r.text @@ -1222,7 +1222,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1239,7 +1239,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) @@ -1256,7 +1256,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.accepted: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = r.text @@ -1273,7 +1273,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.accepted: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = r.text @@ -1292,7 +1292,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1310,7 +1310,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1328,7 +1328,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1347,7 +1347,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1363,7 +1363,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1379,7 +1379,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.accepted: + if r.status_code in (200, 201, 202, 204): result['error'] = False else: result['data'] = r.text @@ -1397,7 +1397,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.ok: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result @@ -1415,7 +1415,7 @@ class Client(object): log.exception(e) result['data'] = str(e) return result - if r.status_code == requests.codes.created: + if r.status_code in (200, 201, 202, 204): result['error'] = False result['data'] = Util.json_loads_byteified(r.text) return result diff --git a/netslicehandler/template/nst_list.html b/netslicehandler/template/nst_list.html index 57e940f..dadde87 100644 --- a/netslicehandler/template/nst_list.html +++ b/netslicehandler/template/nst_list.html @@ -149,10 +149,13 @@ Network Slices Templates { "render": function (data, type, row) { return '
' + +<<<<<<< Updated upstream ' \n'+ +======= +>>>>>>> Stashed changes '