From 6d9d053d70240a559b8c3b58701d42b240310f1a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 31 Mar 2015 14:49:48 +0100 Subject: Logging to /var/log/firehose.log Change-Id: I442786ec8ac9387172ff7918e50b4320600204c1 --- firehose/plugin/firehose_plugin.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/firehose/plugin/firehose_plugin.py b/firehose/plugin/firehose_plugin.py index b1ddad6..200467e 100644 --- a/firehose/plugin/firehose_plugin.py +++ b/firehose/plugin/firehose_plugin.py @@ -19,6 +19,7 @@ from contextlib import closing, contextmanager from fs.tempfs import TempFS import os import re +import logging from firehose.config import FirehoseConfig import morphlib @@ -39,6 +40,8 @@ def firehose_git(app): class FirehosePlugin(cliapp.Plugin): def enable(self): + logging.basicConfig(filename='/var/log/firehose.log',level=logging.INFO) + logging.info("Firehose plugin enabled") self.app.add_subcommand('firehose', self.firehose_cmd, arg_synopsis='some-firehose.yaml...') self.app.settings.string(['gerrit-username'], @@ -55,6 +58,7 @@ class FirehosePlugin(cliapp.Plugin): default=None) def disable(self): + logging.info("Firehose plugin disabled") pass def firehose_cmd(self, args): @@ -102,21 +106,26 @@ class FirehosePlugin(cliapp.Plugin): self.commit_and_push(os.path.basename(fname.replace(".yaml", ""))) def make_path(self, *subpath): + logging.info("make_path: " + self.base_path) return os.path.join(self.base_path, *subpath) def make_workspace(self): + logging.info("make_workspace: " + self.make_path("ws")) self.app.subcommands['init']([self.make_path("ws")]) def setup_git(self): git_username = self.app.settings['git-username'] git_email = self.app.settings['git-email'] if (len(git_username) > 1) and (len(git_email) > 1): + logging.info("setup_git: " + git_username + " " + git_email) self.app.runcmd(['git', 'config', '--global', 'user.name', git_username]) self.app.runcmd(['git', 'config', '--global', 'user.email', git_email]) def make_branch(self, root): os.chdir(self.make_path("ws")) try: + logging.info("make_branch: " + \ + root['repo'] + " " + root['destref'] + " " + root['baseref']) self.app.subcommands['branch']([root['repo'], root['destref'], root['baseref']]) except cliapp.AppException, ae: if "already exists in" in str(ae): @@ -125,6 +134,7 @@ class FirehosePlugin(cliapp.Plugin): raise repopath = root['repo'].replace(':', '/') self.gitpath = self.make_path("ws", root['destref'], repopath) + logging.info("gitpath: " + self.gitpath) def log_sha(self, name): sha = self.app.runcmd(['git', 'rev-parse', 'HEAD'], cwd=self.gitpath).strip() @@ -132,19 +142,23 @@ class FirehosePlugin(cliapp.Plugin): if (os.path.exists(os.path.abspath(filename))): log = open(filename).read() if sha in log: + logging.info('Everything up-to-date') print 'Everything up-to-date' exit(0) log = open(filename, 'w') log.write('{\"sha\":\"'+sha+'\"}') + logging.info('log_sha: wrote {\"sha\":\"'+sha+'\"}') def insert_githook(self): gerrit_username = self.app.settings['gerrit-username'] gerrit_url = self.app.settings['gerrit-url'] scp_cmd = ('scp', '-p', '-P', '29418', gerrit_username+'@'+gerrit_url+':hooks/commit-msg', self.gitpath+'/.git/hooks/commit-msg') + logging.info('insert_githook: ' + str(scp_cmd)) os.system(' '.join(scp_cmd)) def reset_to_tracking(self, root): + logging.info('reset_to_tracking') branch_head_sha = self.app.runcmd(['git', 'rev-parse', 'HEAD'], cwd=self.gitpath).strip() self.app.runcmd(['git', 'reset', '--hard', 'origin/%s' % root['baseref']], @@ -153,6 +167,7 @@ class FirehosePlugin(cliapp.Plugin): cwd=self.gitpath) def load_morphologies(self): + logging.info('load_morphologies') ws = morphlib.workspace.open(self.gitpath) sb = morphlib.sysbranchdir.open_from_within(self.gitpath) loader = morphlib.morphloader.MorphologyLoader() @@ -167,6 +182,7 @@ class FirehosePlugin(cliapp.Plugin): self.lrc, self.rrc = morphlib.util.new_repo_caches(self.app) def find_cached_repo(self, stratum, chunk): + logging.info('find_cached_repo') urls = [] def wanted_spec(m, kind, spec): if not m['kind'] == 'stratum' and kind == 'chunks': @@ -193,6 +209,7 @@ class FirehosePlugin(cliapp.Plugin): return self.app.runcmd(args, cwd=repo.path) def all_shas_for_refs(self, repo): + logging.info('all_shas_for_refs') all_lines = self.git_in_repo(repo, "for-each-ref").strip().split("\n") for refline in all_lines: (sha, objtype, name) = refline.split(None, 2) @@ -201,6 +218,7 @@ class FirehosePlugin(cliapp.Plugin): yield name, sha def interested_in_ref(self, conf, refname): + logging.info('interested_in_ref') if conf.tracking_mode == 'follow-tip': return refname == conf.tracking_ref elif conf.tracking_mode == 'refs': @@ -211,12 +229,14 @@ class FirehosePlugin(cliapp.Plugin): conf.tracking_mode, ["tracking", "mode"]) def rewrite_ref(self, conf, ref): + logging.info('rewrite_ref') if conf.tracking_mode == 'refs': for transform in conf.tracking_transforms: ref = re.sub(transform['match'], transform['replacement'], ref) return ref def compare_refs(self, ref1, ref2): + logging.info('compare_refs: ' + str(ref1) + " " + str(ref2)) if ref1[0] == ref2[0]: return 0 v1 = Version(ref1[0].replace("/", "-")) @@ -227,11 +247,14 @@ class FirehosePlugin(cliapp.Plugin): def sanitise_refname(self, refname): if refname.startswith("refs/"): + logging.info('sanitise_refname: ' + \ + refname + " -> " + "/".join((refname.split("/"))[2:])) return "/".join((refname.split("/"))[2:]) else: return refname def update_refs(self, stratum, chunk, sha, refname): + logging.info('update_refs') def wanted_spec(m, kind, spec): if not m['kind'] == 'stratum' and kind == 'chunks': return False @@ -246,6 +269,7 @@ class FirehosePlugin(cliapp.Plugin): def update_for_conf(self, conf): stratum = conf.landing_stratum chunk = conf.landing_chunk + logging.info('update_for_conf: ' + stratum + " " + chunk) crc = self.find_cached_repo(stratum, chunk) interesting_refs = [ (self.rewrite_ref(conf, name), name, sha) @@ -257,6 +281,7 @@ class FirehosePlugin(cliapp.Plugin): self.update_refs(stratum, chunk, sha, refname) def updated_morphologies(self): + logging.info('updated_morphologies') if not any(m.dirty for m in self.morphs.morphologies): return False for morph in self.morphs.morphologies: @@ -276,6 +301,7 @@ class FirehosePlugin(cliapp.Plugin): (code, out, err) = self.app.runcmd_unchecked( ['git', 'commit', '-a', '-m', commit_msg], cwd=self.gitpath) + logging.info('commit_and_push: ' + str(code)) if code == 0: self.app.runcmd(['git', 'push', 'ssh://'+gerrit_username+'@'+gerrit_url+ ':29418/baserock/baserock/definitions', branch_name], cwd=self.gitpath) -- cgit v1.2.1