Skip to content

fix(pro): pass machine_model_uuid when disabling Ubuntu Pro - #1023

Merged
freyes merged 1 commit into
canonical:mainfrom
vsz-work:open-4916-fix-pro-disable
Nov 24, 2026
Merged

freyes merged 1 commit into
canonical:mainfrom
vsz-work:open-4916-fix-pro-disable

Conversation

@vsz-work

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

Copy link
Copy Markdown

sunbeam disable pro always fails, and the Ubuntu Pro application is never removed:

$ sunbeam disable pro
Error: terraform command failed: /snap/openstack/x1/bin/terraform apply -input=false -auto-approve -no-color -json
No value for required variable: The root module input variable "machine_model_uuid" is not set, and has no default value. Use a -var or -var-file command line argument to provide a value for this variable.

The pro plan doesn't save its Terraform variables between runs (tfvar_config=None), so update_tfvars writes terraform.tfvars.json from the current run's override_tfvars only. The enable step passes machine_model_uuid and token, but the disable step passed only the empty token. That left machine_model_uuid, which deploy-pro/variables.tf requires with no default, unset, so Terraform refused to run.

This PR makes the disable step look up the machine model UUID the same way the enable step does, and pass it along with the empty token. run_disable_plans now passes the Juju helper and the machine model to DisableUbuntuProApplicationStep.

Both the enable and disable steps now look up the model UUID inside their try block. A missing model (ModelNotFoundException) or another JujuException fails the step with its message, instead of escaping as an unhandled exception.

The disable step now also catches TerraformStateLockedException, as the enable step already did. It isn't a subclass of TerraformException, so a locked Terraform state during disable showed a traceback instead of failing the step.

Tests:

  • test_disable asserted the broken variables ({"token": ""}); it now expects machine_model_uuid as well.
  • New TestRequiredTerraformVariables reads deploy-pro/variables.tf and checks that both the enable and disable steps pass every variable without a default, so a future required variable can't break disable the same way. Its regex only handles flat variable blocks, as deploy-pro has today; the helper's docstring notes this.
  • New test_enable_model_lookup_failed and test_disable_model_lookup_failed check that each step returns FAILED, without running Terraform, when the model lookup raises ModelNotFoundException or JujuException.
  • test_disable_tf_apply_failed now also covers TerraformStateLockedException.

The same pro code is on stable/2025.1 and stable/2026.1, so disable pro is broken there too.

This fix is needed for the ubuntu-advantage → ubuntu-pro charm switch (OPEN-4793). The only supported migration path is sunbeam disable pro followed by sunbeam enable pro, which can't work while disable fails.

Related-bug: #2158218

QA steps

Automated:

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

Reproduce on the current snap (needs an Ubuntu Pro token):

  1. Bootstrap a cluster with the 2026.1/edge snap and run sunbeam enable pro <token>.
  2. Run sunbeam disable pro.
    • On 2026.1/edge (rev 1165) it fails with an empty error: Error: terraform command failed: .../terraform apply ... -json followed by a blank stderr:. Sunbeam runs Terraform with -json, which writes the error to stdout, and stable/2026.1 prints only stderr.
    • On main, where 5d3e0fc extracts the error from the JSON output, it fails with No value for required variable ... "machine_model_uuid".
    • terraform.tfvars.json in the ubuntu-pro-plan working folder contains only {"token": ""}.
    • juju status -m openstack-machines ubuntu-pro still shows the application.

Verify the fix:

  1. Install a snap built from this branch: sudo snap install --dangerous <snap>, then reconnect the interfaces as in docs/CONTRIBUTING.md.
  2. Run sunbeam disable pro.
    • The command succeeds.
    • The ubuntu-pro application and its juju-info integration with sunbeam-machine are removed. juju status -m openstack-machines --format json | jq '.applications | has("ubuntu-pro")' returns false.
  3. Run sunbeam enable pro <token>.
    • The application is deployed again and the command succeeds.

Tested

On 2026-11-10, a single-node 2026.1 cluster in an LXD VM, with pro enabled on the 2026.1/edge snap (charm ubuntu-advantage):

Snap sunbeam disable pro
2026.1/edge rev 1165 Fails, with an empty stderr:
Build of main + the ubuntu-pro charm switch, without this fix Fails: No value for required variable ... "machine_model_uuid"
The same build with this fix Succeeds. The application and its juju-info integration are removed. ubuntu-pro was already gone when the command returned, so the Terraform Juju provider waits for the removal and no extra wait is needed

A following sunbeam enable pro with the fixed build deployed the new ubuntu-pro charm and attached the machine.

Known gap, not changed here: disable doesn't detach the machine. sudo pro status still shows it attached after disable. The charm has no remove or stop handler and only runs pro detach when its token config is set to empty. This plan deletes the application instead (count = 0), so machines stay attached and keep using a seat. The fix, a detach step that empties the token and waits for every unit before Terraform removes the application, is in a follow-up PR stacked on this one: #1028.

Logs for sunbeam disable pro:
disable.log

Links

Jira card: OPEN-4916

@vsz-work
vsz-work force-pushed the open-4916-fix-pro-disable branch from c028f72 to f6bb530 Compare November 10, 2026 13:38
@hmlanigan hmlanigan self-assigned this Nov 10, 2026
@vsz-work vsz-work closed this Nov 10, 2026
@vsz-work vsz-work reopened this Nov 10, 2026
@vsz-work
vsz-work force-pushed the open-4916-fix-pro-disable branch 2 times, most recently from 48f5b9b to 38c4fe1 Compare November 10, 2026 18:27

@hmlanigan hmlanigan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but i have a question on whether this is the correct approach and follows the patterns set out by different features.

Raven-182
Raven-182 previously approved these changes Nov 10, 2026

@Raven-182 Raven-182 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM, the change makes sense given your explanation in the comments

@hmlanigan

Copy link
Copy Markdown

I'll approve once the merge conflicts are resolved.

hmlanigan
hmlanigan previously approved these changes Nov 19, 2026
Raven-182
Raven-182 previously approved these changes Nov 19, 2026
ahmad-can
ahmad-can previously approved these changes Nov 20, 2026
@hmlanigan

Copy link
Copy Markdown

@vsz-work please resolve the merge conflicts

@gboutry

gboutry commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Can you mark the comments as resolved if they are please? @vsz-work

@vsz-work
vsz-work dismissed stale reviews from ahmad-can and Raven-182 via c753f0f November 23, 2026 12:07
@vsz-work

Copy link
Copy Markdown
Author

Can you mark the comments as resolved if they are please? @vsz-work

Done. Merge conflicts with main are resolved too (rebased on top of #1032).

`sunbeam disable pro` always failed with:

  No value for required variable: The root module input variable
  "machine_model_uuid" is not set, and has no default value.

The pro plan does not persist its tfvars (tfvar_config=None), so
update_tfvars writes only the override_tfvars of the current run. The
disable step passed only the emptied token, leaving the required
machine_model_uuid unset and terraform refusing to plan. The
application was never removed.

Resolve the machine model UUID in the disable step, the same way the
enable step does, and pass it alongside the empty token.

In both steps, look the model UUID up inside the try block, so a
missing model or a Juju error fails the step instead of escaping as an
unhandled exception. Also catch TerraformStateLockedException in the
disable step, as the enable step does: it is not a TerraformException,
so a locked state showed a traceback instead of failing the step.

Update test_disable, which asserted the broken tfvars, and add
regression tests checking that both the enable and disable steps pass
every deploy-pro variable that has no default, and that both fail
cleanly when the model lookup fails.

Jira: OPEN-4916
Assisted-By: Claude Code (Claude Opus 5.5)
Related-Bug: #2158218
Signed-off-by: Vítor Zeni <vitor.zeni@bairesdev.com>
@vsz-work
vsz-work force-pushed the open-4916-fix-pro-disable branch from 47f23b5 to 51a2c8b Compare November 23, 2026 20:08

@freyes freyes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@freyes
freyes merged commit 4bcd640 into canonical:main Nov 24, 2026
8 of 9 checks passed
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.

6 participants