Browse code

[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>

Toshio Kuratomi authored on 2019/10/20 04:40:45
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+---
1
+bugfixes:
2
+- The ansible-galaxy publish command was using an incorrect URL for v3 servers.
3
+  The configuration for v3 servers includes part of the path fragment that was
4
+  added in the new test.
... ...
@@ -453,7 +453,7 @@ class GalaxyAPI:
453 453
 
454 454
         # Construct the appropriate URL per version
455 455
         if 'v3' in self.available_api_versions:
456
-            full_url = _urljoin(self.api_server, 'automation-hub', self.available_api_versions['v3'],
456
+            full_url = _urljoin(self.api_server, self.available_api_versions['v3'],
457 457
                                 'imports/collections', task_id, '/')
458 458
         else:
459 459
             # TODO: Should we have a trailing slash here?  I'm working with what the unittests ask
... ...
@@ -57,6 +57,8 @@ def get_test_galaxy_api(url, version, token_ins=None, token_value=None):
57 57
     token_value = token_value or "my token"
58 58
     token_ins = token_ins or GalaxyToken(token_value)
59 59
     api = GalaxyAPI(None, "test", url)
60
+    # Warning, this doesn't test g_connect() because _availabe_api_versions is set here.  That means
61
+    # that urls for v2 servers have to append '/api/' themselves in the input data.
60 62
     api._available_api_versions = {version: '%s' % version}
61 63
     api.token = token_ins
62 64
 
... ...
@@ -332,16 +334,16 @@ def test_publish_failure(api_version, collection_url, response, expected, collec
332 332
         api.publish_collection(collection_artifact)
333 333
 
334 334
 
335
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
336
-    ('v2', 'Token', GalaxyToken('my token'),
335
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
336
+    ('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
337 337
      '1234',
338 338
      'https://galaxy.server.com/api/v2/collection-imports/1234'),
339
-    ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
339
+    ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
340 340
      '1234',
341 341
      'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
342 342
 ])
343
-def test_wait_import_task(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
344
-    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
343
+def test_wait_import_task(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
344
+    api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
345 345
 
346 346
     if token_ins:
347 347
         mock_token_get = MagicMock()
... ...
@@ -365,16 +367,16 @@ def test_wait_import_task(api_version, token_type, token_ins, import_uri, full_i
365 365
     assert mock_display.mock_calls[0][1][0] == 'Waiting until Galaxy import task %s has completed' % full_import_uri
366 366
 
367 367
 
368
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
369
-    ('v2', 'Token', GalaxyToken('my token'),
368
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
369
+    ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
370 370
      '1234',
371 371
      'https://galaxy.server.com/api/v2/collection-imports/1234'),
372
-    ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
372
+    ('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
373 373
      '1234',
374 374
      'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
375 375
 ])
376
-def test_wait_import_task_multiple_requests(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
377
-    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
376
+def test_wait_import_task_multiple_requests(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
377
+    api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
378 378
 
379 379
     if token_ins:
380 380
         mock_token_get = MagicMock()
... ...
@@ -412,16 +414,16 @@ def test_wait_import_task_multiple_requests(api_version, token_type, token_ins,
412 412
         'Galaxy import process has a status of test, wait 2 seconds before trying again'
413 413
 
414 414
 
415
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri,', [
416
-    ('v2', 'Token', GalaxyToken('my token'),
415
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri,', [
416
+    ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my token'),
417 417
      '1234',
418 418
      'https://galaxy.server.com/api/v2/collection-imports/1234'),
419
-    ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
419
+    ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
420 420
      '1234',
421 421
      'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
422 422
 ])
423
-def test_wait_import_task_with_failure(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
424
-    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
423
+def test_wait_import_task_with_failure(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
424
+    api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
425 425
 
426 426
     if token_ins:
427 427
         mock_token_get = MagicMock()
... ...
@@ -489,16 +491,16 @@ def test_wait_import_task_with_failure(api_version, token_type, token_ins, impor
489 489
     assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
490 490
 
491 491
 
492
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
493
-    ('v2', 'Token', GalaxyToken('my_token'),
492
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
493
+    ('https://galaxy.server.com/api/', 'v2', 'Token', GalaxyToken('my_token'),
494 494
      '1234',
495 495
      'https://galaxy.server.com/api/v2/collection-imports/1234'),
496
-    ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
496
+    ('https://galaxy.server.com/api/automation-hub/', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
497 497
      '1234',
498 498
      'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
499 499
 ])
500
-def test_wait_import_task_with_failure_no_error(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
501
-    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
500
+def test_wait_import_task_with_failure_no_error(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
501
+    api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
502 502
 
503 503
     if token_ins:
504 504
         mock_token_get = MagicMock()
... ...
@@ -562,16 +564,16 @@ def test_wait_import_task_with_failure_no_error(api_version, token_type, token_i
562 562
     assert mock_err.mock_calls[0][1][0] == u'Galaxy import error message: Somé error'
563 563
 
564 564
 
565
-@pytest.mark.parametrize('api_version, token_type, token_ins, import_uri, full_import_uri', [
566
-    ('v2', 'Token', GalaxyToken('my token'),
565
+@pytest.mark.parametrize('server_url, api_version, token_type, token_ins, import_uri, full_import_uri', [
566
+    ('https://galaxy.server.com/api', 'v2', 'Token', GalaxyToken('my token'),
567 567
      '1234',
568 568
      'https://galaxy.server.com/api/v2/collection-imports/1234'),
569
-    ('v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
569
+    ('https://galaxy.server.com/api/automation-hub', 'v3', 'Bearer', KeycloakToken(auth_url='https://api.test/'),
570 570
      '1234',
571 571
      'https://galaxy.server.com/api/automation-hub/v3/imports/collections/1234/'),
572 572
 ])
573
-def test_wait_import_task_timeout(api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
574
-    api = get_test_galaxy_api('https://galaxy.server.com/api/', api_version, token_ins=token_ins)
573
+def test_wait_import_task_timeout(server_url, api_version, token_type, token_ins, import_uri, full_import_uri, monkeypatch):
574
+    api = get_test_galaxy_api(server_url, api_version, token_ins=token_ins)
575 575
 
576 576
     if token_ins:
577 577
         mock_token_get = MagicMock()