### 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)
+++ /dev/null
-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()
-
-
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
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
--- /dev/null
+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()
+
+
&& echo 'Done'
ENTRYPOINT ["/son-emu/utils/docker/entrypoint.sh"]
+
+EXPORT
\ No newline at end of file