Skip to content

Commit

Permalink
test: trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Jan 18, 2024
1 parent 6d99d8d commit 0e07706
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,7 @@ def _on_debug_ssh_relation_changed(self, _: ops.RelationChangedEvent) -> None:
"""Handle debug ssh relation changed event."""
runner_manager = self._get_runner_manager()
runner_manager.flush(flush_busy=False)
self._reconcile_runners(runner_manager)


if __name__ == "__main__":
Expand Down
27 changes: 25 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
reconcile,
wait_for,
)
from tests.status_name import ACTIVE


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -250,12 +251,34 @@ async def app_runner(

@pytest_asyncio.fixture(scope="module", name="tmate_ssh_server_app")
async def tmate_ssh_server_app_fixture(
model: Model, app: Application
model: Model,
charm_file: str,
app_name: str,
path: str,
token: str,
http_proxy: str,
https_proxy: str,
no_proxy: str,
) -> AsyncIterator[Application]:
"""tmate-ssh-server charm application related to GitHub-Runner app charm."""
# 5 min reconcile period to register flushed runners after relation data changed event.
app: Application = await deploy_github_runner_charm(
model=model,
charm_file=charm_file,
app_name=app_name,
path=path,
token=token,
runner_storage="memory",
http_proxy=http_proxy,
https_proxy=https_proxy,
no_proxy=no_proxy,
reconcile_interval=60,
wait_idle=False,
)
await app.set_config({"virtual-machines": "1"})
tmate_app: Application = await model.deploy("tmate-ssh-server", channel="edge")
await app.relate("debug-ssh", f"{tmate_app.name}:debug-ssh")
await model.wait_for_idle(raise_on_error=False, timeout=60 * 30)
await model.wait_for_idle(status=ACTIVE, timeout=60 * 30)

return tmate_app

Expand Down
6 changes: 5 additions & 1 deletion tests/integration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ async def deploy_github_runner_charm(
https_proxy: str,
no_proxy: str,
reconcile_interval: int,
wait_idle: bool = True,
) -> Application:
"""Deploy github-runner charm.
Expand All @@ -320,6 +321,7 @@ async def deploy_github_runner_charm(
https_proxy: HTTPS proxy for the application to use.
no_proxy: No proxy configuration for the application.
reconcile_interval: Time between reconcile for the application.
wait_idle: wait for model to become idle.
"""
subprocess.run(["sudo", "modprobe", "br_netfilter"])

Expand Down Expand Up @@ -353,7 +355,9 @@ async def deploy_github_runner_charm(
storage=storage,
)

await model.wait_for_idle(status=ACTIVE, timeout=60 * 30)
if wait_idle:
await model.wait_for_idle(status=ACTIVE, timeout=60 * 30)

return application


Expand Down
6 changes: 6 additions & 0 deletions tests/integration/test_debug_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See LICENSE file for licensing details.

"""Integration tests for github-runner charm with ssh-debug integration."""
import logging
import typing
import zipfile
from io import BytesIO
Expand All @@ -14,6 +15,8 @@

from tests.integration.helpers import wait_for

logger = logging.getLogger(__name__)


async def test_ssh_debug(
github_repository: Repository,
Expand All @@ -28,6 +31,7 @@ async def test_ssh_debug(
assert: the ssh connection info from action-log and tmate-ssh-server matches.
"""
# trigger tmate action
logger.info("Dispatching workflow_dispatch_ssh_debug.yaml workflow.")
workflow: Workflow = github_repository.get_workflow("workflow_dispatch_ssh_debug.yaml")
assert workflow.create_dispatch(
test_github_branch, inputs={"runner": app_name}
Expand All @@ -37,6 +41,7 @@ async def test_ssh_debug(
def latest_workflow_run() -> typing.Optional[WorkflowRun]:
"""Get latest workflow run."""
try:
logger.info("Fetching latest workflow run on branch %s.", test_github_branch.name)
# The test branch is unique per test, hence there can only be one run per branch.
last_run: WorkflowRun = workflow.get_runs(branch=test_github_branch)[0]
except IndexError:
Expand All @@ -49,6 +54,7 @@ def latest_workflow_run() -> typing.Optional[WorkflowRun]:
def is_workflow_complete():
"""Return if the workflow is complete."""
lastest_run.update()
logger.info("Fetched latest workflow status %s.", lastest_run.status)
return lastest_run.status == "completed"

await wait_for(is_workflow_complete, timeout=60 * 45, check_interval=60)
Expand Down

0 comments on commit 0e07706

Please sign in to comment.