2 Test suite to automatically test emulator REST API endpoints.
7 from emuvim
.test
.api_base
import SimpleTestTopology
9 from emuvim
.dcemulator
.node
import EmulatorCompute
12 class testRestApi( SimpleTestTopology
):
14 Tests to check the REST API endpoints of the emulator.
17 def testRestApi(self
):
20 self
.createNet(nswitches
=0, ndatacenter
=2, nhosts
=2, ndockers
=0)
23 self
.net
.addLink(self
.dc
[0], self
.h
[0])
24 self
.net
.addLink(self
.h
[1], self
.dc
[1])
25 self
.net
.addLink(self
.dc
[0], self
.dc
[1])
30 # start Mininet network
33 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf1 ->>>>>>>>>>>>>>>')
34 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
35 subprocess
.call("son-emu-cli compute start -d datacenter0 -n vnf1", shell
=True)
36 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf2 ->>>>>>>>>>>>>>>')
37 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
38 subprocess
.call("son-emu-cli compute start -d datacenter0 -n vnf2", shell
=True)
39 print('->>>>>>> son-emu-cli compute start -d datacenter0 -n vnf3 ->>>>>>>>>>>>>>>')
40 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
41 subprocess
.call("son-emu-cli compute start -d datacenter1 -n vnf3", shell
=True)
42 subprocess
.call("son-emu-cli compute list", shell
=True)
43 print('->>>>>>> checking running nodes, compute list, and connectivity >>>>>>>>>>')
45 # check number of running nodes
46 self
.assertTrue(len(self
.getContainernetContainers()) == 3)
47 self
.assertTrue(len(self
.net
.hosts
) == 5)
48 self
.assertTrue(len(self
.net
.switches
) == 2)
50 # check compute list result
51 self
.assertTrue(len(self
.dc
[0].listCompute()) == 2)
52 self
.assertTrue(len(self
.dc
[1].listCompute()) == 1)
53 self
.assertTrue(isinstance(self
.dc
[0].listCompute()[0], EmulatorCompute
))
54 self
.assertTrue(isinstance(self
.dc
[0].listCompute()[1], EmulatorCompute
))
55 self
.assertTrue(isinstance(self
.dc
[1].listCompute()[0], EmulatorCompute
))
56 self
.assertTrue(self
.dc
[0].listCompute()[1].name
== "vnf1")
57 self
.assertTrue(self
.dc
[0].listCompute()[0].name
== "vnf2")
58 self
.assertTrue(self
.dc
[1].listCompute()[0].name
== "vnf3")
60 # check connectivity by using ping
61 self
.assertTrue(self
.net
.ping([self
.dc
[0].listCompute()[1], self
.dc
[0].listCompute()[0]]) <= 0.0)
62 self
.assertTrue(self
.net
.ping([self
.dc
[0].listCompute()[0], self
.dc
[1].listCompute()[0]]) <= 0.0)
63 self
.assertTrue(self
.net
.ping([self
.dc
[1].listCompute()[0], self
.dc
[0].listCompute()[1]]) <= 0.0)
65 print('network add vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
66 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
67 subprocess
.call("son-emu-cli network add -src vnf1 -dst vnf2 -b -c 10", shell
=True)
68 print('network remove vnf1 vnf2->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
69 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
70 subprocess
.call("son-emu-cli network remove -src vnf1 -dst vnf2 -b", shell
=True)
72 print('>>>>> checking --> son-emu-cli compute stop -d datacenter0 -n vnf2 ->>>>>>')
73 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
74 subprocess
.call("son-emu-cli compute stop -d datacenter0 -n vnf2", shell
=True)
76 # check number of running nodes
77 self
.assertTrue(len(self
.getContainernetContainers()) == 2)
78 self
.assertTrue(len(self
.net
.hosts
) == 4)
79 self
.assertTrue(len(self
.net
.switches
) == 2)
80 # check compute list result
81 self
.assertTrue(len(self
.dc
[0].listCompute()) == 1)
82 self
.assertTrue(len(self
.dc
[1].listCompute()) == 1)
84 print('>>>>> checking --> son-emu-cli compute list ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
85 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
86 subprocess
.call("son-emu-cli compute list", shell
=True)
87 output
= subprocess
.check_output("son-emu-cli compute list", shell
=True)
89 # check datacenter list result
90 self
.assertTrue("datacenter0" in output
)
92 print('>>>>> checking --> son-emu-cli compute status -d datacenter0 -n vnf1 ->>>>')
93 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
94 subprocess
.call("son-emu-cli compute status -d datacenter0 -n vnf1", shell
=True)
95 output
= subprocess
.check_output("son-emu-cli compute status -d datacenter0 -n vnf1", shell
=True)
96 output
= ast
.literal_eval(output
)
98 # check compute status result
99 self
.assertTrue(output
["name"] == "vnf1")
100 self
.assertTrue(output
["state"]["Running"])
102 print('>>>>> checking --> son-emu-cli datacenter list ->>>>>>>>>>>>>>>>>>>>>>>>>>')
103 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
104 subprocess
.call("son-emu-cli datacenter list", shell
=True)
105 output
= subprocess
.check_output("son-emu-cli datacenter list", shell
=True)
107 # check datacenter list result
109 self
.assertTrue("datacenter0" in output
)
111 print('->>>>> checking --> son-emu-cli datacenter status -d datacenter0 ->>>>>>>>')
112 print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
113 subprocess
.call("son-emu-cli datacenter status -d datacenter0", shell
=True)
114 output
= subprocess
.check_output("son-emu-cli datacenter status -d datacenter0", shell
=True)
116 # check datacenter status result
117 self
.assertTrue("datacenter0" in output
)
122 if __name__
== '__main__':