Skip to content

Commit

Permalink
coreos-ostree-importer: only do parent commit check on prod repo
Browse files Browse the repository at this point in the history
Sometimes we do multiple builds in a stream before we release one
(i.e. if we found a problem before release). Each new build will
have a parent commit corresponding to the last *released* build,
which is the correct thing to do. In that case our parent commit
check won't be valid, so let's only do that check on the prod repo.

As part of this I moved the sanity checks out of ostree_pull_local
so I could use the target_repo variable without having to change
the function call signature of ostree_pull_local.
  • Loading branch information
dustymabe committed Apr 17, 2020
1 parent 56cd9a0 commit 49cb095
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions coreos-ostree-importer/coreos_ostree_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,33 @@ def process(self, message: fedora_messaging.api.Message):
untar_file_from_url(url=commit_url, tmpdir=tmpdir, sha256sum=sha256sum)
source_repo_path = tmpdir

# one more sanity check: make sure buildid == version
# variables that are used in sanity checks below
branch_exists = ostree_branch_exists(repo=target_repo_path, branch=ostree_ref)
has_parent_commit = \
ostree_has_parent_commit(repo=source_repo_path, commit=ostree_checksum)

# sanity check: make sure buildid == version
assert_commit_has_version(
repo=source_repo_path, commit=ostree_checksum, version=build_id
)

# sanity check: If we're making a new branch let's make sure it's the
# first commit (i.e. has no parent). There could be cases where we
# actually want to do this but let's do it manually in releng to make
# sure it's what we actually want to do.
if has_parent_commit and not branch_exists:
raise Exception("Refusing to import non-origin commit into a new branch")

# sanity check: If we have a parent commit and the branch is already in
# the repo then verify the parent commit of the new commit is in the
# destination repo and also that the current branch in the repo points
# to it. We don't need to perform this check on the compose repo as
# sometimes we do multiple builds for a stream (which get imported
# into the compose repo) before we actually do a release.
if target_repo != "compose" and has_parent_commit and branch_exists:
parent = ostree_get_parent_commit(repo=srcrepo, commit=commit)
assert_branch_points_to_commit(repo=dstrepo, branch=branch, commit=parent)

# Import the commit into the target repo
ostree_pull_local(
commit=ostree_checksum,
Expand Down Expand Up @@ -263,22 +286,6 @@ def untar_file_from_url(url: str, tmpdir: str, sha256sum: str):


def ostree_pull_local(srcrepo: str, dstrepo: str, branch: str, commit: str):
branch_exists = ostree_branch_exists(repo=dstrepo, branch=branch)
has_parent_commit = ostree_has_parent_commit(repo=srcrepo, commit=commit)

# If we're making a new branch let's make sure it's the first commit (i.e.
# has no parent). There could be cases where we actually want to do this
# but let's do it manually in releng to make sure it's what we actually
# want to do.
if has_parent_commit and not branch_exists:
raise Exception("Refusing to import non-origin commit into a new branch")

# If we have a parent commit and the branch is already in the repo then
# verify the parent commit of the new commit is in the destination repo
# and also that the current branch in the repo points to it
if has_parent_commit and branch_exists:
parent = ostree_get_parent_commit(repo=srcrepo, commit=commit)
assert_branch_points_to_commit(repo=dstrepo, branch=branch, commit=parent)

# pull content
logger.info("Running ostree pull-local to perform import")
Expand Down

0 comments on commit 49cb095

Please sign in to comment.