From 78588d65c1e42b9690f5e6303690bcb9963100fa Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 1 Apr 2015 12:30:30 +0100 Subject: Error trap for missing ssh key This enables better error checking when interacting with gerrit Change-Id: Ic8f6f31e24a694da1aa81e27acc58460c7ff1d2f --- firehose/plugin/firehose_plugin.py | 48 +++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/firehose/plugin/firehose_plugin.py b/firehose/plugin/firehose_plugin.py index ace7bdf..fdd5b20 100644 --- a/firehose/plugin/firehose_plugin.py +++ b/firehose/plugin/firehose_plugin.py @@ -156,10 +156,24 @@ class FirehosePlugin(cliapp.Plugin): 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)) + status, output, error = \ + self.app.runcmd_unchecked(['scp', '-p', '-P', '29418', + gerrit_username+'@'+ + gerrit_url+':hooks/commit-msg', + self.gitpath+ + '/.git/hooks/commit-msg'], + cwd=self.gitpath) + if status != 0: + # Remove the previously recorded hash + os.remove(self.sha_filename) + if "publickey" in error: + raise cliapp.AppException( + "Cannot insert githook. "+ + "Check your ssh public key is registered in gerrit") + else: + self.app.output.write(error) + raise cliapp.AppException( + "Woah! unable to insert githook") def reset_to_tracking(self, root): logging.info('reset_to_tracking') @@ -309,14 +323,22 @@ class FirehosePlugin(cliapp.Plugin): cwd=self.gitpath) logging.info('commit_and_push: ' + str(code)) if code == 0: - try: - # Note: cliapp needs updating such that it supports callbacks - self.app.runcmd(['git', 'push', - 'ssh://'+gerrit_username+'@'+gerrit_url+ - ':29418/baserock/baserock/definitions', - branch_name], cwd=self.gitpath) - except cliapp.AppException: + status, output, error = \ + self.app.runcmd_unchecked(['git', 'push', + 'ssh://'+gerrit_username+ + '@'+gerrit_url+ + ':29418/baserock/'+ + 'baserock/definitions', + branch_name], cwd=self.gitpath) + if status != 0: # Remove the previously recorded hash os.remove(self.sha_filename) - raise cliapp.AppException( - "Woah! unable to push changes to gerrit") + if "publickey" in error: + raise cliapp.AppException( + "Could not push to gerrit. "+ + "Check your ssh public key is "+ + "registered in gerrit") + else: + self.app.output.write(error) + raise cliapp.AppException( + "Woah! unable to push changes to gerrit") -- cgit v1.2.1