From: tierno Date: Fri, 16 Sep 2016 12:17:46 +0000 (+0200) Subject: v0.4.53 fix an issue instanciating with params a scenario defined with old version... X-Git-Tag: v1.0.0~38 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=efd80c982df1301bf4bdaaf8c8ae78919a03964f;p=osm%2FRO.git v0.4.53 fix an issue instanciating with params a scenario defined with old version schema Change-Id: I82216a2a4e27949f95a064b8249a541729f317d2 Signed-off-by: tierno --- diff --git a/httpserver.py b/httpserver.py index a4e7fb9b..d9d6cc85 100644 --- a/httpserver.py +++ b/httpserver.py @@ -143,7 +143,7 @@ def run_bottle(db, host_='localhost', port_=9090): @bottle.route(url_base + '/', method='GET') def http_get(): - print + #print return 'works' #TODO: to be completed # @@ -172,7 +172,7 @@ def change_keys_http2db(data, http_db, reverse=False): def format_out(data): '''return string of dictionary data according to requested json, yaml, xml. By default json''' - logger.debug(yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) ) + logger.debug("OUT: " + yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) ) if 'application/yaml' in bottle.request.headers.get('Accept'): bottle.response.content_type='application/yaml' return yaml.safe_dump(data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) #, canonical=True, default_style='"' @@ -207,14 +207,14 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None): elif 'application/xml' in format_type: bottle.abort(501, "Content-Type: application/xml not supported yet.") else: - print 'Content-Type ' + str(format_type) + ' not supported.' + logger.warning('Content-Type ' + str(format_type) + ' not supported.') bottle.abort(HTTP_Not_Acceptable, 'Content-Type ' + str(format_type) + ' not supported.') return #if client_data == None: # bottle.abort(HTTP_Bad_Request, "Content error, empty") # return - #logger.debug('client-data: %s', client_data) + logger.debug('IN: %s', yaml.safe_dump(client_data, explicit_start=True, indent=4, default_flow_style=False, tags=False, encoding='utf-8', allow_unicode=True) ) #look for the client provider version error_text = "Invalid content " client_version = None @@ -241,10 +241,10 @@ def format_in(default_schema, version_fields=None, version_dict_schema=None): return client_data, used_schema except (ValueError, yaml.YAMLError) as exc: error_text += str(exc) - print error_text + logger.error(error_text) bottle.abort(HTTP_Bad_Request, error_text) except js_e.ValidationError as exc: - print "validate_in error, jsonschema exception ", exc.message, "at", exc.path + logger.error("validate_in error, jsonschema exception at '%s' '%s' ", str(exc.path), str(exc.message)) error_pos = "" if len(exc.path)>0: error_pos=" at " + ":".join(map(json.dumps, exc.path)) bottle.abort(HTTP_Bad_Request, error_text + exc.message + error_pos) @@ -344,7 +344,8 @@ def http_post_tenants(): logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) http_content,_ = format_in( tenant_schema ) r = utils.remove_extra_items(http_content, tenant_schema) - if r is not None: print "http_post_tenants: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) try: data = nfvo.new_tenant(mydb, http_content['tenant']) return http_get_tenant_id(data) @@ -359,7 +360,8 @@ def http_edit_tenant_id(tenant_id): logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) http_content,_ = format_in( tenant_edit_schema ) r = utils.remove_extra_items(http_content, tenant_edit_schema) - if r is not None: print "http_edit_tenant_id: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) #obtain data, check that only one exist try: @@ -457,7 +459,7 @@ def http_get_datacenter_id(tenant_id, datacenter_id): config_dict = yaml.load(datacenter['config']) datacenter['config'] = config_dict except Exception, e: - print "Exception '%s' while trying to load config information" % str(e) + logger.error("Exception '%s' while trying to load config information", str(e)) #change_keys_http2db(content, http2db_datacenter, reverse=True) convert_datetime2str(datacenter) data={'datacenter' : datacenter} @@ -473,7 +475,8 @@ def http_post_datacenters(): logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) http_content,_ = format_in( datacenter_schema ) r = utils.remove_extra_items(http_content, datacenter_schema) - if r is not None: print "http_post_datacenters: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) try: data = nfvo.new_datacenter(mydb, http_content['datacenter']) return http_get_datacenter_id('any', data) @@ -488,7 +491,8 @@ def http_edit_datacenter_id(datacenter_id_name): #parse input data http_content,_ = format_in( datacenter_edit_schema ) r = utils.remove_extra_items(http_content, datacenter_edit_schema) - if r is not None: print "http_edit_datacenter_id: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) try: datacenter_id = nfvo.edit_datacenter(mydb, datacenter_id_name, http_content['datacenter']) @@ -576,8 +580,8 @@ def http_postnetmap_datacenter_id(tenant_id, datacenter_id): #parse input data http_content,_ = format_in( netmap_new_schema ) r = utils.remove_extra_items(http_content, netmap_new_schema) - if r is not None: print "http_postnetmap_datacenter_id: Warning: remove extra items ", r - + if r: + logger.debug("Remove received extra items %s", str(r)) try: #obtain data, check that only one exist netmaps = nfvo.datacenter_new_netmap(mydb, tenant_id, datacenter_id, http_content) @@ -596,7 +600,8 @@ def http_putnettmap_datacenter_id(tenant_id, datacenter_id, netmap_id): #parse input data http_content,_ = format_in( netmap_edit_schema ) r = utils.remove_extra_items(http_content, netmap_edit_schema) - if r is not None: print "http_putnettmap_datacenter_id: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) #obtain data, check that only one exist try: @@ -614,8 +619,8 @@ def http_action_datacenter_id(tenant_id, datacenter_id): #parse input data http_content,_ = format_in( datacenter_action_schema ) r = utils.remove_extra_items(http_content, datacenter_action_schema) - if r is not None: print "http_action_datacenter_id: Warning: remove extra items ", r - + if r: + logger.debug("Remove received extra items %s", str(r)) try: #obtain data, check that only one exist result = nfvo.datacenter_action(mydb, tenant_id, datacenter_id, http_content) @@ -647,7 +652,8 @@ def http_associate_datacenters(tenant_id, datacenter_id): #parse input data http_content,_ = format_in( datacenter_associate_schema ) r = utils.remove_extra_items(http_content, datacenter_associate_schema) - if r != None: print "http_associate_datacenters: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) try: id_ = nfvo.associate_datacenter_to_tenant(mydb, tenant_id, datacenter_id, http_content['datacenter'].get('vim_tenant'), @@ -746,7 +752,8 @@ def http_post_vnfs(tenant_id): logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url) http_content, used_schema = format_in( vnfd_schema_v01, ("schema_version",), {"0.2": vnfd_schema_v02}) r = utils.remove_extra_items(http_content, used_schema) - if r is not None: print "http_post_vnfs: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) try: if used_schema == vnfd_schema_v01: vnf_id = nfvo.new_vnf(mydb,tenant_id,http_content) @@ -788,11 +795,11 @@ def http_get_hosts(tenant_id, datacenter): result, data = nfvo.get_hosts_info(mydb, tenant_id) #, datacenter) if result < 0: - print "http_get_hosts error %d %s" % (-result, data) + #print "http_get_hosts error %d %s" % (-result, data) bottle.abort(-result, data) else: convert_datetime2str(data) - print json.dumps(data, indent=4) + #print json.dumps(data, indent=4) return format_out(data) except (nfvo.NfvoException, db_base_Exception) as e: logger.error("http_get_hosts error {}: {}".format(e.http_code, str(e))) @@ -877,7 +884,8 @@ def http_post_scenario_action(tenant_id, scenario_id): #parse input data http_content,_ = format_in( scenario_action_schema ) r = utils.remove_extra_items(http_content, scenario_action_schema) - if r is not None: print "http_post_scenario_action: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) if "start" in http_content: data = nfvo.start_scenario(mydb, tenant_id, scenario_id, http_content['start']['instance_name'], \ http_content['start'].get('description',http_content['start']['instance_name']), @@ -1074,7 +1082,8 @@ def http_post_instance_scenario_action(tenant_id, instance_id): #parse input data http_content,_ = format_in( instance_scenario_action_schema ) r = utils.remove_extra_items(http_content, instance_scenario_action_schema) - if r is not None: print "http_post_instance_scenario_action: Warning: remove extra items ", r + if r: + logger.debug("Remove received extra items %s", str(r)) #print "http_post_instance_scenario_action input: ", http_content #obtain data instance = mydb.get_instance_scenario(instance_id, tenant_id) diff --git a/nfvo.py b/nfvo.py index 4da9f554..d3fc9255 100644 --- a/nfvo.py +++ b/nfvo.py @@ -953,6 +953,7 @@ def new_scenario(mydb, tenant_id, topo): #1.4 get list of connections conections = topo['topology']['connections'] conections_list = [] + conections_list_name = [] for k in conections.keys(): if type(conections[k]['nodes'])==dict: #dict with node:iface pairs ifaces_list = conections[k]['nodes'].items() @@ -981,7 +982,7 @@ def new_scenario(mydb, tenant_id, topo): if con_type == "dataplane_net" or con_type == "bridge_net": other_nets[k]["model"] = con_type - + conections_list_name.append(k) conections_list.append(set(ifaces_list)) #from list to set to operate as a set (this conversion removes elements that are repeated in a list) #print set(ifaces_list) #check valid VNF and iface names @@ -1001,6 +1002,7 @@ def new_scenario(mydb, tenant_id, topo): if len(conections_list[index] & conections_list[index2])>0: #common interface, join nets conections_list[index] |= conections_list[index2] del conections_list[index2] + del conections_list_name[index2] else: index2 += 1 conections_list[index] = list(conections_list[index]) # from set to list again @@ -1107,7 +1109,8 @@ def new_scenario(mydb, tenant_id, topo): net_type_bridge=False net_type_data=False net_target = "__-__net"+str(net_nb) - net_list[net_target] = {'name': "net-"+str(net_nb), 'description':"net-%s in scenario %s" %(net_nb,topo['name']), + net_list[net_target] = {'name': conections_list_name[net_nb], #"net-"+str(net_nb), + 'description':"net-%s in scenario %s" %(net_nb,topo['name']), 'external':False} for iface in con: vnfs[ iface[0] ]['ifaces'][ iface[1] ]['net_key'] = net_target diff --git a/openmanod.py b/openmanod.py index 5294a9ff..a1015d59 100755 --- a/openmanod.py +++ b/openmanod.py @@ -33,7 +33,7 @@ It loads the configuration file and launches the http_server thread that will li ''' __author__="Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ ="$26-aug-2014 11:09:29$" -__version__="0.4.52-r494" +__version__="0.4.53-r495" version_date="Sep 2016" database_version="0.13" #expected database schema version