(no commit message)
[tests.git] / system / TestPlc.py
index cc844e4..3fbcb09 100644 (file)
@@ -325,61 +325,61 @@ class TestPlc:
                         self.display_key_spec (key)
             elif passno == 1:
                 if key not in ['sites','initscripts','slices','keys']:
-                    print '*   ',key,':',val
+                    print '+   ',key,':',val
 
     def display_site_spec (self,site):
-        print '* ======== site',site['site_fields']['name']
+        print '+ ======== site',site['site_fields']['name']
         for (k,v) in site.iteritems():
             if k=='nodes':
                 if v: 
-                    print '*       ','nodes : ',
+                    print '+       ','nodes : ',
                     for node in v:  
                         print node['node_fields']['hostname'],'',
                     print ''
             elif k=='users':
                 if v: 
-                    print '*       users : ',
+                    print '+       users : ',
                     for user in v:  
                         print user['name'],'',
                     print ''
             elif k == 'site_fields':
-                print '*       login_base',':',v['login_base']
+                print '+       login_base',':',v['login_base']
             elif k == 'address_fields':
                 pass
             else:
-                print '*       ',k,
+                print '+       ',k,
                 PrettyPrinter(indent=8,depth=2).pprint(v)
         
     def display_initscript_spec (self,initscript):
-        print '* ======== initscript',initscript['initscript_fields']['name']
+        print '+ ======== initscript',initscript['initscript_fields']['name']
 
     def display_key_spec (self,key):
-        print '* ======== key',key['name']
+        print '+ ======== key',key['name']
 
     def display_slice_spec (self,slice):
-        print '* ======== slice',slice['slice_fields']['name']
+        print '+ ======== slice',slice['slice_fields']['name']
         for (k,v) in slice.iteritems():
             if k=='nodenames':
                 if v: 
-                    print '*       nodes : ',
+                    print '+       nodes : ',
                     for nodename in v:  
                         print nodename,'',
                     print ''
             elif k=='usernames':
                 if v: 
-                    print '*       users : ',
+                    print '+       users : ',
                     for username in v:  
                         print username,'',
                     print ''
             elif k=='slice_fields':
-                print '*       fields',':',
+                print '+       fields',':',
                 print 'max_nodes=',v['max_nodes'],
                 print ''
             else:
-                print '*       ',k,v
+                print '+       ',k,v
 
     def display_node_spec (self,node):
-        print "*           node",node['name'],"host_box=",node['host_box'],
+        print "+           node",node['name'],"host_box=",node['host_box'],
         print "hostname=",node['node_fields']['hostname'],
         print "ip=",node['interface_fields']['ip']
     
@@ -391,18 +391,18 @@ class TestPlc:
 
     @staticmethod
     def display_mapping_plc (plc_spec):
-        print '* MyPLC',plc_spec['name']
-        print '*\tvserver address = root@%s:/vservers/%s'%(plc_spec['hostname'],plc_spec['vservername'])
-        print '*\tIP = %s/%s'%(plc_spec['PLC_API_HOST'],plc_spec['vserverip'])
+        print '+ MyPLC',plc_spec['name']
+        print '+\tvserver address = root@%s:/vservers/%s'%(plc_spec['hostname'],plc_spec['vservername'])
+        print '+\tIP = %s/%s'%(plc_spec['PLC_API_HOST'],plc_spec['vserverip'])
         for site_spec in plc_spec['sites']:
             for node_spec in site_spec['nodes']:
                 TestPlc.display_mapping_node(node_spec)
 
     @staticmethod
     def display_mapping_node (node_spec):
-        print '*   NODE %s'%(node_spec['name'])
-        print '*\tqemu box %s'%node_spec['host_box']
-        print '*\thostname=%s'%node_spec['node_fields']['hostname']
+        print '+   NODE %s'%(node_spec['name'])
+        print '+\tqemu box %s'%node_spec['host_box']
+        print '+\thostname=%s'%node_spec['node_fields']['hostname']
 
     def local_pre (self):
         "run site-dependant pre-test script as defined in LocalTestResources"
@@ -469,16 +469,24 @@ class TestPlc:
     ### install_rpm 
     def install(self):
         "yum install myplc, noderepo, and the plain bootstrapfs"
+
+        # workaround for getting pgsql5.2 on centos5
+        if self.options.fcdistro == "centos5":
+            self.run_in_guest("rpm -Uvh http://yum.pgsqlrpms.org/8.2/pgdg-centos-8.2-4.noarch.rpm")
+            self.run_in_guest("rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm")
+
         if self.options.personality == "linux32":
             arch = "i386"
         elif self.options.personality == "linux64":
             arch = "x86_64"
         else:
             raise Exception, "Unsupported personality %r"%self.options.personality
+        
+        nodefamily="%s-%s-%s"%(self.options.pldistro,self.options.fcdistro,arch)
         return \
             self.run_in_guest("yum -y install myplc")==0 and \
-            self.run_in_guest("yum -y install noderepo-%s-%s"%(self.options.pldistro,arch))==0 and \
-            self.run_in_guest("yum -y install bootstrapfs-%s-%s-plain"%(self.options.pldistro,arch))==0 
+            self.run_in_guest("yum -y install noderepo-%s"%nodefamily)==0 and \
+            self.run_in_guest("yum -y install bootstrapfs-%s-plain"%nodefamily)==0 
 
     ### 
     def configure(self):
@@ -540,11 +548,6 @@ class TestPlc:
             os.mkdir(dir)
         vservername=self.vservername
         overall=True
-        prefix = 'root_ssh_key'
-        for ext in [ 'pub', 'rsa' ] :
-            src="/vservers/%(vservername)s/etc/planetlab/%(prefix)s.%(ext)s"%locals()
-            dst="keys/%(vservername)s.%(ext)s"%locals()
-            if self.test_ssh.fetch(src,dst) != 0: overall=False
         prefix = 'debug_ssh_key'
         for ext in [ 'pub', 'rsa' ] :
             src="/vservers/%(vservername)s/etc/planetlab/%(prefix)s.%(ext)s"%locals()
@@ -679,12 +682,15 @@ class TestPlc:
                     overall=False
         return overall
 
-    def all_hostnames (self) :
-        hostnames = []
+    # return a list of tuples (nodename,qemuname)
+    def all_node_infos (self) :
+        node_infos = []
         for site_spec in self.plc_spec['sites']:
-            hostnames += [ node_spec['node_fields']['hostname'] \
+            node_infos += [ (node_spec['node_fields']['hostname'],node_spec['host_box']) \
                            for node_spec in site_spec['nodes'] ]
-        return hostnames
+        return node_infos
+    
+    def all_nodenames (self): return [ x[0] for x in self.all_node_infos() ]
 
     # silent_minutes : during the first <silent_minutes> minutes nothing gets printed
     def nodes_check_boot_state (self, target_boot_state, timeout_minutes, silent_minutes,period=15):
@@ -733,9 +739,9 @@ class TestPlc:
         return True
 
     def nodes_booted(self):
-        return self.nodes_check_boot_state('boot',timeout_minutes=20,silent_minutes=15)
+        return self.nodes_check_boot_state('boot',timeout_minutes=30,silent_minutes=20)
 
-    def check_nodes_ssh(self,debug,timeout_minutes,silent_minutes,period=20):
+    def check_nodes_ssh(self,debug,timeout_minutes,silent_minutes,period=15):
         # compute timeout
         timeout = datetime.datetime.now()+datetime.timedelta(minutes=timeout_minutes)
         graceout = datetime.datetime.now()+datetime.timedelta(minutes=silent_minutes)
@@ -745,43 +751,35 @@ class TestPlc:
             local_key = "keys/%(vservername)s-debug.rsa"%locals()
         else: 
             message="boot"
-            local_key = "keys/%(vservername)s.rsa"%locals()
-        tocheck = self.all_hostnames()
-        utils.header("checking ssh access (expected in %s mode) to nodes %r"%(message,tocheck))
+           local_key = "keys/key1.rsa"
+        node_infos = self.all_node_infos()
+        utils.header("checking ssh access (expected in %s mode) to nodes:"%message)
+        for (nodename,qemuname) in node_infos:
+            utils.header("hostname=%s -- qemubox=%s"%(nodename,qemuname))
         utils.header("max timeout is %d minutes, silent for %d minutes (period is %s)"%\
                          (timeout_minutes,silent_minutes,period))
-        while tocheck:
-            for hostname in tocheck:
+        while node_infos:
+            for node_info in node_infos:
+                (hostname,qemuname) = node_info
                 # try to run 'hostname' in the node
                 command = TestSsh (hostname,key=local_key).actual_command("hostname;uname -a")
                 # don't spam logs - show the command only after the grace period 
-                if datetime.datetime.now() > graceout:
-                    success=utils.system(command)
-                else:
-                    # truly silent, just print out a dot to show we're alive
-                    print '.',
-                    sys.stdout.flush()
-                    command += " 2>/dev/null"
-                    if self.options.dry_run:
-                        print 'dry_run',command
-                        success=0
-                    else:
-                        success=os.system(command)
+                success = utils.system ( command, silent=datetime.datetime.now() < graceout)
                 if success==0:
                     utils.header('Successfully entered root@%s (%s)'%(hostname,message))
-                    # refresh tocheck
-                    tocheck.remove(hostname)
+                    # refresh node_infos
+                    node_infos.remove(node_info)
                 else:
                     # we will have tried real nodes once, in case they're up - but if not, just skip
                     (site_spec,node_spec)=self.locate_hostname(hostname)
                     if TestNode.is_real_model(node_spec['node_fields']['model']):
                         utils.header ("WARNING : check ssh access into real node %s - skipped"%hostname)
-                       tocheck.remove(hostname)
-            if  not tocheck:
+                       node_infos.remove(node_info)
+            if  not node_infos:
                 return True
             if datetime.datetime.now() > timeout:
-                for hostname in tocheck:
-                    utils.header("FAILURE to ssh into %s"%hostname)
+                for (hostname,qemuname) in node_infos:
+                    utils.header("FAILURE to ssh into %s (on %s)"%(hostname,qemuname))
                 return False
             # otherwise, sleep for a while
             time.sleep(period)
@@ -790,11 +788,11 @@ class TestPlc:
         
     def nodes_ssh_debug(self):
         "Tries to ssh into nodes in debug mode with the debug ssh key"
-        return self.check_nodes_ssh(debug=True,timeout_minutes=30,silent_minutes=10)
+        return self.check_nodes_ssh(debug=True,timeout_minutes=30,silent_minutes=5)
     
     def nodes_ssh_boot(self):
         "Tries to ssh into nodes in production mode with the root ssh key"
-        return self.check_nodes_ssh(debug=False,timeout_minutes=30,silent_minutes=10)
+        return self.check_nodes_ssh(debug=False,timeout_minutes=30,silent_minutes=15)
     
     @node_mapper
     def init_node (self): 
@@ -949,25 +947,27 @@ class TestPlc:
             arch = "x86_64"
         else:
             raise Exception, "Unsupported personality %r"%self.options.personality
-        return \
-            self.run_in_guest("yum -y install sfa")==0 and \
-            self.run_in_guest("yum -y install sfa-client")==0 and \
-            self.run_in_guest("yum -y install sfa-plc")==0
+        return self.run_in_guest("yum -y install sfa sfa-client sfa-plc sfa-sfatables")==0
+
     ###
     def configure_sfa(self):
         "run sfa-config-tty"
         tmpname='%s.sfa-config-tty'%(self.name())
         fileconf=open(tmpname,'w')
-        fileconf.write ('u\n')
         for var in [ 'SFA_REGISTRY_ROOT_AUTH',
                      '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']:
-            fileconf.write ('%s\n'%(self.plc_spec['sfa'][var]))
+                     'SFA_PLC_DB_PASSWORD',
+                    'SFA_PLC_URL']:
+            fileconf.write ('e %s\n%s\n'%(var,self.plc_spec['sfa'][var]))
         fileconf.write('w\n')
+        fileconf.write('R\n')
         fileconf.write('q\n')
         fileconf.close()
         utils.system('cat %s'%tmpname)
@@ -978,14 +978,13 @@ class TestPlc:
     def import_sfa(self):
         "sfa-import-plc"
        auth=self.plc_spec['sfa']['SFA_REGISTRY_ROOT_AUTH']
-        self.run_in_guest('sfa-import-plc.py')
-        self.run_in_guest('cp /etc/sfa/authorities/%s/%s.pkey /etc/sfa/authorities/server.key'%(auth,auth))
-        return True
+        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 start_sfa(self):
         "service sfa start"
-        self.run_in_guest('service sfa start')
-        return True
+        return self.run_in_guest('service sfa start')==0
 
     def setup_sfa(self):
         "sfi client configuration"
@@ -1006,9 +1005,11 @@ class TestPlc:
        SFI_USER=SFI_AUTH+'.fake-pi1'
         fileconf.write ("SFI_USER='%s'"%SFI_USER)
        fileconf.write('\n')
-        fileconf.write ("SFI_REGISTRY='http://localhost:12345/'")
+       SFI_REGISTRY='http://' + self.plc_spec['sfa']['SFA_PLC_DB_HOST'] + ':12345/'
+        fileconf.write ("SFI_REGISTRY='%s'"%SFI_REGISTRY)
        fileconf.write('\n')
-        fileconf.write ("SFI_SM='http://localhost:12347/'")
+       SFI_SM='http://' + self.plc_spec['sfa']['SFA_PLC_DB_HOST'] + ':12347/'
+        fileconf.write ("SFI_SM='%s'"%SFI_SM)
        fileconf.write('\n')
         fileconf.close()
 
@@ -1079,7 +1080,7 @@ class TestPlc:
        self.run_in_guest("sfi.py -d /root/.sfi/ list %s.main"%auth)==0 and \
        self.run_in_guest("sfi.py -d /root/.sfi/ show %s.main"%auth)==0 and \
        self.run_in_guest("sfi.py -d /root/.sfi/ slices")==0 and \
-       self.run_in_guest("sfi.py -d /root/.sfi/ resources")==0
+       self.run_in_guest("sfi.py -d /root/.sfi/ resources -o resources")==0
 
     @slice_mapper_options_sfa
     def check_slice_sfa(self): 
@@ -1101,8 +1102,7 @@ class TestPlc:
 
     def stop_sfa(self):
         "service sfa stop"
-        self.run_in_guest('service sfa stop')
-        return True
+        return self.run_in_guest('service sfa stop')==0
 
     def populate (self):
         "creates random entries in the PLCAPI"
@@ -1173,9 +1173,9 @@ class TestPlc:
             test_site = TestSite (self,site_spec)
             for node_spec in site_spec['nodes']:
                 test_node=TestNode(self,test_site,node_spec)
-                test_ssh = TestSsh (test_node.name(),key="/etc/planetlab/root_ssh_key.rsa")
-                to_plc = self.actual_command_in_guest ( test_ssh.actual_command("tar -C /var/log -cf - ."))
-                command = to_plc + "| tar -C logs/node.var-log.%s -xf -"%test_node.name()
+                test_ssh = TestSsh (test_node.name(),key="keys/key1.rsa")
+                command = test_ssh.actual_command("tar -C /var/log -cf - .")
+                command = command + "| tar -C logs/node.var-log.%s -xf -"%test_node.name()
                 utils.system("mkdir -p logs/node.var-log.%s"%test_node.name())
                 utils.system(command)