Skip to content

Commit

Permalink
Merge pull request #444 from vrutkovs/error-in-build-response
Browse files Browse the repository at this point in the history
buildresponse: return a meaningful error message
  • Loading branch information
lcarva authored Jun 24, 2016
2 parents 3497641 + 03a1a58 commit 0609b30
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions osbs/build/build_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ def get_logs(self, decode_logs=True):
else:
return logs

def get_error_message(self):
"""
Return an error message based on atomic-reactor's metadata
"""
try:
str_metadata = graceful_chain_get(self.get_annotations_or_labels(), "plugins-metadata")
metadata_dict = json.loads(str_metadata)
plugin, error_message = list(metadata_dict['errors'].items())[0]
if error_message:
# Plugin has non-empty error description
return "Error in plugin %s: %s" % (plugin, error_message)
else:
return "Error in plugin %s" % plugin
except Exception:
return None

def get_commit_id(self):
return graceful_chain_get(self.get_annotations_or_labels(), "commit_id")

Expand Down
22 changes: 22 additions & 0 deletions tests/build/test_build_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
of the BSD license. See the LICENSE file for details.
"""
import json
import pytest
from osbs.build.build_response import BuildResponse

class TestBuildResponse(object):
Expand Down Expand Up @@ -39,3 +40,24 @@ def test_get_koji_build_id(self):
})
assert build_response.get_koji_build_id() == koji_build_id

@pytest.mark.parametrize(('plugin', 'message', 'expected_error_message'), [
('dockerbuild', None, 'Error in plugin dockerbuild'),
('foo', 'bar', 'Error in plugin foo: bar'),
(None, None, None)
])
def test_error_message(self, plugin, message, expected_error_message):
plugins_metadata = json.dumps({
'errors': {
plugin: message,
},
})
if not plugin:
plugins_metadata = ''
build_response = BuildResponse({
'metadata': {
'annotations': {
'plugins-metadata': plugins_metadata
}
}
})
assert build_response.get_error_message() == expected_error_message

0 comments on commit 0609b30

Please sign in to comment.