[Erp5-report] r36128 luke - /erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Jun 9 10:00:33 CEST 2010
Author: luke
Date: Wed Jun 9 10:00:33 2010
New Revision: 36128
URL: http://svn.erp5.org?rev=36128&view=rev
Log:
- make it class alike even more
- move separate steps to small methods, with docstrings
Modified:
erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py
Modified: erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py?rev=36128&r1=36127&r2=36128&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] (original)
+++ erp5/trunk/utils/erp5.timmy/src/erp5/timmy/timmy.py [utf8] Wed Jun 9 10:00:33 2010
@@ -403,6 +403,9 @@
def __init__(self):
socket.setdefaulttimeout(30.0)
self.options = self.parseOptions()[0]
+ self.buildout = self.options.buildout_binary
+ self.buildout_profile = self.options.main_output
+ self.buildout_offline = self.options.buildout_offline
logging_kw = dict(level=logging.INFO,
format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
if self.options.log_file is not None:
@@ -446,9 +449,9 @@
try:
try:
try:
- server = XMLRPCServer(self.options.server_url,
+ self.server = XMLRPCServer(self.options.server_url,
getServerKey(self.options.key_file))
- partition_dict_list = server.call('getComputerConfigurationDictList')
+ partition_dict_list = self.server.call('getComputerConfigurationDictList')
except socket.error, e:
logging.error('Unable to connect to remote server, verify if the URL is'
' accessible.')
@@ -458,14 +461,14 @@
' %s.' % e.faultString)
sys.exit(1)
- computer_id = getServerKey(self.options.key_file)
- server.call('updatePartitionState', computer_id, 'reportStarted',
+ self.computer_id = getServerKey(self.options.key_file)
+ self.server.call('updatePartitionState', self.computer_id, 'reportStarted',
'timmy is running on computer')
- supervisor_id = computer_id
+ self.supervisor_id = self.computer_id
supervisor_list = [q for q in partition_dict_list if q['TYPE'] == \
'Supervisor Server']
if len(supervisor_list) > 0:
- supervisor_id = supervisor_list[0]['PARTITION_ID']
+ self.supervisor_id = supervisor_list[0]['PARTITION_ID']
# prepare - run supervisor
try:
@@ -473,7 +476,7 @@
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(result_std, result_err) = supervisord_popen.communicate()
except:
- server.call('updatePartitionState', supervisor_id, 'reportError',
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportError',
'Unsupported issue while trying to start supervisord: %s:%s' % (
str(sys.exc_info()[0]), str(sys.exc_info()[1])))
raise
@@ -481,7 +484,7 @@
if supervisord_popen.returncode == 0:
log_message = 'Supervisord started with: stdout = %r stderr = %r' % (
result_std, result_err)
- server.call('updatePartitionState', supervisor_id, 'reportStarted',
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportStarted',
log_message)
logging.info(log_message)
else:
@@ -491,7 +494,7 @@
else:
log_message = 'Supervisord unknown problem: stdout = %r stderr = %r' \
% (result_std, result_err)
- server.call('updatePartitionState', supervisor_id, 'reportError',
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportError',
log_message)
logging.info(log_message)
@@ -500,7 +503,7 @@
self.updateInstanceProfiles(self.template_directory_list,
self.options.instances_directory, partition_dict_list)
except:
- server.call('updatePartitionState', computer_id, 'reportError',
+ self.server.call('updatePartitionState', self.computer_id, 'reportError',
'Unexpected issue while updating instance profiles: %s:%s' % (
str(sys.exc_info()[0]), str(sys.exc_info()[1])))
raise
@@ -510,60 +513,14 @@
self.options.base_profile, self.options.instances_directory,
partition_dict_list)
except:
- server.call('updatePartitionState', computer_id, 'reportError',
+ self.server.call('updatePartitionState', self.computer_id, 'reportError',
'Unexpected issue while updating base profile: %s:%s' % (
str(sys.exc_info()[0]), str(sys.exc_info()[1])))
raise
# 2 pass - run buildout
- try:
- return_code, result_std, result_err = self.runBuildout(
- self.options.buildout_binary, self.options.main_output,
- self.options.buildout_offline)
- if return_code != 0:
- server.call('updatePartitionState', computer_id, 'reportError',
- 'Buildout finished with bad status code (%s). Stdout = "%s", stde'
- 'rr = "%s"' % (return_code, result_std, result_err))
- except:
- server.call('updatePartitionState', computer_id, 'reportError',
- 'Unexpected issue while running buildout: %s:%s' % (
- str(sys.exc_info()[0]), str(sys.exc_info()[1])))
- raise
-
- # force supervisor to reload its configuration
- supervisorctl_popen = subprocess.Popen([SUPERVISORCTL, 'update'],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (result_std, result_err) = supervisorctl_popen.communicate()
- if supervisorctl_popen.returncode == 0:
- log_message = 'Supervisorctl updated with: stdout = %r stderr = %r' % (
- result_std, result_err)
- server.call('updatePartitionState', supervisor_id, 'reportStarted',
- log_message)
- logging.info(log_message)
- else:
- log_message = 'Supervisorctl issue during update: stdout = %r stderr ='\
- ' %r' % (result_std, result_err)
- server.call('updatePartitionState', supervisor_id, 'reportError',
- log_message)
- logging.error(log_message)
-
- # do start all of supervisor controlled programs
- # it is noop in case if all is running
- # it forces to start problematic services (FATAL state)
- supervisorctl_popen = subprocess.Popen([SUPERVISORCTL, 'start', 'all'],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (result_std, result_err) = supervisorctl_popen.communicate()
- if supervisorctl_popen.returncode != 0:
- log_message = 'Supervisorctl issue during start all: stdout = %r std'\
- 'err = %r' % (result_std, result_err)
- server.call('updatePartitionState', supervisor_id, 'reportError',
- log_message)
- logging.error(log_message)
- elif len(result_std) > 0 or len(result_err) > 0:
- # emit log only in case if something important was done by supervisor
- # no need to pollute master server, as this is only local server hack
- logging.info('Supervisorctl start all with: stdout = %r stderr = %r' % (
- result_std, result_err))
-
+ self.runBuildout()
+ self.updateSupervisor()
+ self.startAllSupervisor()
# 3 pass - manage instances
# XXX-Luke: To be moved to proper recipe
@@ -582,7 +539,7 @@
install = 'manageInstall',
)
action = getattr(helper, switcher_dict[partition_dict['ACTION']])
- action(partition, server)
+ action(partition, self.server)
except xmlrpclib.Fault, e:
logging.error('Unexpected error in xml-rpc communication, unable to co'
'ntinue, failed: %s.' % e.faultString)
@@ -596,30 +553,39 @@
logging.info('[%s] Timmy finished, invocation time: %.3fs' % (os.getpid(),
time.time() - self.time_begin))
- def runBuildout(self, buildout, profile, offline):
- invoke_list = [buildout]
- if offline:
- invoke_list.append('-N')
- invoke_list.extend(['-c', profile, '-t', '5'])
- logging.info('invoking %s' % ' '.join(invoke_list))
- popen = subprocess.Popen([buildout, '-c', profile],
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (result_std, result_err) = popen.communicate()
- # TODO: check that site is accesible in Data.fs, we cannot belive in
- # Popen.returncode, as subprocesses of subprocesses are not handled
- # properly
-
- # TODO: parse result_std and result_err
-
- if popen.returncode == 0:
- log_method = logging.info
- else:
- log_method = logging.error
- log_method('Buildout finished with bad status code (%s)' % \
- popen.returncode)
- log_method('Standard output:\n%s' % result_std)
- log_method('Error output:\n%s' % result_err)
- return popen.returncode, result_std, result_err
+ def runBuildout(self):
+ try:
+ invoke_list = [self.buildout]
+ if self.buildout_offline:
+ invoke_list.append('-N')
+ invoke_list.extend(['-c', self.buildout_profile, '-t', '5'])
+ logging.info('invoking %s' % ' '.join(invoke_list))
+ popen = subprocess.Popen([self.buildout, '-c', self.buildout_profile],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (result_std, result_err) = popen.communicate()
+ # TODO: check that site is accesible in Data.fs, we cannot belive in
+ # Popen.returncode, as subprocesses of subprocesses are not handled
+ # properly
+
+ # TODO: parse result_std and result_err
+
+ if popen.returncode == 0:
+ log_method = logging.info
+ else:
+ log_method = logging.error
+ log_method('Buildout finished with bad status code (%s)' % \
+ popen.returncode)
+ log_method('Standard output:\n%s' % result_std)
+ log_method('Error output:\n%s' % result_err)
+ except:
+ self.server.call('updatePartitionState', self.computer_id, 'reportError',
+ 'Unexpected issue while running buildout: %s:%s' % (
+ str(sys.exc_info()[0]), str(sys.exc_info()[1])))
+ raise
+ if popen.returncode != 0:
+ self.server.call('updatePartitionState', self.computer_id, 'reportError',
+ 'Buildout finished with bad status code (%s). Stdout = "%s", stde'
+ 'rr = "%s"' % (popen.returncode, result_std, result_err))
def updateInstanceProfiles(self, template_directory_list, output_directory,
instance_dict_list):
@@ -777,6 +743,43 @@
os.path.abspath(options.instances_directory))
return options, args
+ def updateSupervisor(self):
+ """Forces configuration reload of supervisor"""
+ supervisorctl_popen = subprocess.Popen([SUPERVISORCTL, 'update'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (result_std, result_err) = supervisorctl_popen.communicate()
+ if supervisorctl_popen.returncode == 0:
+ log_message = 'Supervisorctl updated with: stdout = %r stderr = %r' % (
+ result_std, result_err)
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportStarted',
+ log_message)
+ logging.info(log_message)
+ else:
+ log_message = 'Supervisorctl issue during update: stdout = %r stderr ='\
+ ' %r' % (result_std, result_err)
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportError',
+ log_message)
+ logging.error(log_message)
+
+ def startAllSupervisor(self):
+ """Invoke start on all supervisor controlled programs
+
+ It is no-op in case of running program, but forces start of problematic
+ services, for example in FATAL state"""
+ supervisorctl_popen = subprocess.Popen([SUPERVISORCTL, 'start', 'all'],
+ stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (result_std, result_err) = supervisorctl_popen.communicate()
+ if supervisorctl_popen.returncode != 0:
+ log_message = 'Supervisorctl issue during start all: stdout = %r std'\
+ 'err = %r' % (result_std, result_err)
+ self.server.call('updatePartitionState', self.supervisor_id, 'reportError',
+ log_message)
+ logging.error(log_message)
+ elif len(result_std) > 0 or len(result_err) > 0:
+ # emit log only in case if something important was done by supervisor
+ # no need to pollute master server, as this is only local server hack
+ logging.info('Supervisorctl start all with: stdout = %r stderr = %r' % (
+ result_std, result_err))
def run():
return Timmy().run()
More information about the Erp5-report
mailing list