Skip to content

Commit

Permalink
Use sources configuration URL from POST response
Browse files Browse the repository at this point in the history
When requesting a source bundle to cachito, the initial response
also returns the proper URL with the endpoint for the additional
configuration files. There is no need to assemble that URL.

* CLOUDBLD-427

Signed-off-by: Athos Ribeiro <athos@redhat.com>
  • Loading branch information
Athos Ribeiro authored and rcerven committed Jun 9, 2020
1 parent 40e072f commit dad1f02
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 deletions.
5 changes: 3 additions & 2 deletions atomic_reactor/plugins/pre_resolve_remote_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def run(self):

remote_source_json = self.source_request_to_json(source_request)
remote_source_url = self.cachito_session.assemble_download_url(source_request)
remote_source_conf_url = self.cachito_session.assemble_request_config_url(source_request)
remote_source_conf_url = remote_source_json.get('configuration_files')
self.set_worker_params(source_request, remote_source_url, remote_source_conf_url)

dest_dir = self.workflow.source.workdir
Expand Down Expand Up @@ -122,7 +122,8 @@ def set_worker_params(self, source_request, remote_source_url, remote_source_con
def source_request_to_json(self, source_request):
"""Create a relevant representation of the source request"""
required = ('ref', 'repo')
optional = ('dependencies', 'flags', 'packages', 'pkg_managers', 'environment_variables')
optional = ('dependencies', 'flags', 'packages', 'pkg_managers', 'environment_variables',
'configuration_files')

data = {}
try:
Expand Down
12 changes: 0 additions & 12 deletions atomic_reactor/utils/cachito.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,6 @@ def assemble_download_url(self, request):
request_id = self._get_request_id(request)
return '{}/api/v1/requests/{}/download'.format(self.api_url, request_id)

def assemble_request_config_url(self, request):
"""Return the URL to download the configuration files associated with a request
:param request: int or dict, either the Cachito request ID or a dict with 'id' key
:return: str, the URL to download the configuration files
"""
request_id = self._get_request_id(request)
logger.debug('Retrieving configuration files for request %ds', request_id)
url = '{}/api/v1/requests/{}/configuration-files'.format(self.api_url, request_id)
return url

def _get_request_id(self, request):
if isinstance(request, int):
return request
Expand Down
7 changes: 2 additions & 5 deletions tests/plugins/test_resolve_remote_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def mock_cachito_api(workflow, user=KOJI_TASK_OWNER, source_request=None,
'version': 'v2.0.3'
}
],
'configuration_files': CACHITO_REQUEST_CONFIG_URL,
'extra_cruft': 'ignored',
}

Expand Down Expand Up @@ -174,11 +175,6 @@ def mock_cachito_api(workflow, user=KOJI_TASK_OWNER, source_request=None,
.with_args(source_request)
.and_return(CACHITO_REQUEST_DOWNLOAD_URL))

(flexmock(CachitoAPI)
.should_receive('assemble_request_config_url')
.with_args(source_request)
.and_return(CACHITO_REQUEST_CONFIG_URL))


def mock_koji(user=KOJI_TASK_OWNER):
koji_session = flexmock()
Expand Down Expand Up @@ -355,6 +351,7 @@ def run_plugin_with_args(workflow, dependency_replacements=None, expect_error=No
'version': 'v2.0.3'
}
],
'configuration_files': CACHITO_REQUEST_CONFIG_URL
}
assert results['remote_source_path'] == expected_dowload_path(workflow)

Expand Down
10 changes: 0 additions & 10 deletions tests/utils/test_cachito.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,3 @@ def test_download_sources_bad_request_type(tmpdir):
def test_assemble_download_url(tmpdir, cachito_request):
url = CachitoAPI(CACHITO_URL).assemble_download_url(cachito_request)
assert url == CACHITO_REQUEST_DOWNLOAD_URL


@pytest.mark.parametrize('cachito_request', (
CACHITO_REQUEST_ID,
{'id': CACHITO_REQUEST_ID},
))
def test_assemble_request_config_url(tmpdir, cachito_request):
expected = '{}/api/v1/requests/{}/configuration-files'.format(CACHITO_URL, CACHITO_REQUEST_ID)
url = CachitoAPI(CACHITO_URL).assemble_request_config_url(cachito_request)
assert url == expected

0 comments on commit dad1f02

Please sign in to comment.