2f5642da406f1c67ea096854222fceb0eb60386f
[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
8 class plc_install(Test):
9     """
10     Installs a myplc
11     """
12
13     def call(self, url=None):
14         
15         url_path = self.config.path
16         # Determine url
17         if not url:
18             try:
19                 url_file = open("%s/URL" % url_path)
20                 url = url_file.read().strip()
21                 url_file.close()
22             except IOError:
23                 pass 
24         if not url:
25             print "URL not specified" 
26             sys.exit(1)  
27                 
28         # Save url
29         if self.config.verbose:
30             utils.header('Saving current myplc url into %s/URL' % url_path)
31         fsave=open('%s/URL' % url_path, "w")
32         fsave.write(url+'\n')
33         fsave.close()
34         
35         # Instal myplc from url          
36         if self.config.verbose:
37             utils.header('Downloading myplc from url %s' % url)
38
39         url_parts = url.split(os.sep)
40         rpm_file = url[-1:]
41         download_cmd = "wget %(url)s /tmp/%(rpm_file)s" % locals()
42
43         # build command
44         rpm_install = "rpm -Uvh /tmp/%(rpm_file)s" % locals()
45         yum_install = "yum -y localinstall /tmp/%(rpm_file)s" % locals()
46
47         if self.config.verbose:
48             utils.header("Trying: %(rpm_install)s" % locals())
49         try: 
50             (stdout, stderr) = utils.popen(rpm_install)
51         except:
52             if self.config.verbose:
53                 utils.header("Trying %(yum_install)s" % locals()) 
54             (stdout, stderr) = utils.popen(yum_install)
55
56         if self.config.verbose:
57             utils.header("\n".join(stdout))
58         
59         return 1
60
61 if __name__ == '__main__':
62     args = tuple(sys.argv[1:])
63     plc_install()(*args)