From e0c28c1feee0fac059bad64eb8601e9c6e47fefc Mon Sep 17 00:00:00 2001 From: tierno Date: Thu, 4 May 2017 18:44:40 +0200 Subject: [PATCH] fix bugs at host_thread; start net controller thread; sharing same variables db_lock and db between the two ovim instances; logger name at openflow thread Change-Id: I02cbd50a0c9922764a945490cb885bb63c75e9c0 Signed-off-by: tierno --- osm_openvim/host_thread.py | 10 +++++----- osm_openvim/httpserver.py | 4 +++- osm_openvim/openflow_thread.py | 16 ++++++++++------ osm_openvim/ovim.py | 34 ++++++++++++++++++---------------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py index 897d70e..cdc4209 100644 --- a/osm_openvim/host_thread.py +++ b/osm_openvim/host_thread.py @@ -318,12 +318,12 @@ class host_thread(threading.Thread): continue if task[0] == 'instance': - self.logger.debug("processing task instance " + task[1]['action']) - retry=0 - while retry <2: + self.logger.debug("processing task instance " + str(task[1]['action'])) + retry = 0 + while retry < 2: retry += 1 - r=self.action_on_server(task[1], retry==2) - if r>=0: + r = self.action_on_server(task[1], retry==2) + if r >= 0: break elif task[0] == 'image': pass diff --git a/osm_openvim/httpserver.py b/osm_openvim/httpserver.py index edf1e8d..17925ac 100644 --- a/osm_openvim/httpserver.py +++ b/osm_openvim/httpserver.py @@ -1831,7 +1831,9 @@ def http_server_action(server_id, tenant_id, action): delete_dhcp_ovs_bridge(vlan, net_id) delete_mac_dhcp(vm_ip, vlan, mac) config_dic['host_threads'][server['host_id']].insert_task('del-ovs-port', vlan, net_id) - return format_out(data + warn_text) + if warn_text: + data["result"] += warn_text + return format_out(data) diff --git a/osm_openvim/openflow_thread.py b/osm_openvim/openflow_thread.py index 2f39fab..24fc77f 100644 --- a/osm_openvim/openflow_thread.py +++ b/osm_openvim/openflow_thread.py @@ -93,18 +93,22 @@ class openflow_thread(threading.Thread): """ This thread interacts with a openflow controller to create dataplane connections """ - def __init__(self, of_uuid, of_connector, db, db_lock, of_test, pmp_with_same_vlan=False, debug='ERROR'): + def __init__(self, of_uuid, of_connector, db, db_lock, of_test, pmp_with_same_vlan=False, logger_name=None, + debug=None): threading.Thread.__init__(self) self.of_uuid = of_uuid self.db = db self.pmp_with_same_vlan = pmp_with_same_vlan - self.name = "openflow" self.test = of_test self.db_lock = db_lock self.OF_connector = of_connector - self.logger = logging.getLogger('vim.OF-' + of_uuid) - self.logger.setLevel(getattr(logging, debug)) - self.logger.name = of_connector.name + " " + self.OF_connector.dpid + if logger_name: + self.logger_name = logger_name + else: + self.logger_name = "openvim.ofc." + of_uuid + self.logger = logging.getLogger(self.logger_name) + if debug: + self.logger.setLevel(getattr(logging, debug)) self.queueLock = threading.Lock() self.taskQueue = Queue.Queue(2000) @@ -115,7 +119,7 @@ class openflow_thread(threading.Thread): self.queueLock.release() return 1, None except Queue.Full: - return -1, "timeout inserting a task over openflow thread " + self.name + return -1, "timeout inserting a task over openflow thread " + self.of_uuid def run(self): self.logger.debug("Start openflow thread") diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index c79f86a..c999049 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -100,8 +100,6 @@ class ovim(): self.logger = logging.getLogger(self.logger_name) self.db = None self.db = self._create_database_connection() - self.db_lock = None - self.db_of = None self.of_test_mode = False def _create_database_connection(self): @@ -189,10 +187,8 @@ class ovim(): self.logger.critical("Starting ovim server version: '{} {}' database version '{}'".format( self.get_version(), self.get_version_date(), self.get_database_version())) # create database connection for openflow threads - self.db_of = self._create_database_connection() - self.config["db"] = self.db_of - self.db_lock = threading.Lock() - self.config["db_lock"] = self.db_lock + self.config["db"] = self._create_database_connection() + self.config["db_lock"] = threading.Lock() self.of_test_mode = False if self.config['mode'] == 'normal' or self.config['mode'] == "OF only" else True # precreate interfaces; [bridge:, VLAN used at Host, uuid of network camping in this bridge, @@ -236,7 +232,8 @@ class ovim(): dhcp_params = self.config.get("dhcp_server") if dhcp_params: thread = dt.dhcp_thread(dhcp_params=dhcp_params, test=host_test_mode, dhcp_nets=self.config["dhcp_nets"], - db=self.db_of, db_lock=self.db_lock, logger_name=self.logger_name + ".dhcp", + db=self.config["db"], db_lock=self.config["db_lock"], + logger_name=self.logger_name + ".dhcp", debug=self.config.get('log_level_of')) thread.start() self.config['dhcp_thread'] = thread @@ -254,9 +251,11 @@ class ovim(): self.config['host_threads'] = {} for host in hosts: host['image_path'] = '/opt/VNF/images/openvim' - thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.db_of, - db_lock=self.db_lock, test=host_test_mode, image_path=self.config['image_path'], - version=self.config['version'], host_id=host['uuid'], develop_mode=host_develop_mode, + thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], + db_lock=self.config["db_lock"], test=host_test_mode, + image_path=self.config['image_path'], + version=self.config['version'], host_id=host['uuid'], + develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface, logger_name=self.logger_name + ".host." + host['name'], debug=self.config.get('log_level_host')) @@ -417,8 +416,11 @@ class ovim(): # ofc_net_same_vlan = False ofc_net_same_vlan = False - thread = oft.openflow_thread(ofc_uuid, of_conn, of_test=self.of_test_mode, db=self.db_of, db_lock=self.db_lock, - pmp_with_same_vlan=ofc_net_same_vlan, debug=self.config['log_level_of']) + thread = oft.openflow_thread(ofc_uuid, of_conn, of_test=self.of_test_mode, db=self.config["db"], + db_lock=self.config["db_lock"], + pmp_with_same_vlan=ofc_net_same_vlan, + logger_name=self.logger_name + ".ofc." + ofc_uuid, + debug=self.config.get('log_level_of')) #r, c = thread.OF_connector.obtain_port_correspondence() #if r < 0: # raise ovimException("Cannot get openflow information %s", c) @@ -1357,13 +1359,13 @@ class ovim(): host_develop_mode = True if self.config['mode'] == 'development' else False dhcp_host = ht.host_thread(name='openvim_controller', user=ovs_controller_user, host=controller_ip, - db=self.db_of, - db_lock=self.db_lock, test=host_test_mode, + db=self.config["db"], db_lock=self.config["db_lock"], test=host_test_mode, image_path=self.config['image_path'], version=self.config['version'], host_id='openvim_controller', develop_mode=host_develop_mode, - develop_bridge_iface=bridge_ifaces, logger_name=self.logger_name + ".host.controller", + develop_bridge_iface=bridge_ifaces, + logger_name=self.logger_name + ".host.controller", debug=self.config.get('log_level_host')) - + dhcp_host.start() self.config['host_threads']['openvim_controller'] = dhcp_host if not host_test_mode: dhcp_host.ssh_connect() -- 2.25.1