Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : skvidal-backend
>---------------------------------------------------------------
commit 15066b2d6c9c9a00994d2b7be1f13612466367a7
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Dec 5 15:08:52 2012 -0500
- make opts behave in face of cli-opts and on config reread
- make exit be a bit quieter on ctrl-c (I hope)
- prepare for a case where our builders are not dynamically created
- obey pyflakes and pychecker suggestions
>---------------------------------------------------------------
backend/dispatcher.py | 19 +++++++++++--------
copr-be.py | 20 +++++++++++++-------
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py
index 434e671..f96bdb1 100644
--- a/backend/dispatcher.py
+++ b/backend/dispatcher.py
@@ -95,6 +95,7 @@ class Worker(multiprocessing.Process):
self.opts = opts
self.kill_received = False
self.callback = callback
+ self.create = create
if not self.callback:
self.logfile = self.opts.worker_logdir + '/worker-%s.log' % self.worker_num
self.callback = WorkerCallback(logfile = self.logfile)
@@ -193,14 +194,15 @@ class Worker(multiprocessing.Process):
job.jobfile = jobfile
# spin up our build instance
- try:
- ip = self.spawn_instance()
- if not ip:
- raise errors.CoprWorkerError, "No IP found from creating instance"
+ if self.create:
+ try:
+ ip = self.spawn_instance()
+ if not ip:
+ raise errors.CoprWorkerError, "No IP found from creating instance"
- except ansible.errors.AnsibleError, e:
- self.callback.log('failure to setup instance: %s' % e)
- raise
+ except ansible.errors.AnsibleError, e:
+ self.callback.log('failure to setup instance: %s' % e)
+ raise
status = 1
job.started_on = time.time()
@@ -243,5 +245,6 @@ class Worker(multiprocessing.Process):
self.return_results(job)
self.callback.log('worker finished build: %s' % ip)
# clean up the instance
- self.terminate_instance(ip)
+ if self.create:
+ self.terminate_instance(ip)
diff --git a/copr-be.py b/copr-be.py
index a3e372a..3be1828 100644
--- a/copr-be.py
+++ b/copr-be.py
@@ -20,7 +20,7 @@ def _get_conf(cp, section, option, default):
class CoprBackend(object):
- def __init__(self, config_file=None):
+ def __init__(self, config_file=None, ext_opts=None):
# read in config file
# put all the config items into a single self.opts bunch
@@ -28,6 +28,7 @@ class CoprBackend(object):
raise errors.CoprBackendError, "Must specify config_file"
self.config_file = config_file
+ self._ext_opts = ext_opts # to stow our cli options for read_conf()
self.opts = self.read_conf()
logdir = os.path.dirname(self.opts.logfile)
@@ -78,6 +79,9 @@ class CoprBackend(object):
if not opts.jobsdir or not opts.destdir:
raise errors.CoprBackendError, "Incomplete Config - must specify jobsdir and destdir in configuration"
+ if self._ext_opts:
+ for v in self._ext_opts:
+ setattr(opts, v, self.ext_opts.get(v))
return opts
@@ -188,17 +192,19 @@ def parse_args(args):
print "No config file found at: %s" % opts.config_file
sys.exit(1)
- return opts,args
+ ret_opts = Bunch()
+ for o in ('daemonize', 'exit_on_worker', 'pidfile', 'config_file'):
+ setattr(ret_opts, o, getattr(opts, o))
+
+ return ret_opts
def main(args):
- opts,args = parse_args(args)
+ opts = parse_args(args)
try:
- cbe = CoprBackend(opts.config_file)
- cbe.opts.daemonize = opts.daemonize # just so we have it on hand
- cbe.opts.exit_on_worker = opts.exit_on_worker
+ cbe = CoprBackend(opts.config_file, ext_opts=opts)
if opts.daemonize:
daemonize(opts.pidfile)
cbe.run()
@@ -207,7 +213,7 @@ def main(args):
if 'cbe' in locals():
for w in cbe.workers:
w.terminate()
- raise
+
if __name__ == '__main__':
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : skvidal-backend
>---------------------------------------------------------------
commit 8fc0c3e6a2eb3cd253ccdc75f4c2c05743e3590d
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Dec 5 01:37:24 2012 -0500
touch up the log outputs to make it easier to know what to do
>---------------------------------------------------------------
backend/dispatcher.py | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py
index eff1f27..e1a47dc 100644
--- a/backend/dispatcher.py
+++ b/backend/dispatcher.py
@@ -102,7 +102,7 @@ class Worker(multiprocessing.Process):
if ip:
self.callback.log('creating worker: %s' % ip)
else:
- self.callback.log('creating worker: with dynamic ip')
+ self.callback.log('creating worker: dynamic ip')
def spawn_instance(self):
"""call the spawn playbook to startup/provision a building instance"""
@@ -130,7 +130,9 @@ class Worker(multiprocessing.Process):
# if we get here we're in trouble
self.callback.log('No IP back from spawn_instance - dumping cache output')
self.callback.log(str(play.SETUP_CACHE))
- self.callback.log(play.stats.summarize('localhost'))
+ self.callback.log(str(play.stats.summarize('localhost')))
+ self.callback.log('Test spawn_instance playbook manually')
+
return None
def terminate_instance(self,ip):
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : skvidal-backend
>---------------------------------------------------------------
commit c881da21fc3f7fa723610919f627411b25e1a8e2
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Wed Dec 5 00:59:54 2012 -0500
localhost as string to get back debug on heisenbug
>---------------------------------------------------------------
backend/dispatcher.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py
index 796a9b6..eff1f27 100644
--- a/backend/dispatcher.py
+++ b/backend/dispatcher.py
@@ -130,7 +130,7 @@ class Worker(multiprocessing.Process):
# if we get here we're in trouble
self.callback.log('No IP back from spawn_instance - dumping cache output')
self.callback.log(str(play.SETUP_CACHE))
- self.callback.log(play.stats.summarize(localhost))
+ self.callback.log(play.stats.summarize('localhost'))
return None
def terminate_instance(self,ip):
Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : skvidal-backend
>---------------------------------------------------------------
commit 31ab388e827dbe9a279a8bb8eac76ff1acb60212
Author: Seth Vidal <skvidal(a)fedoraproject.org>
Date: Tue Dec 4 16:37:43 2012 -0500
more logging in error conditions having to do with spawning instances
>---------------------------------------------------------------
backend/dispatcher.py | 9 ++++++++-
copr-be.py | 1 +
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/backend/dispatcher.py b/backend/dispatcher.py
index 225b75d..bf80e28 100644
--- a/backend/dispatcher.py
+++ b/backend/dispatcher.py
@@ -99,7 +99,10 @@ class Worker(multiprocessing.Process):
self.logfile = self.opts.worker_logdir + '/worker-%s.log' % self.worker_num
self.callback = WorkerCallback(logfile = self.logfile)
- self.callback.log('creating worker: %s' % ip)
+ if ip:
+ self.callback.log('creating worker: %s' % ip)
+ else:
+ self.callback.log('creating worker: with dynamic ip')
def spawn_instance(self):
"""call the spawn playbook to startup/provision a building instance"""
@@ -123,6 +126,10 @@ class Worker(multiprocessing.Process):
if i =='localhost':
continue
return i
+
+ # if we get here we're in trouble
+ self.callback.log('No IP back from spawn_instance - dumping cache output')
+ self.callback.log(str(play.SETUP_CACHE))
return None
def terminate_instance(self,ip):
diff --git a/copr-be.py b/copr-be.py
index 2cc0fba..73ab70a 100644
--- a/copr-be.py
+++ b/copr-be.py
@@ -117,6 +117,7 @@ class CoprBackend(object):
# #insert a poison pill? Kill after something? I dunno.
# FIXME - if a worker bombs out - we need to check them
# and startup a new one if it happens
+ # check for dead workers and abort
for w in self.workers:
if not w.is_alive():
raise errors.CoprBackendError, "Worker died unexpectedly"