From f9240a120e0a013508ab2171f305355a510b1646 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 15 Dec 2023 16:03:37 +0100 Subject: [PATCH] wip No-Issue --- .../tests/integration/api/test_api_base.py | 35 +++++------------ .../integration/api/test_artifact_download.py | 30 +++++---------- galaxy_ng/tests/integration/api/test_gw.py | 7 ++-- galaxy_ng/tests/integration/conftest.py | 21 ++++------ .../tests/integration/utils/iqe_utils.py | 38 ++++++++++--------- 5 files changed, 50 insertions(+), 81 deletions(-) diff --git a/galaxy_ng/tests/integration/api/test_api_base.py b/galaxy_ng/tests/integration/api/test_api_base.py index 4856f33ab0..8a1da69329 100644 --- a/galaxy_ng/tests/integration/api/test_api_base.py +++ b/galaxy_ng/tests/integration/api/test_api_base.py @@ -5,51 +5,34 @@ @pytest.mark.min_hub_version("4.6dev") @pytest.mark.all -def test_galaxy_api_root(ansible_config, artifact): +def test_galaxy_api_root(galaxy_client, artifact): """Test galaxy API root.""" # TODO: change to `basic_user` profile when can access pulp-v3 api root - config = ansible_config("admin") - api_prefix = config.get("api_prefix") - api_prefix = api_prefix.rstrip("/") - - api_client = get_client( - config=config, - request_token=True, - require_auth=True - ) - + gc = galaxy_client("admin") # verify api root works - response = api_client(api_prefix + '/') + response = gc.get(gc.galaxy_root) assert "v3" in response["available_versions"] assert "pulp-v3" in response["available_versions"] - v3_root = api_client(api_prefix + '/' + response['available_versions']['v3']) + v3_root = gc.get(response['available_versions']['v3']) assert "published" in v3_root - pulp_root = api_client(api_prefix + '/' + response['available_versions']['pulp-v3']) + pulp_root = gc.get(response['available_versions']['pulp-v3']) assert "tasks" in pulp_root @pytest.mark.max_hub_version("4.5.5") @pytest.mark.all -def test_galaxy_api_root_v_4_5(ansible_config, artifact): +def test_galaxy_api_root_v_4_5(galaxy_client, artifact): """Test galaxy API root.""" # TODO: change to `basic_user` profile when can access pulp-v3 api root - config = ansible_config("admin") - api_prefix = config.get("api_prefix") - api_prefix = api_prefix.rstrip("/") - - api_client = get_client( - config=config, - request_token=True, - require_auth=True - ) + gc = galaxy_client("admin") # verify api root works - response = api_client(api_prefix + '/') + response = gc.get(gc.galaxy_root) assert "v3" in response["available_versions"] - v3_root = api_client(api_prefix + '/' + response['available_versions']['v3']) + v3_root = gc.get(response['available_versions']['v3']) assert "published" in v3_root diff --git a/galaxy_ng/tests/integration/api/test_artifact_download.py b/galaxy_ng/tests/integration/api/test_artifact_download.py index 4d8eff83d2..494931aa0d 100644 --- a/galaxy_ng/tests/integration/api/test_artifact_download.py +++ b/galaxy_ng/tests/integration/api/test_artifact_download.py @@ -6,6 +6,8 @@ import pytest from orionutils.generator import build_collection, randstr +from galaxykit.collections import upload_artifact +from galaxykit.utils import GalaxyClientError, wait_for_task from ..conftest import is_hub_4_5 from ..constants import USERNAME_PUBLISHER from ..utils import ( @@ -13,7 +15,6 @@ CollectionInspector, get_client, set_certification, - wait_for_task ) logger = logging.getLogger(__name__) @@ -22,9 +23,7 @@ # TODO Refactor get_client to provide access to bearer token @pytest.mark.deployment_standalone @pytest.mark.installer_smoke_test -def test_download_artifact(ansible_config, upload_artifact, galaxy_client): - config = ansible_config("partner_engineer") - api_client = get_client(config, request_token=True, require_auth=True) +def test_download_artifact(ansible_config, galaxy_client): gc = galaxy_client("partner_engineer") # create, upload and certify a collection @@ -36,30 +35,21 @@ def test_download_artifact(ansible_config, upload_artifact, galaxy_client): "name": name, "version": version, }) - - with patch("ansible.galaxy.api.GalaxyError", CapturingGalaxyError): - try: - resp = upload_artifact(config, api_client, artifact) - except CapturingGalaxyError as capture: - error_body = capture.http_error.read() - logger.error("Upload failed with error response: %s", error_body) - raise - else: - resp = wait_for_task(api_client, resp) - assert resp["state"] == "completed" - + resp = upload_artifact(None, gc, artifact) + logger.debug("Waiting for upload to be completed") + resp = wait_for_task(gc, resp) + assert resp["state"] == "completed" hub_4_5 = is_hub_4_5(ansible_config) - + # TODO set_certification(api_client, gc, artifact, hub_4_5=hub_4_5) # download collection config = ansible_config("basic_user") with tempfile.TemporaryDirectory() as dir: - api_root = config["url"] filename = f"{namespace}-{name}-{version}.tar.gz" tarball_path = f"{dir}/{filename}" - url = f"{api_root}v3/plugin/ansible/content/published/collections/artifacts/{filename}" + url = f"{gc.galaxy_root}v3/plugin/ansible/content/published/collections/artifacts/{filename}" cmd = [ "curl", @@ -69,7 +59,7 @@ def test_download_artifact(ansible_config, upload_artifact, galaxy_client): "-H", "'Content-Type: application/json'", "-u", - f"{config['username']}:{config['password']}", + f"{gc.username}:{gc.password}", "-o", tarball_path, url, diff --git a/galaxy_ng/tests/integration/api/test_gw.py b/galaxy_ng/tests/integration/api/test_gw.py index bcbf9099aa..719891f426 100644 --- a/galaxy_ng/tests/integration/api/test_gw.py +++ b/galaxy_ng/tests/integration/api/test_gw.py @@ -3,6 +3,7 @@ import tempfile import pytest +from galaxykit import GalaxyClient from galaxykit.collections import get_all_collections, upload_artifact from galaxykit.namespaces import get_namespace from galaxykit.users import get_me @@ -15,7 +16,7 @@ from ..schemas import ( schema_objectlist, ) -from ..utils.iqe_utils import galaxy_stage_ansible_user_cleanup +from ..utils.iqe_utils import galaxy_stage_ansible_user_cleanup, get_ansible_config from ..utils.rbac_utils import create_test_user logger = logging.getLogger(__name__) @@ -23,6 +24,6 @@ @pytest.mark.this def test_gw(galaxy_client): - gc = galaxy_client("admin", gw_auth=True) - logger.debug(gc) + gc = galaxy_client("admin") + logger.debug(gc._get_server_version()) diff --git a/galaxy_ng/tests/integration/conftest.py b/galaxy_ng/tests/integration/conftest.py index cb47e2fff0..a309b9a45d 100755 --- a/galaxy_ng/tests/integration/conftest.py +++ b/galaxy_ng/tests/integration/conftest.py @@ -296,20 +296,13 @@ def galaxy_client(ansible_config): def pytest_sessionstart(session): - if aap_gateway(): - ansible_config = get_ansible_config() - url = ansible_config("admin").get("url") - username = ansible_config("admin").PROFILES.get("admin").get("username") - password = ansible_config("admin").PROFILES.get("admin").get("password") - gc = GalaxyClient(galaxy_root=url, auth={"username": username, "password": password}, - gw_auth=True, https_verify=False) - pass - else: - ansible_config = get_ansible_config() - hub_version = get_hub_version(ansible_config) - if not is_standalone() and not is_ephemeral_env() and not is_dev_env_standalone(): - set_test_data(ansible_config, hub_version) - logger.debug(f"Running tests against hub version {hub_version}") + ansible_config = get_ansible_config() + hub_version = get_hub_version(ansible_config) + if not is_standalone() and not is_ephemeral_env() and not is_dev_env_standalone(): + # if not aap_gateway(): + # TODO what should be done here? + set_test_data(ansible_config, hub_version) + logger.debug(f"Running tests against hub version {hub_version}") def pytest_runtest_setup(item): diff --git a/galaxy_ng/tests/integration/utils/iqe_utils.py b/galaxy_ng/tests/integration/utils/iqe_utils.py index 60263cf248..917dcaabec 100755 --- a/galaxy_ng/tests/integration/utils/iqe_utils.py +++ b/galaxy_ng/tests/integration/utils/iqe_utils.py @@ -100,9 +100,8 @@ def gen_authorized_client( remote=False, basic_token=False, github_social_auth=False, - gw_auth=False, ): - + gw_auth=aap_gateway() self._basic_token = basic_token try: config = self.config() @@ -174,6 +173,7 @@ def gen_authorized_client( container_engine = config.get("container_engine") container_registry = config.get("container_registry") token_type = None if not basic_token else "Basic" + gw_root_url = config.get("gw_root_url") g_client = GalaxyClient( url, auth=auth, @@ -183,7 +183,8 @@ def gen_authorized_client( https_verify=ssl_verify, token_type=token_type, github_social_auth=github_social_auth, - gw_auth=gw_auth + gw_auth=gw_auth, + gw_root_url=gw_root_url ) client_cache[cache_key] = g_client if ignore_cache: @@ -272,7 +273,7 @@ def is_dev_env_standalone(): return dev_env_standalone in ('true', 'True', 1, '1', True) def aap_gateway(): - dev_env_standalone = os.getenv("AAP_GATEWAY", True) + dev_env_standalone = os.getenv("AAP_GATEWAY", False) return dev_env_standalone in ('true', 'True', 1, '1', True) @@ -387,12 +388,6 @@ def __init__(self, profile=None, namespace=None, url=None, auth_url=None): if is_sync_testing(): self.PROFILES = SYNC_PROFILES - elif aap_gateway(): - self.PROFILES = DEPLOYED_PAH_PROFILES - admin_pass = os.getenv("HUB_ADMIN_PASS", "AdminPassword") - self.PROFILES["admin"]["username"] = "admin" - self.PROFILES["admin"]["password"] = admin_pass - self.PROFILES["admin"]["token"] = None elif is_stage_environment(): self.PROFILES = EPHEMERAL_PROFILES elif not is_dev_env_standalone(): @@ -464,9 +459,10 @@ def _set_credentials_when_not_docker_pah(self): self.PROFILES["ee_admin"]["password"] = "Th1sP4ssd" self.PROFILES["org_admin"]["token"] = None self.PROFILES["org_admin"]["password"] = "Th1sP4ssd" - token = get_standalone_token(self.PROFILES["admin"], server=self.get("url"), - ssl_verify=False) - self.PROFILES["admin"]["token"] = token + if not aap_gateway(): + token = get_standalone_token(self.PROFILES["admin"], server=self.get("url"), + ssl_verify=False) + self.PROFILES["admin"]["token"] = token def __repr__(self): return f'' @@ -605,7 +601,11 @@ def __getitem__(self, key): 'LOCAL_AUTH_URL', None ) - + elif key == 'gw_root_url': + return os.environ.get( + 'GW_ROOT_URL', + None + ) else: raise Exception(f'Unknown config key: {self.namespace}.{key}') @@ -640,10 +640,12 @@ def has_old_credentials(): @lru_cache() def get_hub_version(ansible_config): if aap_gateway(): - galaxy_client = get_galaxy_client(ansible_config) - role = "admin" - gc = galaxy_client(role, gw_auth=True, ignore_cache=True) - galaxy_ng_version = gc.get(gc.galaxy_root)["galaxy_ng_version"] + username = ansible_config("admin").PROFILES.get("admin").get("username") + password = ansible_config("admin").PROFILES.get("admin").get("password") + gw_root_url = ansible_config("admin").get("gw_root_url") + gc = GalaxyClient(galaxy_root="foo", auth={"username": username, "password": password}, + gw_auth=True, https_verify=False, gw_root_url=gw_root_url) + galaxy_ng_version = gc.get(gc.gw_galaxy_url)["galaxy_ng_version"] return galaxy_ng_version else: if is_standalone():