caf0336ecf2f84af80cca188576ebc25d81a64c0
[tests.git] / qaapi / qa / tests / plc_install.py
1
2 import os, sys
3 import traceback
4 from qa import utils
5 from Test import Test
6
7 class plc_install(Test):
8     """
9     Installs a myplc
10     """
11
12     def call(self, system_type, root_dir, url=None):
13         
14         url_path = self.config.path
15         # Determine url
16         if not url:
17             try:
18
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('Installing myplc from url %s' % url)
38
39         # build command
40         full_command = ""
41         install_command = " rpm -Uvh %(url)s "
42         if system_type in ['vserv', 'vserver']:
43             full_command += " vserver %(root_dir)s exec "
44         elif system_type in ['chroot']:
45             pass
46         else:
47             raise Exception, "Invalid system type %(system_type)s" % locals() 
48
49         full_command += install_command % locals()
50         try: (stdout, stderr) = utils.popen(full_command)
51         except: (stdout, stderr) = utils.popen("yum localupdate %(url)s")
52
53         if self.config.verbose:
54             utils.header("\n".join(stdout))
55         
56         return 1
57
58 if __name__ == '__main__':
59     args = tuple(sys.argv[1:])
60     plc_install()(*args)