Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
No-Issue
  • Loading branch information
chr-stian committed Dec 12, 2023
1 parent 9faa346 commit bad2a16
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 26 deletions.
28 changes: 28 additions & 0 deletions galaxy_ng/tests/integration/api/test_gw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
import subprocess
import tempfile
import pytest

from galaxykit.collections import get_all_collections, upload_artifact
from galaxykit.namespaces import get_namespace
from galaxykit.users import get_me
from galaxykit.utils import wait_for_task
from ..utils import ansible_galaxy, wait_for_url, CollectionInspector
from ..constants import GALAXY_STAGE_ANSIBLE_PROFILES

from jsonschema import validate as validate_json

from ..schemas import (
schema_objectlist,
)
from ..utils.iqe_utils import galaxy_stage_ansible_user_cleanup
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)

31 changes: 25 additions & 6 deletions galaxy_ng/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from orionutils.utils import increment_version
from pkg_resources import parse_version, Requirement

from galaxykit import GalaxyClient
from galaxykit.collections import delete_collection
from galaxykit.groups import get_group_id
from galaxykit.namespaces import create_namespace
Expand All @@ -29,7 +30,7 @@
is_standalone,
is_ephemeral_env,
galaxy_stage_ansible_user_cleanup, remove_from_cache,
get_ansible_config, get_galaxy_client, AnsibleConfigFixture, get_hub_version
get_ansible_config, get_galaxy_client, AnsibleConfigFixture, get_hub_version, aap_gateway
)
from .utils.tools import generate_random_artifact_version

Expand Down Expand Up @@ -295,11 +296,20 @@ def galaxy_client(ansible_config):


def pytest_sessionstart(session):
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}")
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}")


def pytest_runtest_setup(item):
Expand Down Expand Up @@ -517,6 +527,15 @@ def gh_user_1_pre(ansible_config):
return gc("github_user", github_social_auth=True, ignore_cache=True)


@pytest.fixture(scope="function")
def gw_user_1(ansible_config):
"""
Returns a galaxy kit client with a GitHub user logged into beta galaxy stage
"""
gc = get_galaxy_client(ansible_config)
return gc("github_user", github_social_auth=True)


@pytest.fixture(scope="function")
def generate_test_artifact(ansible_config):
"""
Expand Down
59 changes: 39 additions & 20 deletions galaxy_ng/tests/integration/utils/iqe_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def gen_authorized_client(
token=None,
remote=False,
basic_token=False,
github_social_auth=False
github_social_auth=False,
gw_auth=False,
):

self._basic_token = basic_token
Expand Down Expand Up @@ -144,7 +145,7 @@ def gen_authorized_client(
if isinstance(role, str):
profile_config = self.config(role)
user = profile_config
if not github_social_auth:
if not github_social_auth and not gw_auth:
if profile_config.get("auth_url"):
token = profile_config.get("token")
if token is None:
Expand All @@ -158,7 +159,7 @@ def gen_authorized_client(
"auth_url": profile_config.get("auth_url"),
"token": token,
}
elif not github_social_auth:
elif not github_social_auth and not gw_auth:
token = get_standalone_token(
role,
url,
Expand All @@ -181,7 +182,8 @@ def gen_authorized_client(
container_tls_verify=ssl_verify,
https_verify=ssl_verify,
token_type=token_type,
github_social_auth=github_social_auth
github_social_auth=github_social_auth,
gw_auth=gw_auth
)
client_cache[cache_key] = g_client
if ignore_cache:
Expand Down Expand Up @@ -269,6 +271,10 @@ def is_dev_env_standalone():
dev_env_standalone = os.getenv("DEV_ENV_STANDALONE", True)
return dev_env_standalone in ('true', 'True', 1, '1', True)

def aap_gateway():
dev_env_standalone = os.getenv("AAP_GATEWAY", True)
return dev_env_standalone in ('true', 'True', 1, '1', True)


def avoid_docker_limit_rate():
avoid_limit_rate = os.getenv("AVOID_DOCKER_LIMIT_RATE", False)
Expand Down Expand Up @@ -381,6 +387,12 @@ 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 @@ -627,26 +639,33 @@ def has_old_credentials():

@lru_cache()
def get_hub_version(ansible_config):
if is_standalone():
role = "iqe_admin"
elif is_ephemeral_env():
# I can't get a token from the ephemeral environment.
# Changed to Basic token authentication until the issue is resolved
del os.environ["HUB_AUTH_URL"]
role = "partner_engineer"
if aap_gateway():
galaxy_client = get_galaxy_client(ansible_config)
gc = galaxy_client(role, basic_token=True, ignore_cache=True)
role = "admin"
gc = galaxy_client(role, gw_auth=True, ignore_cache=True)
galaxy_ng_version = gc.get(gc.galaxy_root)["galaxy_ng_version"]
return galaxy_ng_version
else:
role = "admin"
try:
gc = GalaxyKitClient(ansible_config).gen_authorized_client(role)
except GalaxyError:
# FIXME: versions prior to 4.7 have different credentials. This needs to be fixed.
gc = GalaxyClient(galaxy_root="http://localhost:5001/api/automation-hub/",
auth={"username": "admin", "password": "admin"})
return gc.get(gc.galaxy_root)["galaxy_ng_version"]
if is_standalone():
role = "iqe_admin"
elif is_ephemeral_env():
# I can't get a token from the ephemeral environment.
# Changed to Basic token authentication until the issue is resolved
del os.environ["HUB_AUTH_URL"]
role = "partner_engineer"
galaxy_client = get_galaxy_client(ansible_config)
gc = galaxy_client(role, basic_token=True, ignore_cache=True)
galaxy_ng_version = gc.get(gc.galaxy_root)["galaxy_ng_version"]
return galaxy_ng_version
else:
role = "admin"
try:
gc = GalaxyKitClient(ansible_config).gen_authorized_client(role)
except GalaxyError:
# FIXME: versions prior to 4.7 have different credentials. This needs to be fixed.
gc = GalaxyClient(galaxy_root="http://localhost:5001/api/automation-hub/",
auth={"username": "admin", "password": "admin"})
return gc.get(gc.galaxy_root)["galaxy_ng_version"]


@lru_cache()
Expand Down

0 comments on commit bad2a16

Please sign in to comment.