fixes
[tests.git] / system / TestPlc.py
index 1c3cb7c..4e9a99b 100644 (file)
@@ -69,10 +69,12 @@ class TestPlc:
                      'init_node','bootcd', 'configure_qemu', 'export_qemu',
                      'kill_all_qemus', 'reinstall_node','start_node', SEP,
                      'nodes_booted', 'nodes_ssh', 'check_slice',
-                     'check_initscripts', 'check_tcp',SEP,
+                     'check_initscripts', 'check_tcp', 'plcsh_stress_test', SEP,
                      'force_gather_logs', 'force_kill_qemus', 'force_record_tracker','force_free_tracker' ]
-    other_steps = [ 'stop_all_vservers','fresh_install', 'cache_rpm', 'stop', SEP,
-                    'clean_sites', 'clean_nodes', 'clean_slices', 'clean_keys', SEP,
+    other_steps = [ 'stop_all_vservers','fresh_install', 'cache_rpm', 'stop', 'vs_start', SEP,
+                    'clean_initscripts', 'clean_all_sites',
+                    'clean_sites', 'clean_nodes', 
+                    'clean_slices', 'clean_keys', SEP,
                     'show_boxes', 'list_all_qemus', 'list_qemus', SEP,
                     'db_dump' , 'db_restore', ' cleanup_tracker',
                     'standby_1 through 20'
@@ -116,6 +118,9 @@ class TestPlc:
     def actual_command_in_guest (self,command):
         return self.test_ssh.actual_command(self.host_to_guest(command))
     
+    def start_guest (self):
+      return utils.system(self.test_ssh.actual_command(self.start_guest_in_host()))
+    
     def run_in_guest (self,command):
         return utils.system(self.actual_command_in_guest(command))
     
@@ -126,6 +131,10 @@ class TestPlc:
     def host_to_guest(self,command):
         return "vserver %s exec %s"%(self.vservername,command)
     
+    #command gets run in the vserver
+    def start_guest_in_host(self):
+        return "vserver %s start"%(self.vservername)
+    
     # xxx quick n dirty
     def run_in_guest_piped (self,local,remote):
         return utils.system(local+" | "+self.test_ssh.actual_command(self.host_to_guest(remote),keep_stdin=True))
@@ -279,10 +288,12 @@ class TestPlc:
 
     ### install
     def install(self):
-        # we need build dir for vtest-init-vserver
         if self.is_local():
             # a full path for the local calls
-            build_dir=os.path.dirname(sys.argv[0])+"/build"
+            build_dir=os.path.dirname(sys.argv[0])
+            # sometimes this is empty - set to "." in such a case
+            if not build_dir: build_dir="."
+            build_dir += "/build"
         else:
             # use a standard name - will be relative to remote buildname
             build_dir="build"
@@ -341,11 +352,15 @@ class TestPlc:
     def start(self):
         self.run_in_guest('service plc start')
         return True
-        
+
     def stop(self):
         self.run_in_guest('service plc stop')
         return True
         
+    def vs_start (self):
+        self.start_guest()
+        return True
+
     # could use a TestKey class
     def store_keys(self):
         for key_spec in self.plc_spec['keys']:
@@ -376,6 +391,13 @@ class TestPlc:
                 test_site.create_users()
         return True
 
+    def clean_all_sites (self):
+        print 'auth_root',self.auth_root()
+        site_ids = [s['site_id'] for s in self.apiserver.GetSites(self.auth_root(), {}, ['site_id'])]
+        for site_id in site_ids:
+            print 'Deleting site_id',site_id
+            self.apiserver.DeleteSite(self.auth_root(),site_id)
+
     def nodes (self):
         return self.do_nodes()
     def clean_nodes (self):
@@ -417,13 +439,43 @@ class TestPlc:
                         groups_dict[nodegroupname].append(test_node.name())
         auth=self.auth_root()
         for (nodegroupname,group_nodes) in groups_dict.iteritems():
-            try:
-                self.apiserver.GetNodeGroups(auth,{'name':nodegroupname})[0]
-            except:
-                self.apiserver.AddNodeGroup(auth,{'name':nodegroupname})
-            for node in group_nodes:
-                self.apiserver.AddNodeToNodeGroup(auth,node,nodegroupname)
-        return True
+            print 'nodegroups:','dealing with nodegroup',nodegroupname,'on nodes',group_nodes
+            # first, check if the nodetagtype is here
+            tag_types = self.apiserver.GetTagTypes(auth,{'tagname':nodegroupname})
+            if tag_types:
+                tag_type_id = tag_types[0]['node_tag_type_id']
+            else:
+                tag_type_id = self.apiserver.AddNodeTagType(auth,
+                                                            {'tagname':nodegroupname,
+                                                             'description': 'for nodegroup %s'%nodegroupname,
+                                                             'category':'test',
+                                                             'min_role_id':10})
+            # create nodegroup
+            nodegroups = self.apiserver.GetNodeGroups (auth, {'groupname':nodegroupname})
+            if not nodegroups:
+                self.apiserver.AddNodeGroup(auth, nodegroupname, tag_type_id, 'yes')
+            # set node tag on all nodes, value='yes'
+            overall = True
+            for nodename in group_nodes:
+                try:
+                    self.apiserver.AddNodeTag(auth, nodename, nodegroupname, "yes")
+                except:
+                    print 'node',nodename,'seems to already have tag',nodegroupname
+                # check anyway
+                try:
+                    expect_yes = self.apiserver.GetNodeTags(
+                        auth,
+                        {'hostname':nodename,
+                         'tagname':nodegroupname},
+                        ['tagvalue'])[0]['tagvalue']
+                    if expect_yes != "yes":
+                        print 'Mismatch node tag on node',nodename,'got',expect_yes
+                        overall=False
+                except:
+                    if not self.options.dry_run:
+                        print 'Cannot find tag',nodegroupname,'on node',nodename
+                        overall = False
+        return overall
 
     def all_hostnames (self) :
         hostnames = []
@@ -433,7 +485,7 @@ class TestPlc:
         return hostnames
 
     # gracetime : during the first <gracetime> minutes nothing gets printed
-    def do_nodes_booted (self, minutes, gracetime,period=30):
+    def do_nodes_booted (self, minutes, gracetime,period=15):
         if self.options.dry_run:
             print 'dry_run'
             return True
@@ -481,7 +533,7 @@ class TestPlc:
     def nodes_booted(self):
         return self.do_nodes_booted(minutes=20,gracetime=15)
 
-    def do_nodes_ssh(self,minutes,gracetime,period=30):
+    def do_nodes_ssh(self,minutes,gracetime,period=15):
         # compute timeout
         timeout = datetime.datetime.now()+datetime.timedelta(minutes=minutes)
         graceout = datetime.datetime.now()+datetime.timedelta(minutes=gracetime)
@@ -556,6 +608,17 @@ class TestPlc:
             self.apiserver.AddInitScript(self.auth_root(),initscript['initscript_fields'])
         return True
 
+    def clean_initscripts (self):
+        for initscript in self.plc_spec['initscripts']:
+            initscript_name = initscript['initscript_fields']['name']
+            print('Attempting to delete %s in plc %s'%(initscript_name,self.plc_spec['name']))
+            try:
+                self.apiserver.DeleteInitScript(self.auth_root(),initscript_name)
+                print initscript_name,'deleted'
+            except:
+                print 'deletion went wrong - probably did not exist'
+        return True
+
     def slices (self):
         return self.do_slices()
 
@@ -619,7 +682,17 @@ class TestPlc:
             if not c_test_sliver.run_tcp_client(s_test_sliver.test_node.name(),port):
                 overall=False
         return overall
-    
+
+    def plcsh_stress_test (self):
+        # 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 += " -- --check"
+        if self.options.small_test:
+            command +=  " --tiny"
+        return ( self.run_in_guest(command) == 0)
 
     def gather_logs (self):
         # (1) get the plc's /var/log and store it locally in logs/myplc.var-log.<plcname>/*