Skip to content

Commit

Permalink
pro: honor but warn on custom ubuntu_advantage in /etc/cloud/cloud.cfg (
Browse files Browse the repository at this point in the history
canonical#5030)

Add RENAMED_MODULES to allow support for custom /etc/cloud/cloud.cfg.d/*
which may still contain the old ubuntu_advantage module name instead of
ubuntu_pro.

While the typical package upgrade path would replace ubuntu_avantage
with ubuntu_pro in /etc/cloud/cloud.cfg. It's possible a customer has
a customized /etc/cloud/cloud.cfg that they do not wish to update
with the version delivered by the cloud-init upstream package.

In cases where ubuntu_advantage is listed in system config, allow
cloud-init to WARN about the rename, but still load and run ubuntu_pro.

Fixes canonicalGH-5019
  • Loading branch information
blackboxsw authored and holmanb committed Mar 9, 2024
1 parent 9be6317 commit a0f0ec0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cloudinit/config/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"cc_rightscale_userdata", # Removed in 24.1
]

RENAMED_MODULES = {
"cc_ubuntu_advantage": "cc_ubuntu_pro", # Renamed 24.1
}


class ModuleDetails(NamedTuple):
module: ModuleType
Expand Down Expand Up @@ -190,14 +194,26 @@ def _fixup_modules(self, raw_mods) -> List[ModuleDetails]:
if not mod_name:
continue
if freq and freq not in FREQUENCIES:
LOG.warning(
"Config specified module %s has an unknown frequency %s",
raw_name,
freq,
util.deprecate(
deprecated=(
f"Config specified module {raw_name} has an unknown"
f" frequency {freq}"
),
deprecated_version="22.1",
)
# Misconfigured in /etc/cloud/cloud.cfg. Reset so cc_* module
# default meta attribute "frequency" value is used.
freq = None
if mod_name in RENAMED_MODULES:
util.deprecate(
deprecated=(
f"Module has been renamed from {mod_name} to "
f"{RENAMED_MODULES[mod_name][1]}. Update any"
" references in /etc/cloud/cloud.cfg"
),
deprecated_version="24.1",
)
mod_name = RENAMED_MODULES[mod_name]
mod_locs, looked_locs = importer.find_module(
mod_name, ["", type_utils.obj_name(config)], ["handle"]
)
Expand Down
13 changes: 13 additions & 0 deletions tests/integration_tests/modules/test_ubuntu_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ def test_valid_token(self, client: IntegrationInstance):
log = client.read_from_file("/var/log/cloud-init.log")
verify_clean_log(log)
assert is_attached(client)
client.execute("pro detach")
# Replace ubuntu_pro with previously named ubuntu_advantage
client.execute(
"sed -i 's/ubuntu_pro$/ubuntu_advantage/' /etc/cloud/cloud.cfg"
)
client.restart()
status_resp = client.execute("cloud-init status --format json")
status = json.loads(status_resp.stdout)
assert (
"Module has been renamed from cc_ubuntu_advantage to cc_ubuntu_pro"
in "\n".join(status["recoverable_errors"]["DEPRECATED"])
)
assert is_attached(client)

@pytest.mark.user_data(ATTACH.format(token=CLOUD_INIT_UA_TOKEN))
def test_idempotency(self, client: IntegrationInstance):
Expand Down

0 comments on commit a0f0ec0

Please sign in to comment.