trailing spaces
[tests.git] / qaapi / qa / tests / plc_install.py
index caf0336..6f7130a 100644 (file)
@@ -1,21 +1,25 @@
+#!/usr/bin/python
 
 import os, sys
 import traceback
 from qa import utils
 from Test import Test
+from qa.PLCs import PLC, PLCs
 
 class plc_install(Test):
     """
     Installs a myplc
     """
 
-    def call(self, system_type, root_dir, url=None):
+    def call(self, plc_name, url=None):
        
+       # Get plc qa config
+       plc = self.config.get_plc(plc_name)     
        url_path = self.config.path
+
        # Determine url
        if not url:
            try:
-
                url_file = open("%s/URL" % url_path)
                url = url_file.read().strip()
                url_file.close()
@@ -27,32 +31,32 @@ class plc_install(Test):
                
        # Save url
        if self.config.verbose:
-           utils.header('Saving current myplc url into %s/URL' % url_path)
+           utils.header('Saving current myplc url into %s/URL' % url_path, logfile = self.config.logfile)
        fsave=open('%s/URL' % url_path, "w")
        fsave.write(url+'\n')
        fsave.close()
        
        # Instal myplc from url          
        if self.config.verbose:
-           utils.header('Installing myplc from url %s' % url)
-
-       # build command
-       full_command = ""
-       install_command = " rpm -Uvh %(url)s "
-       if system_type in ['vserv', 'vserver']:
-           full_command += " vserver %(root_dir)s exec "
-       elif system_type in ['chroot']:
-           pass
-       else:
-           raise Exception, "Invalid system type %(system_type)s" % locals() 
-
-       full_command += install_command % locals()
-        try: (stdout, stderr) = utils.popen(full_command)
-       except: (stdout, stderr) = utils.popen("yum localupdate %(url)s")
+           utils.header('Downloading myplc from url %s' % url, logfile = self.config.logfile )
+
+       # build commands
+       url_parts = url.split(os.sep)
+       rpm_file = url[-1:]
+       download_cmd = "wget %(url)s /tmp/%(rpm_file)s" % locals()
+       rpm_install = "rpm -Uvh /tmp/%(rpm_file)s" % locals()
+       yum_install = "yum -y localinstall /tmp/%(rpm_file)s" % locals()
 
        if self.config.verbose:
-           utils.header("\n".join(stdout))
-       
+           utils.header("Trying: %(rpm_install)s" % locals(), logfile = self.config.logfile)
+        try: 
+           (status, output) = plc.commands(rpm_install)
+       except:
+           if self.config.verbose:
+               utils.header("Trying %(yum_install)s" % locals(), logfile = self.config.logfile)
+           (status, output) = plc.commands(download_cmd) 
+           (status, output) = plc.commands(yum_install)
+
        return 1
 
 if __name__ == '__main__':