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 version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
20 # NOTE: Manifold API can not be tested yet with OMF nodes because there
21 # no OMF platforms connected currently.
23 from nepi.util.manifoldapi import MANIFOLDAPIFactory
24 from nepi.util.manifoldapi import MANIFOLDAPI
27 from multiprocessing import Process
29 class MFAPIFactoryTestCase(unittest.TestCase):
31 Test for the Manifold API Factory. Check that the same instance is used
32 when credentials match.
35 def test_factory(self):
37 Check that the same API instance is used when the credentials match.
39 username="lucia.guevgeozian_odizzio@inria.fr"
41 api1 = MANIFOLDAPIFactory.get_api(username, password)
42 api2 = MANIFOLDAPIFactory.get_api(username, password)
44 self.assertIsInstance(api1, MANIFOLDAPI)
45 self.assertIsInstance(api2, MANIFOLDAPI)
46 self.assertEquals(api1, api2)
49 class MANIFOLDAPITestCase(unittest.TestCase):
52 self.username="lucia.guevgeozian_odizzio@inria.fr"
54 self.slicename = "ple.inria.sfatest"
55 self.api = MANIFOLDAPIFactory.get_api(self.username, self.password)
57 def test_get_resource_info(self):
59 Check that the API retrieves the right set of info acoridng to the
60 filters and fields defined.
64 filters['hostname'] = 'planetlab2.tlm.unavarra.es'
66 r_info = self.api.get_resource_info(filters=filters)
67 hostname = r_info[0]['hostname']
68 self.assertEquals(hostname, 'planetlab2.tlm.unavarra.es')
70 # query with 2 filters
71 filters['network'] = 'ple'
73 r_info = self.api.get_resource_info(filters=filters)
74 hostname = r_info[0]['hostname']
75 self.assertEquals(hostname, 'planetlab2.tlm.unavarra.es')
77 # query with fields only, without filters
78 fields = ['latitude','longitude']
80 r_info = self.api.get_resource_info(fields=fields)
82 self.assertEquals(value.keys(), fields)
84 # query with 2 filters and 2 fields
85 r_info = self.api.get_resource_info(filters, fields)
87 result = {'latitude': '42.7993', 'longitude': '-1.63544'}
88 self.assertEquals(value, result)
90 # query with filters where the AND should be zero resources
91 filters['network'] = 'omf'
93 r_info = self.api.get_resource_info(filters, fields)
94 self.assertEquals(r_info, [])
96 def test_fail_if_invalid_field(self):
98 Check that the invalid field is not used for the query
101 filters['network'] = 'omf'
102 filters['component_id'] = 'urn:publicid:IDN+omf:nitos+node+node001'
105 r_info = self.api.get_resource_info(filters, fields)
107 self.assertNotEqual(len(value), 1)
109 def test_get_slice_resources(self):
111 Test that the API retrives the resources in the user's slice.
112 The slice used is ple.inria.sfatest, change slice and nodes in order
113 for the test not to fail.
115 resources = self.api.get_slice_resources(self.slicename)
117 result = ['urn:publicid:IDN+ple:lilleple+node+node2pl.planet-lab.telecom-lille1.eu',
118 'urn:publicid:IDN+ple:uttple+node+planetlab2.utt.fr',
119 'urn:publicid:IDN+ple:lilleple+node+node1pl.planet-lab.telecom-lille1.eu']
121 self.assertEquals(resources, result)
123 def test_update_resources_from_slice(self):
125 Test that the nodes are correctly added to the user's slice.
126 Test that the nodes are correctly removed from the user's slice.
128 new_resource = 'urn:publicid:IDN+ple:unavarraple+node+planetlab2.tlm.unavarra.es'
129 self.api.add_resource_to_slice(self.slicename, new_resource)
131 resources = self.api.get_slice_resources(self.slicename)
132 self.assertIn(new_resource, resources)
134 resource_to_remove = 'urn:publicid:IDN+ple:unavarraple+node+planetlab2.tlm.unavarra.es'
135 self.api.remove_resource_from_slice(self.slicename, resource_to_remove)
137 resources = self.api.get_slice_resources(self.slicename)
138 self.assertNotIn(resource_to_remove, resources)
140 def test_concurrence(self):
141 resources = ['urn:publicid:IDN+ple:itaveirople+node+planet2.servers.ua.pt',
142 'urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it',
143 'urn:publicid:IDN+ple:elteple+node+planet1.elte.hu',
144 'urn:publicid:IDN+ple:inria+node+wlab39.pl.sophia.inria.fr',
145 'urn:publicid:IDN+ple:poznanple+node+planetlab-2.man.poznan.pl',
146 'urn:publicid:IDN+ple:tmsp+node+planetlab-node3.it-sudparis.eu',
147 'urn:publicid:IDN+ple:colbudple+node+evghu6.colbud.hu',
148 'urn:publicid:IDN+ple:erlangenple+node+planetlab1.informatik.uni-erlangen.de',
149 'urn:publicid:IDN+ple:kitple+node+iraplab1.iralab.uni-karlsruhe.de',
150 'urn:publicid:IDN+ple:polimiple+node+planetlab1.elet.polimi.it',
151 'urn:publicid:IDN+ple:colbudple+node+evghu12.colbud.hu',
152 'urn:publicid:IDN+ple:ccsr+node+pl2.ccsrfi.net',
153 'urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it',
154 'urn:publicid:IDN+ple:cambridgeple+node+planetlab1.xeno.cl.cam.ac.uk',
155 'urn:publicid:IDN+ple:lig+node+planetlab-1.imag.fr',
156 'urn:publicid:IDN+ple:polslple+node+plab3.ple.silweb.pl',
157 'urn:publicid:IDN+ple:uc3mple+node+planetlab1.uc3m.es',
158 'urn:publicid:IDN+ple:colbudple+node+evghu4.colbud.hu',
159 'urn:publicid:IDN+ple:hiitple+node+planetlab3.hiit.fi',
160 'urn:publicid:IDN+ple:l3sple+node+planet1.l3s.uni-hannover.de',
161 'urn:publicid:IDN+ple:colbudple+node+evghu5.colbud.hu',
162 'urn:publicid:IDN+ple:dbislab+node+planetlab2.ionio.gr',
163 'urn:publicid:IDN+ple:forthple+node+planetlab2.ics.forth.gr',
164 'urn:publicid:IDN+ple:netmodeple+node+vicky.planetlab.ntua.gr',
165 'urn:publicid:IDN+ple:colbudple+node+evghu1.colbud.hu',
166 'urn:publicid:IDN+ple:cyprusple+node+planetlab-3.cs.ucy.ac.cy',
167 'urn:publicid:IDN+ple:darmstadtple+node+host1.planetlab.informatik.tu-darmstadt.de',
168 'urn:publicid:IDN+ple:cnetple+node+plab2.create-net.org',
169 'urn:publicid:IDN+ple:unictple+node+gschembra3.diit.unict.it',
170 'urn:publicid:IDN+ple:sevillaple+node+ait05.us.es']
172 def add_resource(new_resource):
173 self.api.add_resource_to_slice(self.slicename, new_resource)
175 def runInParallel(fns):
177 p = Process(target=fn)
183 funcs.append(add_resource(r))
187 slice_res = self.api.get_slice_resources(self.slicename)
189 self.assertIn(r, slice_res)
192 self.api.remove_resource_from_slice(self.slicename, r)
194 if __name__ == '__main__':