+ # populate runs the same utility without slightly different options
+ # in particular runs with --preserve (dont cleanup) and without --check
+ # also it gets run twice, once with the --foreign option for creating fake foreign entries
+
+ ### sfa_install_rpm
+ def sfa_install(self):
+ "yum install sfa, sfa-plc and sfa-client"
+ # ignore yum retcod
+ self.run_in_guest("yum -y install sfa sfa-client sfa-plc sfa-sfatables")
+ return self.run_in_guest("rpm -q sfa sfa-client sfa-plc sfa-sfatables")==0
+
+
+ def sfa_dbclean(self):
+ "thoroughly wipes off the SFA database"
+ self.run_in_guest("sfa-nuke-plc.py")==0
+ return True
+
+ def sfa_plcclean(self):
+ "cleans the PLC entries that were created as a side effect of running the script"
+ # ignore result
+ sfa_spec=self.plc_spec['sfa']
+
+ slicename='%s_%s'%(sfa_spec['login_base'],sfa_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
+
+ print "REMEMBER TO RUN sfa_import AGAIN"
+ return True
+
+ def sfa_uninstall(self):
+ "uses rpm to uninstall sfa - ignore result"
+ self.run_in_guest("rpm -e sfa sfa-sfatables sfa-client sfa-plc")
+ self.run_in_guest("rm -rf /var/lib/sfa")
+ self.run_in_guest("rm -rf /etc/sfa")
+ self.run_in_guest("rm -rf /var/log/sfa_access.log /var/log/sfa_import_plc.log /var/log/sfa.daemon")
+ # xxx tmp
+ self.run_in_guest("rpm -e --noscripts sfa-plc")
+ return True
+
+ ### sfa_install_rpm
+ def sfa_utest_install(self):
+ "yum install sfa-tests"
+ # ignore yum retcod
+ self.run_in_guest("yum -y install sfa-tests")
+ return self.run_in_guest("rpm -q sfa-tests")==0
+
+ def sfa_utest_run(self):
+ "run SFA unittests"
+ return self.run_in_guest("/usr/share/sfa/tests/testAll.py")==0
+
+ ###
+ def confdir(self):
+ dirname="conf.%s"%self.plc_spec['name']
+ if not os.path.isdir(dirname):
+ utils.system("mkdir -p %s"%dirname)
+ if not os.path.isdir(dirname):
+ raise "Cannot create config dir for plc %s"%self.name()
+ return dirname
+
+ def conffile(self,filename):
+ return "%s/%s"%(self.confdir(),filename)
+ def confsubdir(self,dirname,clean):
+ subdirname="%s/%s"%(self.confdir(),dirname)
+ if clean:
+ utils.system("rm -rf %s"%subdirname)
+ if not os.path.isdir(subdirname):
+ utils.system("mkdir -p %s"%subdirname)
+ if not os.path.isdir(subdirname):
+ raise "Cannot create config subdir %s for plc %s"%(dirname,self.name())
+ return subdirname
+
+ def conffile_clean (self,filename):
+ filename=self.conffile(filename)
+ return utils.system("rm -rf %s"%filename)==0
+
+ ###
+ def sfa_configure(self):
+ "run sfa-config-tty"
+ tmpname=self.conffile("sfa-config-tty")
+ fileconf=open(tmpname,'w')
+ for var in [ 'SFA_REGISTRY_ROOT_AUTH',
+ 'SFA_INTERFACE_HRN',
+# 'SFA_REGISTRY_LEVEL1_AUTH',
+ 'SFA_REGISTRY_HOST',
+ 'SFA_AGGREGATE_HOST',
+ 'SFA_SM_HOST',
+ 'SFA_PLC_USER',
+ 'SFA_PLC_PASSWORD',
+ 'SFA_PLC_DB_HOST',
+ 'SFA_PLC_DB_USER',
+ 'SFA_PLC_DB_PASSWORD',
+ 'SFA_PLC_URL',
+ ]:
+ fileconf.write ('e %s\n%s\n'%(var,self.plc_spec['sfa'][var]))
+ # the way plc_config handles booleans just sucks..
+ for var in ['SFA_API_DEBUG']:
+ val='false'
+ if self.plc_spec['sfa'][var]: val='true'
+ fileconf.write ('e %s\n%s\n'%(var,val))
+ fileconf.write('w\n')
+ fileconf.write('R\n')
+ fileconf.write('q\n')
+ fileconf.close()
+ utils.system('cat %s'%tmpname)
+ self.run_in_guest_piped('cat %s'%tmpname,'sfa-config-tty')
+ return True
+
+ def aggregate_xml_line(self):
+ return '<aggregate addr="%s" hrn="%s" port="12346"/>' % \
+ (self.vserverip,self.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH'])
+
+ def registry_xml_line(self):
+ return '<registry addr="%s" hrn="%s" port="12345"/>' % \
+ (self.vserverip,self.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH'])
+
+
+ # a cross step that takes all other plcs in argument
+ def cross_sfa_configure(self, other_plcs):
+ "writes aggregates.xml and registries.xml that point to all other PLCs in the test"
+ # of course with a single plc, other_plcs is an empty list
+ if not other_plcs:
+ return True
+ agg_fname=self.conffile("agg.xml")
+ file(agg_fname,"w").write("<aggregates>%s</aggregates>\n" % \
+ " ".join([ plc.aggregate_xml_line() for plc in other_plcs ]))
+ utils.header ("(Over)wrote %s"%agg_fname)
+ reg_fname=self.conffile("reg.xml")
+ file(reg_fname,"w").write("<registries>%s</registries>\n" % \
+ " ".join([ plc.registry_xml_line() for plc in other_plcs ]))
+ utils.header ("(Over)wrote %s"%reg_fname)
+ return self.test_ssh.copy_abs(agg_fname,'/vservers/%s/etc/sfa/aggregates.xml'%self.vservername)==0 \
+ and self.test_ssh.copy_abs(reg_fname,'/vservers/%s/etc/sfa/registries.xml'%self.vservername)==0
+
+ def sfa_import(self):
+ "sfa-import-plc"
+ auth=self.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
+ return self.run_in_guest('sfa-import-plc.py')==0
+# not needed anymore
+# self.run_in_guest('cp /etc/sfa/authorities/%s/%s.pkey /etc/sfa/authorities/server.key'%(auth,auth))
+
+ def sfa_start(self):
+ "service sfa start"
+ return self.run_in_guest('service sfa start')==0
+
+ def sfi_configure(self):
+ "Create /root/.sfi on the plc side"
+ sfa_spec=self.plc_spec['sfa']
+ "sfi client configuration"
+ dir_name=self.confsubdir("dot-sfi",clean=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)
+
+ file_name=dir_name + os.sep + 'person.xml'
+ fileconf=open(file_name,'w')
+ for record in sfa_spec['sfa_person_xml']:
+ person_record=record
+ fileconf.write(person_record)
+ fileconf.write('\n')
+ fileconf.close()
+ utils.header ("(Over)wrote %s"%file_name)
+
+ file_name=dir_name + os.sep + 'slice.xml'
+ fileconf=open(file_name,'w')
+ for record in sfa_spec['sfa_slice_xml']:
+ slice_record=record
+ #slice_record=sfa_spec['sfa_slice_xml']
+ fileconf.write(slice_record)
+ fileconf.write('\n')
+ utils.header ("(Over)wrote %s"%file_name)
+ fileconf.close()
+
+ file_name=dir_name + os.sep + 'slice.rspec'
+ fileconf=open(file_name,'w')
+ slice_rspec=''
+ for (key, value) in sfa_spec['sfa_slice_rspec'].items():
+ slice_rspec +=value
+ fileconf.write(slice_rspec)
+ fileconf.write('\n')
+ fileconf.close()
+ utils.header ("(Over)wrote %s"%file_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)
+
+ return True
+
+ def sfi_clean (self):
+ "clean up /root/.sfi on the plc side"
+ self.run_in_guest("rm -rf /root/.sfi")
+ return True
+
+ def sfa_add_user(self):
+ "run sfi.py add using person.xml"
+ return TestUserSfa(self).add_user()
+
+ def sfa_update_user(self):
+ "run sfi.py update using person.xml"
+ return TestUserSfa(self).update_user()
+
+ @slice_sfa_mapper
+ def sfa_add_slice(self):
+ "run sfi.py add (on Registry) from slice.xml"
+ pass
+
+ @slice_sfa_mapper
+ def sfa_discover(self):
+ "discover resources into resouces_in.rspec"
+ pass
+
+ @slice_sfa_mapper
+ def sfa_create_slice(self):
+ "run sfi.py create (on SM) - 1st time"
+ pass
+
+ @slice_sfa_mapper
+ def sfa_update_slice(self):
+ "run sfi.py create (on SM) on existing object"
+ pass
+
+ 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
+
+ @slice_sfa_mapper
+ def ssh_slice_sfa(self):
+ "tries to ssh-enter the SFA slice"
+ pass
+
+ def sfa_delete_user(self):
+ "run sfi.py delete (on SM) for user"
+ test_user_sfa=TestUserSfa(self)
+ return test_user_sfa.delete_user()
+
+ @slice_sfa_mapper
+ def sfa_delete_slice(self):
+ "run sfi.py delete (on SM), sfi.py remove (on Registry) to clean slices"
+ pass
+
+ def sfa_stop(self):
+ "service sfa stop"
+ self.run_in_guest('service sfa stop')==0
+ return True
+
+ def populate (self):
+ "creates random entries in the PLCAPI"
+ # install the stress-test in the plc image
+ location = "/usr/share/plc_api/plcsh_stress_test.py"
+ remote="/vservers/%s/%s"%(self.vservername,location)
+ self.test_ssh.copy_abs("plcsh_stress_test.py",remote)
+ command = location
+ command += " -- --preserve --short-names"
+ local = (self.run_in_guest(command) == 0);
+ # second run with --foreign
+ command += ' --foreign'
+ remote = (self.run_in_guest(command) == 0);
+ return ( local and remote)
+