summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2023-05-12 11:29:15 -0600
committerGitHub <noreply@github.com>2023-05-12 11:29:15 -0600
commit73f34575da4f99a376998516a13c3a79cc640ae3 (patch)
tree06f396d4fcda64ad8cb4476538b50d524c59a2b9 /cloudinit
parent9f8450368c2ae713de0a2308f5d3cb73de5b39f2 (diff)
downloadcloud-init-git-73f34575da4f99a376998516a13c3a79cc640ae3.tar.gz
schema: read_cfg_paths call init.fetch to lookup /v/l/c/instance
Fix cloud-init schema --system being unable to find merged userdata stored at /var/lib/cloud/instance/cloud_config.txt. Init.paths.get_ipath only has visibility to merged cloud config in /var/lib/cloud/<instance_id>/cloud-config.txt after fetching the existing cached datasource which provides instance-id from metadata in order to determine the unique instance-id which represents the path to the cloud-config.txt. To support reuse of read_cfg_paths helper function, add an optional parameter fetch_existing_datasource which indicates whether reading the existing datasource is necessary for this helper function. cloud-init schema --system calls read_cfg_paths providing fetch_existing_datasource="trust" prior to calls to paths.get_ipath().
Diffstat (limited to 'cloudinit')
-rw-r--r--[-rwxr-xr-x]cloudinit/cmd/devel/__init__.py12
-rw-r--r--cloudinit/config/schema.py2
2 files changed, 11 insertions, 3 deletions
diff --git a/cloudinit/cmd/devel/__init__.py b/cloudinit/cmd/devel/__init__.py
index 9a8f2ebd..357c4ae7 100755..100644
--- a/cloudinit/cmd/devel/__init__.py
+++ b/cloudinit/cmd/devel/__init__.py
@@ -17,9 +17,17 @@ def addLogHandlerCLI(logger, log_level):
return logger
-def read_cfg_paths() -> Paths:
- """Return a Paths object based on the system configuration on disk."""
+def read_cfg_paths(fetch_existing_datasource: str = "") -> Paths:
+ """Return a Paths object based on the system configuration on disk.
+
+ :param fetch_existing_datasource: String one of check or trust. Whether to
+ load the pickled datasource before returning Paths. This is necessary
+ when using instance paths via Paths.get_ipath method which are only
+ known from the instance-id metadata in the detected datasource.
+ """
init = Init(ds_deps=[])
+ if fetch_existing_datasource:
+ init.fetch(existing=fetch_existing_datasource)
init.read_cfg()
return init.paths
diff --git a/cloudinit/config/schema.py b/cloudinit/config/schema.py
index 9005e924..4b7e8016 100644
--- a/cloudinit/config/schema.py
+++ b/cloudinit/config/schema.py
@@ -1264,7 +1264,7 @@ def handle_schema_args(name, args):
if args.docs:
print(load_doc(args.docs))
return
- paths = read_cfg_paths()
+ paths = read_cfg_paths(fetch_existing_datasource="trust")
if args.instance_data:
instance_data_path = args.instance_data
elif os.getuid() != 0: