From: tierno Date: Wed, 29 Nov 2017 16:20:13 +0000 (+0100) Subject: fix some more issues at SDN assist and deleting openstack ports X-Git-Tag: v3.0.3~19 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F5742%2F4;p=osm%2FRO.git fix some more issues at SDN assist and deleting openstack ports Change-Id: I9eaac0d8955ac55d50e14aba77238dc74cab46d4 Signed-off-by: tierno --- diff --git a/openmanod b/openmanod index a516a52c..ca870e90 100755 --- a/openmanod +++ b/openmanod @@ -48,7 +48,7 @@ import osm_ro __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes" __date__ = "$26-aug-2014 11:09:29$" -__version__ = "0.5.44-r554" +__version__ = "0.5.45-r555" version_date = "Nov 2017" database_version = 27 # expected database schema version diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 6dff906f..ce969107 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -4341,29 +4341,35 @@ def vim_action_create(mydb, tenant_id, datacenter, item, descriptor): #If the datacenter has a SDN controller defined and the network is of dataplane type, then create the sdn network if get_sdn_controller_id(mydb, datacenter) != None and (net_type == 'data' or net_type == 'ptp'): + #obtain datacenter_tenant_id + datacenter_tenant_id = mydb.get_rows(SELECT=('uuid',), + FROM='datacenter_tenants', + WHERE={'datacenter_id': datacenter})[0]['uuid'] try: sdn_network = {} sdn_network['vlan'] = net_vlan sdn_network['type'] = net_type sdn_network['name'] = net_name + sdn_network['region'] = datacenter_tenant_id ovim_content = ovim.new_network(sdn_network) except ovimException as e: - self.logger.error("ovimException creating SDN network={} ".format( + logger.error("ovimException creating SDN network={} ".format( sdn_network) + str(e), exc_info=True) raise NfvoException("ovimException creating SDN network={} ".format(sdn_network) + str(e), HTTP_Internal_Server_Error) # Save entry in in dabase mano_db in table instance_nets to stablish a dictionary vim_net_id <->sdn_net_id # use instance_scenario_id=None to distinguish from real instaces of nets - correspondence = {'instance_scenario_id': None, 'sdn_net_id': ovim_content, 'vim_net_id': content} - #obtain datacenter_tenant_id - correspondence['datacenter_tenant_id'] = mydb.get_rows(SELECT=('uuid',), FROM='datacenter_tenants', WHERE={'datacenter_id': datacenter})[0]['uuid'] - + correspondence = {'instance_scenario_id': None, + 'sdn_net_id': ovim_content, + 'vim_net_id': content, + 'datacenter_tenant_id': datacenter_tenant_id + } try: mydb.new_row('instance_nets', correspondence, add_uuid=True) except db_base_Exception as e: - raise NfvoException("Error saving correspondence for VIM/SDN dataplane networks{}: ".format(correspondence) + - str(e), HTTP_Internal_Server_Error) + raise NfvoException("Error saving correspondence for VIM/SDN dataplane networks{}: {}".format( + correspondence, e), HTTP_Internal_Server_Error) elif item=="tenants": tenant = descriptor["tenant"] content = myvim.new_tenant(tenant["name"], tenant.get("description")) diff --git a/osm_ro/vim_thread.py b/osm_ro/vim_thread.py index fe094ed3..e401502f 100644 --- a/osm_ro/vim_thread.py +++ b/osm_ro/vim_thread.py @@ -599,11 +599,11 @@ class vim_thread(threading.Thread): if to_supersede["action"] == "FIND" and to_supersede.get("vim_id"): task["vim_id"] = to_supersede["vim_id"] if to_supersede["action"] == "CREATE" and to_supersede["extra"].get("created", True) and \ - (to_supersede.get("vim_id") or to_supersede["extra"].get("sdn_vim_id")): + (to_supersede.get("vim_id") or to_supersede["extra"].get("sdn_net_id")): need_delete_action = True task["vim_id"] = to_supersede["vim_id"] - if to_supersede["extra"].get("sdn_vim_id"): - task["extra"]["sdn_vim_id"] = to_supersede["extra"]["sdn_vim_id"] + if to_supersede["extra"].get("sdn_net_id"): + task["extra"]["sdn_net_id"] = to_supersede["extra"]["sdn_net_id"] if to_supersede["extra"].get("interfaces"): task["extra"]["interfaces"] = to_supersede["extra"]["interfaces"] if to_supersede["extra"].get("created_items"): @@ -800,9 +800,9 @@ class vim_thread(threading.Thread): """ vim_nets = self.vim.get_network_list(filter_param) if not vim_nets: - raise VimThreadExceptionNotFound("Network not found with this criteria: '{}'".format(filter)) + raise VimThreadExceptionNotFound("Network not found with this criteria: '{}'".format(filter_param)) elif len(vim_nets) > 1: - raise VimThreadException("More than one network found with this criteria: '{}'".format(filter)) + raise VimThreadException("More than one network found with this criteria: '{}'".format(filter_param)) vim_net_id = vim_nets[0]["id"] # Discover if this network is managed by a sdn controller @@ -821,7 +821,7 @@ class vim_thread(threading.Thread): task["error_msg"] = None task["vim_id"] = vim_net_id instance_element_update = {"vim_net_id": vim_net_id, "created": False, "status": "BUILD", - "error_msg": None} + "error_msg": None, "sdn_net_id": sdn_net_id} return instance_element_update def get_net(self, task): diff --git a/osm_ro/vimconn_openstack.py b/osm_ro/vimconn_openstack.py index 65e17b5d..117171eb 100644 --- a/osm_ro/vimconn_openstack.py +++ b/osm_ro/vimconn_openstack.py @@ -75,8 +75,8 @@ netStatus2manoFormat={'ACTIVE':'ACTIVE','PAUSED':'PAUSED','INACTIVE':'INACTIVE', supportedClassificationTypes = ['legacy_flow_classifier'] #global var to have a timeout creating and deleting volumes -volume_timeout = 60 -server_timeout = 300 +volume_timeout = 600 +server_timeout = 600 class vimconnector(vimconn.vimconnector): def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, @@ -495,8 +495,8 @@ class vimconnector(vimconn.vimconnector): self._reload_connection() if self.api_version3 and "tenant_id" in filter_dict: filter_dict['project_id'] = filter_dict.pop('tenant_id') #TODO check - net_dict=self.neutron.list_networks(**filter_dict) - net_list=net_dict["networks"] + net_dict = self.neutron.list_networks(**filter_dict) + net_list = net_dict["networks"] self.__net_os2mano(net_list) return net_list except (neExceptions.ConnectionFailed, ksExceptions.ClientException, neExceptions.NeutronException, ConnectionError) as e: @@ -1033,7 +1033,7 @@ class vimconnector(vimconn.vimconnector): if net.get("mac_address"): port_dict["mac_address"]=net["mac_address"] new_port = self.neutron.create_port({"port": port_dict }) - created_items[("port", str(new_port["port"]["id"]))] = True + created_items["port:" + str(new_port["port"]["id"])] = True net["mac_adress"] = new_port["port"]["mac_address"] net["vim_id"] = new_port["port"]["id"] # if try to use a network without subnetwork, it will return a emtpy list @@ -1088,7 +1088,7 @@ class vimconnector(vimconn.vimconnector): else: volume = self.cinder.volumes.create(size=disk['size'], name=name + '_vd' + chr(base_disk_index)) - created_items[("volume", str(volume.id))] = True + created_items["volume:" + str(volume.id)] = True block_device_mapping['_vd' + chr(base_disk_index)] = volume.id base_disk_index += 1 @@ -1283,10 +1283,10 @@ class vimconnector(vimconn.vimconnector): if not v: # skip already deleted continue try: - if k[0] == "port": - self.neutron.delete_port(k[1]) + if k.startswith("port:"): + self.neutron.delete_port(k.strip("port:")) except Exception as e: - self.logger.error("Error deleting port: " + type(e).__name__ + ": "+ str(e)) + self.logger.error("Error deleting port: {}: {}".format(type(e).__name__, e)) # #commented because detaching the volumes makes the servers.delete not work properly ?!? # #dettach volumes attached @@ -1308,13 +1308,14 @@ class vimconnector(vimconn.vimconnector): if not v: # skip already deleted continue try: - if k[0] == "volume": - if self.cinder.volumes.get(k[1]).status != 'available': + if k.startswith("volume:"): + volume_id = k.strip("volume:") + if self.cinder.volumes.get(volume_id).status != 'available': keep_waiting = True else: - self.cinder.volumes.delete(k[1]) + self.cinder.volumes.delete(volume_id) except Exception as e: - self.logger.error("Error deleting volume: " + type(e).__name__ + ": " + str(e)) + self.logger.error("Error deleting volume: {}: {}".format(type(e).__name__, e)) if keep_waiting: time.sleep(1) elapsed_time += 1