From 03ffd06da1e45ad4a229338fc5584bd69ca2dbae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Zeni?= Date: Wed, 18 Nov 2026 09:56:39 -0300 Subject: [PATCH 1/2] feat(pro): set the ubuntu-pro charm channel, revision and config from the manifest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The deploy-pro plan only set the token on the ubuntu-pro charm, so contract_url and the other charm options kept their defaults. The only way to change them was a manual `juju config`, which Sunbeam does not own and can lose on a later apply or redeploy. Register the ubuntu-pro charm in the pro feature's default software config, with UBUNTU_PRO_CHANNEL as its channel, and map its channel, revision and config to new or existing plan variables, as other features do: - ubuntu-pro-channel (existing) - ubuntu-pro-revision (new, default null) - ubuntu-pro-config (new, map(string), default {}) Any charm option can now be set in the manifest, for example: features: pro: software: charms: ubuntu-pro: config: contract_url: https://contracts.example.com The plan merges the manifest config under the token passed on the command line, so the CLI token always wins over a token key in the manifest. Jira: OPEN-4937 Assisted-By: Claude Code (Claude Opus 5.5) Related-Bug: #2174604 Signed-off-by: Vítor Zeni --- .../features/pro/etc/deploy-pro/main.tf | 12 +-- .../features/pro/etc/deploy-pro/variables.tf | 12 +++ .../sunbeam/features/pro/feature.py | 18 ++++- .../tests/unit/sunbeam/features/test_pro.py | 76 ++++++++++++++++++- 4 files changed, 111 insertions(+), 7 deletions(-) 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 86cdb2c39..c9023b0be 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf @@ -22,14 +22,16 @@ resource "juju_application" "ubuntu_pro" { model_uuid = data.juju_model.machine_model.uuid charm { - name = "ubuntu-pro" - channel = var.ubuntu-pro-channel - base = "ubuntu@24.04" + name = "ubuntu-pro" + channel = var.ubuntu-pro-channel + revision = var.ubuntu-pro-revision + base = "ubuntu@24.04" } - config = { + # The token from the CLI always wins over a token key in the manifest config. + config = merge(var.ubuntu-pro-config, { token = var.token - } + }) } resource "juju_integration" "juju_info" { 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 c9425d59a..fcf8a3770 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf @@ -7,6 +7,18 @@ variable "ubuntu-pro-channel" { default = "latest/stable" } +variable "ubuntu-pro-revision" { + description = "Revision number of ubuntu-pro charm" + type = number + default = null +} + +variable "ubuntu-pro-config" { + description = "Config options of the ubuntu-pro charm, such as contract_url" + type = map(string) + default = {} +} + variable "machine_model_uuid" { description = "UUID of Juju model to deploy ubuntu-pro into" type = string diff --git a/sunbeam-python/sunbeam/features/pro/feature.py b/sunbeam-python/sunbeam/features/pro/feature.py index a7df18382..c013f7458 100644 --- a/sunbeam-python/sunbeam/features/pro/feature.py +++ b/sunbeam-python/sunbeam/features/pro/feature.py @@ -18,6 +18,7 @@ from sunbeam.core.deployment import Deployment from sunbeam.core.juju import JujuHelper, JujuStepHelper from sunbeam.core.manifest import ( + CharmManifest, FeatureConfig, Manifest, SoftwareConfig, @@ -198,13 +199,28 @@ def manifest(self) -> Manifest: def default_software_overrides(self) -> SoftwareConfig: """Feature software configuration.""" return SoftwareConfig( + charms={APPLICATION: CharmManifest(channel=UBUNTU_PRO_CHANNEL)}, terraform={ self.tfplan: TerraformManifest( source=Path(__file__).parent / "etc" / self.tfplan_dir ) - } + }, ) + def manifest_attributes_tfvar_map(self) -> dict: + """Manifest attributes terraformvars map.""" + return { + self.tfplan: { + "charms": { + APPLICATION: { + "channel": "ubuntu-pro-channel", + "revision": "ubuntu-pro-revision", + "config": "ubuntu-pro-config", + } + } + } + } + def run_enable_plans( self, deployment: Deployment, config: ProFeatureConfig, show_hints: bool ): diff --git a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py index 9ea16bb48..6fdb4a8c1 100644 --- a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py +++ b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py @@ -6,9 +6,14 @@ from unittest.mock import Mock import pytest +import yaml from sunbeam.core.common import ResultType -from sunbeam.core.terraform import TerraformException +from sunbeam.core.manifest import FeatureManifest, Manifest +from sunbeam.core.terraform import ( + TerraformException, + TerraformHelper, +) from sunbeam.features.pro import feature as pro_feature from sunbeam.features.pro.feature import ( DisableUbuntuProApplicationStep, @@ -190,3 +195,72 @@ def test_channel_default_matches_feature_constant(self): ) assert match, "no default found for ubuntu-pro-channel in variables.tf" assert match.group(1) == pro_feature.UBUNTU_PRO_CHANNEL + + +class TestManifestCharmConfig: + """Charm options such as contract_url can be set via the manifest.""" + + _MANIFEST = """ +features: + pro: + software: + charms: + ubuntu-pro: + revision: 46 + config: + contract_url: https://contracts.example.com +""" + + def _variables(self) -> str: + plan_dir = Path(pro_feature.__file__).parent / "etc" / "deploy-pro" + return (plan_dir / "variables.tf").read_text() + + def test_default_software_registers_charm(self): + feature = pro_feature.ProFeature() + charms = feature.default_software_overrides().charms + assert charms[pro_feature.APPLICATION].channel == ( + pro_feature.UBUNTU_PRO_CHANNEL + ) + + def test_tfvar_map_matches_plan_variables(self): + feature = pro_feature.ProFeature() + tfvar_map = feature.manifest_attributes_tfvar_map()[feature.tfplan] + variables = self._variables() + for tfvar in tfvar_map["charms"][pro_feature.APPLICATION].values(): + assert f'variable "{tfvar}"' in variables, tfvar + + def test_manifest_config_becomes_tfvar(self, tmp_path): + feature = pro_feature.ProFeature() + default = Manifest( + features={ + feature.name: FeatureManifest( + software=feature.default_software_overrides() + ) + } + ) + override = Manifest.model_validate(yaml.safe_load(self._MANIFEST)) + override.validate_against_default(default) + tfhelper = TerraformHelper( + path=tmp_path, + plan=feature.tfplan, + tfvar_map=feature.manifest_attributes_tfvar_map()[feature.tfplan], + ) + + tfvars = tfhelper._get_tfvars(default.merge(override)) + + # A user charm entry replaces the default one, so the channel falls + # back to the variable default in variables.tf. + assert tfvars == { + "ubuntu-pro-revision": 46, + "ubuntu-pro-config": {"contract_url": "https://contracts.example.com"}, + } + + def test_cli_token_wins_over_manifest_config(self): + text = ( + Path(pro_feature.__file__).parent / "etc" / "deploy-pro" / "main.tf" + ).read_text() + assert re.search( + r"config\s*=\s*merge\(\s*var\.ubuntu-pro-config\s*,\s*\{\s*" + r"token\s*=\s*var\.token", + text, + ) From 63bfa2b2badbd267f6256ad971bf51f0e1072d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Zeni?= Date: Wed, 18 Nov 2026 09:56:46 -0300 Subject: [PATCH 2/2] fix(pro): store the manifest passed to `sunbeam enable --manifest pro` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pro feature never stored a manifest given with --manifest. The file only applied to that one run, and a later `sunbeam enable pro ` read the latest manifest from clusterd, fell back to an empty charm config and dropped options such as contract_url again. Start the enable plan with AddManifestStep when --manifest is given, as the OpenStack features and telemetry already do. Like for those features, the file is stored as the whole latest manifest, so it should be a full manifest (e.g. from `sunbeam manifest show latest`) with the pro section added, not a pro-only file. Without --manifest the plan is unchanged. Jira: OPEN-4937 Assisted-By: Claude Code (Claude Opus 5.5) Closes-Bug: #2174604 Signed-off-by: Vítor Zeni --- .../sunbeam/features/pro/feature.py | 30 ++++++++----- .../tests/unit/sunbeam/features/test_pro.py | 42 ++++++++++++++++++- 2 files changed, 60 insertions(+), 12 deletions(-) diff --git a/sunbeam-python/sunbeam/features/pro/feature.py b/sunbeam-python/sunbeam/features/pro/feature.py index c013f7458..caaa290ca 100644 --- a/sunbeam-python/sunbeam/features/pro/feature.py +++ b/sunbeam-python/sunbeam/features/pro/feature.py @@ -18,6 +18,7 @@ from sunbeam.core.deployment import Deployment from sunbeam.core.juju import JujuHelper, JujuStepHelper from sunbeam.core.manifest import ( + AddManifestStep, CharmManifest, FeatureConfig, Manifest, @@ -227,17 +228,24 @@ def run_enable_plans( """Run the enablement plans.""" tfhelper = deployment.get_tfhelper(self.tfplan) jhelper = JujuHelper(deployment.juju_controller) - plan = [ - TerraformInitStep(tfhelper), - EnableUbuntuProApplicationStep( - deployment.get_client(), - tfhelper, - jhelper, - self.manifest, - config.token, - deployment.openstack_machines_model, - ), - ] + plan: list[BaseStep] = [] + # Store the manifest so later applies, e.g. a re-run of enable + # without --manifest, keep the charm config it sets. + if self.user_manifest: + plan.append(AddManifestStep(deployment.get_client(), self.user_manifest)) + plan.extend( + [ + TerraformInitStep(tfhelper), + EnableUbuntuProApplicationStep( + deployment.get_client(), + tfhelper, + jhelper, + self.manifest, + config.token, + deployment.openstack_machines_model, + ), + ] + ) run_plan(plan, console, show_hints) diff --git a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py index 6fdb4a8c1..6aa37084b 100644 --- a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py +++ b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py @@ -9,10 +9,11 @@ import yaml from sunbeam.core.common import ResultType -from sunbeam.core.manifest import FeatureManifest, Manifest +from sunbeam.core.manifest import AddManifestStep, FeatureManifest, Manifest from sunbeam.core.terraform import ( TerraformException, TerraformHelper, + TerraformInitStep, ) from sunbeam.features.pro import feature as pro_feature from sunbeam.features.pro.feature import ( @@ -264,3 +265,42 @@ def test_cli_token_wins_over_manifest_config(self): r"token\s*=\s*var\.token", text, ) + + +class TestRunEnablePlans: + """enable --manifest must store the manifest so later applies keep it.""" + + @pytest.fixture + def run_plan(self, mocker): + mocker.patch.object(pro_feature, "JujuHelper") + mocker.patch.object(pro_feature.click, "echo") + return mocker.patch.object(pro_feature, "run_plan") + + def _run(self, user_manifest): + feature = pro_feature.ProFeature() + feature.user_manifest = user_manifest + feature._manifest = Mock() + feature.run_enable_plans( + Mock(), pro_feature.ProFeatureConfig(token="t"), show_hints=False + ) + + def test_user_manifest_is_stored_first(self, run_plan, tmp_path): + manifest_file = tmp_path / "manifest.yaml" + self._run(manifest_file) + + plan = run_plan.call_args.args[0] + assert [type(step) for step in plan] == [ + AddManifestStep, + TerraformInitStep, + EnableUbuntuProApplicationStep, + ] + assert plan[0].manifest_file == manifest_file + + def test_no_user_manifest_stores_nothing(self, run_plan): + self._run(None) + + plan = run_plan.call_args.args[0] + assert [type(step) for step in plan] == [ + TerraformInitStep, + EnableUbuntuProApplicationStep, + ]