[bug] ephemeral directory module not used
Bug report
In PR #4677, /run/ was relocated to /var/run on BSD. However, due to inconsistent use of the Paths object, several parts of cloud-init still have directories hard-coded to /run/cloud-init/. It should be fairly straightforward to update all of these with a reference to path.run_dir (where path is an instance of cloudinit.helpers.Paths).
A quick grep shows:
$ rg '/run/cloud-init' cloudinit
cloudinit/settings.py
19:RUN_CLOUD_CONFIG = "/run/cloud-init/cloud.cfg"
cloudinit/cmd/devel/logs.py
25:CLOUDINIT_RUN_DIR = "/run/cloud-init"
135: """Return a list of files to ignore for /run/cloud-init directory"""
cloudinit/cmd/devel/render.py
44: " /run/cloud-init/instance-data.json"
cloudinit/cmd/main.py
705: link_d = os.path.normpath("/run/cloud-init")
cloudinit/sources/helpers/azure.py
42:LOG_PUSHED_TO_KVP_INDEX_FILE = "/run/cloud-init/log_pushed_to_kvp_index"
cloudinit/helpers.py
310: self.run_dir: str = path_cfgs.get("run_dir", "/run/cloud-init")
cloudinit/stages.py
1072: # runtime config. I.e., /run/cloud-init/cloud.cfg
cloudinit/temp_utils.py
14:_ROOT_TMPDIR = "/run/cloud-init/tmp"
33: When root, cloud-init will use /run/cloud-init/tmp to avoid
More annoying, and maybe more difficult to solve, is the fact that some parts of the codebase blindly call Path({}).
cloudinit/cmd/devel/logs.py
141: ignored_files.append(Paths({}).lookups["instance_data_sensitive"])
cloudinit/stages.py
260: no_cfg_paths = helpers.Paths({}, self.datasource)
This is particularly troublesome, for example, in the second call where /run/ is being called, since this is used to identify from the configuration which distro this is - a chicken / egg scenario.
the function cloudinit.cmd.devel.read_cfg_paths may be helpful in a lot of these cases for grabbing the configured run_dir from Paths.
the function cloudinit.cmd.devel.read_cfg_paths may be helpful in a lot of these cases for grabbing the configured run_dir from Paths.
@blackboxsw This can't be done in stages.py, since cloudinit.cmd.devel.read_cfg_paths literally calls the problematic line:
cloudinit/stages.py
260: no_cfg_paths = helpers.Paths({}, self.datasource)
That would cause infinite recursion.