Skip to content

Commit

Permalink
Skip downloading database dumps when reasonable.
Browse files Browse the repository at this point in the history
Prior to this commit, every run of the integration test suite would
download a copy of the Fedora Infrastructure's database dumps. The
infrastructure only produces a backup once a day, so this is
inefficient for developers who work on Bodhi often.

This commit adjusts it to only download the database dump if we
don't have it already or if the copy we have is older than a day.

Signed-off-by: Randy Barlow <randy@electronsweatshop.com>
  • Loading branch information
bowlofeggs committed Feb 6, 2019
1 parent 360304e commit 7092c4f
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions devel/ci/bodhi-ci
Expand Up @@ -1017,14 +1017,38 @@ class IntegrationDumpDownloadJob(BuildJob):

self._app_name = app_name
self._label = 'integration-dump-download-{}'.format(app_name)
filepath = os.path.join("devel", "ci", "integration", "dumps", "{}.dump".format(self._app_name))
self.filepath = os.path.join(
"devel", "ci", "integration", "dumps", "{}.dump".format(self._app_name))
url = "https://infrastructure.fedoraproject.org/infra/db-dumps/{app}.dump.xz".format(app=self._app_name)
self._popen_kwargs['shell'] = True
self._command = ["curl -o {filepath}.xz -R -z {filepath}.xz {url} && xz -d --keep --force {filepath}.xz".format(url=url, filepath=filepath)]
self._command = [
(f"curl -o {self.filepath}.xz {url} && xz -d --keep --force {self.filepath}.xz")]

def __repr__(self):
return "<{} app={!r}>".format(self.__class__.__name__, self._app_name)

async def run(self) -> 'IntegrationDumpDownloadJob':
"""
Run the download, unless we already have the file and it's recent enough.
Returns:
Returns self.
"""
if os.path.exists(self.filepath):
# st_mtime is going to use the filesystem's timestamp, not necessarily UTC. Thus, we
# will use tz=None on fromttimestamp() so that the time is expressed in the system's
# local time. Therefore, we also need to collect the current time in the system's local
# time for comparison.
modified_time = datetime.datetime.fromtimestamp(os.stat(self.filepath).st_mtime)
if datetime.datetime.now() - modified_time < datetime.timedelta(days=1):
# Our download is within a day and infrastructure only produces downloads once a
# day, so let's skip this task.
self.complete.set()
self.skipped = True
else:
await super(IntegrationDumpDownloadJob, self).run()
return self


class IntegrationJob(Job):
"""
Expand Down

0 comments on commit 7092c4f

Please sign in to comment.