From: mirabal Date: Wed, 14 Jun 2017 10:42:30 +0000 (-0500) Subject: Fix 295:Check conectivity btw nodes when net type is ovs X-Git-Tag: v3.0.0rc14~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=42ca00981cfa569e26fcca537e4c1e18d32653b1;p=osm%2Fopenvim.git Fix 295:Check conectivity btw nodes when net type is ovs Change-Id: Ic956b7994c75c66205284b851fe147c699649836 Signed-off-by: mirabal --- diff --git a/openvimd b/openvimd index f2dbd53..b50187d 100755 --- a/openvimd +++ b/openvimd @@ -231,10 +231,22 @@ if __name__ == "__main__": logger.error(error_msg) exit(1) + if config_dic['network_type'] == 'ovs' \ + and config_dic['ovs_controller_ip'] == 'localhost' \ + and not (config_dic['mode'] == 'test' or config_dic['mode'] == "OF only"): + + error_msg = "Error: invalid value '{}' for ovs_controller_ip at {}. " \ + "Use a valid IP address".format(config_dic['ovs_controller_ip'], config_file) + + print ("!! {} ".format(error_msg)) + logger.error(error_msg) + exit(1) + if config_dic['mode'] != 'normal': print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') print ("!! Warning, openvimd in TEST mode '{}'".format(config_dic['mode'])) print ('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') + config_dic['version'] = ovim.ovim.get_version() config_dic["logger_name"] = "openvim" diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py index 00d253e..b8f051c 100644 --- a/osm_openvim/host_thread.py +++ b/osm_openvim/host_thread.py @@ -101,6 +101,7 @@ class host_thread(threading.Thread): self.queueLock = threading.Lock() self.taskQueue = Queue.Queue(2000) self.ssh_conn = None + self.connectivity = True self.lvirt_conn_uri = "qemu+ssh://{user}@{host}/system?no_tty=1&no_verify=1".format( user=self.user, host=self.host) if keyfile: @@ -118,6 +119,28 @@ class host_thread(threading.Thread): text = e.args[0] self.logger.error("ssh_connect ssh Exception: " + text) + def check_connectivity(self): + if not self.test: + + try: + if not self.ssh_conn: + self.ssh_connect() + + command = 'sudo brctl show' + (_, stdout, stderr) = self.ssh_conn.exec_command(command, timeout=10) + content = stderr.read() + if len(content) > 0: + self.connectivity = False + self.logger.error("ssh conection error") + except paramiko.ssh_exception.SSHException as e: + text = e.args[0] + self.connectivity = False + self.logger.error("ssh_connect ssh Exception: " + text) + raise paramiko.ssh_exception.SSHException("ssh error conection") + except Exception as e: + self.connectivity = False + raise paramiko.ssh_exception.SSHException("ssh error conection") + def load_localinfo(self): if not self.test: try: @@ -732,8 +755,10 @@ class host_thread(threading.Thread): Create a bridge in compute OVS to allocate VMs :return: True if success """ - if self.test: + if self.test or not self.connectivity: return True + + try: command = 'sudo ovs-vsctl --may-exist add-br br-int -- set Bridge br-int stp_enable=true' self.logger.debug("command: " + command) @@ -757,7 +782,7 @@ class host_thread(threading.Thread): :return: """ - if self.test: + if self.test or not self.connectivity: return True try: port_name = 'ovim-' + str(vlan) @@ -783,7 +808,7 @@ class host_thread(threading.Thread): :param dhcp_path: conf fiel path that live in namespace side :return: """ - if self.test: + if self.test or not self.connectivity: return True if not self.is_dhcp_port_free(vlan, net_uuid): return True @@ -1253,7 +1278,7 @@ class host_thread(threading.Thread): :param remote_ip: tunnel endpoint remote compute ip. :return: """ - if self.test: + if self.test or not self.connectivity: return True try: command = 'sudo ovs-vsctl add-port br-int ' + vxlan_interface + \ @@ -1279,7 +1304,7 @@ class host_thread(threading.Thread): :param vxlan_interface: vlxan name to be delete it. :return: True if success. """ - if self.test: + if self.test or not self.connectivity: return True try: command = 'sudo ovs-vsctl del-port br-int ' + vxlan_interface @@ -1302,7 +1327,7 @@ class host_thread(threading.Thread): Delete a OVS bridge from a compute. :return: True if success """ - if self.test: + if self.test or not self.connectivity: return True try: command = 'sudo ovs-vsctl del-br br-int' diff --git a/osm_openvim/httpserver.py b/osm_openvim/httpserver.py index aa23d89..7126e21 100644 --- a/osm_openvim/httpserver.py +++ b/osm_openvim/httpserver.py @@ -640,8 +640,9 @@ def http_post_hosts(): test=host_test_mode, image_path=config_dic['host_image_path'], version=config_dic['version'], host_id=content['uuid'], develop_mode=host_develop_mode, develop_bridge_iface=host_develop_bridge_iface) + thread.start() - config_dic['host_threads'][ content['uuid'] ] = thread + config_dic['host_threads'][content['uuid']] = thread if config_dic['network_type'] == 'ovs': # create bridge @@ -650,7 +651,7 @@ def http_post_hosts(): # check if more host exist create_vxlan_mesh(content['uuid']) - #return host data + # return host data change_keys_http2db(content, http2db_host, reverse=True) if len(warning_text)>0: content["warning"]= warning_text diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index 82d06ce..dc21e2d 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -191,6 +191,40 @@ class ovim(): self.config["db_lock"] = threading.Lock() self.of_test_mode = False if self.config['mode'] == 'normal' or self.config['mode'] == "OF only" else True + + # Create one thread for each host + host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False + host_develop_mode = True if self.config['mode'] == 'development' else False + host_develop_bridge_iface = self.config.get('development_bridge', None) + + # get host list from data base before starting threads + r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid', 'password', 'keyfile'), + FROM='hosts', WHERE={'status': 'ok'}) + if r < 0: + raise ovimException("Cannot get hosts from database {}".format(hosts)) + + self.config['host_threads'] = {} + + for host in hosts: + thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], + password=host['password'], + keyfile=host.get('keyfile', self.config["host_ssh_keyfile"]), + db_lock=self.config["db_lock"], test=host_test_mode, + image_path=self.config['host_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')) + + try: + thread.check_connectivity() + except Exception as e: + self.logger.critical('Error detected for compute = {} with ip = {}' + .format(host['name'], host['ip_name'])) + + self.config['host_threads'][host['uuid']] = thread + # precreate interfaces; [bridge:, VLAN used at Host, uuid of network camping in this bridge, # speed in Gbit/s @@ -238,31 +272,7 @@ class ovim(): thread.start() self.config['dhcp_thread'] = thread - # Create one thread for each host - host_test_mode = True if self.config['mode'] == 'test' or self.config['mode'] == "OF only" else False - host_develop_mode = True if self.config['mode'] == 'development' else False - host_develop_bridge_iface = self.config.get('development_bridge', None) - # get host list from data base before starting threads - r, hosts = self.db.get_table(SELECT=('name', 'ip_name', 'user', 'uuid', 'password', 'keyfile'), - FROM='hosts', WHERE={'status': 'ok'}) - if r < 0: - raise ovimException("Cannot get hosts from database {}".format(hosts)) - - self.config['host_threads'] = {} - for host in hosts: - thread = ht.host_thread(name=host['name'], user=host['user'], host=host['ip_name'], db=self.config["db"], - password=host['password'], - keyfile=host.get('keyfile', self.config["host_ssh_keyfile"]), - db_lock=self.config["db_lock"], test=host_test_mode, - image_path=self.config['host_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')) - thread.start() - self.config['host_threads'][host['uuid']] = thread # create ovs dhcp thread result, content = self.db.get_table(FROM='nets') @@ -1375,8 +1385,11 @@ class ovim(): 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() + try: + dhcp_host.check_connectivity() + except Exception as e: + pass + return dhcp_host def launch_dhcp_server(self, vlan, first_ip, last_ip, cidr, gateway):