canonical / canonical/cloud-init

on clean system: cloud-init devel hotplug-hook query has side-effect of discovering and DatasourceNone

Open
#4,824 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report
On a instance where cloud-init has not yet run or was cleaned, `cloud-init devel hotplug-hook query -s net` has the side-effect of trying to discover a new datasource base on a missing obj.pkl cache file and falling back to DataSourceNone.

There should be no side-effects of the subcommand `cloud-init devel hotplug-hook query` as it should be a read-only operation as far as cloud-init is concerned. Ideally we also don't care about logging messages in cloud-init.log for read-only operations like query either as it just adds artifacts that shouldn't affect the system configuration.

The issue of datasource detection is due to a side-effect of `Init.fetch()` which will fall through and automatically try to discover a viable datasource if the cache is not found [cloudinit.stages.Init._get_data_source](https://github.com/canonical/cloud-init/blob/main/cloudinit/stages.py#L344)

## Steps to reproduce the problem
```
lxc launch ubuntu-daily:noble test-n
lxc exec test-n -- cloud-init status --wait --format=json
lxc exec test-n -- cat /run/cloud-init/instance-data.json | jq .v1.cloud_name
> "lxd"
lxc exec test-n -- cloud-init clean --logs
lxc exec test-n -- cloud-init devel hotplug-hook -s net query
lxc exec test-n -- cat /run/cloud-init/instance-data.json | jq .v1.cloud_name
> "none"
```

## Environment details
- Cloud-init version: daily builds 20240130.
- Operating System Distribution: Any
- Cloud provider, platform or installer type: Any

## cloud-init logs

Logs after a cloud-init clean --logs and `cloud-init devel hotplug-hook -s net query` call
```
2024-01-30 19:33:38,322 - hotplug_hook.py[DEBUG]: hotplug-hook called with the following arguments: {hotplug_action: query, subsystem: net, udevaction: None, devpath: None}
2024-01-30 19:33:38,322 - handlers.py[DEBUG]: start: hotplug-hook: Handle reconfiguration on hotplug events.
2024-01-30 19:33:38,322 - hotplug_hook.py[DEBUG]: Fetching datasource
2024-01-30 19:33:38,323 - handlers.py[DEBUG]: start: hotplug-hook/check-cache: attempting to read from cache [trust]
2024-01-30 19:33:38,323 - util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
2024-01-30 19:33:38,323 - stages.py[DEBUG]: no cache found
2024-01-30 19:33:38,323 - handlers.py[DEBUG]: finish: hotplug-hook/check-cache: SUCCESS: no cache found
2024-01-30 19:33:38,323 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
2024-01-30 19:33:38,323 - stages.py[DEBUG]: Using distro class
2024-01-30 19:33:38,323 - sources[DEBUG]: Looking for data source in: ['LXD', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies []
2024-01-30 19:33:38,324 - sources[DEBUG]: Searching for local data source in: ['DataSourceNone']
2024-01-30 19:33:38,325 - handlers.py[DEBUG]: start: hotplug-hook/search-None: searching for local data from DataSourceNone
2024-01-30 19:33:38,325 - sources[DEBUG]: Seeing if we can get any data from
2024-01-30 19:33:38,325 - sources[DEBUG]: Update datasource metadata and network config due to events: boot-new-instance
2024-01-30 19:33:38,325 - sources[DEBUG]: Detected platform: DataSourceNone. Checking for active instance data
2024-01-30 19:33:38,325 - util.py[DEBUG]: Reading from /etc/hosts (quiet=False)
2024-01-30 19:33:38,325 - util.py[DEBUG]: Read 221 bytes from /etc/hosts
2024-01-30 19:33:38,325 - util.py[DEBUG]: Writing to /run/cloud-init/cloud-id-none - wb: [644] 5 bytes
2024-01-30 19:33:38,325 - util.py[DEBUG]: Creating symbolic link from '/run/cloud-init/cloud-id' => '/run/cloud-init/cloud-id-none'
2024-01-30 19:33:38,325 - util.py[DEBUG]: Attempting to remove /run/cloud-init/cloud-id-lxd
2024-01-30 19:33:38,326 - atomic_helper.py[DEBUG]: Atomically writing to file /run/cloud-init/instance-data-sensitive.json (via temporary file /run/cloud-init/tmpc74o7x3h) - w: [600] 7961 bytes/chars
2024-01-30 19:33:38,326 - atomic_helper.py[DEBUG]: Atomically writing to file /run/cloud-init/instance-data.json (via temporary file /run/cloud-init/tmpcvdjdwa3) - w: [644] 1426 bytes/chars
2024-01-30 19:33:38,326 - handlers.py[DEBUG]: finish: hotplug-hook/search-None: SUCCESS: found local data from DataSourceNone
2024-01-30 19:33:38,326 - stages.py[INFO]: Loaded datasource DataSourceNone - DataSourceNone
2024-01-30 19:33:38,326 - util.py[DEBUG]: Reading from /etc/cloud/cloud.cfg (quiet=False)
2024-01-30 19:33:38,326 - util.py[DEBUG]: Read 3695 bytes from /etc/cloud/cloud.cfg
2024-01-30 19:33:38,326 - util.py[DEBUG]: Attempting to load yaml from string of length 3695 with allowed root types (,)
2024-01-30 19:33:38,329 - util.py[DEBUG]: Reading from /etc/cloud/cloud.cfg.d/90_dpkg.cfg (quiet=False)
2024-01-30 19:33:38,329 - util.py[DEBUG]: Read 328 bytes from /etc/cloud/cloud.cfg.d/90_dpkg.cfg
2024-01-30 19:33:38,329 - util.py[DEBUG]: Attempting to load yaml from string of length 328 with allowed root types (,)
2024-01-30 19:33:38,330 - util.py[DEBUG]: Reading from /etc/cloud/cloud.cfg.d/05_logging.cfg (quiet=False)
2024-01-30 19:33:38,330 - util.py[DEBUG]: Read 2070 bytes from /etc/cloud/cloud.cfg.d/05_logging.cfg
2024-01-30 19:33:38,330 - util.py[DEBUG]: Attempting to load yaml from string of length 2070 with allowed root types (,)
2024-01-30 19:33:38,331 - util.py[DEBUG]: Reading from /run/cloud-init/cloud.cfg (quiet=False)
2024-01-30 19:33:38,331 - util.py[DEBUG]: Read 31 bytes from /run/cloud-init/cloud.cfg
2024-01-30 19:33:38,331 - util.py[DEBUG]: Attempting to load yaml from string of length 31 with allowed root types (,)
2024-01-30 19:33:38,331 - util.py[DEBUG]: Attempting to load yaml from string of length 0 with allowed root types (,)
2024-01-30 19:33:38,331 - util.py[DEBUG]: loaded blob returned None, returning default.
2024-01-30 19:33:38,331 - stages.py[DEBUG]: Allowed events: {: {}}
2024-01-30 19:33:38,331 - stages.py[DEBUG]: Event Denied: scopes=['network'] EventType=hotplug
2024-01-30 19:33:38,331 - hotplug_hook.py[DEBUG]: hotplug not enabled for event of type net
2024-01-30 19:33:38,331 - handlers.py[DEBUG]: finish: hotplug-hook: SUCCESS: Handle reconfiguration on hotplug events.
2024-01-30 19:33:38,331 - hotplug_hook.py[DEBUG]: Exiting hotplug handler
2024-01-30 19:33:38,331 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
2024-01-30 19:33:38,332 - util.py[DEBUG]: Read 12 bytes from /proc/uptime
2024-01-30 19:33:38,332 - util.py[DEBUG]: cloud-init mode 'hotplug-hook' took 0.019 seconds (0.02)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.