From e2c6ed9eb1ee3cb6175611d3520f2b36c76e42d1 Mon Sep 17 00:00:00 2001 From: charlie4284 Date: Thu, 7 Mar 2024 15:53:04 +0800 Subject: [PATCH] chore: block all hooks on openstack config --- src-docs/openstack_manager.py.md | 4 ++-- src/charm.py | 29 +++++++++++++++++++++++++++++ src/openstack_manager.py | 8 +++++++- tests/integration/conftest.py | 1 + tests/integration/test_openstack.py | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src-docs/openstack_manager.py.md b/src-docs/openstack_manager.py.md index bb830c02a..cad6898a2 100644 --- a/src-docs/openstack_manager.py.md +++ b/src-docs/openstack_manager.py.md @@ -74,7 +74,7 @@ Build and upload an image to OpenStack. --- - + ## function `create_instance_config` @@ -101,7 +101,7 @@ Create an instance config from charm data. --- - + ## function `create_instance` diff --git a/src/charm.py b/src/charm.py index f995b890a..cbc04fe21 100755 --- a/src/charm.py +++ b/src/charm.py @@ -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( @@ -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) @@ -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( @@ -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) @@ -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() diff --git a/src/openstack_manager.py b/src/openstack_manager.py index ffdff4aa6..0634c0a50 100644 --- a/src/openstack_manager.py +++ b/src/openstack_manager.py @@ -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 diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 897f10f54..e9f631c94 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -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 diff --git a/tests/integration/test_openstack.py b/tests/integration/test_openstack.py index aa25df0d9..9515f53c0 100644 --- a/tests/integration/test_openstack.py +++ b/tests/integration/test_openstack.py @@ -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(