Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
chr-stian committed Dec 15, 2023
1 parent bad2a16 commit f9240a1
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 81 deletions.
35 changes: 9 additions & 26 deletions galaxy_ng/tests/integration/api/test_api_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 10 additions & 20 deletions galaxy_ng/tests/integration/api/test_artifact_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
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 (
CapturingGalaxyError,
CollectionInspector,
get_client,
set_certification,
wait_for_task
)

logger = logging.getLogger(__name__)
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions galaxy_ng/tests/integration/api/test_gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,14 +16,14 @@
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__)


@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())

21 changes: 7 additions & 14 deletions galaxy_ng/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
38 changes: 20 additions & 18 deletions galaxy_ng/tests/integration/utils/iqe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand All @@ -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:
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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'<AnsibleConfigFixture: {self.namespace}>'
Expand Down Expand Up @@ -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}')

Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit f9240a1

Please sign in to comment.