From: Thierry Parmentelat Date: Fri, 21 Oct 2011 10:42:39 +0000 (+0200) Subject: should support pl and pg modes for sfa slices X-Git-Tag: tests-5.0-30~3 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=86a192a57b7e78ea5b0bbb8427e30efc546a5bf6;p=tests.git should support pl and pg modes for sfa slices cleanup sfa slices and users --- diff --git a/system/TestPlc.py b/system/TestPlc.py index 79580c7..a21f42f 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -20,7 +20,6 @@ from TestBoxQemu import TestBoxQemu from TestSsh import TestSsh from TestApiserver import TestApiserver from TestSliceSfa import TestSliceSfa -from TestUserSfa import TestUserSfa # step methods must take (self) and return a boolean (options is a member of the class) @@ -1123,13 +1122,13 @@ class TestPlc: sfa_spec=self.plc_spec['sfa'] for sfa_slice_spec in sfa_spec['sfa_slice_specs']: - slicename='%s_%s'%(sfa_spec['login_base'],sfa_slice_spec['slicename']) + slicename='%s_%s'%(sfa_slice_spec['login_base'],sfa_slice_spec['slicename']) try: self.apiserver.DeleteSlice(self.auth_root(),slicename) except: print "Slice %s already absent from PLC db"%slicename - username="%s@%s"%(sfa_spec['regularuser'],sfa_spec['domain']) - try: self.apiserver.DeletePerson(self.auth_root(),username) - except: print "User %s already absent from PLC db"%username + username="%s@%s"%(sfa_slice_spec['regularuser'],sfa_slice_spec['domain']) + try: self.apiserver.DeletePerson(self.auth_root(),username) + except: print "User %s already absent from PLC db"%username print "REMEMBER TO RUN sfa_import AGAIN" return True @@ -1259,59 +1258,40 @@ class TestPlc: return self.run_in_guest('service sfa start')==0 def sfi_configure(self): - "Create /root/.sfi on the plc side for sfi client configuration" + "Create /root/sfi on the plc side for sfi client configuration" + if self.options.dry_run: + utils.header("DRY RUN - skipping step") + return True sfa_spec=self.plc_spec['sfa'] - dir_name=self.confsubdir("dot-sfi",clean=True,dry_run=self.options.dry_run) - if self.options.dry_run: return True - file_name=dir_name + os.sep + sfa_spec['piuser'] + '.pkey' - fileconf=open(file_name,'w') - fileconf.write (self.plc_spec['keys'][0]['private']) - 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.%s"%(sfa_spec['SFA_REGISTRY_ROOT_AUTH'],sfa_spec['login_base']) - fileconf.write ("SFI_AUTH='%s'"%SFI_AUTH) - fileconf.write('\n') - SFI_USER=SFI_AUTH + '.' + sfa_spec['piuser'] - fileconf.write ("SFI_USER='%s'"%SFI_USER) - fileconf.write('\n') - SFI_REGISTRY='http://' + sfa_spec['SFA_PLC_DB_HOST'] + ':12345/' - fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY) - fileconf.write('\n') - SFI_SM='http://' + sfa_spec['SFA_PLC_DB_HOST'] + ':12347/' - fileconf.write ("SFI_SM='%s'"%SFI_SM) - fileconf.write('\n') - fileconf.close() - utils.header ("(Over)wrote %s"%file_name) - # cannot use sfa_slice_mapper to pass dir_name for slice_spec in self.plc_spec['sfa']['sfa_slice_specs']: site_spec = self.locate_site (slice_spec['sitename']) test_site = TestSite(self,site_spec) test_slice=TestSliceSfa(self,test_site,slice_spec) + dir_name=self.confsubdir("dot-sfi/%s"%slice_spec['slicename'],clean=True,dry_run=self.options.dry_run) test_slice.sfi_config(dir_name) - - # push to the remote root's .sfi - location = "root/.sfi" - remote="/vservers/%s/%s"%(self.vservername,location) - self.test_ssh.copy_abs(dir_name, remote, recursive=True) + # push into the remote /root/sfi area + location = test_slice.sfi_path() + remote="/vservers/%s/%s"%(self.vservername,location) + self.test_ssh.mkdir(remote,abs=True) + # need to strip last level or remote otherwise we get an extra dir level + self.test_ssh.copy_abs(dir_name, os.path.dirname(remote), recursive=True) return True def sfi_clean (self): - "clean up /root/.sfi on the plc side" - self.run_in_guest("rm -rf /root/.sfi") + "clean up /root/sfi on the plc side" + self.run_in_guest("rm -rf /root/sfi") return True + @slice_sfa_mapper def sfa_add_user(self): - "run sfi.py add using person.xml" - return TestUserSfa(self).add_user() + "run sfi.py add" + pass + @slice_sfa_mapper def sfa_update_user(self): - "run sfi.py update using person.xml" - return TestUserSfa(self).update_user() + "run sfi.py update" @slice_sfa_mapper def sfa_add_slice(self): @@ -1338,25 +1318,20 @@ class TestPlc: "run sfi.py create (on SM) on existing object" pass + @slice_sfa_mapper def sfa_view(self): - "run sfi.py list and sfi.py show (both on Registry) and sfi.py slices and sfi.py resources (both on SM)" - sfa_spec=self.plc_spec['sfa'] - auth=sfa_spec['SFA_REGISTRY_ROOT_AUTH'] - return \ - self.run_in_guest("sfi.py -d /root/.sfi/ list %s.%s"%(auth,sfa_spec['login_base']))==0 and \ - self.run_in_guest("sfi.py -d /root/.sfi/ show %s.%s"%(auth,sfa_spec['login_base']))==0 and \ - self.run_in_guest("sfi.py -d /root/.sfi/ slices")==0 and \ - self.run_in_guest("sfi.py -d /root/.sfi/ resources -o resources")==0 + "various registry-related calls" + pass @slice_sfa_mapper def ssh_slice_sfa(self): "tries to ssh-enter the SFA slice" pass + @slice_sfa_mapper def sfa_delete_user(self): - "run sfi.py delete (on SM) for user" - test_user_sfa=TestUserSfa(self) - return test_user_sfa.delete_user() + "run sfi.py delete" + pass @slice_sfa_mapper def sfa_delete_slice(self): diff --git a/system/TestSliceSfa.py b/system/TestSliceSfa.py index e996122..eb865b7 100644 --- a/system/TestSliceSfa.py +++ b/system/TestSliceSfa.py @@ -10,32 +10,35 @@ from TestKey import TestKey from TestUser import TestUser from TestNode import TestNode from TestSsh import TestSsh +from TestUserSfa import TestUserSfa class TestSliceSfa: - def __init__ (self,test_plc,test_site,slice_spec): + def __init__ (self,test_plc,test_site,sfa_slice_spec): self.test_plc=test_plc self.test_site=test_site - self.slice_spec=slice_spec + self.sfa_slice_spec=sfa_slice_spec self.test_ssh=TestSsh(self.test_plc.test_ssh) # shortcuts self.sfa_spec=test_plc.plc_spec['sfa'] - self.piuser=self.sfa_spec['piuser'] - self.regularuser=self.sfa_spec['regularuser'] - self.slicename=self.slice_spec['slicename'] - self.login_base=self.sfa_spec['login_base'] + 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 name(self): - return self.slice_spec['slice_fields']['name'] + return self.sfa_slice_spec['slice_fields']['name'] - def mode (self): return self.slice_spec['mode'] + def mode (self): return self.sfa_slice_spec['mode'] def hrn(self): root_auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH'] return "%s.%s.%s"%(root_auth,self.login_base,self.slicename) - def addslicefile (self): - return self.resname("addslice","rspec") - def resname (self,name,ext): return "%s_%s.%s"%(self.slicename,name,ext) +# def resname (self,name,ext): return "%s_%s.%s"%(self.slicename,name,ext) + def resname (self,name,ext): return "%s.%s"%(name,ext) + + def addslicefile (self): return self.resname("addslice","xml") + def addpersonfile (self): return self.resname("addperson","xml") def adfile (self): return self.resname("ad","rspec") def reqfile (self): return self.resname("req","rspec") def nodefile (self): return self.resname("nodes","txt") @@ -43,8 +46,11 @@ class TestSliceSfa: if self.mode()=='pg': return "-r protogeni" else: return "" + def sfi_path (self): + return "/root/sfi/%s"%self.slicename + def locate_key(self): - for username,keyname in self.slice_spec['usernames']: + for username,keyname in self.sfa_slice_spec['usernames']: key_spec=self.test_plc.locate_key(keyname) test_key=TestKey(self.test_plc,key_spec) publickey=test_key.publicpath() @@ -53,34 +59,80 @@ class TestSliceSfa: found=True return (found,privatekey) - # dir_name is local and will be pushed later on + # dir_name is local and will be pushed later on by TestPlc def sfi_config (self,dir_name): - # TODO this needs to be done remotely - file_name=dir_name + os.sep + self.addslicefile() + plc_spec=self.test_plc.plc_spec + sfa_spec=self.sfa_spec + sfa_slice_spec=self.sfa_slice_spec + # + file_name=dir_name + os.sep + self.piuser + '.pkey' fileconf=open(file_name,'w') - fileconf.write(self.slice_spec['slice_add_xml']) - fileconf.write('\n') + fileconf.write (plc_spec['keys'][0]['private']) + fileconf.close() utils.header ("(Over)wrote %s"%file_name) + # + file_name=dir_name + os.sep + self.addpersonfile() + fileconf=open(file_name,'w') + fileconf.write(sfa_slice_spec['slice_person_xml']) + fileconf.write('\n') fileconf.close() - file_name=dir_name + os.sep + 'person.xml' + utils.header ("(Over)wrote %s"%file_name) + # + file_name=dir_name + os.sep + 'sfi_config' fileconf=open(file_name,'w') - fileconf.write(self.slice_spec['slice_person_xml']) + SFI_AUTH="%s.%s"%(sfa_spec['SFA_REGISTRY_ROOT_AUTH'],self.login_base) + 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_PLC_DB_HOST'] + ':12345/' + fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY) + fileconf.write('\n') + SFI_SM='http://' + sfa_spec['SFA_PLC_DB_HOST'] + ':12347/' + fileconf.write ("SFI_SM='%s'"%SFI_SM) fileconf.write('\n') fileconf.close() utils.header ("(Over)wrote %s"%file_name) - + # + file_name=dir_name + os.sep + self.addslicefile() + fileconf=open(file_name,'w') + fileconf.write(sfa_slice_spec['slice_add_xml']) + fileconf.write('\n') + utils.header ("(Over)wrote %s"%file_name) + fileconf.close() + + # user management + def sfa_add_user (self, options): + return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).add_user() + def sfa_update_user (self, options): + return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).update_user() + def sfa_delete_user (self, options): + return TestUserSfa(self.test_plc, self.sfa_slice_spec, self).delete_user() + + # those are step names exposed as methods of TestPlc, hence the _sfa + def sfa_view (self, options): + "run sfi.py list and sfi.py show (both on Registry) and sfi.py slices (on SM)" + root_auth=self.test_plc.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH'] + return \ + self.test_plc.run_in_guest("sfi.py -d %s list %s.%s"%(self.sfi_path(),root_auth,self.login_base))==0 and \ + self.test_plc.run_in_guest("sfi.py -d %s show %s.%s"%(self.sfi_path(),root_auth,self.login_base))==0 and \ + self.test_plc.run_in_guest("sfi.py -d %s slices"%self.sfi_path())==0 + def sfa_add_slice(self,options): - return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ add %s"%(self.addslicefile()))==0 + return self.test_plc.run_in_guest("sfi.py -d %s add %s"%(self.sfi_path(),self.addslicefile()))==0 def sfa_discover(self,options): - return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ %s resources -o /root/.sfi/%s"%(self.discover_option(),self.adfile()))==0 + return self.test_plc.run_in_guest("sfi.py -d %s resources %s -o %s/%s"%\ + (self.sfi_path(),self.discover_option(),self.sfi_path(),self.adfile()))==0 def sfa_create_slice(self,options): commands=[ - "sfiListNodes.py -i /root/.sfi/%s -o /root/.sfi/%s"%(self.adfile(),self.nodefile()), - "sfiAddSliver.py -i /root/.sfi/%s -n /root/.sfi/%s -o /root/.sfi/%s"%(self.adfile(),self.nodefile(),self.reqfile()), - "sfi.py -d /root/.sfi/ create %s %s"%(self.hrn(),self.reqfile()), + "sfiListNodes.py -i %s/%s -o %s/%s"%(self.sfi_path(),self.adfile(),self.sfi_path(),self.nodefile()), + "sfiAddSliver.py -i %s/%s -n %s/%s -o %s/%s"%\ + (self.sfi_path(),self.adfile(),self.sfi_path(),self.nodefile(),self.sfi_path(),self.reqfile()), + "sfi.py -d %s create %s %s"%(self.sfi_path(),self.hrn(),self.reqfile()), ] for command in commands: if self.test_plc.run_in_guest(command)!=0: return False @@ -88,7 +140,7 @@ class TestSliceSfa: # all local nodes in slice ? def sfa_check_slice_plc (self,options): - slice_fields = self.slice_spec['slice_fields'] + slice_fields = self.sfa_slice_spec['slice_fields'] slice_name = slice_fields['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}) @@ -106,8 +158,8 @@ class TestSliceSfa: return self.sfa_create_slice(options) def sfa_delete_slice(self,options): - self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ delete %s"%(self.hrn())) - return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ remove -t slice %s"%(self.hrn()))==0 + self.test_plc.run_in_guest("sfi.py -d %s delete %s"%(self.sfi_path(),self.hrn())) + return self.test_plc.run_in_guest("sfi.py -d %s remove -t slice %s"%(self.sfi_path(),self.hrn()))==0 # check the resulting sliver def ssh_slice_sfa(self,options,timeout_minutes=40,silent_minutes=30,period=15): @@ -120,10 +172,10 @@ class TestSliceSfa: return False # convert nodenames to real hostnames - slice_spec = self.slice_spec + sfa_slice_spec = self.sfa_slice_spec restarted=[] tocheck=[] - for nodename in slice_spec['nodenames']: + for nodename in sfa_slice_spec['nodenames']: (site_spec,node_spec) = self.test_plc.locate_node(nodename) tocheck.append(node_spec['node_fields']['hostname']) @@ -165,3 +217,4 @@ class TestSliceSfa: time.sleep (period) # for an empty slice return True + diff --git a/system/TestSsh.py b/system/TestSsh.py index f56db3c..c5333cf 100644 --- a/system/TestSsh.py +++ b/system/TestSsh.py @@ -117,15 +117,16 @@ class TestSsh: return 0 return self.run("rm -rf %s"%dirname) - def mkdir (self,dirname=None): + def mkdir (self,dirname=None,abs=False): if self.is_local(): if dirname: return os.path.mkdir(dirname) return 0 - if dirname: - dirname="%s/%s"%(self.buildname,dirname) - else: - dirname=self.buildname + if not abs: + if dirname: + dirname="%s/%s"%(self.buildname,dirname) + else: + dirname=self.buildname return self.run("mkdir -p %s"%dirname) def rmdir (self,dirname=None): diff --git a/system/TestUserSfa.py b/system/TestUserSfa.py index 6408b3e..d0a6f97 100644 --- a/system/TestUserSfa.py +++ b/system/TestUserSfa.py @@ -8,22 +8,31 @@ import utils class TestUserSfa: - def __init__ (self,test_plc): + 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 # shortcuts self.sfa_spec=test_plc.plc_spec['sfa'] - self.piuser=self.sfa_spec['piuser'] - self.regularuser=self.sfa_spec['regularuser'] - self.login_base=self.sfa_spec['login_base'] + self.piuser=self.sfa_slice_spec['piuser'] + self.regularuser=self.sfa_slice_spec['regularuser'] + self.login_base=self.sfa_slice_spec['login_base'] + def sfi_path(self): return self.test_slice_sfa.sfi_path() + def addpersonfile(self): return self.test_slice_sfa.addpersonfile() + + # xxx todo - not the right place any longer - or is it ? def add_user (self): - return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ add person.xml")==0 + return self.test_plc.run_in_guest("sfi.py -d %s add %s"% + (self.sfi_path(),self.addpersonfile()))==0 def update_user (self): - return self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ update person.xml")==0 + return self.test_plc.run_in_guest("sfi.py -d %s update %s"% + (self.sfi_path(),self.addpersonfile()))==0 def delete_user(self): auth=self.sfa_spec['SFA_REGISTRY_ROOT_AUTH'] return \ - self.test_plc.run_in_guest("sfi.py -d /root/.sfi/ remove -t user %s.%s.%s"%(auth,self.login_base,self.regularuser))==0 + self.test_plc.run_in_guest("sfi.py -d %s remove -t user %s.%s.%s"%( + self.sfi_path(),auth,self.login_base,self.regularuser))==0 diff --git a/system/config_default.py b/system/config_default.py index 96955a7..2f9b519 100644 --- a/system/config_default.py +++ b/system/config_default.py @@ -14,16 +14,14 @@ domain="onelab.eu" ### for the sfa dual setup def login_base (index): - if index==1: return 'inria' - elif index==2: return 'princeton' + if index==1: return 'inri' + elif index==2: return 'princ' # index=3=>'sitea' 4=>'siteb' else: return 'site%s'%chr(index+94) def sfa_root (index): - if index==1: return 'ple' - elif index==2: return 'plc' - else: return 'plx%s'%chr(index+94) - + # pla, plb, ... + return 'pl%s'%chr(index+96) def nodes(options,index): return [{'name':'node%d'%index, @@ -196,7 +194,7 @@ def initscripts(options,index): # one has an initscript code, the other one an initscript name def slices (options,index): def theslice (i): - slice_spec = { 'slice_fields': {'name':'%s_slcpl%d'%(login_base(index),i), + slice_spec = { 'slice_fields': {'name':'%s_slpl%d'%(login_base(index),i), 'instantiation':'plc-instantiated', 'url':'http://foo%d.com'%index, 'description':'testslice number %d'%i, @@ -226,18 +224,18 @@ def tcp_tests (options,index): return [ # local test { 'server_node': 'node1', - 'server_slice' : '%s_slcpl1'%login_base(index), + 'server_slice' : '%s_slpl1'%login_base(index), 'client_node' : 'node1', - 'client_slice' : '%s_slcpl1'%login_base(index), + 'client_slice' : '%s_slpl1'%login_base(index), 'port' : 2000, }] elif index == 2: return [ # remote test { 'server_node': 'node2', - 'server_slice' : '%s_slcpl3'%login_base(index), + 'server_slice' : '%s_slpl3'%login_base(index), 'client_node' : 'node2', - 'client_slice' : '%s_slcpl4'%login_base(index), + 'client_slice' : '%s_slpl4'%login_base(index), 'port' : 4000, }, ] @@ -296,13 +294,7 @@ def plc (options,index) : } def sfa (options,index) : - piuser='fake-pi%d'%index - regularuser='sfafakeuser%d'%index return { - 'login_base' : login_base(index), - 'piuser' : piuser, - 'regularuser':regularuser, - 'domain':domain, # the default is to use AMs in the various aggregates.xml # stack config_sfamesh to point to SMs instead 'neighbours-port':12346, @@ -320,17 +312,17 @@ def sfa (options,index) : 'SFA_PLC_URL' : 'deferred-myplc-api-url', 'SFA_API_DEBUG': True, # details of the slices to create - 'sfa_slice_specs' : [ sfa_slice_spec(options,index,piuser,regularuser,i) for i in [0]], + 'sfa_slice_specs' : [ sfa_slice_spec(options,index,mode) + for mode in ['pl','pg']], } # subindex is 0 (pl slice) or 1 (pg slice) -def sfa_slice_spec (options,index,piuser,regularuser,subindex): - if subindex==0: - mode='pl' - else: - mode='pg' - slicename='slcsfa%d%s'%(index,mode) - prefix='%s.%s'%(sfa_root(index),login_base(index)) +def sfa_slice_spec (options,index,mode): + the_login_base=login_base(index) + piuser='fake-pi%d'%index + regularuser='sfauser%d%s'%(index,mode) + slicename='slsfa%d%s'%(index,mode) + prefix='%s.%s'%(sfa_root(index),the_login_base) hrn=prefix+'.'+slicename researcher=prefix+'.'+piuser slice_add_xml = ''' @@ -343,14 +335,18 @@ last_name="Sfa" name="%(hrn)s" type="user"> %(key)s2010 1piadmin%(prefix)s'''%locals() - return { 'slice_fields': {'name':'%s_%s'%(login_base(index),slicename), + return { 'slice_fields': {'name':'%s_%s'%(the_login_base,slicename), 'url':'http://foo%d@foo.com'%index, 'description':'SFA-testing', 'max_nodes':2, }, + 'login_base' : the_login_base, + 'piuser' : piuser, + 'regularuser':regularuser, + 'domain':domain, 'usernames' : [ (regularuser,'key1') ], 'nodenames' : all_nodenames(options,index), - 'sitename' : login_base(index), + 'sitename' : the_login_base, 'slicename' : slicename, 'slice_add_xml' : slice_add_xml, 'slice_person_xml' : slice_person_xml,