canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
2.85k stars 855 forks source link

ds-identify doesn't look in /usr/local/etc/cloud/ but only in /etc/cloud/ [FreeBSD] #4481

Closed dch closed 11 months ago

dch commented 11 months ago

Bug report

ds-identify doesn't look in /usr/local/etc/cloud/ but only in /etc/cloud/, which is in conflict with all the other cloud-init tools on FreeBSD, and probably the other BSDs.

In particular, ds-identify looks in /etc/cloud/cloud.cfg to find things like datasource_list: ... but these files live in /usr/local/etc/cloud/... on FreeBSD, and possibly other BSDs.

This then likely breaks cloudinit for anybody using a non-OpenStack config, as the DataSource will be overridden.

Steps to reproduce the problem

default with path hack

# /usr/local/etc/cloud/cloud.cfg
syslog_fix_perms: root:wheel
disable_root: false
preserve_hostname: false
ssh_deletekeys: false
network: {config: disabled}
datasource_list: ['Ec2']
phone_home:
    url: http://...
    post:
    - instance_id
    tries: 5
datasource:
    Ec2:
        strict_id: false
        timeout: 60
        max_wait: 120
        metadata_urls:
         - https://...
        dsmode: net
cloud_init_modules:
    - migrator
    - ssh
cloud_final_modules:
    - phone-home
    - scripts-user
    - ssh-authkey-fingerprints
    - keys-to-console
    - final-message
system_info:
    distro: freebsd

Environment details

logs without /etc/cloud/ds-identify.cfg

root@metal:~ # env DI_LOG=stderr /usr/local/lib/cloud-init/ds-identify --force
[up unavailables] ds-identify --force
policy loaded: mode=search report=false found=all maybe=all notfound=enabled
no datasource_list found, using default: MAAS ConfigDrive NoCloud AltCloud Azure Bigstep CloudSigma CloudStack DigitalOcean Vultr AliYun Ec2 GCE OpenNebula OpenStack OVF SmartOS Scaleway Hetzner IBMCloud Oracle Exoscale RbxCloud UpCloud VMware LXD NWCS Akamai
DMI_PRODUCT_NAME=SYS-510T-MR-EI018
DMI_SYS_VENDOR=Supermicro
DMI_PRODUCT_SERIAL=S482931X2814219
DMI_PRODUCT_UUID=3ac39800-6cff-11ec-8000-3cecefc84871
PID_1_PRODUCT_NAME=
DMI_CHASSIS_ASSET_TAG=To be filled by O.E.M.
DMI_BOARD_NAME=X12STH-SYS
FS_LABELS=efiboot,biosboot,swapspace,root
ISO9660_DEVS=
KERNEL_CMDLINE=unavailable:no-cmdline
VIRT=none
UNAME_KERNEL_NAME=FreeBSD
UNAME_KERNEL_RELEASE=14.0-BETA4
UNAME_KERNEL_VERSION=FreeBSD 14.0-BETA4 #0 releng/14.0-n265159-ced511bd972a: Fri Sep 29 06:08:27 UTC 2023
UNAME_MACHINE=root@releng1.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC
UNAME_NODENAME=metal.af
UNAME_OPERATING_SYSTEM=amd64
DSNAME=
DSLIST=MAAS ConfigDrive NoCloud AltCloud Azure Bigstep CloudSigma CloudStack DigitalOcean Vultr AliYun Ec2 GCE OpenNebula OpenStack OVF SmartOS Scaleway Hetzner IBMCloud Oracle Exoscale RbxCloud UpCloud VMware LXD NWCS Akamai
MODE=search
ON_FOUND=all
ON_MAYBE=all
ON_NOTFOUND=enabled
pid=25078 ppid=24804
is_container=false
is_ds_enabled(IBMCloud) = true.
ec2 platform is 'Unknown'.
is_ds_enabled(IBMCloud) = true.
check for 'OpenStack' returned maybe
1 datasources returned maybe: OpenStack
[up unavailables] returning 0
2023-10-02 22:01:30,933 - url_helper.py[ERROR]: Timed out, no response from urls: ['http://[fe80::a9fe:a9fe]/openstack', 'http://169.254.169.254/openstack']
dch commented 11 months ago

I think patching PATH_DI_CONFIG=/etc/cloud/ds-identify.cfg is the simplest change.

igalic commented 11 months ago

yes, but also, this is related to https://github.com/canonical/cloud-init/issues/4180

to generalise: unlike the python code, we currently have no method of relocating paths in our shell code.

(not that I've dared to try and relocate /run in the python code yet to /var/run. at least the tools exist already. but i can't tell how consistently they are used until i try to do it)

dch commented 11 months ago

Then perhaps judicious use of %%LOCALBASE%% and %%PREFIX%% in the port may be the best approach, at leeast initially.

dch commented 11 months ago

see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274260 for work-around for FreeBSD ports.

igalic commented 11 months ago

here's my attempt at fixing it: https://github.com/canonical/cloud-init/pull/4485