miscell cosmetic + pass the substrate object to TestBonding so it can compute an...
[tests.git] / qaapi / qa / tests / plc_install.py
1 #!/usr/bin/python
2
3 import os, sys
4 import traceback
5 from qa import utils
6 from Test import Test
7 from qa.PLCs import PLC, PLCs
8
9 class plc_install(Test):
10     """
11     Installs a myplc
12     """
13
14     def call(self, plc_name, url=None):
15         
16         # Get plc qa config
17         plc = self.config.get_plc(plc_name)     
18         url_path = self.config.path
19
20         # Determine url
21         if not url:
22             try:
23                 url_file = open("%s/URL" % url_path)
24                 url = url_file.read().strip()
25                 url_file.close()
26             except IOError:
27                 pass 
28         if not url:
29             print "URL not specified" 
30             sys.exit(1)  
31                 
32         # Save url
33         if self.config.verbose:
34             utils.header('Saving current myplc url into %s/URL' % url_path, logfile = self.config.logfile)
35         fsave=open('%s/URL' % url_path, "w")
36         fsave.write(url+'\n')
37         fsave.close()
38         
39         # Instal myplc from url          
40         if self.config.verbose:
41             utils.header('Downloading myplc from url %s' % url, logfile = self.config.logfile )
42
43         # build commands
44         url_parts = url.split(os.sep)
45         rpm_file = url[-1:]
46         download_cmd = "wget %(url)s /tmp/%(rpm_file)s" % locals()
47         rpm_install = "rpm -Uvh /tmp/%(rpm_file)s" % locals()
48         yum_install = "yum -y localinstall /tmp/%(rpm_file)s" % locals()
49
50         if self.config.verbose:
51             utils.header("Trying: %(rpm_install)s" % locals(), logfile = self.config.logfile)
52         try: 
53             (status, output) = plc.commands(rpm_install)
54         except:
55             if self.config.verbose:
56                 utils.header("Trying %(yum_install)s" % locals(), logfile = self.config.logfile)
57             (status, output) = plc.commands(download_cmd) 
58             (status, output) = plc.commands(yum_install)
59
60         return 1
61
62 if __name__ == '__main__':
63     args = tuple(sys.argv[1:])
64     plc_install()(*args)