Skip to content

Commit

Permalink
wait until workflow complete
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Apr 11, 2024
1 parent 011022e commit 0e92df9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
7 changes: 4 additions & 3 deletions tests/integration/test_charm_base_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ensure_charm_has_runner,
get_runner_name,
run_in_lxd_instance,
wait_for,
)


Expand All @@ -38,12 +39,14 @@ async def test_runner_base_image(
await model.wait_for_idle(apps=[app_no_wait.name], timeout=35 * 60)
await ensure_charm_has_runner(app_no_wait, model)

# Runner with noble base image is created
unit = app_no_wait.units[0]
runner_name = await get_runner_name(unit)
code, stdout, stderr = await run_in_lxd_instance(unit, runner_name, "lsb_release -a")
assert code == 0, f"Unable to get release name, {stdout} {stderr}"
assert "noble" in str(stdout)

# Workflow completes successfully
workflow = await dispatch_workflow(
app=app_no_wait,
branch=test_github_branch,
Expand All @@ -52,6 +55,4 @@ async def test_runner_base_image(
workflow_id_or_name=DISPATCH_E2E_TEST_RUN_WORKFLOW_FILENAME,
dispatch_input={"runner-tag": app_no_wait.name},
)

workflow_run: WorkflowRun = workflow.get_runs()[0]
assert workflow_run.status == "completed"
wait_for(lambda: workflow.get_runs()[0].status == "completed")
27 changes: 14 additions & 13 deletions tests/integration/test_openstack_base_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from openstack.compute.v2.server import Server

from charm_state import BASE_IMAGE_CONFIG_NAME
from tests.integration.helpers import DISPATCH_E2E_TEST_RUN_WORKFLOW_FILENAME, dispatch_workflow
from tests.integration.helpers import (
DISPATCH_E2E_TEST_RUN_WORKFLOW_FILENAME,
dispatch_workflow,
wait_for,
)


async def test_noble_base_image(
Expand All @@ -25,7 +29,7 @@ async def test_noble_base_image(
"""
arrange: A runner with noble as base image.
act: Dispatch a workflow.
assert: A runner should work with the different base image.
assert: A server with noble image base is created and the workflow runs successfully.
"""
await app_openstack_runner.set_config(
{
Expand All @@ -34,7 +38,13 @@ async def test_noble_base_image(
)
await model.wait_for_idle(apps=[app_openstack_runner.name], status="blocked", timeout=50 * 60)

# 1. when the e2e_test_run workflow is created.
# Server with noble base image is created
servers = openstack_connection.list_servers(detailed=True)
assert len(servers) == 1, f"Unexpected number of servers: {len(servers)}"
server: Server = servers[0]
assert "noble" in server.image.name

# Workflow completes successfully
workflow = await dispatch_workflow(
app=app_openstack_runner,
branch=test_github_branch,
Expand All @@ -43,13 +53,4 @@ async def test_noble_base_image(
workflow_id_or_name=DISPATCH_E2E_TEST_RUN_WORKFLOW_FILENAME,
dispatch_input={"runner-tag": app_openstack_runner.name},
)
# 1. the workflow run completes successfully.
workflow_run: WorkflowRun = workflow.get_runs()[0]
assert workflow_run.status == "completed"

# 2. when the servers are listed.
servers = openstack_connection.list_servers(detailed=True)
assert len(servers) == 1, f"Unexpected number of servers: {len(servers)}"
server: Server = servers[0]
# 2. a server with image name containing noble is created.
assert "noble" in server.image.name
wait_for(lambda: workflow.get_runs()[0].status == "completed")

0 comments on commit 0e92df9

Please sign in to comment.