9283eff6b71965e96bb67dbdbc8be23eed8e3e2f
[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 = PLC(self.config)
18         plcs = getattr(self.config, 'plcs', [])  
19         for p in plcs:
20             if p['name'] in [plc_name]:
21                 plc.update(p) 
22       
23         
24         url_path = self.config.path
25
26         # Determine url
27         if not url:
28             try:
29                 url_file = open("%s/URL" % url_path)
30                 url = url_file.read().strip()
31                 url_file.close()
32             except IOError:
33                 pass 
34         if not url:
35             print "URL not specified" 
36             sys.exit(1)  
37                 
38         # Save url
39         if self.config.verbose:
40             utils.header('Saving current myplc url into %s/URL' % url_path)
41         fsave=open('%s/URL' % url_path, "w")
42         fsave.write(url+'\n')
43         fsave.close()
44         
45         # Instal myplc from url          
46         if self.config.verbose:
47             utils.header('Downloading myplc from url %s' % url)
48
49         # build commands
50         url_parts = url.split(os.sep)
51         rpm_file = url[-1:]
52         download_cmd = "wget %(url)s /tmp/%(rpm_file)s" % locals()
53         rpm_install = "rpm -Uvh /tmp/%(rpm_file)s" % locals()
54         yum_install = "yum -y localinstall /tmp/%(rpm_file)s" % locals()
55
56         if self.config.verbose:
57             utils.header("Trying: %(rpm_install)s" % locals())
58         try: 
59             (status, output) = plc.commands(rpm_install)
60         except:
61             if self.config.verbose:
62                 utils.header("Trying %(yum_install)s" % locals())
63             (status, output) = plc.commands(download_cmd) 
64             (status, output) = plc.commands(yum_install)
65
66         return 1
67
68 if __name__ == '__main__':
69     args = tuple(sys.argv[1:])
70     plc_install()(*args)