now that we create an SFA auth to hold the sfa entities involved:
Thierry Parmentelat [Fri, 1 Jun 2012 18:00:42 +0000 (20:00 +0200)]
refactored tests to split TestAuthSfa and TestSliceSfa
cleaned up the config side a lot as well as a bonus

system/TestAuthSfa.py [new file with mode: 0644]
system/TestNode.py
system/TestPlc.py
system/TestSlice.py
system/TestSliceSfa.py
system/TestUserSfa.py
system/config_default.py
system/macros.py

diff --git a/system/TestAuthSfa.py b/system/TestAuthSfa.py
new file mode 100644 (file)
index 0000000..af713d6
--- /dev/null
@@ -0,0 +1,181 @@
+# Thierry Parmentelat <thierry.parmentelat@inria.fr>
+# Copyright (C) 2010 INRIA 
+#
+import utils
+import os, os.path
+import datetime
+import time
+
+from TestKey import TestKey
+from TestNode import TestNode
+from TestSsh import TestSsh
+from TestUserSfa import TestUserSfa
+from TestSliceSfa import TestSliceSfa
+
+
+def slice_sfa_mapper (method):
+    def actual(self,*args, **kwds):
+        overall=True
+        slice_method = TestSliceSfa.__dict__[method.__name__]
+        for slice_spec in [ self.auth_sfa_spec['slice_spec'] ]:
+            test_slice_sfa = TestSliceSfa(self,slice_spec)
+            if not slice_method(test_slice_sfa, *args, **kwds): overall=False
+        return overall
+    # restore the doc text
+    actual.__doc__=TestSliceSfa.__dict__[method.__name__].__doc__
+    return actual
+
+
+def user_sfa_mapper (method):
+    def actual(self,*args, **kwds):
+        overall=True
+        user_method = TestUserSfa.__dict__[method.__name__]
+        for user_spec in [ self.auth_sfa_spec['user_spec'] ]:
+            test_user_sfa = TestUserSfa(self,user_spec)
+            if not user_method(test_user_sfa, *args, **kwds): overall=False
+        return overall
+    # restore the doc text
+    actual.__doc__=TestUserSfa.__dict__[method.__name__].__doc__
+    return actual
+
+
+class TestAuthSfa:
+
+    def __init__ (self,test_plc,auth_sfa_spec):
+       self.test_plc=test_plc
+       self.auth_sfa_spec=auth_sfa_spec
+        self.test_ssh=TestSsh(self.test_plc.test_ssh)
+#        # shortcuts
+        self.login_base=self.auth_sfa_spec['login_base']
+#        self.piuser=self.auth_sfa_spec['piuser']
+#        self.regularuser=self.auth_sfa_spec['regularuser']
+#        self.slicename=self.auth_sfa_spec['slicename']
+#        
+#    def plc_name(self):
+#        return self.auth_sfa_spec['plc_slicename']
+    
+    def rspec_style (self): return self.auth_sfa_spec['rspec_style']
+
+    def sfi_path (self):
+        return "/root/sfi/%s"%(self.rspec_style())
+
+    # the hrn for the root authority
+    def root_hrn (self):
+        return self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
+
+    # the hrn for the auth/site
+    def hrn (self):
+        return "%s.%s"%(self.root_hrn(),self.login_base)
+
+    # something in this site (users typically)
+    def qualified (self, name):
+#        return "%s.%s"%(self.auth_sfa_spec['hrn_prefix'],name)
+        return "%s.%s"%(self.hrn(),name)
+
+    # xxx this needs tweaks with more recent versions of sfa that have pgv2 as the default ?
+    # dir_name is local and will be pushed later on by TestPlc
+    # by default set SFI_USER to the pi, we'll overload this
+    # on the command line when needed
+    def sfi_configure (self,dir_name):
+        plc_spec=self.test_plc.plc_spec
+        # cheat a bit: retrieve the global SFA spec from the plc obj
+        sfa_spec=self.test_plc.plc_spec['sfa']
+        # fetch keys in config spec and expose to sfi
+        for spec_name in ['pi_spec','user_spec']:
+            user_spec=self.auth_sfa_spec[spec_name]
+            user_leaf=user_spec['name']
+            key_name=user_spec['key_name']
+            key_spec = self.test_plc.locate_key (key_name)
+            for (kind,ext) in [ ('private', 'pkey'), ('public', 'pub') ] :
+                contents=key_spec[kind]
+                file_name=os.path.join(dir_name,self.qualified(user_leaf))+"."+ext
+                fileconf=open(file_name,'w')
+                fileconf.write (contents)
+                fileconf.close()
+                utils.header ("(Over)wrote %s"%file_name)
+        #
+       file_name=dir_name + os.sep + 'sfi_config'
+        fileconf=open(file_name,'w')
+       SFI_AUTH=self.hrn()
+        fileconf.write ("SFI_AUTH='%s'"%SFI_AUTH)
+       fileconf.write('\n')
+        # default is to run as a PI
+       SFI_USER=self.qualified(self.auth_sfa_spec['pi_spec']['name'])
+        fileconf.write ("SFI_USER='%s'"%SFI_USER)
+       fileconf.write('\n')
+       SFI_REGISTRY='http://' + sfa_spec['SFA_REGISTRY_HOST'] + ':12345/'
+        fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY)
+       fileconf.write('\n')
+       SFI_SM='http://' + sfa_spec['SFA_SM_HOST'] + ':12347/'
+        fileconf.write ("SFI_SM='%s'"%SFI_SM)
+       fileconf.write('\n')
+        fileconf.close()
+        utils.header ("(Over)wrote %s"%file_name)
+
+    # using sfaadmin to bootstrap
+    def sfa_add_site (self, options):
+        "bootstrap a site using sfaadmin"
+        command="sfaadmin reg register -t authority -x %s"%self.hrn()
+        return self.test_plc.run_in_guest(command)==0
+
+    def sfa_add_pi (self, options):
+        "bootstrap a PI user for that site"
+        pi_spec = self.auth_sfa_spec['pi_spec']
+        pi_hrn=self.qualified(pi_spec['name'])
+        pi_mail=pi_spec['email']
+        # as installed by sfi_config
+        pi_key=os.path.join(self.sfi_path(),self.qualified(pi_spec['name']+'.pub'))
+        command="sfaadmin reg register -t user -x %s --email %s --key %s"%(pi_hrn,pi_mail,pi_key)
+        if self.test_plc.run_in_guest(command)!=0: return False
+        command="sfaadmin reg update -t authority -x %s --pi %s"%(self.hrn(),pi_hrn)
+        return self.test_plc.run_in_guest(command)==0
+
+    # run as pi
+    def sfi_pi (self, command):
+        pi_name=self.auth_sfa_spec['pi_spec']['name']
+        return "sfi -d %s -u %s %s"%(self.sfi_path(),self.qualified(pi_name), command,)
+    # the sfi command line option to run as a regular user
+    def sfi_user (self, command):
+        user_name=self.auth_sfa_spec['user_spec']['name']
+        return "sfi -d %s -u %s %s"%(self.sfi_path(),self.qualified(user_name), command,)
+
+    # user management
+    @user_sfa_mapper
+    def sfa_add_user (self, *args, **kwds): pass
+    @user_sfa_mapper
+    def sfa_update_user (self, *args, **kwds): pass
+    @user_sfa_mapper
+    def sfa_delete_user (self, *args, **kwds): pass
+
+    def sfi_list (self, options):
+        "run (as regular user) sfi list (on Registry)"
+       return \
+            self.test_plc.run_in_guest(self.sfi_user("list -r %s"%self.root_hrn()))==0 and \
+            self.test_plc.run_in_guest(self.sfi_user("list %s"%(self.hrn())))==0
+
+    def sfi_show (self, options):
+        "run (as regular user) sfi show (on Registry)"
+       return \
+            self.test_plc.run_in_guest(self.sfi_user("show %s"%(self.hrn())))==0
+
+    def sfi_slices (self, options):
+        "run (as regular user) sfi slices (on SM)"
+       return \
+            self.test_plc.run_in_guest(self.sfi_user("slices"))==0 
+
+    # those are step names exposed as methods of TestPlc, hence the _sfa
+    @slice_sfa_mapper
+    def sfa_add_slice (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def sfa_discover (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def sfa_create_slice (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def sfa_check_slice_plc (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def sfa_update_slice (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def sfa_delete_slice (self, *args, **kwds): pass
+    @slice_sfa_mapper
+    def ssh_slice_sfa     (self, *args, **kwds): pass
+
index e4cc1d4..238778c 100644 (file)
@@ -2,7 +2,6 @@
 # Copyright (C) 2010 INRIA 
 #
 import sys, os, os.path, time, base64
-import xmlrpclib
 
 import utils
 from TestUser import TestUser
index c6658a1..5b5efe4 100644 (file)
@@ -19,7 +19,7 @@ from TestSliver import TestSliver
 from TestBoxQemu import TestBoxQemu
 from TestSsh import TestSsh
 from TestApiserver import TestApiserver
-from TestSliceSfa import TestSliceSfa
+from TestAuthSfa import TestAuthSfa
 
 # step methods must take (self) and return a boolean (options is a member of the class)
 
@@ -62,16 +62,16 @@ def slice_mapper (method):
     actual.__doc__=TestSlice.__dict__[method.__name__].__doc__
     return actual
 
-def slice_sfa_mapper (method):
+def auth_sfa_mapper (method):
     def actual(self):
         overall=True
-        slice_method = TestSliceSfa.__dict__[method.__name__]
-        for slice_spec in self.plc_spec['sfa']['sfa_slice_specs']:
-            test_slice=TestSliceSfa(self,slice_spec)
+        slice_method = TestAuthSfa.__dict__[method.__name__]
+        for slice_spec in self.plc_spec['sfa']['auth_sfa_specs']:
+            test_slice=TestAuthSfa(self,slice_spec)
             if not slice_method(test_slice,self.options): overall=False
         return overall
     # restore the doc text
-    actual.__doc__=TestSliceSfa.__dict__[method.__name__].__doc__
+    actual.__doc__=TestAuthSfa.__dict__[method.__name__].__doc__
     return actual
 
 SEP='<sep>'
@@ -1247,13 +1247,14 @@ class TestPlc:
         # ignore result 
         sfa_spec=self.plc_spec['sfa']
 
-        for sfa_slice_spec in sfa_spec['sfa_slice_specs']:
-            login_base=sfa_slice_spec['login_base']
+        for auth_sfa_spec in sfa_spec['auth_sfa_specs']:
+            login_base=auth_sfa_spec['login_base']
             try: self.apiserver.DeleteSite (self.auth_root(),login_base)
             except: print "Site %s already absent from PLC db"%login_base
 
-            for key in ['piuser','regularuser']:
-                username="%s@%s"%(sfa_slice_spec[key],sfa_slice_spec['domain'])
+            for spec_name in ['pi_spec','user_spec']:
+                user_spec=auth_sfa_spec[spec_name]
+                username=user_spec['email']
                 try: self.apiserver.DeletePerson(self.auth_root(),username)
                 except: 
                     # this in fact is expected as sites delete their members
@@ -1399,9 +1400,9 @@ class TestPlc:
             utils.header("DRY RUN - skipping step")
             return True
         sfa_spec=self.plc_spec['sfa']
-        # cannot use slice_sfa_mapper to pass dir_name
-        for slice_spec in self.plc_spec['sfa']['sfa_slice_specs']:
-            test_slice=TestSliceSfa(self,slice_spec)
+        # cannot use auth_sfa_mapper to pass dir_name
+        for slice_spec in self.plc_spec['sfa']['auth_sfa_specs']:
+            test_slice=TestAuthSfa(self,slice_spec)
             dir_basename=os.path.basename(test_slice.sfi_path())
             dir_name=self.confsubdir("dot-sfi/%s"%dir_basename,clean=True,dry_run=self.options.dry_run)
             test_slice.sfi_configure(dir_name)
@@ -1419,35 +1420,35 @@ class TestPlc:
         self.run_in_guest("rm -rf /root/sfi")
         return True
 
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_add_site (self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_add_pi (self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_add_user(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_update_user(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_add_slice(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_discover(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_create_slice(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_check_slice_plc(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_update_slice(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfi_list(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfi_show(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfi_slices(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def ssh_slice_sfa(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_delete_user(self): pass
-    @slice_sfa_mapper
+    @auth_sfa_mapper
     def sfa_delete_slice(self): pass
 
     def sfa_stop(self):
index 4377e66..3b37d62 100644 (file)
@@ -144,6 +144,7 @@ class TestSlice:
                 date_test_ssh = TestSsh (hostname,key=remote_privatekey,username=self.name())
                 command = date_test_ssh.actual_command("echo hostname ; hostname; echo id; id; echo uname -a ; uname -a")
                 date = utils.system (command, silent=datetime.datetime.now() < graceout)
+                if getattr(options,'dry_run',None): return True
                 if expected:    success = date==0
                 else:           success = date!=0
                     
index 2c90359..fa451ff 100644 (file)
 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
 # Copyright (C) 2010 INRIA 
 #
-import utils
-import os, os.path
-import datetime
-import time
 
-from TestKey import TestKey
+import utils
 from TestUser import TestUser
-from TestNode import TestNode
+from TestBoxQemu import TestBoxQemu
 from TestSsh import TestSsh
-from TestUserSfa import TestUserSfa
+
 
 class TestSliceSfa:
 
-    def __init__ (self,test_plc,sfa_slice_spec):
-       self.test_plc=test_plc
-       self.sfa_slice_spec=sfa_slice_spec
-        self.test_ssh=TestSsh(self.test_plc.test_ssh)
+    def __init__ (self, test_auth_sfa, slice_spec):
+        self.test_auth_sfa=test_auth_sfa
+        self.slice_spec=slice_spec
         # shortcuts
-        self.sfa_spec=test_plc.plc_spec['sfa']
-        self.piuser=self.sfa_slice_spec['piuser']
-        self.regularuser=self.sfa_slice_spec['regularuser']
-        self.slicename=self.sfa_slice_spec['slicename']
-        self.login_base=self.sfa_slice_spec['login_base']
-        
-    def plc_name(self):
-        return self.sfa_slice_spec['plc_slicename']
-    
-    def rspec_style (self): return self.sfa_slice_spec['rspec_style']
-
-    # the hrn for the site
-    def auth_hrn (self):
-        return self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
-
-    # the hrn for the site
-    def site_hrn (self):
-        return "%s.%s"%(self.auth_hrn(),self.login_base)
+        self.test_plc=self.test_auth_sfa.test_plc
 
-    # something in the site (users typically)
-    def qualified_hrn (self, name):
-        return "%s.%s"%(self.site_hrn(),name)
+    def qualified(self,name): return self.test_auth_sfa.qualified(name)
+    def hrn (self): return self.qualified(self.slice_spec['name'])
+    def sfi_path (self): return self.test_auth_sfa.sfi_path()
 
-    # the slice hrn
-    def hrn(self): return self.qualified_hrn (self.slicename)
+    # send back up to the TestAuthSfa
+    def rspec_style (self): return self.test_auth_sfa.rspec_style()
+    def sfi_pi(self,*args,**kwds): return self.test_auth_sfa.sfi_pi(*args, **kwds)
+    def sfi_user(self,*args,**kwds): return self.test_auth_sfa.sfi_user(*args, **kwds)
 
-    # result name
-    def resname (self,name,ext): return "%s.%s"%(name,ext)
-
-    def adfile (self): return self.resname("ad","rspec")
-    def reqfile (self): return self.resname("req","rspec")
-    def nodefile (self): return self.resname("nodes","txt")
-    # xxx this needs tweaks with more recent versions of sfa that have pgv2 as the default ?
     def discover_option(self):
         if self.rspec_style()=='pg': return "-r protogeni"
         else:                        return "-r sfa"
 
-    def sfi_path (self):
-        return "/root/sfi/%s%s"%(self.slicename,self.rspec_style())
-
-    def locate_key(self):
-        for key_name in self.sfa_slice_spec['slice_key_names']:
-            key_spec=self.test_plc.locate_key(key_name)
-            test_key=TestKey(self.test_plc,key_spec)
-            publickey=test_key.publicpath()
-            privatekey=test_key.privatepath()
-            if os.path.isfile(publickey) and os.path.isfile(privatekey):
-                found=True
-        return (found,privatekey)
-
-    # dir_name is local and will be pushed later on by TestPlc
-    # by default set SFI_USER to the pi, we'll overload this
-    # on the command line when needed
-    def sfi_configure (self,dir_name):
-        plc_spec=self.test_plc.plc_spec
-        sfa_spec=self.sfa_spec
-        sfa_slice_spec=self.sfa_slice_spec
-        keys=plc_spec['keys']
-        # fetch keys in config spec and expose to sfi
-        for (hrn_leaf,key_name) in sfa_slice_spec['hrn_keys'].items():
-            key_spec = self.test_plc.locate_key (key_name)
-            for (kind,ext) in [ ('private', 'pkey'), ('public', 'pub') ] :
-                contents=key_spec[kind]
-                file_name=os.path.join(dir_name,self.qualified_hrn(hrn_leaf))+"."+ext
-                fileconf=open(file_name,'w')
-                fileconf.write (contents)
-                fileconf.close()
-                utils.header ("(Over)wrote %s"%file_name)
-        #
-       file_name=dir_name + os.sep + 'sfi_config'
-        fileconf=open(file_name,'w')
-       SFI_AUTH="%s"%(self.site_hrn())
-        fileconf.write ("SFI_AUTH='%s'"%SFI_AUTH)
-       fileconf.write('\n')
-       SFI_USER=SFI_AUTH + '.' + self.piuser
-        fileconf.write ("SFI_USER='%s'"%SFI_USER)
-       fileconf.write('\n')
-       SFI_REGISTRY='http://' + sfa_spec['SFA_REGISTRY_HOST'] + ':12345/'
-        fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY)
-       fileconf.write('\n')
-       SFI_SM='http://' + sfa_spec['SFA_SM_HOST'] + ':12347/'
-        fileconf.write ("SFI_SM='%s'"%SFI_SM)
-       fileconf.write('\n')
-        fileconf.close()
-        utils.header ("(Over)wrote %s"%file_name)
-
-    # using sfaadmin to bootstrap
-    def sfa_add_site (self, options):
-        "bootstrap a site using sfaadmin"
-        command="sfaadmin reg register -t authority -x %s"%self.site_hrn()
-        return self.test_plc.run_in_guest(command)==0
-
-    def sfa_add_pi (self, options):
-        "bootstrap a PI user for that site"
-        pi_hrn=self.qualified_hrn(self.piuser)
-        pi_mail=self.sfa_slice_spec['pimail']
-        # as installed by sfi_config
-        pi_key=os.path.join(self.sfi_path(),self.qualified_hrn(self.piuser+'.pub'))
-        command="sfaadmin reg register -t user -x %s --email %s --key %s"%(pi_hrn,pi_mail,pi_key)
-        if self.test_plc.run_in_guest(command)!=0: return False
-        command="sfaadmin reg update -t authority -x %s --pi %s"%(self.site_hrn(),pi_hrn)
-        return self.test_plc.run_in_guest(command)==0
-
-    # user management
-    def sfa_add_user (self, options):
-        "add a regular user using sfi add"
-        return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).add_user()
-    def sfa_update_user (self, options):
-        "update a user record using sfi update"
-        return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).update_user()
-    def sfa_delete_user (self, options):
-       "run sfi delete"
-        return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).delete_user()
-
-    # run as pi
-    def sfi_pi (self, command):
-        return "sfi -d %s -u %s %s"%(self.sfi_path(),self.qualified_hrn(self.piuser), command,)
-    # the sfi command line option to run as a regular user
-    def sfi_user (self, command):
-        return "sfi -d %s -u %s %s"%(self.sfi_path(),self.qualified_hrn(self.regularuser), command,)
-
     # those are step names exposed as methods of TestPlc, hence the _sfa
 
-    def sfi_list (self, options):
-        "run (as regular user) sfi list (on Registry)"
-       return \
-            self.test_plc.run_in_guest(self.sfi_user("list -r %s"%self.auth_hrn()))==0 and \
-            self.test_plc.run_in_guest(self.sfi_user("list %s"%(self.site_hrn())))==0
-
-    def sfi_show (self, options):
-        "run (as regular user) sfi show (on Registry)"
-       return \
-            self.test_plc.run_in_guest(self.sfi_user("show %s"%(self.site_hrn())))==0
-
-    def sfi_slices (self, options):
-        "run (as regular user) sfi slices (on SM)"
-       return \
-            self.test_plc.run_in_guest(self.sfi_user("slices"))==0 
-
     # needs to be run as pi
     def sfa_add_slice(self,options):
         "run sfi add (on Registry) from slice.xml"
-        sfi_options="add"
-        for opt in self.sfa_slice_spec['slice_sfi_options']:
-            sfi_options += " %s"%(opt)
-       return self.test_plc.run_in_guest(self.sfi_pi(sfi_options))==0
-
+        sfi_command="add"
+        sfi_command += " --type slice"
+        sfi_command += " --xrn %s"%self.qualified(self.slice_spec['name'])
+        for opt in self.slice_spec['sfi_options']:
+            sfi_command += " %s"%(opt)
+       return self.test_plc.run_in_guest(self.sfi_pi(sfi_command))==0
+
+    # helper - filename to store a given result
+    def _resname (self,name,ext): return "%s.%s"%(name,ext)
+    def adfile (self): return self._resname("ad","rspec")
+    def reqfile (self): return self._resname("req","rspec")
+    def nodefile (self): return self._resname("nodes","txt")
+    
     # run as user
     def sfa_discover(self,options):
         "discover resources into resouces_in.rspec"
@@ -188,7 +69,8 @@ class TestSliceSfa:
     # all local nodes in slice ?
     def sfa_check_slice_plc (self,options):
         "check sfa_create_slice at the plcs - all local nodes should be in slice"
-        slice_name = self.plc_name()
+        login_base=self.test_auth_sfa.login_base
+        slice_name = "%s_%s"%(login_base,self.slice_spec['name'])
         slice=self.test_plc.apiserver.GetSlices(self.test_plc.auth_root(), slice_name)[0]
         nodes=self.test_plc.apiserver.GetNodes(self.test_plc.auth_root(), {'peer_id':None})
         result=True
@@ -223,10 +105,9 @@ class TestSliceSfa:
             return False
 
         # convert nodenames to real hostnames
-        sfa_slice_spec = self.sfa_slice_spec
         restarted=[]
         tocheck=[]
-        for nodename in sfa_slice_spec['nodenames']:
+        for nodename in self.auth_sfa_spec['nodenames']:
             (site_spec,node_spec) = self.test_plc.locate_node(nodename)
             tocheck.append(node_spec['node_fields']['hostname'])
 
@@ -269,3 +150,4 @@ class TestSliceSfa:
         # for an empty slice
         return True
 
+    
index ccd07c3..49eb7eb 100644 (file)
@@ -8,23 +8,25 @@ import utils
 
 class TestUserSfa:
 
-    def __init__ (self,test_plc,sfa_slice_spec,test_slice_sfa):
-       self.test_plc=test_plc
-        self.sfa_slice_spec=sfa_slice_spec
-        self.test_slice_sfa=test_slice_sfa
+    def __init__ (self,test_auth_sfa, user_spec):
+        self.test_auth_sfa=test_auth_sfa
+        self.user_spec=user_spec
         # shortcuts
-        self.sfa_spec=test_plc.plc_spec['sfa']
-        self.piuser=self.sfa_slice_spec['piuser']
-        self.regularuser=self.sfa_slice_spec['regularuser']
-        self.login_base=self.sfa_slice_spec['login_base']
+        self.test_plc=self.test_auth_sfa.test_plc
+        self.login_base=self.test_auth_sfa.login_base
 
-    def sfi_path(self): return self.test_slice_sfa.sfi_path()
+    def sfi_path(self): return self.test_auth_sfa.sfi_path()
+    def qualified(self,name): return self.test_auth_sfa.qualified(name)
 
     # xxx todo - not the right place any longer - or is it ?
-    def add_user (self):
-        sfi_add_options = self.sfa_slice_spec['user_sfi_options']
-        user_hrn = self.sfa_slice_spec['user_hrn']
+    def sfa_add_user (self,options):
+        "add a regular user using sfi add"
+        sfi_add_options = self.user_spec['sfi_options']
+        user_hrn = self.qualified(self.user_spec['name'])
         command="sfi -d %s add"%(self.sfi_path())
+        command += " --type user"
+        command += " --xrn %s"%user_hrn
+        command += " --email %s"%self.user_spec['email']
         for opt in sfi_add_options:
             command += " %s"%(opt,)
         # handle key separately because of embedded whitespace
@@ -32,13 +34,15 @@ class TestUserSfa:
         command += " -k %s/%s.pub"%(self.sfi_path(),user_hrn)
        return self.test_plc.run_in_guest(command)==0
 
-    def update_user (self):
+    def sfa_update_user (self,options):
+        "update a user record using sfi update"
         # xxx TODO now that we use sfi arguments
         utils.header ("WARNING: TestUserSfa.update_user needs more work")
         return True
 
-    def delete_user(self):
-       auth=self.sfa_spec['SFA_REGISTRY_ROOT_AUTH']
+    def sfa_delete_user(self,options):
+       "run sfi delete on user record"
+       auth=self.test_auth_sfa.root_hrn()
        return \
             self.test_plc.run_in_guest("sfi -d %s remove -t user %s.%s.%s"%(
                 self.sfi_path(),auth,self.login_base,self.regularuser))==0
index 690e532..3c3cb9f 100644 (file)
@@ -126,7 +126,7 @@ def sites (options,index):
                                'login_base':login_base(index),
                                'abbreviated_name':'PlanetTest%d'%index,
                                'max_slices':100,
-                               'url':'http://test.onelab.eu',
+                               'url':'http://test.%s'%domain,
                                'latitude':float(latitude),
                                'longitude':float(longitude),
                                },
@@ -500,59 +500,56 @@ def sfa (options,index) :
         'SFA_GENERIC_FLAVOUR' : 'pl',
         'SFA_AGGREGATE_ENABLED' : 'true',
         # details of the slices to create
-        'sfa_slice_specs' : [ sfa_slice_spec(options,index,rspec_style) 
-                              for rspec_style in options.rspec_styles ]
+        'auth_sfa_specs' : [ test_auth_sfa_spec(options,index,rspec_style) 
+                             for rspec_style in options.rspec_styles ]
     }
 
 # rspecstyle is 'pl' for sfav1 or 'pg' for pgv2
-def sfa_slice_spec (options,index,rspec_style):
-    the_login_base=sfa_login_base(index,rspec_style)
-    # we're already in a dedicated site/authority so no need to encumber with odd names
-    piuser='pi'
-    pimail=piuser+'@test.onelab.eu'
-    regularuser='us'
-    slicename='sl'
-    prefix='%s.%s'%(sfa_root(index),the_login_base)
-    hrn=prefix+'.'+slicename
-    user_hrn=prefix+'.'+regularuser
-    pi_hrn=prefix+'.'+piuser
-    mail="%s@%s"%(regularuser,domain)
-    # passed to sfi
-    # -k gets computed later on from the hrn (i.e. from the '-x' key..)
-    user_sfi_options = [ '--type','user',
-                         '--xrn',user_hrn,
-                         '--email',mail,
-                         # xxx
-                         '--extra',"enabled=true",
-                         '--extra',"first_name=Fake",
-                         '--extra',"last_name=SFA-style-%s"%rspec_style,
-                         ]
-                       
-    slice_sfi_options = [ '--type', 'slice',
-                          '--xrn', hrn,
-                          '--researchers', user_hrn,
+def test_auth_sfa_spec (options,index,rspec_style):
+    # the auth/site part per se
+    login_base=sfa_login_base(index,rspec_style)
+    hrn_prefix='%s.%s'%(sfa_root(index),login_base)
+    def full_hrn(x):  return "%s.%s"%(hrn_prefix,x)
+    def full_mail(x): return "%s@test.%s"%(x,domain)
+
+    # 2 users
+    pi_spec = {
+        'name':         'pi',
+        'email':        full_mail ('piuser'),
+        'key_name':     'key_sfapi',
+        }
+    user_hrn = full_hrn ('us')
+    user_spec = {
+        'name':         'us',
+        'email':        full_mail ('regularuser'),
+        'key_name':     'key_sfauser',
+        'sfi_options':  [ '--extra',"enabled=true",
+                          '--extra',"first_name=Fake",
+                          '--extra',"last_name=SFA-style-%s"%rspec_style,
+                          ],
+        }
+
+    slice_spec = {
+        'name':          'sl',
+        'sfi_options':  [ '--researchers', user_hrn,
                           # xxx
                           '--extra', "description=SFA-testing-%s"%rspec_style,
                           '--extra', "url=http://slice%d.test.onelab.eu/"%index,
                           '--extra', "max_nodes=2",
-                          ]
+                          ],
+        'key_name':    'key_sfauser',
+        'nodenames':    all_nodenames(options,index),
+        }
+        
+    # we're already in a dedicated site/authority so no need to encumber with odd names
 
-    return { 'plc_slicename': '%s_%s'%(the_login_base,slicename),
-             'login_base' : the_login_base,
-             'piuser' : piuser,
-             'pimail' : pimail,
-             'regularuser':regularuser,
+    return { #'hrn_prefix': hrn_prefix,
+             'login_base' : login_base,
              'domain':domain,
-             'slice_key_names' : [ 'key_sfauser' ],
-             'hrn_keys' : { piuser : 'key_sfapi',
-                            regularuser : 'key_sfauser' },
-             'nodenames' : all_nodenames(options,index),
-             'sitename' : the_login_base,
-             'slicename' : slicename,
              'rspec_style':rspec_style,
-             'user_sfi_options': user_sfi_options,
-             'user_hrn': user_hrn,
-             'slice_sfi_options': slice_sfi_options,
+             'pi_spec': pi_spec,
+             'user_spec': user_spec,
+             'slice_spec': slice_spec,
              } 
 
 
index c807f2f..d52be74 100644 (file)
@@ -50,6 +50,13 @@ sequences['sfa_create'] = [
     'sfa_add_slice',
 ]
 
+sequences['sfa_provision'] = [ 
+    'sfa-discover',
+    'sfa-create_slice',
+    'sfa_check_slice_plc',
+    'sfa_view_all',
+]
+
 # run the whole SFA stuff but from scratch, new vs all reinstalled and all
 sequences['sfa_scratch'] = [
     'show',