3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.resources.omf.wilabt_node import WilabtSfaNode
23 from nepi.util.sfaapi import SFAAPI, SFAAPIFactory
25 from test_utils import skipIfNotSfi
30 import multiprocessing
32 class DummyEC(ExperimentController):
35 class WilabtSfaNodeFactoryTestCase(unittest.TestCase):
37 def test_creation_phase(self):
38 self.assertEquals(WilabtSfaNode._rtype, "WilabtSfaNode")
39 self.assertEquals(len(WilabtSfaNode._attributes), 17)
41 class WilabtSfaNodeTestCase(unittest.TestCase):
43 This tests use inria_nepi slice, from the test instance of MyPLC
44 nepiplc.pl.sophia.inria.fr. This test can fail if the user running
45 the test does not have a user in this instance of MyPLC or is not
46 added to the inria_nepi slice.
51 #slicepl = os.environ.get('SFA_SLICE')
52 #slicename = ['ple'] + slicepl.split('_')
53 #self.slicename = '.'.join(slicename)
54 self.slicename = os.environ.get('SFA_SLICE')
55 self.sfauser = os.environ.get('SFA_USER')
56 self.sfaPrivateKey = os.environ.get('SFA_PK')
59 def test_a_sfaapi(self):
61 Check that the api to discover and reserve resources is well
62 instanciated, and is an instance of SFAAPI. Check that using
63 the same credentials, the same object of the api is used.
65 node1 = self.ec.register_resource("WilabtSfaNode")
66 self.ec.set(node1, "host", "zotacE5")
67 self.ec.set(node1, "slicename", self.slicename)
68 self.ec.set(node1, "sfauser", self.sfauser)
69 self.ec.set(node1, "sfaPrivateKey", self.sfaPrivateKey)
70 self.ec.set(node1, "gatewayUser", "nepi")
71 self.ec.set(node1, "gateway", "bastion.test.iminds.be")
73 wnode_rm1 = self.ec.get_resource(node1)
75 self.assertIsNone(wnode_rm1._node_to_provision)
77 api1 = wnode_rm1.sfaapi
78 self.assertIsInstance(api1, SFAAPI)
79 self.assertEquals(len(api1._reserved), 0)
80 self.assertEquals(len(api1._blacklist), 0)
82 node2 = self.ec.register_resource("WilabtSfaNode")
83 self.ec.set(node2, "host", "zotacM20")
84 self.ec.set(node2, "slicename", self.slicename)
85 self.ec.set(node2, "sfauser", self.sfauser)
86 self.ec.set(node2, "sfaPrivateKey", self.sfaPrivateKey)
87 self.ec.set(node1, "gatewayUser", "nepi")
88 self.ec.set(node1, "gateway", "bastion.test.iminds.be")
90 wnode_rm2 = self.ec.get_resource(node2)
91 api2 = wnode_rm2.sfaapi
92 self.assertEquals(api1, api2)
94 wnode_rm1.sfaapi._reserved = set()
95 wnode_rm1.sfaapi._blacklist = set()
98 def test_discover(self):
100 Check that the method do_discover reserve the right node.
102 node1 = self.ec.register_resource("WilabtSfaNode")
103 self.ec.set(node1, "host", "zotacE5")
104 self.ec.set(node1, "slicename", self.slicename)
105 self.ec.set(node1, "sfauser", self.sfauser)
106 self.ec.set(node1, "sfaPrivateKey", self.sfaPrivateKey)
107 self.ec.set(node1, "gatewayUser", "nepi")
108 self.ec.set(node1, "gateway", "bastion.test.iminds.be")
110 wnode_rm = self.ec.get_resource(node1)
112 host = wnode_rm.get("host")
113 self.assertIsNotNone(host)
115 self.assertEquals(wnode_rm.sfaapi._reserved, set())
117 wnode_rm.do_discover()
118 self.assertEquals(len(wnode_rm.sfaapi._reserved), 1)
119 self.assertEquals(wnode_rm._node_to_provision, 'wilab2.ilabt.iminds.be.zotacE5')
121 wnode_rm.sfaapi._reserved = set()
122 wnode_rm.sfaapi._blacklist = set()
125 def test_provision(self):
127 This test checks that the method do_provision add the node in the slice and check
128 its well functioning.
130 node = self.ec.register_resource("WilabtSfaNode")
131 self.ec.set(node, "host", "zotacE5")
132 self.ec.set(node, "slicename", self.slicename)
133 self.ec.set(node, "sfauser", self.sfauser)
134 self.ec.set(node, "sfaPrivateKey", self.sfaPrivateKey)
135 self.ec.set(node, "gatewayUser", "nepi")
136 self.ec.set(node, "gateway", "bastion.test.iminds.be")
138 wnode_rm = self.ec.get_resource(node)
140 self.assertEquals(wnode_rm.sfaapi._reserved, set())
141 self.assertIsNone(wnode_rm._node_to_provision)
143 wnode_rm.do_discover()
144 #with self.assertRaises(RuntimeError):
145 # wnode_rm.do_provision()
146 wnode_rm.do_provision()
148 if not self.ec.abort and self.ec.state(node) > 2:
149 cmd = 'echo "IT WORKED"'
150 ((out, err), proc) = wnode_rm.execute(cmd)
151 self.assertEquals(out.strip(), "IT WORKED")
153 #wnode_rm.sfaapi._reserved = set()
154 #wnode_rm.sfaapi._blacklist = set()
159 def test_xdeploy1(self):
163 node = self.ec.register_resource("WilabtSfaNode")
164 self.ec.set(node, "host", "zotacM20")
165 self.ec.set(node, "slicename", self.slicename)
166 self.ec.set(node, "sfauser", self.sfauser)
167 self.ec.set(node, "sfaPrivateKey", self.sfaPrivateKey)
168 self.ec.set(node, "gatewayUser", "nepi")
169 self.ec.set(node, "gateway", "bastion.test.iminds.be")
172 self.ec.wait_deployed(node)
173 state = self.ec.state(node)
174 if not self.ec.abort:
175 self.assertIn(state, (3, 4))
177 wnode_rm = self.ec.get_resource(node)
178 wnode_rm.sfaapi._reserved = set()
179 wnode_rm.sfaapi._blacklist = set()
184 def test_xdeploy2(self):
188 node1 = self.ec.register_resource("WilabtSfaNode")
189 self.ec.set(node1, "host", "zotacE3")
190 self.ec.set(node1, "slicename", self.slicename)
191 self.ec.set(node1, "sfauser", self.sfauser)
192 self.ec.set(node1, "sfaPrivateKey", self.sfaPrivateKey)
193 self.ec.set(node1, "gatewayUser", "nepi")
194 self.ec.set(node1, "gateway", "bastion.test.iminds.be")
196 node2 = self.ec.register_resource("WilabtSfaNode")
197 self.ec.set(node2, "host", "zotacM20")
198 self.ec.set(node2, "slicename", self.slicename)
199 self.ec.set(node2, "sfauser", self.sfauser)
200 self.ec.set(node2, "sfaPrivateKey", self.sfaPrivateKey)
201 self.ec.set(node2, "gatewayUser", "nepi")
202 self.ec.set(node2, "gateway", "bastion.test.iminds.be")
205 self.ec.wait_deployed([node1, node2])
206 state1 = self.ec.state(node1)
207 state2 = self.ec.state(node2)
208 if not self.ec.abort:
209 self.assertIn(state1, (3, 4))
210 self.assertIn(state2, (3, 4))
212 wnode_rm = self.ec.get_resource(node1)
213 wnode_rm.sfaapi._reserved = set()
214 wnode_rm.sfaapi._blacklist = set()
219 def test_xdeploy3(self):
221 Test deploy 2 nodes, already in the slice.
223 node1 = self.ec.register_resource("WilabtSfaNode")
224 self.ec.set(node1, "host", "zotacM20")
225 self.ec.set(node1, "slicename", self.slicename)
226 self.ec.set(node1, "sfauser", self.sfauser)
227 self.ec.set(node1, "sfaPrivateKey", self.sfaPrivateKey)
228 self.ec.set(node1, "gatewayUser", "nepi")
229 self.ec.set(node1, "gateway", "bastion.test.iminds.be")
231 node2 = self.ec.register_resource("WilabtSfaNode")
232 self.ec.set(node2, "host", "zotacE3")
233 self.ec.set(node2, "slicename", self.slicename)
234 self.ec.set(node2, "sfauser", self.sfauser)
235 self.ec.set(node2, "sfaPrivateKey", self.sfaPrivateKey)
236 self.ec.set(node2, "gatewayUser", "nepi")
237 self.ec.set(node2, "gateway", "bastion.test.iminds.be")
240 self.ec.wait_deployed([node1, node2])
241 state1 = self.ec.state(node1)
242 state2 = self.ec.state(node2)
243 if not self.ec.abort:
244 self.assertEquals(state1, (3, 4))
245 self.assertEquals(state2, (3, 4))
254 if __name__ == '__main__':