Skip to content

Commit

Permalink
forgotten code back
Browse files Browse the repository at this point in the history
This reverts commit d730cbf.
  • Loading branch information
javierdelapuente committed Dec 16, 2024
1 parent d730cbf commit 19e7cf2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,25 +472,23 @@ def _on_reconcile_runners_action(self, event: ActionEvent) -> None:
self.unit.status = MaintenanceStatus("Reconciling runners")
state = self._setup_state()

if state.instance_type == InstanceType.OPENSTACK:
if not self._get_set_image_ready_status():
event.fail("Openstack image not yet provided/ready.")
return
runner_scaler = self._get_runner_scaler(state)

self.unit.status = MaintenanceStatus("Reconciling runners")
try:
delta = runner_scaler.reconcile(state.runner_config.virtual_machines)
except ReconcileError:
logger.exception(FAILED_TO_RECONCILE_RUNNERS_MSG)
self.unit.status = ActiveStatus(ACTIVE_STATUS_RECONCILIATION_FAILED_MSG)
event.fail(FAILED_RECONCILE_ACTION_ERR_MSG)
return
if not self._get_set_image_ready_status():
event.fail("Openstack image not yet provided/ready.")
return
runner_scaler = self._get_runner_scaler(state)

self.unit.status = ActiveStatus()
event.set_results({"delta": {"virtual-machines": delta}})
self.unit.status = MaintenanceStatus("Reconciling runners")
try:
delta = runner_scaler.reconcile(state.runner_config.virtual_machines)
except ReconcileError:
logger.exception(FAILED_TO_RECONCILE_RUNNERS_MSG)
self.unit.status = ActiveStatus(ACTIVE_STATUS_RECONCILIATION_FAILED_MSG)
event.fail(FAILED_RECONCILE_ACTION_ERR_MSG)
return

self.unit.status = ActiveStatus()
event.set_results({"delta": {"virtual-machines": delta}})

@catch_action_errors
def _on_flush_runners_action(self, event: ActionEvent) -> None:
"""Handle the action of flushing all runner and reconciling afterwards.
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/test_charm_metrics_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"""Integration tests for metrics/logs assuming Github workflow failures or a runner crash."""
import time
from asyncio import sleep
from typing import AsyncIterator

import pytest
import pytest_asyncio
from github.Branch import Branch
from github.Repository import Repository
from github_runner_manager.metrics.runner import PostJobStatus
Expand All @@ -30,6 +32,28 @@
from tests.integration.helpers.openstack import OpenStackInstanceHelper, setup_repo_policy


@pytest_asyncio.fixture(scope="function", name="app")
async def app_fixture(
model: Model, app_for_metric: Application, loop_device: str
) -> AsyncIterator[Application]:
"""Setup and teardown the charm after each test.
Clear the metrics log before each test.
"""
unit = app_for_metric.units[0]
await clear_metrics_log(unit)
await app_for_metric.set_config(
{
VIRTUAL_MACHINES_CONFIG_NAME: "0",
"repo-policy-compliance-token": "",
"repo-policy-compliance-url": "",
}
)
await reconcile(app=app_for_metric, model=model)

yield app_for_metric


@pytest.mark.openstack
@pytest.mark.asyncio
@pytest.mark.abort_on_fail
Expand Down

0 comments on commit 19e7cf2

Please sign in to comment.