From 8970680521bb7ec0501e6ff9a770c8a0c74e6add Mon Sep 17 00:00:00 2001 From: stevenvanrossem Date: Tue, 19 Jul 2016 02:54:45 +0200 Subject: [PATCH] cleanup ryu and leftover containers at startup --- src/emuvim/dcemulator/monitoring.py | 8 ++------ src/emuvim/dcemulator/net.py | 15 +++++++++++++++ src/emuvim/test/unittests/test_emulator.py | 2 ++ utils/ci/test_sdk_monitor.sh | 3 +++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py index 78d6ebb..80b139c 100755 --- a/src/emuvim/dcemulator/monitoring.py +++ b/src/emuvim/dcemulator/monitoring.py @@ -60,8 +60,6 @@ class DCNetworkMonitor(): self.pushgateway = 'localhost:9091' # when sdk is started with docker-compose, we could use # self.pushgateway = 'pushgateway:9091' - # Start up the server to expose the metrics to Prometheus - #start_http_server(8000) # supported Prometheus metrics self.registry = CollectorRegistry() @@ -104,10 +102,8 @@ class DCNetworkMonitor(): self.monitor_flow_thread.start() # helper tools - # Prometheus pushgateway and DB are started as external contianer, outside of son-emu - #self.pushgateway_process = self.start_PushGateway() - #self.prometheus_process = self.start_Prometheus() - #self.cadvisor_process = self.start_cadvisor() + # cAdvisor, Prometheus pushgateway and DB are started as external container, outside of son-emu + # first set some parameters, before measurement can start def setup_flow(self, vnf_name, vnf_interface=None, metric='tx_packets', cookie=0): diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py index 0e3882c..2c5ce14 100755 --- a/src/emuvim/dcemulator/net.py +++ b/src/emuvim/dcemulator/net.py @@ -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: diff --git a/src/emuvim/test/unittests/test_emulator.py b/src/emuvim/test/unittests/test_emulator.py index ef1fb51..ae18609 100755 --- a/src/emuvim/test/unittests/test_emulator.py +++ b/src/emuvim/test/unittests/test_emulator.py @@ -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 diff --git a/utils/ci/test_sdk_monitor.sh b/utils/ci/test_sdk_monitor.sh index e5cd13b..8c3ce47 100755 --- a/utils/ci/test_sdk_monitor.sh +++ b/utils/ci/test_sdk_monitor.sh @@ -1,4 +1,7 @@ #!/bin/bash +set -e +set -x + # test if a vnf can be deployed and monitored #start test emulator topology -- 2.25.1