Skip to content

Commit

Permalink
Do not download artifacts from unsuccessful builds
Browse files Browse the repository at this point in the history
We should fetch artifacts only when the build is in COMPLETE state.
In all other cases, build is in incorrect state, we should not fetch
any artifacts in such case.

Fixes cekit#415
  • Loading branch information
goldmann committed Mar 4, 2019
1 parent 4656398 commit d638d99
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cekit/tools.py
Expand Up @@ -83,6 +83,18 @@ def get_brew_url(md5):
get_build_cmd = ['brew', 'call', '--json-output', 'getBuild', 'buildInfo=%s' % build_id]
logger.debug("Executing '%s'" % " ".join(get_build_cmd))
build = yaml.safe_load(subprocess.check_output(get_build_cmd))

# State 1 means: COMPLETE which is the only success state. Other states are:
#
# 'BUILDING': 0
# 'COMPLETE': 1
# 'DELETED': 2
# 'FAILED': 3
# 'CANCELED': 4
if build['state'] != 1:
raise CekitError(
"Artifact with checksum {} was found in Koji metadata but the build was removed making the artifact not available for downloading anymore".format(md5))

package = build['package_name']
release = build['release']

Expand Down
40 changes: 37 additions & 3 deletions tests/test_unit_tools.py
Expand Up @@ -139,7 +139,7 @@ def test_merge_run_cmd():
assert override['user'] == 'foo'


def brew_call(*args, **kwargs):
def brew_call_ok(*args, **kwargs):
if 'listArchives' in args[0]:
return """
[
Expand All @@ -155,19 +155,53 @@ def brew_call(*args, **kwargs):
return """
{
"package_name": "package_name",
"release": "release"
"release": "release",
"state": 1
}
"""
return ""


def brew_call_removed(*args, **kwargs):
if 'listArchives' in args[0]:
return """
[
{
"build_id": "build_id",
"filename": "filename",
"group_id": "group_id",
"artifact_id": "artifact_id",
"version": "version",
}
]"""
if 'getBuild' in args[0]:
return """
{
"package_name": "package_name",
"release": "release",
"state": 2
}
"""
return ""


def test_get_brew_url(mocker):
mocker.patch('subprocess.check_output', side_effect=brew_call)
mocker.patch('subprocess.check_output', side_effect=brew_call_ok)
url = tools.get_brew_url('aa')
assert url == "http://download.devel.redhat.com/brewroot/packages/package_name/" + \
"version/release/maven/group_id/artifact_id/version/filename"


def test_get_brew_url_when_build_was_removed(mocker):
mocker.patch('subprocess.check_output', side_effect=brew_call_removed)

with pytest.raises(CekitError) as excinfo:
tools.get_brew_url('aa')

assert 'Artifact with checksum aa was found in Koji metadata but the build was removed making the artifact not available for downloading anymore' in str(
excinfo.value)


@contextmanager
def mocked_dependency_handler(mocker, data="ID=fedora\nNAME=somefedora\nVERSION=123"):
dh = None
Expand Down

0 comments on commit d638d99

Please sign in to comment.