summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlberto Contreras <alberto.contreras@canonical.com>2022-11-24 08:39:08 +0100
committergit-ubuntu importer <ubuntu-devel-discuss@lists.ubuntu.com>2022-11-24 19:09:08 +0000
commit5ad5f24e03b5c16fec60dd7bd8b113f204ad98eb (patch)
treeec1b04842d6e7c32a005e4911928e015f587cebe
parentf7dd4c453a1712562483368d9d65184ec65d74b3 (diff)
downloadcloud-init-git-5ad5f24e03b5c16fec60dd7bd8b113f204ad98eb.tar.gz
22.4.2-0ubuntu1 (patches unapplied)
Imported using git-ubuntu import.
-rw-r--r--ChangeLog3
-rw-r--r--cloudinit/cmd/status.py20
-rw-r--r--cloudinit/version.py2
-rw-r--r--debian/changelog7
-rw-r--r--tests/unittests/cmd/test_cloud_id.py11
-rw-r--r--tests/unittests/cmd/test_status.py34
6 files changed, 69 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e149189..6e6c0fb4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+22.4.2
+ - status: handle ds not defined in status.json (#1876) (LP: #1997559)
+
22.4.1
- net: skip duplicate mac check for netvsc nic and its VF (#1853)
[Anh Vo] (LP: #1844191)
diff --git a/cloudinit/cmd/status.py b/cloudinit/cmd/status.py
index df136288..e1c37a78 100644
--- a/cloudinit/cmd/status.py
+++ b/cloudinit/cmd/status.py
@@ -13,11 +13,12 @@ import json
import os
import sys
from time import gmtime, sleep, strftime
-from typing import Any, Dict, List, NamedTuple, Tuple, Union
+from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union
from cloudinit import safeyaml
from cloudinit.cmd.devel import read_cfg_paths
from cloudinit.distros import uses_systemd
+from cloudinit.helpers import Paths
from cloudinit.util import get_cmdline, load_file, load_json
CLOUDINIT_DISABLED_FILE = "/etc/cloud/cloud-init.disabled"
@@ -63,7 +64,7 @@ class StatusDetails(NamedTuple):
description: str
errors: List[str]
last_update: str
- datasource: str
+ datasource: Optional[str]
TABULAR_LONG_TMPL = """\
@@ -124,7 +125,7 @@ def handle_status_args(name, args) -> int:
sys.stdout.flush()
details = get_status_details(paths)
sleep(0.25)
- details_dict: Dict[str, Union[str, List[str], Dict[str, Any]]] = {
+ details_dict: Dict[str, Union[None, str, List[str], Dict[str, Any]]] = {
"datasource": details.datasource,
"boot_status_code": details.boot_status_code.value,
"status": details.status.value,
@@ -195,7 +196,7 @@ def get_bootstatus(disable_file, paths) -> Tuple[UXAppBootStatusCode, str]:
return (bootstatus_code, reason)
-def get_status_details(paths=None) -> StatusDetails:
+def get_status_details(paths: Optional[Paths] = None) -> StatusDetails:
"""Return a dict with status, details and errors.
@param paths: An initialized cloudinit.helpers.paths object.
@@ -206,7 +207,7 @@ def get_status_details(paths=None) -> StatusDetails:
status = UXAppStatus.NOT_RUN
errors = []
- datasource = ""
+ datasource: Optional[str] = ""
status_v1 = {}
status_file = os.path.join(paths.run_dir, "status.json")
@@ -228,9 +229,14 @@ def get_status_details(paths=None) -> StatusDetails:
status = UXAppStatus.RUNNING
description = "Running in stage: {0}".format(value)
elif key == "datasource":
+ if value is None:
+ # If ds not yet written in status.json, then keep previous
+ # description
+ datasource = value
+ continue
description = value
- datasource, _, _ = value.partition(" ")
- datasource = datasource.lower().replace("datasource", "")
+ ds, _, _ = value.partition(" ")
+ datasource = ds.lower().replace("datasource", "")
elif isinstance(value, dict):
errors.extend(value.get("errors", []))
start = value.get("start") or 0
diff --git a/cloudinit/version.py b/cloudinit/version.py
index 4b739354..f2d62c04 100644
--- a/cloudinit/version.py
+++ b/cloudinit/version.py
@@ -4,7 +4,7 @@
#
# This file is part of cloud-init. See LICENSE file for license information.
-__VERSION__ = "22.4.1"
+__VERSION__ = "22.4.2"
_PACKAGED_VERSION = "@@PACKAGED_VERSION@@"
FEATURES = [
diff --git a/debian/changelog b/debian/changelog
index 323aed6f..1c32173b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+cloud-init (22.4.2-0ubuntu1) lunar; urgency=medium
+
+ * Upstream snapshot based on upstream commit 893df0d6.
+ - Bugs fixed in this snapshot: (LP: #1997559)
+
+ -- Alberto Contreras <alberto.contreras@canonical.com> Thu, 24 Nov 2022 08:39:08 +0100
+
cloud-init (22.4.1-0ubuntu1) lunar; urgency=medium
* Upstream snapshot based on upstream commit c038808e.
diff --git a/tests/unittests/cmd/test_cloud_id.py b/tests/unittests/cmd/test_cloud_id.py
index 80600555..bf87269a 100644
--- a/tests/unittests/cmd/test_cloud_id.py
+++ b/tests/unittests/cmd/test_cloud_id.py
@@ -45,6 +45,16 @@ STATUS_DETAILS_RUNNING = status.StatusDetails(
)
+STATUS_DETAILS_RUNNING_DS_NONE = status.StatusDetails(
+ status.UXAppStatus.RUNNING,
+ status.UXAppBootStatusCode.UNKNOWN,
+ "",
+ [],
+ "",
+ None,
+)
+
+
@pytest.fixture(autouse=True)
def setup_mocks(mocker):
mocker.patch(
@@ -203,6 +213,7 @@ class TestCloudId:
(STATUS_DETAILS_DISABLED, 2),
(STATUS_DETAILS_NOT_RUN, 3),
(STATUS_DETAILS_RUNNING, 0),
+ (STATUS_DETAILS_RUNNING_DS_NONE, 0),
),
)
@mock.patch(M_PATH + "get_status_details")
diff --git a/tests/unittests/cmd/test_status.py b/tests/unittests/cmd/test_status.py
index 6ae3b398..52a02c35 100644
--- a/tests/unittests/cmd/test_status.py
+++ b/tests/unittests/cmd/test_status.py
@@ -38,6 +38,40 @@ def config(tmpdir):
class TestStatus:
maxDiff = None
+ @mock.patch(
+ M_PATH + "load_file",
+ return_value=(
+ '{"v1": {"datasource": null, "init": {"errors": [], "finished": '
+ 'null, "start": null}, "init-local": {"errors": [], "finished": '
+ 'null, "start": 1669231096.9621563}, "modules-config": '
+ '{"errors": [], "finished": null, "start": null},'
+ '"modules-final": {"errors": [], "finished": null, '
+ '"start": null}, "modules-init": {"errors": [], "finished": '
+ 'null, "start": null}, "stage": "init-local"} }'
+ ),
+ )
+ @mock.patch(M_PATH + "os.path.exists", return_value=True)
+ @mock.patch(
+ M_PATH + "get_bootstatus",
+ return_value=(
+ status.UXAppBootStatusCode.ENABLED_BY_GENERATOR,
+ "Cloud-init enabled by systemd cloud-init-generator",
+ ),
+ )
+ def test_get_status_details_ds_none(
+ self, m_get_boot_status, m_p_exists, m_load_json, tmpdir
+ ):
+ paths = mock.Mock()
+ paths.run_dir = str(tmpdir)
+ assert status.StatusDetails(
+ status.UXAppStatus.RUNNING,
+ status.UXAppBootStatusCode.ENABLED_BY_GENERATOR,
+ "Running in stage: init-local",
+ [],
+ "Wed, 23 Nov 2022 19:18:16 +0000",
+ None, # datasource
+ ) == status.get_status_details(paths)
+
@pytest.mark.parametrize(
[
"ensured_file",