Skip to content

backport: feat(pro): manage the ubuntu-advantage charm from the manifest and store enable --manifest - #1039

Open
vsz-work wants to merge 2 commits into
canonical:stable/2024.1from
vsz-work:2024.1/lp2174604-pro-contract-url
Open

vsz-work wants to merge 2 commits into
canonical:stable/2024.1from
vsz-work:2024.1/lp2174604-pro-contract-url

Conversation

@vsz-work

@vsz-work vsz-work commented Nov 23, 2026 •

Copy link
Copy Markdown
Commit Cherry-picked from Change
feat(pro): set the ubuntu-advantage charm channel, revision and config from the manifest 03ffd06d Manifest passthrough for the pro charm's channel, revision and config. The CLI token always wins over a token key in the manifest
fix(pro): store the manifest passed to sunbeam enable --manifest <file> pro 63bfa2b2 enable --manifest stores the file as the latest manifest, so later enable pro runs keep the settings

Adaptations for 2024.1

stable/2024.1 still deploys the ubuntu-advantage charm. The switch to ubuntu-pro (#1020) is only on main, so the first commit doesn't apply cleanly and was adapted by hand:

  • Manifest key ubuntu-advantage, not ubuntu-pro. A new CHARM constant holds it. The Juju application is still named ubuntu-pro (APPLICATION), but manifest charm keys are charm names: sunbeam cluster refresh looks entries up by the deployed charm name (find_charm), so the key has to match the charm.
  • Tfvars: ubuntu-advantage-channel (existing), plus new ubuntu-advantage-revision and ubuntu-advantage-config.
  • Default channel latest/edge (UBUNTU_ADVANTAGE_CHANNEL), the existing default of the plan's channel variable. Main's latest/stable would silently move existing deployments to another channel on their next enable or refresh. A unit test checks that the constant and the variable default stay in sync.
  • Tests: main's TestTerraformPlan checks the ubuntu-pro charm from feat(pro): deploy the ubuntu-pro charm instead of ubuntu-advantage #1020, so it isn't included. The new TestManifestCharmConfig and TestRunEnablePlans use the 2024.1 names.

The second commit applied with only an import conflict in the tests.

Manifest example on 2024.1:

features:
  pro:
    software:
      charms:
        ubuntu-advantage:
          config:
            contract_url: https://contracts.example.com

Caveat: latest/edge → latest/stable can't be done on 2024.1

On 24.04 amd64, ubuntu-advantage latest/edge (rev 147, the 2024.1 default) is a charm format v2 build, and latest/stable (rev 143) is v1. Juju refuses v2 → v1, so a manifest that sets channel: latest/stable on a deployment running edge fails in sunbeam cluster refresh (QA B7):

Added charm-hub charm "ubuntu-advantage", revision 143 in channel latest/stable, to the model
ERROR cannot downgrade from v2 charm format to v1

The charm is left unchanged and stays attached. enable pro would most likely fail the same way, since the Juju provider issues the same refresh. Moving to stable needs a disable, then an enable with the stable channel. stable → edge works (QA B7c). This is a limit of the charm's packaging, not of this backport, but it's worth a line in the docs.

Upgrade caveat: the manifest key differs from main

Sunbeam validates the stored manifest's charm keys on every command. If a 2024.1 deployment stores a features.pro.software.charms.ubuntu-advantage entry and is later moved to a snap that only knows ubuntu-pro, every command that loads the manifest fails with Manifest Software charms keys should be one of …. Deployments that never set a pro section aren't affected. Options:

  • an upgrade note: drop or rename the pro section, e.g. with sunbeam cluster refresh --manifest <file>, before moving to a release with the ubuntu-pro charm
  • or accept ubuntu-advantage as a legacy alias on main and rename it to ubuntu-pro on load

Open to opinions. This doesn't block the backport, since 2024.1 deployments can't set a pro section today at all.

QA steps

Unit tests:

cd sunbeam-python
tox -e py3 -- tests/unit/sunbeam/features/test_pro.py
tox -e pep8 && tox -e mypy

On a 2024.1 single-node deployment, with a snap built from this branch:

sunbeam manifest show latest > base.yaml
yq -y '.features.pro.software.charms["ubuntu-advantage"].config.contract_url = "https://contracts.canonical.com/"' base.yaml > pro.yaml
sunbeam enable --manifest pro.yaml pro <token>
juju config -m openstack-machines ubuntu-pro contract_url   # https://contracts.canonical.com/

sunbeam enable pro <token>                                   # no --manifest
juju config -m openstack-machines ubuntu-pro contract_url   # still the manifest value
sudo pro status --format json | jq .attached                 # true

Tested

Check Result
Unit suite on stable/2024.1 + this branch 4423 passed. ruff format, ruff check and mypy sunbeam are clean
terraform fmt -check and terraform validate on deploy-pro Done
B1. Enable with no pro config ubuntu-advantage latest/edge rev 147, as before; tfvars ubuntu-advantage-channel: latest/edge, no -config; contract_url is the charm default
B2. contract_url from --manifest (key ubuntu-advantage) Tfvars ubuntu-advantage-config; juju config and uaclient.conf show the value; the charm re-attached; attached
B3. Re-enable without --manifest The stored manifest holds the ubuntu-advantage entry; the value is kept
B4. A token key in the manifest config Ignored: Juju holds the CLI token
B5. Option removed from the manifest contract_url back to the charm default
B6. Unknown option name enable pro fails: unknown option "contrct_url"; the unit stays active and attached
B7. cluster refresh --manifest, latest/edge → latest/stable Refresh found the entry (Running refresh for app ubuntu-pro with manifest config), but Juju refused the downgrade (see the caveat above). Charm unchanged, still attached
B7b/B7c. Redeploy on latest/stable, then cluster refresh to latest/edge Fresh deploy on latest/stable rev 143 from the manifest. Refresh with no pro section used the default entry: rev 143 → latest/edge rev 147, upgrade-charm + config-changed, no detach. CLI token kept; attached; stored manifest has no pro section
B8. enable pro after the refresh Tfvars latest/edge; Apply complete! Resources: 0 added, 0 changed, 0 destroyed; charm unchanged; attached
B10. Disable "Ubuntu Pro disabled."; no ubuntu-pro app or juju-info relation left. Needs #1023

Sunbeam VM run (2026-11-23):

B2, tfvars written by Sunbeam (token removed) and the charm's log:

{ "ubuntu-advantage-config": { "contract_url": "https://contracts.canonical.com/" }, "machine_model_uuid": "…" }
unit-ubuntu-pro-0: 16:51:01 INFO unit.ubuntu-pro/0.juju-log Updating uaclient.conf
unit-ubuntu-pro-0: 16:51:08 INFO unit.ubuntu-pro/0.juju-log Detaching ubuntu-advantage subscription
unit-ubuntu-pro-0: 16:51:22 INFO unit.ubuntu-pro/0.juju-log Attaching to new subscription with services: None

B7c, refresh from latest/stable to the default latest/edge:

{"charm":"ubuntu-advantage","channel":"latest/stable","rev":143}   # before
{"charm":"ubuntu-advantage","channel":"latest/edge","rev":147}     # after
unit-ubuntu-pro-1: 17:05:37 INFO juju.worker.uniter.operation ran "upgrade-charm" hook
unit-ubuntu-pro-1: 17:05:47 INFO juju.worker.uniter.operation ran "config-changed" hook
{"attached":true,"services":["esm-apps","esm-infra","livepatch"]}

The behaviour was tested end to end on main in #1032 (T1–T10, including sunbeam cluster refresh).

Links

Jira card: OPEN-4732

…g from the manifest

The deploy-pro plan only set the token on the ubuntu-advantage 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-advantage charm in the pro feature's default
software config, with UBUNTU_ADVANTAGE_CHANNEL (latest/edge, the
existing plan default) as its channel, and map its channel, revision
and config to new or existing plan variables, as other features do:

- ubuntu-advantage-channel (existing)
- ubuntu-advantage-revision (new, default null)
- ubuntu-advantage-config (new, map(string), default {})

Any charm option can now be set in the manifest, for example:

  features:
    pro:
      software:
        charms:
          ubuntu-advantage:
            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.

Backport notes: stable/2024.1 still deploys the ubuntu-advantage charm
(the switch to ubuntu-pro is only on main), so the manifest key,
tfvars and default channel use the ubuntu-advantage names. The new
CHARM constant holds the charm name, which differs from the ubuntu-pro
application name; refresh looks manifest entries up by charm name.
The ubuntu-pro plan tests from main are not included.

Jira: OPEN-4937
Assisted-By: Claude Code (Claude Opus 5.5)
Related-Bug: #2174604
(cherry picked from commit 03ffd06)
Signed-off-by: Vítor Zeni <vitor.zeni@bairesdev.com>
@gboutry

gboutry commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Wrong merge base I guess?

@vsz-work
vsz-work changed the base branch from main to stable/2024.1 November 23, 2026 13:48
@vsz-work

vsz-work commented Nov 23, 2026 •

Copy link
Copy Markdown
Author

Wrong merge base I guess?

Yep. Fixed it.
Still draft as I want to run tests on a live deployment
EDIT: Test evidence in PR description

@vsz-work
vsz-work marked this pull request as ready for review November 23, 2026 17:22
@vsz-work
vsz-work force-pushed the 2024.1/lp2174604-pro-contract-url branch 2 times, most recently from 3c5d965 to d294736 Compare November 24, 2026 11:55
…le> pro`

The pro feature never stored a manifest given with --manifest. The file
only applied to that one run, and a later `sunbeam enable pro <token>`
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 <vitor.zeni@bairesdev.com>
(cherry picked from commit 63bfa2b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants