put lxcname.timestamp file inside /var/lib/lxc/lxcname/
[tests.git] / system / TestPlc.py
index 9c20112..cbdb2d2 100644 (file)
@@ -41,7 +41,7 @@ def node_mapper (method):
     def actual(self,*args, **kwds):
         overall=True
         node_method = TestNode.__dict__[method.__name__]
-        for test_node in self.all_node():
+        for test_node in self.all_nodes():
             if not node_method(test_node, *args, **kwds): overall=False
         return overall
     # restore the doc text
@@ -179,30 +179,32 @@ class TestPlc:
     #command gets run in the plc's vm
     def host_to_guest(self,command):
         if self.options.plcs_use_lxc:
-            # XXX TODO-lxc how to run a command in the plc context from an lxc-based host
-            return "TODO-lxc TestPlc.host_to_guest"
+            return "ssh -o StrictHostKeyChecking=no %s %s"%(self.vserverip,command)
         else:
             return "vserver %s exec %s"%(self.vservername,command)
     
-    def vm_root_in_guest(self):
+    def vm_root_in_host(self):
         if self.options.plcs_use_lxc:
-            # TODO-lxc
-            return "TODO TestPlc.vm_root_in_guest"
+            return "/var/lib/lxc/%s/rootfs/"%(self.vservername)
         else:
-            return "/vservers/%s"%self.vservername
+            return "/vservers/%s"%(self.vservername)
+
+    def vm_timestamp_path (self):
+        if self.options.plcs_use_lxc:
+            return "/var/lib/lxc/%s/%s.timestamp"%(self.vservername,self.vservername)
+        else:
+            return "/vservers/%s.timestamp"%(self.vservername)
 
     #start/stop the vserver
     def start_guest_in_host(self):
         if self.options.plcs_use_lxc:
-            # XXX TODO-lxc how to run a command in the plc context from an lxc-based host
-            return "TODO-lxc TestPlc.start_guest_in_host"
+            return "lxc-start --daemon --name=%s"%(self.vservername)
         else:
             return "vserver %s start"%(self.vservername)
     
     def stop_guest_in_host(self):
         if self.options.plcs_use_lxc:
-            # XXX TODO-lxc how to run a command in the plc context from an lxc-based host
-            return "TODO-lxc TestPlc.stop_guest_in_host"
+            return "lxc-stop --name=%s"%(self.vservername)
         else:
             return "vserver %s stop"%(self.vservername)
     
@@ -365,8 +367,13 @@ class TestPlc:
         domain=socket.gethostname().split('.',1)[1]
         fqdn="%s.%s"%(self.plc_spec['host_box'],domain)
         print "export BUILD=%s"%self.options.buildname
-        print "export PLCHOST=%s"%fqdn
-        print "export GUEST=%s"%self.plc_spec['vservername']
+        if self.options.plcs_use_lxc:
+            print "export PLCHOSTLXC=%s"%fqdn
+        else:
+            print "export PLCHOSTVS=%s"%fqdn
+        print "export GUESTNAME=%s"%self.plc_spec['vservername']
+        vplcname=self.plc_spec['vservername'].split('-')[-1]
+        print "export GUESTHOSTNAME=%s.%s"%(vplcname,domain)
         # find hostname of first node
         (hostname,qemubox) = self.all_node_infos()[0]
         print "export KVMHOST=%s.%s"%(qemubox,domain)
@@ -483,19 +490,20 @@ class TestPlc:
         now=int(time.time())
         # TODO-lxc check this one
         # a first approx. is to store the timestamp close to the VM root like vs does
-        stamp_path="%s.timestamp"%self.vm_root_in_guest()
+        stamp_path=self.vm_timestamp_path ()
+        stamp_dir = os.path.dirname (stamp_path)
+        utils.system(self.test_ssh.actual_command("mkdir -p %s"%stamp_dir))
         return utils.system(self.test_ssh.actual_command("echo %d > %s"%(now,stamp_path)))==0
         
     # this is called inconditionnally at the beginning of the test sequence 
     # just in case this is a rerun, so if the vm is not running it's fine
     def vs_delete(self):
         "vserver delete the test myplc"
-        stamp_path="%s.timestamp"%self.vm_root_in_guest()
+        stamp_path=self.vm_timestamp_path()
         self.run_in_host("rm -f %s"%stamp_path)
         if self.options.plcs_use_lxc:
-            # TODO-lxc : how to trash a VM altogether and the related timestamp as well
-            # might make sense to test that this has been done - unlike for vs
-            print "TODO TestPlc.vs_delete"
+            self.run_in_host("lxc-stop --name %s"%self.vservername)
+            self.run_in_host("lxc-destroy --name %s"%self.vservername)
             return True
         else:
             self.run_in_host("vserver --silent %s delete"%self.vservername)
@@ -531,7 +539,6 @@ class TestPlc:
         test_env_options += " -d %s"%self.options.pldistro
         test_env_options += " -f %s"%self.options.fcdistro
         if self.options.plcs_use_lxc:
-            # TODO-lxc : might need some tweaks
             script="vtest-init-lxc.sh"
         else:
             script="vtest-init-vserver.sh"
@@ -644,7 +651,7 @@ class TestPlc:
         if not os.path.isdir(dir):
             os.mkdir(dir)
         vservername=self.vservername
-        vm_root=self.vm_root_in_guest()
+        vm_root=self.vm_root_in_host()
         overall=True
         prefix = 'debug_ssh_key'
         for ext in [ 'pub', 'rsa' ] :
@@ -1146,8 +1153,7 @@ class TestPlc:
         "runs PLCAPI stress test, that checks Add/Update/Delete on all types - preserves contents"
         # install the stress-test in the plc image
         location = "/usr/share/plc_api/plcsh_stress_test.py"
-        # TODO-lxc
-        remote="%s/%s"%(self.vm_root_in_guest(),location)
+        remote="%s/%s"%(self.vm_root_in_host(),location)
         self.test_ssh.copy_abs("plcsh_stress_test.py",remote)
         command = location
         command += " -- --check"
@@ -1316,8 +1322,8 @@ class TestPlc:
         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,'/%s/etc/sfa/aggregates.xml'%self.vm_root_in_guest())==0 \
-            and  self.test_ssh.copy_abs(reg_fname,'/%s/etc/sfa/registries.xml'%self.vm_root_in_guest())==0
+        return self.test_ssh.copy_abs(agg_fname,'/%s/etc/sfa/aggregates.xml'%self.vm_root_in_host())==0 \
+            and  self.test_ssh.copy_abs(reg_fname,'/%s/etc/sfa/registries.xml'%self.vm_root_in_host())==0
 
     def sfa_import(self):
         "sfa-import-plc"
@@ -1347,7 +1353,7 @@ class TestPlc:
             test_slice.sfi_config(dir_name)
             # push into the remote /root/sfi area
             location = test_slice.sfi_path()
-            remote="%s/%s"%(self.vm_root_in_guest(),location)
+            remote="%s/%s"%(self.vm_root_in_host(),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)
@@ -1422,7 +1428,7 @@ class TestPlc:
         "creates random entries in the PLCAPI"
         # install the stress-test in the plc image
         location = "/usr/share/plc_api/plcsh_stress_test.py"
-        remote="%s/%s"%(self.vm_root_in_guest(),location)
+        remote="%s/%s"%(self.vm_root_in_host(),location)
         self.test_ssh.copy_abs("plcsh_stress_test.py",remote)
         command = location
         command += " -- --preserve --short-names"