Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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" {
Expand Down
1 change: 1 addition & 0 deletions sunbeam-python/sunbeam/features/pro/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
64 changes: 64 additions & 0 deletions sunbeam-python/tests/unit/sunbeam/features/test_pro.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Loading