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 = PLC(self.config)
18 plcs = getattr(self.config, 'plcs', [])
20 if p['name'] in [plc_name]:
23 services = ['API', 'DB', 'WWW', 'BOOT']
26 # Turn off plc (for good measure)
27 command = "/sbin/service plc stop"
28 if self.config.verbose: utils.header(command)
29 (status, output) = plc.commands(command)
31 # mount plc (need to do this optionally, as we do not want this for myplc-native)
32 command = "/sbin/service plc mount"
33 if self.config.verbose: utils.header(command)
34 (status, output) = plc.commands(command)
36 # Get plc configuration variables
37 if plc_config_option is not None and \
38 plc_config_value is not None:
39 # Set option passed in from user
40 plc_options.append((plc_config_option, plc_config_value))
42 # Use hostname and ip of host we are running on
43 for service in services:
44 host_option = 'PLC_%(service)s_HOST' % locals()
45 ip_option = 'PLC_%(service)s_IP' % locals()
46 plc_options.append((host_option, plc['host']))
47 plc_options.append((ip_option, plc['ip']))
48 # Load any other options found in config file
49 for attr in dir(self.config):
50 if attr.startswith('PLC'):
51 plc_options.append((attr, getattr(self.config, attr)))
53 # Write temporary plc-config file
54 # XX use plc instance to copy file
55 tmpfconf, tmpfname = tempfile.mkstemp(".config","plc-config-tty", '/usr/tmp/')
56 tmpfname_parts = tempfname.split(os.sep)
57 if self.config.verbose:
58 utils.header("generating temporary config file %(tmpfname)s"%locals())
59 for (option, value) in plc_options:
60 os.write(tmpfconf, 'e %s\n%s\n' % (option, value))
61 os.write(tmpfconf,'w\nq\n')
63 plc.scp(tmpfname, "%s:/usr/tmp" % (plc['host']))
66 command = "plc-config-tty < %(tmpfname)s" % locals()
67 if self.config.verbose: utils.header(command)
68 (status, output) = plc.commands(command)
70 # clean up temporary conf file
71 # XX use plc instance to copy file
72 if self.config.verbose: utils.header("removing %(tmpfname)s"%locals())
75 # umount plc (need to do this optionally, as we do not want this for myplc-native)
76 command = "/sbin/service plc umount"
77 if self.config.verbose: utils.header(command)
78 (status, output) = plc.commands(command)
82 if __name__ == '__main__':
83 args = tuple(sys.argv[1:])
84 plc_configure()(*args)