Merge pull request #127 from hadik3r/master
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Thu, 30 Jun 2016 10:05:15 +0000 (12:05 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Thu, 30 Jun 2016 10:05:15 +0000 (12:05 +0200)
modify rest api test

src/emuvim/test/unittests/test_restapi.py

index 67e97f2..144917f 100755 (executable)
@@ -6,6 +6,8 @@ import time
 import unittest
 from emuvim.test.api_base import SimpleTestTopology
 import subprocess
+from emuvim.dcemulator.node import EmulatorCompute
+import ast
 
 class testRestApi( SimpleTestTopology ):
     """
@@ -16,26 +18,49 @@ class testRestApi( SimpleTestTopology ):
 
         # 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.h[1], self.dc[1])
         self.net.addLink(self.dc[0], self.dc[1])
+
         # start api
         self.startApi()
+
         # start Mininet network
         self.startNet()
-        print('compute start datacenter0, vnf1 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+
+        print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf1 ->>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute start -d datacenter0 -n vnf1", shell=True)
-        print('compute start datacenter0, vnf2 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf2 ->>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute start -d datacenter0 -n vnf2", shell=True)
-        print('compute start datacenter1, vnf3 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf3 ->>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute start -d datacenter1 -n vnf3", shell=True)
-        print('compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
-        print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute list", shell=True)
+        print('->>>>>>> checking running nodes, compute list, and connectivity >>>>>>>>>>')
+
+        # 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()) == 2)
+        self.assertTrue(len(self.dc[1].listCompute()) == 1)
+        self.assertTrue(isinstance(self.dc[0].listCompute()[0], EmulatorCompute))
+        self.assertTrue(isinstance(self.dc[0].listCompute()[1], EmulatorCompute))
+        self.assertTrue(isinstance(self.dc[1].listCompute()[0], EmulatorCompute))
+        self.assertTrue(self.dc[0].listCompute()[1].name == "vnf1")
+        self.assertTrue(self.dc[0].listCompute()[0].name == "vnf2")
+        self.assertTrue(self.dc[1].listCompute()[0].name == "vnf3")
+
+        # check connectivity by using ping
+        self.assertTrue(self.net.ping([self.dc[0].listCompute()[1], self.dc[0].listCompute()[0]]) <= 0.0)
+        self.assertTrue(self.net.ping([self.dc[0].listCompute()[0], self.dc[1].listCompute()[0]]) <= 0.0)
+        self.assertTrue(self.net.ping([self.dc[1].listCompute()[0], self.dc[0].listCompute()[1]]) <= 0.0)
 
         print('network add vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
@@ -44,21 +69,53 @@ class testRestApi( SimpleTestTopology ):
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli network remove -src vnf1 -dst vnf2 -b", shell=True)
 
-        print('compute stop datacenter0, vnf2 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        print('>>>>> checking --> son-emu-cli compute stop -d datacenter0 -n vnf2 ->>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute stop -d datacenter0 -n vnf2", shell=True)
-        print('compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+
+        # check number of running nodes
+        self.assertTrue(len(self.getContainernetContainers()) == 2)
+        self.assertTrue(len(self.net.hosts) == 4)
+        self.assertTrue(len(self.net.switches) == 2)
+        # check compute list result
+        self.assertTrue(len(self.dc[0].listCompute()) == 1)
+        self.assertTrue(len(self.dc[1].listCompute()) == 1)
+
+        print('>>>>> checking --> son-emu-cli compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute list", shell=True)
-        print('compute status datacenter0, vnf1 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        output = subprocess.check_output("son-emu-cli compute list", shell=True)
+
+        # check datacenter list result
+        self.assertTrue("datacenter0" in output)
+
+        print('>>>>> checking --> son-emu-cli compute status -d datacenter0 -n vnf1 ->>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli compute status -d datacenter0 -n vnf1", shell=True)
-        print('datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        output = subprocess.check_output("son-emu-cli compute status -d datacenter0 -n vnf1", shell=True)
+        output= ast.literal_eval(output)
+
+        # check compute status result
+        self.assertTrue(output["name"] == "vnf1")
+        self.assertTrue(output["state"]["Running"])
+
+        print('>>>>> checking --> son-emu-cli datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli datacenter list", shell=True)
-        print('datacenter status datacenter0 ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
+        output = subprocess.check_output("son-emu-cli datacenter list", shell=True)
+
+        # check datacenter list result
+
+        self.assertTrue("datacenter0" in output)
+
+        print('->>>>> checking --> son-emu-cli datacenter status -d datacenter0 ->>>>>>>>')
         print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
         subprocess.call("son-emu-cli datacenter status -d datacenter0", shell=True)
+        output = subprocess.check_output("son-emu-cli datacenter status -d datacenter0", shell=True)
+
+        # check datacenter status result
+        self.assertTrue("datacenter0" in output)
+
         self.stopNet()