7 from qa.PLCs import PLC, PLCs
9 class plc_configure(Test):
11 Configure the myplc from config options in config file
14 def call(self, plc_name, plc_config_option=None, plc_config_value=None):
16 # Get plc configuration from config
17 plc = self.config.get_plc(plc_name)
18 services = ['API', 'DB', 'WWW', 'BOOT']
21 # Turn off plc (for good measure)
22 command = "/sbin/service plc stop"
23 if self.config.verbose: utils.header(command)
24 (status, output) = plc.commands(command)
26 # mount plc (need to do this optionally, as we do not want this for myplc-native)
27 command = "/sbin/service plc mount"
28 if self.config.verbose: utils.header(command)
29 (status, output) = plc.commands(command)
31 # Get plc configuration variables
32 if plc_config_option is not None and \
33 plc_config_value is not None:
34 # Set option passed in from user
35 plc_options.append((plc_config_option, plc_config_value))
37 # Use hostname and ip of host we are running on
38 for service in services:
39 host_option = 'PLC_%(service)s_HOST' % locals()
40 ip_option = 'PLC_%(service)s_IP' % locals()
41 plc_options.append((host_option, plc['host']))
42 plc_options.append((ip_option, plc['ip']))
43 # Load any other options found in config file
44 for attr in dir(self.config):
45 if attr.startswith('PLC'):
46 plc_options.append((attr, getattr(self.config, attr)))
48 # Write temporary plc-config file
49 # XX use plc instance to copy file
50 tmpfconf, tmpfname = tempfile.mkstemp(".config","plc-config-tty", '/usr/tmp/')
51 tmpfname_parts = tmpfname.split(os.sep)
52 if self.config.verbose:
53 utils.header("generating temporary config file %(tmpfname)s"%locals())
54 for (option, value) in plc_options:
55 os.write(tmpfconf, 'e %s\n%s\n' % (option, value))
56 os.write(tmpfconf,'w\nq\n')
58 #plc.scp(tmpfname, "%s:/usr/tmp" % (plc['host']))
61 command = "plc-config-tty < %(tmpfname)s" % locals()
62 if self.config.verbose: utils.header(command)
63 (status, output) = plc.commands(command)
65 # clean up temporary conf file
66 # XX use plc instance to copy file
67 if self.config.verbose: utils.header("removing %(tmpfname)s"%locals())
70 # umount plc (need to do this optionally, as we do not want this for myplc-native)
71 command = "/sbin/service plc umount"
72 if self.config.verbose: utils.header(command)
73 (status, output) = plc.commands(command)
77 if __name__ == '__main__':
78 args = tuple(sys.argv[1:])
79 plc_configure()(*args)