Skip to content

Commit

Permalink
cloud-init: check for cloud-init-base package also
Browse files Browse the repository at this point in the history
In the future, cloud-init will be available in a more minimal
`cloud-init-base` package, which is expected to provide the
functionality we expect.  Version check that one, if present, along with
the existing `cloud-init` package.
  • Loading branch information
dbungert committed Oct 4, 2024
1 parent c56f96a commit a348c8b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 8 additions & 5 deletions subiquity/cloudinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ def get_host_combined_cloud_config() -> dict:

def cloud_init_version() -> str:
# looks like 24.1~3gb729a4c4-0ubuntu1
cmd = ["dpkg-query", "-W", "-f=${Version}", "cloud-init"]
sp = run_command(cmd, check=False)
version = re.split("[-~]", sp.stdout)[0]
log.debug(f"cloud-init version: {version}")
return version
for pkg in "cloud-init", "cloud-init-base":
cmd = ["dpkg-query", "-W", "-f=${Version}", pkg]
sp = run_command(cmd, check=False)
if version := re.split("[-~]", sp.stdout)[0]:
log.debug(f"cloud-init version: {version}")
return version
log.debug("cloud-init not installed")
return ""


def supports_format_json() -> bool:
Expand Down
10 changes: 10 additions & 0 deletions subiquity/tests/test_cloudinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ def test_cloud_init_not_present(self):
rc.return_value.stdout = ""
self.assertEqual("", cloud_init_version())

def test_cloud_init_full(self):
with patch("subiquity.cloudinit.run_command") as rc:
rc.side_effect = [Mock(stdout="1.2.3"), Mock(stdout="4.5.6")]
self.assertEqual("1.2.3", cloud_init_version())

def test_cloud_init_base(self):
with patch("subiquity.cloudinit.run_command") as rc:
rc.side_effect = [Mock(stdout=""), Mock(stdout="4.5.6")]
self.assertEqual("4.5.6", cloud_init_version())

@parameterized.expand(
(
("22.3", False),
Expand Down

0 comments on commit a348c8b

Please sign in to comment.