summaryrefslogtreecommitdiff
path: root/lorrycontroller/gerrit.py
diff options
context:
space:
mode:
Diffstat (limited to 'lorrycontroller/gerrit.py')
-rw-r--r--lorrycontroller/gerrit.py34
1 files changed, 14 insertions, 20 deletions
diff --git a/lorrycontroller/gerrit.py b/lorrycontroller/gerrit.py
index c5498e2..5a35920 100644
--- a/lorrycontroller/gerrit.py
+++ b/lorrycontroller/gerrit.py
@@ -37,26 +37,20 @@ class GerritDownstream(hosts.DownstreamHost):
'Cannot create non-private repositories in Gerrit')
def __init__(self, app_settings):
- # XXX These need to be configurable
- host = 'localhost'
- port = 29418
- user = 'lorry'
-
- self._ssh_command_args = [
- 'ssh', '-oStrictHostKeyChecking=no', '-oBatchMode=yes', '-p%i' % port,
- '%s@%s' % (user, host)]
-
- def _ssh_command(self, command):
- out = cliapp.runcmd(self._ssh_command_args + command)
- if isinstance(out, bytes):
- out = out.decode('utf-8', errors='replace')
- return out
+ url = app_settings['downstream-ssh-url']
+ if url is None:
+ url = 'ssh://lorry@localhost:29418'
+ key_check = 'no'
+ else:
+ key_check = 'yes'
+ self._ssh_command = hosts.SshCommand(
+ url, StrictHostKeyChecking=key_check)
def _has_project(self, name):
# There's no 'does this project exist' command in Gerrit 2.9.4; 'list
# all projects with this prefix' is as close we can get.
- output = self._ssh_command([
+ output = self._ssh_command.run([
'gerrit', 'ls-projects', '--type=ALL', '--prefix=%s' % name])
projects = output.strip().split('\n')
@@ -76,17 +70,17 @@ class GerritDownstream(hosts.DownstreamHost):
logging.info('Project %s exists in local Gerrit already.',
name)
else:
- self._ssh_command(['gerrit', 'create-project', name])
+ self._ssh_command.run(['gerrit', 'create-project', name])
logging.info('Created %s project in local Gerrit.', name)
# We can only set this metadata if we're the owner of the
# repository. For now, ignore failures.
try:
if 'head' in metadata:
- self._ssh_command(['gerrit', 'set-head', name,
- '--new-head', metadata['head']])
+ self._ssh_command.run(['gerrit', 'set-head', name,
+ '--new-head', metadata['head']])
if 'description' in metadata:
- self._ssh_command(['gerrit', 'set-project', name,
- '-d', metadata['description']])
+ self._ssh_command.run(['gerrit', 'set-project', name,
+ '-d', metadata['description']])
except cliapp.AppException:
pass