-
Notifications
You must be signed in to change notification settings - Fork 36
fix: skip non-HA cinder-volume deploy when HA app exists #797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| ) | ||
| from sunbeam.core.deployment import Deployment, Networks | ||
| from sunbeam.core.juju import ( | ||
| ApplicationNotFoundException, | ||
| ControllerNotFoundException, | ||
| ControllerNotReachableException, | ||
| JujuException, | ||
|
|
@@ -424,6 +425,29 @@ def run(self, context: StepContext) -> Result: | |
| self.backend_name, | ||
| validated_config, | ||
| ) | ||
|
|
||
| # If the HA cinder-volume application exists and this backend is | ||
| # non-HA, override the principal_application so the backend | ||
| # subordinates to the existing HA app. | ||
| actual_principal = self.backend_instance.principal_application | ||
| if actual_principal != APPLICATION: | ||
| try: | ||
| self.jhelper.get_application(APPLICATION, self.model) | ||
| LOG.debug( | ||
| f"Overriding principal application for backend" | ||
| f" {self.backend_name!r} from" | ||
| f" {actual_principal!r} to {APPLICATION!r}" | ||
| ) | ||
| backends[backend_key]["principal_application"] = APPLICATION | ||
| actual_principal = APPLICATION | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add log to mention the principal is overrided
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| except ApplicationNotFoundException: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to handle JujuException here.. its done in other class
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| pass | ||
|
ahmad-can marked this conversation as resolved.
|
||
| except JujuException as e: | ||
| LOG.debug( | ||
| f"Unable to confirm whether HA {APPLICATION} exists" | ||
| f" for backend {self.backend_name!r}: {e}" | ||
| ) | ||
|
|
||
| try: | ||
| # Update Terraform variables and apply with merged map | ||
| self.tfhelper.update_tfvars_and_apply_tf( | ||
|
|
@@ -447,7 +471,7 @@ def run(self, context: StepContext) -> Result: | |
| "name": self.backend_name, | ||
| "backend_type": self.backend_instance.backend_type, | ||
| "config": validated_config.model_dump(exclude_none=True, by_alias=True), | ||
| "principal": self.backend_instance.principal_application, | ||
| "principal": actual_principal, | ||
| "model_uuid": model["model-uuid"], | ||
| } | ||
| try: | ||
|
|
@@ -663,6 +687,34 @@ def is_skip(self, context: StepContext) -> Result: | |
| " skipping specific cinder-volume deployment.", | ||
| ) | ||
|
|
||
| # Skip deploying non-HA cinder-volume if the HA cinder-volume | ||
| # application already exists in the model. Non-HA backends should | ||
| # subordinate to the existing HA application instead. | ||
| try: | ||
| self.jhelper.get_application(APPLICATION, self.model) | ||
| LOG.debug( | ||
| "HA cinder-volume application already exists in model %r;" | ||
| " skipping non-HA cinder-volume deployment for backend %r.", | ||
| self.model, | ||
| self.backend_name, | ||
| ) | ||
| return Result( | ||
| ResultType.SKIPPED, | ||
| f"HA {APPLICATION} already exists in model {self.model!r};" | ||
| f" backend {self.backend_name} will use the existing application.", | ||
| ) | ||
| except ApplicationNotFoundException: | ||
| pass | ||
|
ahmad-can marked this conversation as resolved.
|
||
| except JujuException as exc: | ||
| LOG.debug( | ||
| "Unable to confirm whether HA %s exists in model %r for backend %r;" | ||
| " proceeding with specific cinder-volume deployment: %s", | ||
| APPLICATION, | ||
| self.model, | ||
| self.backend_name, | ||
| exc, | ||
| ) | ||
|
|
||
| return Result(ResultType.COMPLETED) | ||
|
|
||
| def _get_offers(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,9 @@ | |
|
|
||
| import pytest | ||
|
|
||
| from sunbeam.core.common import ResultType | ||
| from sunbeam.steps.cinder_volume import ( | ||
| APPLICATION, | ||
| CINDER_VOLUME_APP_TIMEOUT, | ||
| CINDER_VOLUME_UNIT_TIMEOUT, | ||
| DeployCinderVolumeApplicationStep, | ||
|
|
@@ -337,6 +339,53 @@ def test_extra_tfvars_telemetry_feature_disabled( | |
| deployment_with_tfhelpers, "telemetry" | ||
| ) | ||
|
|
||
| def test_is_skip_no_backends_proceeds( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add test where there is HA and non-HA backend exists
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| self, deploy_cinder_volume_step, basic_client, step_context | ||
| ): | ||
| basic_client.cluster.get_storage_backends.return_value = Mock(root=[]) | ||
| result = deploy_cinder_volume_step.is_skip(step_context) | ||
| assert result.result_type == ResultType.COMPLETED | ||
|
|
||
| def test_is_skip_all_non_ha_backends_skips( | ||
| self, deploy_cinder_volume_step, basic_client, step_context | ||
| ): | ||
| non_ha_backend = Mock(principal="cinder-volume-noha") | ||
| basic_client.cluster.get_storage_backends.return_value = Mock( | ||
| root=[non_ha_backend] | ||
| ) | ||
| result = deploy_cinder_volume_step.is_skip(step_context) | ||
| assert result.result_type == ResultType.SKIPPED | ||
|
|
||
| def test_is_skip_ha_backend_exists_proceeds( | ||
| self, deploy_cinder_volume_step, basic_client, step_context | ||
| ): | ||
| ha_backend = Mock(principal=APPLICATION) | ||
| basic_client.cluster.get_storage_backends.return_value = Mock(root=[ha_backend]) | ||
| result = deploy_cinder_volume_step.is_skip(step_context) | ||
| assert result.result_type == ResultType.COMPLETED | ||
|
|
||
| def test_is_skip_mixed_ha_and_non_ha_backends_proceeds( | ||
| self, deploy_cinder_volume_step, basic_client, step_context | ||
| ): | ||
| ha_backend = Mock(principal=APPLICATION) | ||
| non_ha_backend = Mock(principal="cinder-volume-noha") | ||
| basic_client.cluster.get_storage_backends.return_value = Mock( | ||
| root=[ha_backend, non_ha_backend] | ||
| ) | ||
| result = deploy_cinder_volume_step.is_skip(step_context) | ||
| assert result.result_type == ResultType.COMPLETED | ||
|
|
||
| def test_is_skip_exception_proceeds( | ||
| self, deploy_cinder_volume_step, basic_client, step_context | ||
| ): | ||
| from sunbeam.clusterd.service import ClusterServiceUnavailableException | ||
|
|
||
| basic_client.cluster.get_storage_backends.side_effect = ( | ||
| ClusterServiceUnavailableException("err") | ||
| ) | ||
| result = deploy_cinder_volume_step.is_skip(step_context) | ||
| assert result.result_type == ResultType.COMPLETED | ||
|
|
||
|
|
||
| class TestRemoveCinderVolumeUnitsStep: | ||
| @pytest.fixture | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.