summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLauren Perry <lauren.perry@codethink.co.uk>2015-01-09 16:43:40 +0000
committerLauren Perry <lauren.perry@codethink.co.uk>2015-01-09 16:43:40 +0000
commitc754d504cb3825ab00fe82cf40b2352d21818bda (patch)
treee734e79a002f9e73856b0efb43d1ce01ee2a0de7
parent63b5ad5b246df02c5cae2f31075283b385c582c4 (diff)
downloadfirehose-c754d504cb3825ab00fe82cf40b2352d21818bda.tar.gz
Obtain Gerrit user identity and Gerrit URL from firehose.morph during
deployment, rather than hardcoding values, and remove changing of git identity, which is now also set in firehose.morph
-rw-r--r--firehose.configure33
-rwxr-xr-xfirehose.sh2
-rw-r--r--firehose/plugin/firehose_plugin.py24
3 files changed, 36 insertions, 23 deletions
diff --git a/firehose.configure b/firehose.configure
index c17fe59..27a5fe6 100644
--- a/firehose.configure
+++ b/firehose.configure
@@ -3,7 +3,7 @@ set -e
ROOT="$1"
-# Clone the Firehose repo
+# Clone the Firehose repo (temporary hack)
git clone git://git.baserock.org/baserock/baserock/firehose
# Move Firehose arguments to specific directory and timer/service
@@ -28,13 +28,32 @@ systemctl enable firehose.timer
systemctl start firehose.timer
systemctl enable firehose.service
+# Check necessary parameters were filled in firehose.morph before
+# the system was deployed, and exit if not
+if
+ [ -z "$GERRIT_USERNAME" -a \
+ -z "$GERRIT_URL" -a \
+ -z "$GIT_USERNAME" -a \
+ -z "$GIT_EMAIL" -a]; then
+ exit 0
+fi
+
+# Create firehose.conf to store parameters obtained from .morph file
+cat >>"$ROOT"/etc/firehose.conf <<EOF
+[config]
+gerrit_username = $GERRIT_USERNAME
+gerrit_url = $GERRIT_URL
+git_username = $GIT_USERNAME
+git_email = $GIT_EMAIL
+EOF
+
# Add firehose user, then become firehose user
-adduser firehose -s /bin/false -D
-sudo -u firehose --ssh-keygen -C "firehose@baserock.org" -N ""
-sudo chown -R firehose:firehose /var/lib/firehose/
-sudo -u firehose -s
+adduser "$GERRIT_USER" -s /bin/false -D
+sudo -u "$GERRIT_USER" --ssh-keygen -C "$GERRIT_USER@baserock.org" -N ""
+sudo chown -R "$GERRIT_USER":"$GERRIT_USER" /var/lib/firehose
+sudo -u "$GERRIT_USER" -s
# Configure a git identity for Firehose
-git config --global user.name "Firehose"
-git config --global user.email firehose@firehose.baserock.org
+git config --global user.name "$GIT_USER"
+git config --global user.email "$GIT_EMAIL"
diff --git a/firehose.sh b/firehose.sh
index 4d272d3..a61ba6c 100755
--- a/firehose.sh
+++ b/firehose.sh
@@ -18,4 +18,4 @@ PYTHONPATH="${BASE}${PYTHONPATH:+:${PYTHONPATH}}:"
export PYTHONPATH
-exec ${MORPH} firehose "$@"
+exec ${MORPH} firehose "$@" --config=/etc/firehose.conf
diff --git a/firehose/plugin/firehose_plugin.py b/firehose/plugin/firehose_plugin.py
index 66116bf..5e9a55b 100644
--- a/firehose/plugin/firehose_plugin.py
+++ b/firehose/plugin/firehose_plugin.py
@@ -26,23 +26,13 @@ import morphlib
from debian.debian_support import Version
@contextmanager
-def firehose_git(app):
- try:
- username = (app.runcmd_unchecked(["git", "config", "--global", "user.name"]))[1].strip()
- email = (app.runcmd_unchecked(["git", "config", "--global", "user.email"]))[1].strip()
- app.runcmd(["git", "config", "--global", "user.name", "Firehose merge bot"])
- app.runcmd(["git", "config", "--global", "user.email", "firehose@firehose.baserock.org"])
- yield ()
- finally:
- app.runcmd(["git", "config", "--global", "user.name", username])
- app.runcmd(["git", "config", "--global", "user.email", email])
-
-
class FirehosePlugin(cliapp.Plugin):
def enable(self):
self.app.add_subcommand('firehose', self.firehose_cmd,
arg_synopsis='some-firehose.yaml...')
+ self.app.settings(['gerrit_username'], 'gerrit_username')
+ self.app.settings(['gerrit_url'], 'gerrit_url')
def disable(self):
pass
@@ -120,7 +110,9 @@ class FirehosePlugin(cliapp.Plugin):
log.write('{\"sha\":\"'+sha+'\"}')
def insert_githook(self):
- scp_cmd = ('scp', '-p', '-P', '29418', 'firehose@testgerrit.baserock.org:hooks/commit-msg',
+ 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')
os.system(' '.join(scp_cmd))
@@ -249,12 +241,14 @@ class FirehosePlugin(cliapp.Plugin):
return True
def commit_and_push(self, name):
+ gerrit_username = self.app.settings['gerrit_username']
+ gerrit_url = self.app.settings['gerrit_url']
commit_msg = 'Update to '+name+' ref in definitions.git'
branch_name = 'HEAD:refs/for/master/firehose/'+name
(code, out, err) = self.app.runcmd_unchecked(
['git', 'commit', '-a', '-m', commit_msg],
cwd=self.gitpath)
if code == 0:
- self.app.runcmd(['git', 'push', 'ssh://firehose@testgerrit.baserock.org:29418/baserock/baserock/definitions',
- branch_name], cwd=self.gitpath)
+ self.app.runcmd(['git', 'push', 'ssh://'+gerrit_username+'@'+gerrit_url+
+ ':29418/baserock/baserock/definitions', branch_name], cwd=self.gitpath)