Skip to content

Commit

Permalink
fix: AWX now used commans-line params (avoids confusing env name chna…
Browse files Browse the repository at this point in the history
…ges)
  • Loading branch information
Alan Christie committed Jan 9, 2025
1 parent a98be9c commit 71a3b88
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/latest-stack-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ jobs:
playwright install
behave --tags=-wip
env:
BEHAVIOUR_CONTROLLER_HOST: https://${{ secrets.BEHAVIOUR_AWX_HOSTNAME }}
BEHAVIOUR_CONTROLLER_USERNAME: ${{ secrets.BEHAVIOUR_AWX_USERNAME }}
BEHAVIOUR_CONTROLLER_PASSWORD: ${{ secrets.BEHAVIOUR_AWX_PASSWORD }}
BEHAVIOUR_AWX_HOST: ${{ secrets.BEHAVIOUR_AWX_HOSTNAME }}
BEHAVIOUR_AWX_USERNAME: ${{ secrets.BEHAVIOUR_AWX_USERNAME }}
BEHAVIOUR_AWX_PASSWORD: ${{ secrets.BEHAVIOUR_AWX_PASSWORD }}
BEHAVIOUR_STACK_USERNAME: ${{ secrets.BEHAVIOUR_STACK_USERNAME }}
BEHAVIOUR_STACK_PASSWORD: ${{ secrets.BEHAVIOUR_STACK_PASSWORD }}
BEHAVIOUR_STACK_CLIENT_ID_SECRET: ${{ secrets.BEHAVIOUR_STACK_CLIENT_ID_SECRET }}
Expand Down
39 changes: 21 additions & 18 deletions behaviour/features/steps/awx_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,47 @@
# In order to deploy production-like stacks (to kubernetes) we'll need a number of variables.
# The AWX host (without a protocol, i.e. 'example.com') and
# a user that can run the Job Templates we'll be using.
_CONTROLLER_HOST: Optional[str] = os.environ.get("BEHAVIOUR_CONTROLLER_HOST")
_CONTROLLER_USERNAME: Optional[str] = os.environ.get("BEHAVIOUR_CONTROLLER_USERNAME")
_CONTROLLER_PASSWORD: Optional[str] = os.environ.get("BEHAVIOUR_CONTROLLER_PASSWORD")
_AWX_HOST: Optional[str] = os.environ.get("BEHAVIOUR_AWX_HOST")
_AWX_USERNAME: Optional[str] = os.environ.get("BEHAVIOUR_AWX_USERNAME")
_AWX_PASSWORD: Optional[str] = os.environ.get("BEHAVIOUR_AWX_PASSWORD")


def get_stack_url(name: str) -> str:
"""Returns the stack URL (i.e. https://example.com) that is expected to have been
created by the AWX Job Template for the AWX user."""
if not _CONTROLLER_USERNAME:
raise ValueError("BEHAVIOUR_CONTROLLER_USERNAME is not set")
return f"https://fragalysis-{_CONTROLLER_USERNAME}-{name}.xchem-dev.diamond.ac.uk"
if not _AWX_USERNAME:
raise ValueError("BEHAVIOUR_AWX_USERNAME is not set")
return f"https://fragalysis-{_AWX_USERNAME.lower()}-{name.lower()}.xchem-dev.diamond.ac.uk"


def get_stack_username() -> str:
"""Returns the AWX username - tha author of the stack."""
if not _CONTROLLER_USERNAME:
raise ValueError("BEHAVIOUR_CONTROLLER_USERNAME is not set")
return _CONTROLLER_USERNAME
if not _AWX_USERNAME:
raise ValueError("BEHAVIOUR_AWX_USERNAME is not set")
return _AWX_USERNAME


def launch_awx_job_template(template, *, extra_vars) -> None:
"""A utility to launch the named AWX JobTemplate
while also providing extra variables via a temporary file.
"""

if not _CONTROLLER_HOST:
raise ValueError("BEHAVIOUR_CONTROLLER_HOST is not set (e.g. example.com)")
if not _CONTROLLER_USERNAME:
raise ValueError("BEHAVIOUR_CONTROLLER_USERNAME is not set")
if not _CONTROLLER_PASSWORD:
raise ValueError("BEHAVIOUR_CONTROLLER_PASSWORD is not set")
if not _AWX_HOST:
raise ValueError("BEHAVIOUR_AWX_HOST is not set (e.g. example.com)")
if not _AWX_USERNAME:
raise ValueError("BEHAVIOUR_AWX_USERNAME is not set")
if not _AWX_PASSWORD:
raise ValueError("BEHAVIOUR_AWX_PASSWORD is not set")

print(f"Launching AWX JobTemplate '{template}'...")
print(f"AWX JobTemplate extra_vars={extra_vars}")

cmd = "awx job_templates launch --wait"
cmd = (
"awx job_templates launch --wait"
+ " --conf.host https://{_AWX_HOST}"
+ " --conf.username {_AWX_USERNAME}"
+ " --conf.password {_AWX_PASSWORD}"
)

# Put any extra_vars into a local temporary YAML file
fp = None
Expand All @@ -67,8 +72,6 @@ def launch_awx_job_template(template, *, extra_vars) -> None:
print(f"process.returncode: {cmd_process.returncode}")
print(f"STDOUT:\n{cmd_process.stdout}")
print(f"STDERR:\n{cmd_process.stderr}")
print(f"_CONTROLLER_HOST={_CONTROLLER_HOST}")
print(f"_CONTROLLER_USERNAME={_CONTROLLER_USERNAME}")
assert False

print(f"Successfully launched AWX JobTemplate '{template}'...")
Expand Down
2 changes: 1 addition & 1 deletion behaviour/features/steps/steps_given.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def step_impl(context, stack_name, image_tag) -> None:
# "fragalysis-alan-behaviour-xchem-dev"

stack_oidc_rp_client_id: str = (
f"fragalysis-{get_stack_username()}-{lower_stack_name}-xchem-dev"
f"fragalysis-{get_stack_username().lower()}-{lower_stack_name}-xchem-dev"
)

extra_vars: Dict[str, str] = {
Expand Down

0 comments on commit 71a3b88

Please sign in to comment.