Skip to content
Snippets Groups Projects
Commit 4316399e authored by Georges Racinet's avatar Georges Racinet
Browse files

Heptapod: backup handling impl in the abstract base class

Instead of just declaring `backup_create()` and `backup_restore()`,
we implement them generically, relying on a new set of primitives
to be implemented in subclasses:

- `ctl_services()`: service management
- `RAILS_SERVICES`: class attribute listing the Rails app services
  (web and background). These will be different in the Docker and
  GDK cases.
- `rake()`
- `remove_all_backups()`
parent 89573da1
Branches
Tags
1 merge request!37Service management utilities and support for GDK installations
......@@ -257,6 +257,23 @@
"for %r", route_path, self.__class__)
raise NotImplementedError('force_remove_route')
def backup_create(self):
raise NotImplementedError('backup_create')
def rake(self, *args):
"""Call GitLab Rake"""
raise NotImplementedError('rake')
def remove_all_backups(self):
"""Remove all existing backups with no impediment for new backups.
"""
raise NotImplementedError('remove_all_backups')
def backup_create(self, clean_previous=True):
"""Create a new backup
: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.
"""
if clean_previous:
self.remove_all_backups()
self.rake('gitlab:backup:create')
......@@ -262,2 +279,3 @@
@contextlib.contextmanager
def backup_restore(self):
......@@ -263,5 +281,27 @@
def backup_restore(self):
raise NotImplementedError('backup_restore')
"""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…
"""
try:
self.ctl_services('stop', self.RAILS_SERVICES)
self.rake('gitlab:backup:restore', 'force=yes')
self.ctl_services('start', self.RAILS_SERVICES)
self.wait_startup()
yield
except Exception:
# these are idempotent
self.ctl_services('start', self.RAILS_SERVICES)
# Worst case scenario, we lost all our data. We need to
# reprepare the server for subsequent tests
self.prepare(self.users['root']['password'])
raise
class DockerHeptapod(Heptapod):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment