Commit 932b0073 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Heptapod: reworked services management API

Finally settled to `gitlab_ctl()` to express both
management of all services and of a sublist of services.

The naming and behaviour is more intuitive than the `ctl_services`,
and it matches the Omnibus (hence Docker) CLI.
parent ed3d9dfe355d
......@@ -271,7 +271,7 @@ class Heptapod:
def restart_rails(self):
logger.info("Restarting the Rails application.")
self.ctl_services('restart', self.RAILS_SERVICES)
self.gitlab_ctl('restart', services=self.RAILS_SERVICES)
self.wait_startup()
def set_application_settings(self, **settings):
......@@ -332,6 +332,18 @@ class Heptapod:
"for %r", route_path, self.__class__)
raise NotImplementedError('force_remove_route')
def gitlab_ctl(self, command, services=None):
"""Apply service management command.
'command' would typically be 'start', 'stop', etc.
:param services: an iterable of service names (who can themselves
be different depending on the concrete subclass).
If supplied, the command will apply only to those
services.
"""
raise NotImplementedError('gitlab_ctl')
def rake(self, *args):
"""Call GitLab Rake"""
raise NotImplementedError('rake')
......@@ -362,16 +374,16 @@ class Heptapod:
maybe wait again for it, reinitialize passwords and tokens…
"""
try:
self.ctl_services('stop', self.RAILS_SERVICES)
self.gitlab_ctl('stop', services=self.RAILS_SERVICES)
self.rake('gitlab:backup:restore', 'force=yes')
self.ctl_services('start', self.RAILS_SERVICES)
self.gitlab_ctl('start', services=self.RAILS_SERVICES)
self.wait_startup()
yield
except Exception:
# these are idempotent
self.ctl_services('start', self.RAILS_SERVICES)
self.gitlab_ctl('start', services=self.RAILS_SERVICES)
# Worst case scenario, we lost all our data. We need to
# reprepare the server for subsequent tests
......@@ -461,9 +473,13 @@ class DockerHeptapod(Heptapod):
'-name', '*.tar',
'-delete'))
def ctl_services(self, command, services):
for service in services:
self.run_shell(('gitlab-ctl', command, service))
def gitlab_ctl(self, command, services=None):
base_cmd = ('gitlab-ctl', command)
if services is None:
self.run_shell(base_cmd)
else:
for service in services:
self.run_shell(base_cmd + (service, ))
def apply_hashed_storage_setting(self, hashed_storage):
# TODO it would be tempting not to restart if the setting is already
......@@ -579,7 +595,14 @@ class GdkHeptapod(SourceHeptapod):
cmd.extend(args)
subprocess.check_call(cmd, cwd=self.rails_root)
def ctl_services(self, command, services):
for service in services:
subprocess.check_call(('gdk', command, service),
cwd=self.rails_root)
def gitlab_ctl(self, command, services=None):
base_cmd = ('gdk', command)
def do_command(*opt_args):
subprocess.check_call(base_cmd + opt_args, cwd=self.rails_root)
if services is None:
do_command()
else:
for service in services:
do_command(service)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment