summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <a.badger@gmail.com>2019-10-19 12:40:45 -0700
committerToshio Kuratomi <a.badger@gmail.com>2019-10-20 19:03:47 -0700
commitdb5382341d6653b612adb98e384f3c3ea3d9ec99 (patch)
tree6d31c45ea3b259a04b53c04572b4f7a0f90694d9
parent3d04f253149b24815bd3f5e56b6de766b4b6b4b3 (diff)
downloadansible-db5382341d6653b612adb98e384f3c3ea3d9ec99.tar.gz
[stable-2.9] AH servers include automation-hub as part of the server configuration. (#63700)
* AH servers include automation-hub as part of the server configuration. So we don't need to add it here. Fixes #63699 * Update unittests for the fix to galaxy wait_import_task (cherry picked from commit cc1ff57) Co-authored-by: Toshio Kuratomi <a.badger@gmail.com>
-rw-r--r--changelogs/fragments/fix-ansible-galaxy-server.yml5
-rw-r--r--lib/ansible/galaxy/api.py2
-rw-r--r--test/units/galaxy/test_api.py52
3 files changed, 33 insertions, 26 deletions
diff --git a/changelogs/fragments/fix-ansible-galaxy-server.yml b/changelogs/fragments/fix-ansible-galaxy-server.yml
new file mode 100644
index 0000000000..87bc27af2f
--- /dev/null
+++ b/changelogs/fragments/fix-ansible-galaxy-server.yml
@@ -0,0 +1,5 @@
+---
+bugfixes:
+- The ansible-galaxy publish command was using an incorrect URL for v3 servers.
+ The configuration for v3 servers includes part of the path fragment that was
+ added in the new test.
diff --git a/lib/ansible/galaxy/api.py b/lib/ansible/galaxy/api.py
index 6c04a215d3..da53f2e70c 100644
--- a/lib/ansible/galaxy/api.py
+++ b/lib/ansible/galaxy/api.py
@@ -453,7 +453,7 @@ class GalaxyAPI:
# Construct the appropriate URL per version
if 'v3' in self.available_api_versions:
- full_url = _urljoin(self.api_server, 'automation-hub', self.available_api_versions['v3'],
+ full_url = _urljoin(self.api_server, self.available_api_versions['v3'],
'imports/collections', task_id, '/')
else:
# TODO: Should we have a trailing slash here? I'm working with what the unittests ask
diff --git a/test/units/galaxy/test_api.py b/test/units/galaxy/test_api.py
index 8c69489e03..11fd435f0e 100644
--- a/test/units/galaxy/test_api.py
+++ b/test/units/galaxy/test_api.py
@@ -57,6 +57,8 @@ def get_test_galaxy_api(url, version, token_ins=None, token_value=None):
token_value = token_value or "my token"
token_ins = token_ins or GalaxyToken(token_value)
api = GalaxyAPI(None, "test", url)
+ # Warning, this doesn't test g_connect() because _availabe_api_versions is set here. That means
+ # that urls for v2 servers have to append '/api/' themselves in the input data.
api._available_api_versions = {version: '%s' % version}
api.token = token_ins
@@ -332,16 +334,16 @@ def test_publish_failure(api_version, collection_url, response, expected, collec
api.publish_collection(collection_artifact)
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
- ('v2', 'Token', GalaxyToken('my token'),
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
+ ('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234'),
- ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
+ ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
-def test_wait_import_task(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
- api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
+def test_wait_import_task(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
+ api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
@@ -365,16 +367,16 @@ def test_wait_import_task(api_version, token_type, token_ins, import_uri, full_i
assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
- ('v2', 'Token', GalaxyToken('my token'),
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
+ ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234'),
- ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
+ ('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
-def test_wait_import_task_multiple_requests(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
- api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
+def test_wait_import_task_multiple_requests(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
+ api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
@@ -412,16 +414,16 @@ def test_wait_import_task_multiple_requests(api_version, token_type, token_ins,
'Galaxy import process has a status of test, wait 2 seconds before trying again'
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri,', [
- ('v2', 'Token', GalaxyToken('my token'),
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri,', [
+ ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234'),
- ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
+ ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
-def test_wait_import_task_with_failure(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
- api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
+def test_wait_import_task_with_failure(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
+ api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
@@ -489,16 +491,16 @@ def test_wait_import_task_with_failure(api_version, token_type, token_ins, impor
assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
- ('v2', 'Token', GalaxyToken('my_token'),
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
+ ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my_token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234'),
- ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
+ ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
-def test_wait_import_task_with_failure_no_error(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
- api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
+def test_wait_import_task_with_failure_no_error(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
+ api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()
@@ -562,16 +564,16 @@ def test_wait_import_task_with_failure_no_error(api_version, token_type, token_i
assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
- ('v2', 'Token', GalaxyToken('my token'),
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
+ ('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
'1234',
'https://galaxy.server.com/api/v2/collection-imports/1234'),
- ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
+ ('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
'1234',
'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
])
-def test_wait_import_task_timeout(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
- api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
+def test_wait_import_task_timeout(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
+ api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
if token_ins:
mock_token_get = MagicMock()