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 # NOTE: Manifold API can not be tested yet with OMF nodes because there
22 # no OMF platforms connected currently.
24 from nepi.util.manifoldapi import MANIFOLDAPIFactory
25 from nepi.util.manifoldapi import MANIFOLDAPI
28 from multiprocessing import Process
30 class MFAPIFactoryTestCase(unittest.TestCase):
32 Test for the Manifold API Factory. Check that the same instance is used
33 when credentials match.
36 def test_factory(self):
38 Check that the same API instance is used when the credentials match.
40 username="lucia.guevgeozian_odizzio@inria.fr"
42 api1 = MANIFOLDAPIFactory.get_api(username, password)
43 api2 = MANIFOLDAPIFactory.get_api(username, password)
45 self.assertIsInstance(api1, MANIFOLDAPI)
46 self.assertIsInstance(api2, MANIFOLDAPI)
47 self.assertEquals(api1, api2)
50 class MANIFOLDAPITestCase(unittest.TestCase):
53 self.username="lucia.guevgeozian_odizzio@inria.fr"
55 self.slicename = "ple.inria.sfatest"
56 self.api = MANIFOLDAPIFactory.get_api(self.username, self.password)
58 def test_get_resource_info(self):
60 Check that the API retrieves the right set of info acoridng to the
61 filters and fields defined.
65 filters['hostname'] = 'planetlab2.tlm.unavarra.es'
67 r_info = self.api.get_resource_info(filters=filters)
68 hostname = r_info[0]['hostname']
69 self.assertEquals(hostname, 'planetlab2.tlm.unavarra.es')
71 # query with 2 filters
72 filters['network'] = 'ple'
74 r_info = self.api.get_resource_info(filters=filters)
75 hostname = r_info[0]['hostname']
76 self.assertEquals(hostname, 'planetlab2.tlm.unavarra.es')
78 # query with fields only, without filters
79 fields = ['latitude','longitude']
81 r_info = self.api.get_resource_info(fields=fields)
83 self.assertEquals(value.keys(), fields)
85 # query with 2 filters and 2 fields
86 r_info = self.api.get_resource_info(filters, fields)
88 result = {'latitude': '42.7993', 'longitude': '-1.63544'}
89 self.assertEquals(value, result)
91 # query with filters where the AND should be zero resources
92 filters['network'] = 'omf'
94 r_info = self.api.get_resource_info(filters, fields)
95 self.assertEquals(r_info, [])
97 def test_fail_if_invalid_field(self):
99 Check that the invalid field is not used for the query
102 filters['network'] = 'omf'
103 filters['component_id'] = 'urn:publicid:IDN+omf:nitos+node+node001'
106 r_info = self.api.get_resource_info(filters, fields)
108 self.assertNotEqual(len(value), 1)
110 def test_get_slice_resources(self):
112 Test that the API retrives the resources in the user's slice.
113 The slice used is ple.inria.sfatest, change slice and nodes in order
114 for the test not to fail.
116 resources = self.api.get_slice_resources(self.slicename)
118 result = ['urn:publicid:IDN+ple:lilleple+node+node2pl.planet-lab.telecom-lille1.eu',
119 'urn:publicid:IDN+ple:uttple+node+planetlab2.utt.fr',
120 'urn:publicid:IDN+ple:lilleple+node+node1pl.planet-lab.telecom-lille1.eu']
122 self.assertEquals(resources, result)
124 def test_update_resources_from_slice(self):
126 Test that the nodes are correctly added to the user's slice.
127 Test that the nodes are correctly removed from the user's slice.
129 new_resource = 'urn:publicid:IDN+ple:unavarraple+node+planetlab2.tlm.unavarra.es'
130 self.api.add_resource_to_slice(self.slicename, new_resource)
132 resources = self.api.get_slice_resources(self.slicename)
133 self.assertIn(new_resource, resources)
135 resource_to_remove = 'urn:publicid:IDN+ple:unavarraple+node+planetlab2.tlm.unavarra.es'
136 self.api.remove_resource_from_slice(self.slicename, resource_to_remove)
138 resources = self.api.get_slice_resources(self.slicename)
139 self.assertNotIn(resource_to_remove, resources)
141 def test_concurrence(self):
142 resources = ['urn:publicid:IDN+ple:itaveirople+node+planet2.servers.ua.pt',
143 'urn:publicid:IDN+ple:quantavisple+node+marie.iet.unipi.it',
144 'urn:publicid:IDN+ple:elteple+node+planet1.elte.hu',
145 'urn:publicid:IDN+ple:inria+node+wlab39.pl.sophia.inria.fr',
146 'urn:publicid:IDN+ple:poznanple+node+planetlab-2.man.poznan.pl',
147 'urn:publicid:IDN+ple:tmsp+node+planetlab-node3.it-sudparis.eu',
148 'urn:publicid:IDN+ple:colbudple+node+evghu6.colbud.hu',
149 'urn:publicid:IDN+ple:erlangenple+node+planetlab1.informatik.uni-erlangen.de',
150 'urn:publicid:IDN+ple:kitple+node+iraplab1.iralab.uni-karlsruhe.de',
151 'urn:publicid:IDN+ple:polimiple+node+planetlab1.elet.polimi.it',
152 'urn:publicid:IDN+ple:colbudple+node+evghu12.colbud.hu',
153 'urn:publicid:IDN+ple:ccsr+node+pl2.ccsrfi.net',
154 'urn:publicid:IDN+ple:modenaple+node+planetlab-1.ing.unimo.it',
155 'urn:publicid:IDN+ple:cambridgeple+node+planetlab1.xeno.cl.cam.ac.uk',
156 'urn:publicid:IDN+ple:lig+node+planetlab-1.imag.fr',
157 'urn:publicid:IDN+ple:polslple+node+plab3.ple.silweb.pl',
158 'urn:publicid:IDN+ple:uc3mple+node+planetlab1.uc3m.es',
159 'urn:publicid:IDN+ple:colbudple+node+evghu4.colbud.hu',
160 'urn:publicid:IDN+ple:hiitple+node+planetlab3.hiit.fi',
161 'urn:publicid:IDN+ple:l3sple+node+planet1.l3s.uni-hannover.de',
162 'urn:publicid:IDN+ple:colbudple+node+evghu5.colbud.hu',
163 'urn:publicid:IDN+ple:dbislab+node+planetlab2.ionio.gr',
164 'urn:publicid:IDN+ple:forthple+node+planetlab2.ics.forth.gr',
165 'urn:publicid:IDN+ple:netmodeple+node+vicky.planetlab.ntua.gr',
166 'urn:publicid:IDN+ple:colbudple+node+evghu1.colbud.hu',
167 'urn:publicid:IDN+ple:cyprusple+node+planetlab-3.cs.ucy.ac.cy',
168 'urn:publicid:IDN+ple:darmstadtple+node+host1.planetlab.informatik.tu-darmstadt.de',
169 'urn:publicid:IDN+ple:cnetple+node+plab2.create-net.org',
170 'urn:publicid:IDN+ple:unictple+node+gschembra3.diit.unict.it',
171 'urn:publicid:IDN+ple:sevillaple+node+ait05.us.es']
173 def add_resource(new_resource):
174 self.api.add_resource_to_slice(self.slicename, new_resource)
176 def runInParallel(fns):
178 p = Process(target=fn)
184 funcs.append(add_resource(r))
188 slice_res = self.api.get_slice_resources(self.slicename)
190 self.assertIn(r, slice_res)
193 self.api.remove_resource_from_slice(self.slicename, r)
195 if __name__ == '__main__':