Fix minor service start in ovim 34/2034/5
authormirabal <leonardo.mirabal@altran.com>
Wed, 19 Jul 2017 13:43:09 +0000 (08:43 -0500)
committermirabal <leonardo.mirabal@altran.com>
Thu, 10 Aug 2017 15:00:33 +0000 (10:00 -0500)
fix delete interfaces that can couse issues in a compute reboot
fix few run_command execution to avoid exception raise, make indempotent

Change-Id: Ib4374fb4c85d63197dd0a80b146b3557b367710f
Signed-off-by: mirabal <leonardo.mirabal@altran.com>
osm_openvim/host_thread.py
osm_openvim/ovim.py

index 368dcbc..18a2eab 100644 (file)
@@ -952,7 +952,7 @@ class host_thread(threading.Thread):
             command = 'sudo ip link set dev ovim-{} down'.format(str(vlan))
             self.run_command(command)
 
-            command = 'sudo ifconfig {} down &&  sudo brctl delbr {}'.format(port_name, port_name)
+            command = 'sudo  ip link delete  {}  &&  sudo brctl delbr {}'.format(port_name, port_name)
             self.run_command(command)
             return True
         except RunCommandException as e:
@@ -975,14 +975,14 @@ class host_thread(threading.Thread):
 
             # Delete ovs veth pair
             command = 'sudo ip link set dev {} down'.format(br_ovs_name)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
 
             command = 'sudo ovs-vsctl del-port br-int {}'.format(br_ovs_name)
             self.run_command(command)
 
             # Delete br veth pair
             command = 'sudo ip link set dev {} down'.format(br_tap_name)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
 
             # Delete br veth interface form bridge
             command = 'sudo brctl delif {} {}'.format(link, br_tap_name)
@@ -990,7 +990,7 @@ class host_thread(threading.Thread):
 
             # Delete br veth pair
             command = 'sudo ip link set dev {} down'.format(link)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
 
             return True
         except RunCommandException as e:
@@ -1213,6 +1213,9 @@ class host_thread(threading.Thread):
             command = 'sudo ip link set dev {} down'.format(ovs_veth_name)
             self.run_command(command, ignore_exit_status=True)  # to end session
 
+            command = 'sudo ip link delete {} '.format(ovs_veth_name)
+            self.run_command(command, ignore_exit_status=True)
+
             command = 'sudo ip netns exec {} ip link set dev {} down'.format(dhcp_namespace, br_veth_name)
             self.run_command(command, ignore_exit_status=True)
 
@@ -1291,26 +1294,37 @@ class host_thread(threading.Thread):
             qrouter_ns_router_veth = '{}-vethQB'.format(str(vlan))
 
             command = 'sudo ovs-vsctl del-port br-int {}'.format(qrouter_ovs_veth)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
 
             # down ns veth
             command = 'sudo ip netns exec {} ip link set dev {} down'.format(ns_qouter, qrouter_ns_veth)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
+
+            command = 'sudo ip netns exec {}  ip link delete {} '.format(ns_qouter, qrouter_ns_veth)
+            self.run_command(command, ignore_exit_status=True)
 
             command = 'sudo ip netns del ' + ns_qouter
             self.run_command(command)
 
             # down ovs veth interface
             command = 'sudo ip link set dev {} down'.format(qrouter_br_veth)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
 
             # down br veth interface
             command = 'sudo ip link set dev {} down'.format(qrouter_ovs_veth)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
+
+            # delete  veth interface
+            command = 'sudo ip link delete {} '.format(link, qrouter_ovs_veth)
+            self.run_command(command, ignore_exit_status=True)
 
             # down br veth interface
             command = 'sudo ip link set dev {} down'.format(qrouter_ns_router_veth)
-            self.run_command(command)
+            self.run_command(command, ignore_exit_status=True)
+
+            # delete  veth interface
+            command = 'sudo ip link delete {} '.format(link, qrouter_ns_router_veth)
+            self.run_command(command, ignore_exit_status=True)
 
             # down br veth interface
             command = 'sudo brctl delif {} {}'.format(link, qrouter_br_veth)
@@ -1344,7 +1358,7 @@ class host_thread(threading.Thread):
 
             # Create pait veth
             command = 'sudo ip link add {} type veth peer name {}'.format(qrouter_ns_veth, qrouter_ovs_veth)
-            self.run_command(command)
+            self.run_command(command,  ignore_exit_status=True)
 
             # up ovs veth interface
             command = 'sudo ip link set dev {} up'.format(qrouter_ovs_veth)
index 5650cd5..fe2748f 100755 (executable)
@@ -301,13 +301,14 @@ class ovim():
                     links = net.get('links')
                     if links:
                         links = yaml.safe_load(net.get('links'))
-                    self.launch_dhcp_server(net.get('vlan'),
-                                            net.get('dhcp_first_ip'),
-                                            net.get('dhcp_last_ip'),
-                                            net.get('cidr'),
-                                            net.get('gateway_ip'),
-                                            dns,
-                                            routes)
+                    if net.get('enable_dhcp'):
+                        self.launch_dhcp_server(net.get('vlan'),
+                                                net.get('dhcp_first_ip'),
+                                                net.get('dhcp_last_ip'),
+                                                net.get('cidr'),
+                                                net.get('gateway_ip'),
+                                                dns,
+                                                routes)
                     self.launch_link_bridge_to_ovs(net['vlan'], net.get('gateway_ip'), net.get('cidr'), links, routes)
                     if net["status"] == "ERROR":
                         self.db.update_rows("nets", UPDATE={"status": "ACTIVE", "last_error": None},
@@ -671,11 +672,10 @@ class ovim():
             network['routes'] = yaml.safe_dump(network['routes'], default_flow_style=True, width=256)
 
         result, content = self.db.new_row('nets', network, True, True)
-
         if result >= 0 and dhcp_integrity:
             if bridge_net:
                 bridge_net[3] = content
-            if self.config.get("dhcp_server") and self.config['network_type'] == 'bridge':
+            if self.config.get("dhcp_server") and self.config['network_type'] == 'bridge': # \
                 if network["name"] in self.config["dhcp_server"].get("nets", ()):
                     self.config["dhcp_nets"].append(content)
                     self.logger.debug("dhcp_server: add new net", content)
@@ -784,6 +784,7 @@ class ovim():
         :param network_id:  network id
         :return:
         """
+        net_data = self.show_network(network_id)
 
         # delete from the data base
         result, content = self.db.delete_row('nets', network_id)
@@ -797,7 +798,18 @@ class ovim():
                     break
             if self.config.get("dhcp_server") and network_id in self.config["dhcp_nets"]:
                 self.config["dhcp_nets"].remove(network_id)
-            return content
+
+            if net_data.get('enable_dhcp'):
+                dhcp_path = self.config['ovs_controller_file_path']
+                dhcp_controller = self.get_dhcp_controller()
+                dhcp_controller.delete_dhcp_server(net_data['vlan'], network_id, dhcp_path)
+                dhcp_controller.delete_dhcp_port(net_data['vlan'], network_id, dhcp_path)
+                links = yaml.load(net_data.get('links'))
+                if links:
+                    links = yaml.load(net_data.get('links'))
+                    self.delete_link_bridge_to_ovs(net_data['vlan'], links)
+
+                return content
         else:
             raise ovimException("Error deleting network '{}': {}".format(network_id, content), -result)