diff --git a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf index d962d8005..86cdb2c39 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf @@ -22,8 +22,8 @@ resource "juju_application" "ubuntu_pro" { model_uuid = data.juju_model.machine_model.uuid charm { - name = "ubuntu-advantage" - channel = var.ubuntu-advantage-channel + name = "ubuntu-pro" + channel = var.ubuntu-pro-channel base = "ubuntu@24.04" } diff --git a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf index 2cfea3cb5..c9425d59a 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf @@ -1,10 +1,10 @@ # SPDX-FileCopyrightText: 2023 - Canonical Ltd # SPDX-License-Identifier: Apache-2.0 -variable "ubuntu-advantage-channel" { - description = "Channel to use for deployment of ubuntu-advantage charm" +variable "ubuntu-pro-channel" { + description = "Channel to use for deployment of ubuntu-pro charm" type = string - default = "latest/edge" + default = "latest/stable" } variable "machine_model_uuid" { diff --git a/sunbeam-python/sunbeam/features/pro/feature.py b/sunbeam-python/sunbeam/features/pro/feature.py index f76398936..a7df18382 100644 --- a/sunbeam-python/sunbeam/features/pro/feature.py +++ b/sunbeam-python/sunbeam/features/pro/feature.py @@ -39,6 +39,7 @@ console = Console() APPLICATION = "ubuntu-pro" +UBUNTU_PRO_CHANNEL = "latest/stable" APP_TIMEOUT = 300 # 5 minutes, managing the application should be fast UNIT_TIMEOUT = 1200 # 15 minutes, adding / removing units can take a long time diff --git a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py index c3d765f61..9ea16bb48 100644 --- a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py +++ b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py @@ -1,11 +1,15 @@ # SPDX-FileCopyrightText: 2023 - Canonical Ltd # SPDX-License-Identifier: Apache-2.0 +import re +from pathlib import Path +from unittest.mock import Mock import pytest from sunbeam.core.common import ResultType from sunbeam.core.terraform import TerraformException +from sunbeam.features.pro import feature as pro_feature from sunbeam.features.pro.feature import ( DisableUbuntuProApplicationStep, EnableUbuntuProApplicationStep, @@ -87,6 +91,39 @@ def test_enable_waiting_timed_out(self, enable_step, basic_jhelper, step_context assert result.result_type == ResultType.FAILED assert result.message == "timed out" + def test_enable_blocked_reports_stderr( + self, enable_step, basic_jhelper, step_context + ): + # Message format of ProcessExecutionError raised by the ubuntu-pro charm + # when attaching the subscription fails. + basic_jhelper.get_application.return_value = Mock( + app_status=Mock( + current="blocked", + message=( + "Failed running command 'pro attach' [exit status: 1].\n" + "stderr: Invalid token\n" + "stdout: " + ), + ) + ) + + result = enable_step.run(step_context) + + assert result.result_type == ResultType.FAILED + assert result.message.strip() == "Invalid token" + + def test_enable_blocked_without_stderr( + self, enable_step, basic_jhelper, step_context + ): + basic_jhelper.get_application.return_value = Mock( + app_status=Mock(current="blocked", message="No token configured") + ) + + result = enable_step.run(step_context) + + assert result.result_type == ResultType.FAILED + assert result.message == "No token configured" + class TestDisableUbuntuProApplicationStep: @pytest.fixture @@ -126,3 +163,30 @@ def test_disable_tf_apply_failed(self, disable_step, basic_tfhelper, step_contex basic_tfhelper.update_tfvars_and_apply_tf.assert_called_once() assert result.result_type == ResultType.FAILED assert result.message == "apply failed..." + + +class TestTerraformPlan: + """The deploy-pro plan must deploy the ubuntu-pro charm.""" + + def _plan_dir(self) -> Path: + return Path(pro_feature.__file__).parent / "etc" / "deploy-pro" + + def test_deploys_ubuntu_pro_charm(self): + text = (self._plan_dir() / "main.tf").read_text() + match = re.search(r'charm\s*\{[^}]*?name\s*=\s*"([^"]+)"', text, re.DOTALL) + assert match, "no charm block found in main.tf" + assert match.group(1) == "ubuntu-pro" + + def test_no_ubuntu_advantage_references(self): + for tf_file in self._plan_dir().glob("*.tf"): + assert "ubuntu-advantage" not in tf_file.read_text(), tf_file.name + + def test_channel_default_matches_feature_constant(self): + text = (self._plan_dir() / "variables.tf").read_text() + match = re.search( + r'variable\s+"ubuntu-pro-channel"\s*\{[^}]*?default\s*=\s*"([^"]+)"', + text, + re.DOTALL, + ) + assert match, "no default found for ubuntu-pro-channel in variables.tf" + assert match.group(1) == pro_feature.UBUNTU_PRO_CHANNEL