Commit 1e26572a authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

DockerHeptapod: use backup methods from base class

By implementing the new primitives, we can now leverage the base
implementation of `backup_create()` and `backup_restore()` (which
were largely derived from the first implementation in
`DockerHeptapod` anyway)
parent b81a192e8a51
Pipeline #6525 passed with stages
in 25 minutes and 56 seconds
......@@ -319,6 +319,8 @@ class DockerHeptapod(Heptapod):
repositories_root = '/var/opt/gitlab/git-data/repositories'
RAILS_SERVICES = ('unicorn', 'sidekiq')
def __init__(self, docker_container, **kw):
super(DockerHeptapod, self).__init__(**kw)
self.docker_container = docker_container
......@@ -380,59 +382,20 @@ class DockerHeptapod(Heptapod):
" AND path='%s'" % (source_type, route_path)
])
def backup_create(self, clean_previous=True):
"""Create a new backup
def rake(self, *args):
cmd = ['gitlab-rake']
cmd.extend(args)
self.run_shell(cmd, user='git')
:param bool clean_previous: if true, any previously existing backups
are removed. This is handy so that the restore rake task knows
which one to restore without any need to tell it.
"""
def remove_all_backups(self):
# using find in order not to rely on shell expansion for *.tar
self.run_shell(('find', '/var/opt/gitlab/backups',
'-name', '*.tar',
'-delete'))
self.run_shell(('gitlab-rake', 'gitlab:backup:create'), user='git')
@contextlib.contextmanager
def backup_restore(self):
"""Context manager for backups restoration.
This is a context manager as a way to provide resuming of the
tests session on errors, in a convenient way for the caller.
That means ensuring as much as possible that the server is running,
maybe wait again for it, reinitialize passwords and tokens…
"""
app_services = ('unicorn', 'sidekiq')
try:
for service in app_services:
self.run_shell(('gitlab-ctl', 'stop', service))
self.run_shell(('gitlab-rake', 'gitlab:backup:restore',
'force=yes'),
user='git')
for service in app_services:
self.run_shell(('gitlab-ctl', 'start', service))
self.wait_startup()
yield
except Exception:
# these are idempotent
self.run_shell(('gitlab-ctl', 'start', 'unicorn'))
self.run_shell(('gitlab-ctl', 'start', 'sidekiq'))
# Worst case scenario, we lost all our data. We need to
# reprepare the server for subsequent tests
self.prepare(self.users['root']['password'])
raise
def restart_rails(self):
logger.info("Restarting the Rails application.")
app_services = ('unicorn', 'sidekiq')
for service in app_services:
self.run_shell(('gitlab-ctl', 'restart', service))
self.wait_startup()
def ctl_services(self, command, services):
for service in services:
self.run_shell(('gitlab-ctl', command, service))
def apply_hashed_storage_setting(self, hashed_storage):
# TODO it would be tempting not to restart if the setting is already
......
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