Repository : http://git.fedorahosted.org/cgit/copr.git
On branch : skvidal-backend
commit 15066b2d6c9c9a00994d2b7be1f13612466367a7 Author: Seth Vidal skvidal@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__':
copr-devel@lists.fedorahosted.org