cleanup ryu and leftover containers at startup
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 19 Jul 2016 00:54:45 +0000 (02:54 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Tue, 19 Jul 2016 00:54:45 +0000 (02:54 +0200)
src/emuvim/dcemulator/monitoring.py
src/emuvim/dcemulator/net.py
src/emuvim/test/unittests/test_emulator.py
utils/ci/test_sdk_monitor.sh

index 78d6ebb..80b139c 100755 (executable)
@@ -60,8 +60,6 @@ class DCNetworkMonitor():
         self.pushgateway = 'localhost:9091'\r
         # when sdk is started with docker-compose, we could use\r
         # self.pushgateway = 'pushgateway:9091'\r
-        # Start up the server to expose the metrics to Prometheus\r
-        #start_http_server(8000)\r
 \r
         # supported Prometheus metrics\r
         self.registry = CollectorRegistry()\r
@@ -104,10 +102,8 @@ class DCNetworkMonitor():
         self.monitor_flow_thread.start()\r
 \r
         # helper tools\r
-        # Prometheus pushgateway and DB are started as external contianer, outside of son-emu\r
-        #self.pushgateway_process = self.start_PushGateway()\r
-        #self.prometheus_process = self.start_Prometheus()\r
-        #self.cadvisor_process = self.start_cadvisor()\r
+        # cAdvisor, Prometheus pushgateway and DB are started as external container, outside of son-emu\r
+\r
 \r
     # first set some parameters, before measurement can start\r
     def setup_flow(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0):\r
index 0e3882c..2c5ce14 100755 (executable)
@@ -65,6 +65,11 @@ class DCNetwork(Containernet):
         """
         self.dcs = {}
 
+        # make sure any remaining Ryu processes are killed
+        self.killRyu()
+        # make sure no containers are left over from a previous emulator run.
+        self.removeLeftoverContainers()
+
         # call original Docker.__init__ and setup default controller
         Containernet.__init__(
             self, switch=OVSKernelSwitch, controller=controller, **kwargs)
@@ -500,6 +505,16 @@ class DCNetwork(Containernet):
         if self.ryu_process is not None:
             self.ryu_process.terminate()
             self.ryu_process.kill()
+        self.killRyu()
+
+    @staticmethod
+    def removeLeftoverContainers():
+        # TODO can be more python-based using eg. docker-py?
+        Popen('docker ps -a -q --filter="name=mn.*" | xargs -r docker rm -f', shell=True)
+
+    @staticmethod
+    def killRyu():
+        Popen(['pkill', '-f', 'ryu-manager'])
 
     def ryu_REST(self, prefix, dpid=None, data=None):
         try:
index ef1fb51..ae18609 100755 (executable)
@@ -157,6 +157,8 @@ class testEmulatorNetworking( SimpleTestTopology ):
         self.assertTrue(s2["network"][0]['intf_name'] == 'intf2')
         self.assertTrue(s2["network"][0]['ip'] == '10.0.10.2')
 
+        # should be not not yet connected
+        self.assertTrue(self.net.ping([vnf1, vnf2]) > 0.0)
         # setup links
         self.net.setChain('vnf1', 'vnf2', 'intf1', 'intf2', bidirectional=True, cmd='add-flow')
         # check connectivity by using ping
index e5cd13b..8c3ce47 100755 (executable)
@@ -1,4 +1,7 @@
 #!/bin/bash
+set -e
+set -x
+
 # test if a vnf can be deployed and monitored
 
 #start test emulator topology