iotlab driver: Applying Jordan's changes in iotlabslices.py
[sfa.git] / tests / testXrn.py
1 #!/usr/bin/python
2 import sys
3 import unittest
4
5 from sfa.util.faults import *
6 from sfa.util.xrn import Xrn
7
8 from sfa.planetlab.plxrn import PlXrn
9
10 verbose=False
11
12 class TestXrn(unittest.TestCase):
13
14     def __hrn(self,h,t,exp_urn):
15         if verbose: print 'testing (',h,t,') expecting',exp_urn
16         xrn=Xrn(h,type=t)
17         if verbose: print xrn.dump_string()
18         urn=xrn.get_urn()
19         (h1,t1) = Xrn(urn).get_hrn_type()
20         if h1!=h or t1!=t or urn!=exp_urn:
21             print "hrn->urn->hrn : MISMATCH with in=(%s,%s) -- out=(%s,%s) -- urn=%s"%(h,t,h1,t1,urn)
22         self.assertEqual(h1,h)
23         self.assertEqual(t1,t)
24         self.assertEqual(urn,exp_urn)
25
26     def test_hrn001 (self): 
27         self.__hrn("ple.inria.baris",'user',
28                    "urn:publicid:IDN+ple:inria+user+baris")
29     def test_hnr002 (self): 
30         self.__hrn("emulab\.net.myslice.jktest",'slice',
31                    "urn:publicid:IDN+emulab.net:myslice+slice+jktest")
32     def test_hrn003(self):
33         self.__hrn("emulab\\.net.jktest", "slice",
34                    "urn:publicid:IDN+emulab.net+slice+jktest")
35     def test_hrn004(self):
36         self.__hrn("plc.princeton.tmack",'user',
37                    "urn:publicid:IDN+plc:princeton+user+tmack")
38     def test_hrn005(self):
39         self.__hrn("fake-pi1@onelab.eu",'user',
40                    "urn:publicid:IDN+fake-pi1@onelab+user+eu")
41     def test_hrn006(self):
42         self.__hrn("plc.princeton.tmack", 'user',
43                    "urn:publicid:IDN+plc:princeton+user+tmack" )
44 # not specifying a type ... this gives weird result - xxx todo
45 #     def test_hrn007(self):
46 #         # not providing a type is currently not supporte
47 #         self.__hrn("fake-pi1@onelab.eu",None,
48 #                    None)
49     def test_hrn008(self):
50         self.__hrn("plc.princeton.planetlab1", 'node',
51                    "urn:publicid:IDN+plc:princeton+node+planetlab1" )
52     def test_hrn009(self):
53         self.__hrn("plc.princeton", 'authority',
54                    "urn:publicid:IDN+plc:princeton+authority+sa" )
55     def test_hrn010(self):
56         self.__hrn("plc.vini.site", 'authority',
57                    "urn:publicid:IDN+plc:vini:site+authority+sa" )
58
59     # this one is a bit off limits but it's used in some places
60     # like .e.g when running sfi.py resources
61     def test_void(self):
62         void=Xrn(xrn='',type=None)
63         expected='urn:publicid:IDN++'
64         self.assertEqual(void.get_hrn(),'')
65         self.assertEqual(void.get_type(),None)
66         self.assertEqual(void.get_urn(),expected)
67         loop=Xrn(xrn=expected)
68         self.assertEqual(loop.get_hrn(),'')
69         # xxx - this is not quite right as the first object has type None
70         self.assertEqual(loop.get_type(),'')        
71
72     def test_host001 (self):
73         xrn=PlXrn (auth="ple.inria",hostname="onelab09.pl.sophia.inria.fr")
74         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.onelab09\\.pl\\.sophia\\.inria\\.fr",'node'))
75     def test_host002 (self):
76         xrn=PlXrn (auth="ple\\.inria",hostname="onelab09.pl.sophia.inria.fr")
77         self.assertEqual (xrn.get_hrn_type(), ("ple\\.inria.onelab09\\.pl\\.sophia\\.inria\\.fr",'node'))
78
79     def test_slice001  (self):
80         xrn=PlXrn (auth="ple",slicename="inria_omftest")
81         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.omftest",'slice'))
82
83     def test_person001 (self):
84         xrn=PlXrn (auth="ple.inria",email="first.last@some.domain.com")
85         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
86     def test_person002 (self):
87         xrn=PlXrn (auth="ple.inria",email="first+last@some.domain.com")
88         self.assertEqual (xrn.get_hrn_type(), ("ple.inria.first_last",'person'))
89         
90
91
92     def test_login_base_001 (self):
93         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
94         self.assertEqual(xrn.pl_login_base(),'inria')
95
96     def test_slicename_001 (self):
97         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
98         self.assertEqual(xrn.pl_slicename(),'inria_omftest')
99
100     def test_authname_001 (self):
101         xrn=PlXrn(xrn='ple.inria.omftest',type='slice')
102         self.assertEqual(xrn.pl_authname(),'inria')
103
104