Skip to content

Commit

Permalink
chore: block all hooks on openstack config
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Mar 7, 2024
1 parent 4916391 commit e2c6ed9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src-docs/openstack_manager.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Build and upload an image to OpenStack.

---

<a href="../src/openstack_manager.py#L175"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/openstack_manager.py#L181"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_instance_config`

Expand All @@ -101,7 +101,7 @@ Create an instance config from charm data.

---

<a href="../src/openstack_manager.py#L205"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/openstack_manager.py#L211"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_instance`

Expand Down
29 changes: 29 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ def _on_start(self, _event: StartEvent) -> None:
event: Event of starting the charm.
"""
state = self._setup_state()

if state.charm_config.openstack_clouds_yaml:
# Test out openstack integration and then go
# into BlockedStatus as it is not supported yet
self.unit.status = BlockedStatus(
"OpenStack integration is not supported yet. "
"Please remove the openstack-clouds-yaml config."
)
return

runner_manager = self._get_runner_manager(state)

self._check_and_update_dependencies(
Expand Down Expand Up @@ -532,6 +542,15 @@ def _on_config_changed(self, _event: ConfigChangedEvent) -> None:
state = self._setup_state()
self._set_reconcile_timer()

if state.charm_config.openstack_clouds_yaml:
# Test out openstack integration and then go
# into BlockedStatus as it is not supported yet
self.unit.status = BlockedStatus(
"OpenStack integration is not supported yet. "
"Please remove the openstack-clouds-yaml config."
)
return

prev_config_for_flush: dict[str, str] = {}
if state.charm_config.token != self._stored.token:
prev_config_for_flush["token"] = str(self._stored.token)
Expand Down Expand Up @@ -630,6 +649,11 @@ def _on_reconcile_runners(self, _event: ReconcileRunnersEvent) -> None:
event: Event of reconciling the runner state.
"""
state = self._setup_state()

if state.charm_config.openstack_clouds_yaml:
logger.warning("OpenStack integration is not supported yet. Skipping reconcile.")
return

runner_manager = self._get_runner_manager(state)

self._check_and_update_dependencies(
Expand Down Expand Up @@ -755,6 +779,10 @@ def _on_stop(self, _: StopEvent) -> None:
self._event_timer.disable_event_timer("reconcile-runners")

state = self._setup_state()

if state.charm_config.openstack_clouds_yaml:
return

runner_manager = self._get_runner_manager(state)
runner_manager.flush(FlushMode.FLUSH_BUSY)

Expand All @@ -771,6 +799,7 @@ def _reconcile_runners(
Returns:
Changes in runner number due to reconciling runners.
"""

if not RunnerManager.runner_bin_path.is_file():
logger.warning("Unable to reconcile due to missing runner binary")
raise MissingRunnerBinaryError()
Expand Down
8 changes: 7 additions & 1 deletion src/openstack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,14 @@ def build_image(
try:
conn = _create_connection(cloud_config)
arch = "amd64" if runner_application["architecture"] == "x64" else "arm64"
for existing_image in conn.search_images(name_or_id=IMAGE_NAME):
existing_image: openstack.image.v2.image.Image
# images with same name (different ID) can be created and will error during server
# instantiation.
if not conn.delete_image(name_or_id=existing_image.id, wait=True):
raise ImageBuildError("Failed to delete duplicate image on Openstack.")
return conn.create_image(
name=IMAGE_NAME, filename=IMAGE_PATH_TMPL.format(architecture=arch)
name=IMAGE_NAME, filename=IMAGE_PATH_TMPL.format(architecture=arch), wait=True
)
except OpenStackCloudException as exc:
raise ImageBuildError("Failed to upload image.") from exc
Expand Down
1 change: 1 addition & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ async def app_openstack_runner(
"virt-type": "virtual-machine",
},
config={OPENSTACK_CLOUDS_YAML_CONFIG_NAME: openstack_clouds_yaml},
wait_idle=False,
)
return application

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def test_openstack_integration(
1. the workflow run completes successfully.
2. a server with image name jammy is created.
"""
await model.wait_for_idle(apps=[app_openstack_runner.name], timeout=30 * 60)
await model.wait_for_idle(apps=[app_openstack_runner.name], status="blocked", timeout=40 * 60)

# 1. when the e2e_test_run workflow is created.
workflow = await dispatch_workflow(
Expand Down

0 comments on commit e2c6ed9

Please sign in to comment.