485765176d7ee0a97436857bbf05d662f1b19847
[tests.git] / qaapi / qa / tests / plc_configure.py
1 #!/usr/bin/python
2 import os, sys
3 import traceback
4 from Test import Test
5 from qa import utils
6
7 class plc_configure(Test):
8     """
9     Configure the myplc from config options in config file
10     """
11
12     def call(self):
13
14         # Get plc configuration variables
15         plc_vars = []
16         for attr in dir(self.config):
17             if attr.startswith('PLC'):
18                 plc_vars.append(attr)
19                 
20         # Write temporary plc-config file
21         tmpname = '/tmp/plc-config-tty-%d' % os.getpid()
22         fileconf = open(tmpname, 'w')
23         for var in plc_vars:
24             fileconf.write('e %s\n%s\n' % (var, getattr(self.config, var)))
25         fileconf.write('w\nq\n')
26         fileconf.close()
27
28         # Update config file
29         command = "/sbin/service plc mount && plc-config-tty < %(tmpname)s" % locals()
30         if self.config.verbose:
31             utils.header(command)               
32         (stdout, stderr) = utils.popen(command)
33         (stdout, stderr) = utils.popen("rm %s" % tmpname)
34
35         return 1
36
37 if __name__ == '__main__':
38     args = tuple(sys.argv[1:])
39     plc_configure()(*args)