further restructureing of tests
authorpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 11 May 2016 14:14:22 +0000 (16:14 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Wed, 11 May 2016 14:14:22 +0000 (16:14 +0200)
README.md
src/emuvim/test/integrationtests/test_sonata_dummy_gatekeeper.py [deleted file]
src/emuvim/test/unittests/test_resourcemodel.py
src/emuvim/test/unittests/test_sonata_dummy_gatekeeper.py [new file with mode: 0644]
utils/docker/Dockerfile

index 6d54ca5..7016a22 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -89,7 +89,7 @@ In the `~/son-emu` directory:
 
 ### Run Unit Tests
 * `cd ~/son-emu`
-* `sudo py.test -v src/emuvim` (equivalent to `python setup.py test -v --addopts 'src/emuvim'` but with direct access to the commandline arguments)
+* `sudo py.test -v src/emuvim/test/unittests`
 
 ### CLI
 * [Full CLI command documentation](https://github.com/sonata-nfv/son-emu/wiki/CLI-Command-Overview)
diff --git a/src/emuvim/test/integrationtests/test_sonata_dummy_gatekeeper.py b/src/emuvim/test/integrationtests/test_sonata_dummy_gatekeeper.py
deleted file mode 100644 (file)
index 33a1d57..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-import time
-import requests
-import subprocess
-import os
-import unittest
-from emuvim.test.base import SimpleTestTopology
-from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
-
-
-
-class testSonataDummyGatekeeper(SimpleTestTopology):
-
-    @unittest.skip("disabled test since ubuntu:trusty not used in current example package")
-    def testAPI(self):
-        # create network
-        self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
-        # setup links
-        self.net.addLink(self.dc[0], self.h[0])
-        self.net.addLink(self.dc[0], self.dc[1])
-        self.net.addLink(self.h[1], self.dc[1])
-        # connect dummy GK to data centers
-        sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
-        sdkg1.connectDatacenter(self.dc[0])
-        sdkg1.connectDatacenter(self.dc[1])
-        # run the dummy gatekeeper (in another thread, don't block)
-        sdkg1.start()
-        # start Mininet network
-        self.startNet()
-        time.sleep(1)
-
-        # download example from GitHub
-        print "downloading latest son-demo.son from GitHub"
-        subprocess.call(
-            ["wget",
-             "http://github.com/sonata-nfv/son-schema/blob/master/package-descriptor/examples/sonata-demo.son?raw=true",
-             "-O",
-             "son-demo.son"]
-        )
-
-        print "starting tests"
-        # board package
-        files = {"package": open("son-demo.son", "rb")}
-        r = requests.post("http://127.0.0.1:5000/packages", files=files)
-        self.assertEqual(r.status_code, 200)
-        self.assertTrue(r.json().get("service_uuid") is not None)
-        os.remove("son-demo.son")
-
-        # instantiate service
-        service_uuid = r.json().get("service_uuid")
-        r2 = requests.post("http://127.0.0.1:5000/instantiations", json={"service_uuid": service_uuid})
-        self.assertEqual(r2.status_code, 200)
-
-        # give the emulator some time to instantiate everything
-        time.sleep(2)
-
-        # check get request APIs
-        r3 = requests.get("http://127.0.0.1:5000/packages")
-        self.assertEqual(len(r3.json().get("service_uuid_list")), 1)
-        r4 = requests.get("http://127.0.0.1:5000/instantiations")
-        self.assertEqual(len(r4.json().get("service_instance_list")), 1)
-
-        # check number of running nodes
-        self.assertTrue(len(self.getContainernetContainers()) == 3)
-        self.assertTrue(len(self.net.hosts) == 5)
-        self.assertTrue(len(self.net.switches) == 2)
-        # check compute list result
-        self.assertTrue(len(self.dc[0].listCompute()) == 3)
-        # check connectivity by using ping
-        for vnf in self.dc[0].listCompute():
-            self.assertTrue(self.net.ping([self.h[0], vnf]) <= 0.0)
-        # stop Mininet network
-        self.stopNet()
-
-
index a1d273c..165893d 100644 (file)
@@ -1,5 +1,6 @@
 import time
 import os
+import unittest
 from emuvim.test.base import SimpleTestTopology
 from emuvim.dcemulator.resourcemodel import BaseResourceModel, ResourceFlavor, NotEnoughResourcesAvailable, ResourceModelRegistrar
 from emuvim.dcemulator.resourcemodel.upb.simple import UpbSimpleCloudDcRM, UpbOverprovisioningCloudDcRM, UpbDummyRM
@@ -211,15 +212,13 @@ class testUpbSimpleCloudDcRM(SimpleTestTopology):
         rm.free(c1)
         self.assertTrue(rm.dc_alloc_cu == 0)
 
+    @unittest.skipIf(os.environ.get("SON_EMU_IN_DOCKER") is not None,
+                     "skipping test when running inside Docker container")
     def testInRealTopo(self):
         """
         Start a real container and check if limitations are really passed down to Conteinernet.
         :return:
         """
-        # ATTENTION: This test should only be executed if emu runs not inside a Docker container,
-        # because it manipulates cgroups.
-        if os.environ.get("SON_EMU_IN_DOCKER") is not None:
-            return
         # create network
         self.createNet(nswitches=0, ndatacenter=1, nhosts=2, ndockers=0)
         # setup links
diff --git a/src/emuvim/test/unittests/test_sonata_dummy_gatekeeper.py b/src/emuvim/test/unittests/test_sonata_dummy_gatekeeper.py
new file mode 100644 (file)
index 0000000..428a51f
--- /dev/null
@@ -0,0 +1,65 @@
+import time
+import requests
+import subprocess
+import os
+import unittest
+from emuvim.test.base import SimpleTestTopology
+from emuvim.api.sonata import SonataDummyGatekeeperEndpoint
+
+PACKAGE_PATH = "misc/sonata-demo-docker.son"
+
+class testSonataDummyGatekeeper(SimpleTestTopology):
+
+    @unittest.skipIf(os.environ.get("SON_EMU_IN_DOCKER") is None,
+                     "skipping dummy GK test in local environment")
+    def testAPI(self):
+        # create network
+        self.createNet(nswitches=0, ndatacenter=2, nhosts=2, ndockers=0)
+        # setup links
+        self.net.addLink(self.dc[0], self.h[0])
+        self.net.addLink(self.dc[0], self.dc[1])
+        self.net.addLink(self.h[1], self.dc[1])
+        # connect dummy GK to data centers
+        sdkg1 = SonataDummyGatekeeperEndpoint("0.0.0.0", 5000)
+        sdkg1.connectDatacenter(self.dc[0])
+        sdkg1.connectDatacenter(self.dc[1])
+        # run the dummy gatekeeper (in another thread, don't block)
+        sdkg1.start()
+        # start Mininet network
+        self.startNet()
+        time.sleep(1)
+
+        print "starting tests"
+        # board package
+        files = {"package": open(PACKAGE_PATH, "rb")}
+        r = requests.post("http://127.0.0.1:5000/packages", files=files)
+        self.assertEqual(r.status_code, 200)
+        self.assertTrue(r.json().get("service_uuid") is not None)
+
+        # instantiate service
+        service_uuid = r.json().get("service_uuid")
+        r2 = requests.post("http://127.0.0.1:5000/instantiations", json={"service_uuid": service_uuid})
+        self.assertEqual(r2.status_code, 200)
+
+        # give the emulator some time to instantiate everything
+        time.sleep(2)
+
+        # check get request APIs
+        r3 = requests.get("http://127.0.0.1:5000/packages")
+        self.assertEqual(len(r3.json().get("service_uuid_list")), 1)
+        r4 = requests.get("http://127.0.0.1:5000/instantiations")
+        self.assertEqual(len(r4.json().get("service_instance_list")), 1)
+
+        # check number of running nodes
+        self.assertTrue(len(self.getContainernetContainers()) == 3)
+        self.assertTrue(len(self.net.hosts) == 5)
+        self.assertTrue(len(self.net.switches) == 2)
+        # check compute list result
+        self.assertTrue(len(self.dc[0].listCompute()) == 3)
+        # check connectivity by using ping
+        for vnf in self.dc[0].listCompute():
+            self.assertTrue(self.net.ping([self.h[0], vnf]) <= 0.0)
+        # stop Mininet network
+        self.stopNet()
+
+
index 7270ab5..ef6c8fb 100644 (file)
@@ -15,3 +15,5 @@ RUN cd /son-emu/ansible \
     && echo 'Done'
 
 ENTRYPOINT ["/son-emu/utils/docker/entrypoint.sh"]
+
+EXPORT
\ No newline at end of file