Skip to content

Commit

Permalink
fix build annotations for multiple remote sources
Browse files Browse the repository at this point in the history
* CLOUDBLD-6042

Signed-off-by: Robert Cerven <rcerven@redhat.com>
  • Loading branch information
rcerven committed Jun 10, 2021
1 parent 3314c99 commit a01cb30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 4 additions & 1 deletion atomic_reactor/plugins/exit_store_metadata_in_osv3.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def apply_remote_source_annotations(self, annotations):
]
except (TypeError, KeyError):
return
annotations.update(remote_sources_annotations)

if not remote_sources_annotations:
return
annotations.update({'remote_sources': remote_sources_annotations})

def run(self):
metadata = get_build_json().get("metadata", {})
Expand Down
17 changes: 15 additions & 2 deletions tests/plugins/test_store_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from osbs.exceptions import OsbsResponseException
from atomic_reactor.constants import (PLUGIN_KOJI_UPLOAD_PLUGIN_KEY,
PLUGIN_VERIFY_MEDIA_KEY,
PLUGIN_FETCH_SOURCES_KEY)
PLUGIN_FETCH_SOURCES_KEY,
PLUGIN_RESOLVE_REMOTE_SOURCE)
from atomic_reactor.build import BuildResult
from atomic_reactor.inner import DockerBuildWorkflow
from atomic_reactor.plugin import ExitPluginsRunner, PluginFailedException
Expand Down Expand Up @@ -183,10 +184,11 @@ def update_labels_on_build(build_id, labels):
(["application/vnd.docker.distribution.manifest.v1+json"],
["application/vnd.docker.distribution.manifest.v1+json"]),
))
@pytest.mark.parametrize('remote_sources', [True, False])
def test_metadata_plugin(tmpdir, br_annotations, expected_br_annotations,
br_labels, expected_br_labels, koji,
help_results, expected_help_results, base_from_scratch,
verify_media_results, expected_media_results):
verify_media_results, expected_media_results, remote_sources):
initial_timestamp = datetime.now()
workflow = prepare()
if base_from_scratch:
Expand All @@ -212,6 +214,11 @@ def test_metadata_plugin(tmpdir, br_annotations, expected_br_annotations,
workflow.prebuild_results = {
AddHelpPlugin.key: help_results
}
remote_source_output = [{'name': 'first', 'url': 'cachito_url_for_first'},
{'name': 'second', 'url': 'cachito_url_for_second'}]
if remote_sources:
workflow.prebuild_results[PLUGIN_RESOLVE_REMOTE_SOURCE] = remote_source_output

if help_results is not None:
workflow.annotations['help_file'] = help_results['help_file']

Expand Down Expand Up @@ -381,6 +388,12 @@ def test_metadata_plugin(tmpdir, br_annotations, expected_br_annotations,
else:
assert 'media-types' not in annotations

if remote_sources:
assert 'remote_sources' in annotations
assert remote_source_output == annotations['remote_sources']
else:
assert 'remote_sources' not in annotations


@pytest.mark.parametrize('image_id', ('c9243f9abf2b', None))
@pytest.mark.parametrize(('br_annotations', 'expected_br_annotations'), (
Expand Down

0 comments on commit a01cb30

Please sign in to comment.