cloud-init icon indicating copy to clipboard operation
cloud-init copied to clipboard

CloudStack Datasource Fails to find Default Gateway on FreeBSD due to no proc filesystem

Open loth opened this issue 2 years ago • 2 comments

Bug report

When falling back to obtaining the default gateway using the cloudstack datasource we obtain a exception from cloud-init due to it looking for /proc/net/route and freebsd does not use the /proc filesystem

Steps to reproduce the problem

Create VM, make sure no leases are existing so it falls back to default GW

Environment details

  • Cloud-init version: 23.1.1
  • Operating System Distribution: FreeBSD 13.2
  • Cloud provider, platform or installer type:

cloud-init logs

2023-06-20 14:29:06,491 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.freebsd.Distro'>
2023-06-20 14:29:06,491 - subp.py[DEBUG]: Running command ['ifconfig', '-a'] with allowed return codes [0] (shell=False, capture=True)
2023-06-20 14:29:06,497 - __init__.py[DEBUG]: Looking for data source in: ['CloudStack'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM', 'NETWORK']
2023-06-20 14:29:06,501 - __init__.py[DEBUG]: Searching for network data source in: ['DataSourceCloudStack']
2023-06-20 14:29:06,501 - handlers.py[DEBUG]: start: init-network/search-CloudStack: searching for network data from DataSourceCloudStack
2023-06-20 14:29:06,501 - __init__.py[DEBUG]: Seeing if we can get any data from <class 'cloudinit.sources.DataSourceCloudStack.DataSourceCloudStack'>
2023-06-20 14:29:06,526 - DataSourceCloudStack.py[DEBUG]: DNS Entry data-server not found
2023-06-20 14:29:06,527 - DataSourceCloudStack.py[DEBUG]: No lease file found, using default gateway
2023-06-20 14:29:06,527 - util.py[DEBUG]: Reading from /proc/net/route (quiet=False)
2023-06-20 14:29:06,527 - handlers.py[DEBUG]: finish: init-network/search-CloudStack: FAIL: no network data found from DataSourceCloudStack
2023-06-20 14:29:06,527 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceCloudStack.DataSourceCloudStack'> failed
2023-06-20 14:29:06,527 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceCloudStack.DataSourceCloudStack'> failed
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/cloudinit/sources/__init__.py", line 975, in find_source
    s = cls(sys_cfg, distro, paths)
  File "/usr/local/lib/python3.9/site-packages/cloudinit/sources/DataSourceCloudStack.py", line 90, in __init__
    self.vr_addr = get_vr_address()
  File "/usr/local/lib/python3.9/site-packages/cloudinit/sources/DataSourceCloudStack.py", line 283, in get_vr_address
    return get_default_gateway()
  File "/usr/local/lib/python3.9/site-packages/cloudinit/sources/DataSourceCloudStack.py", line 199, in get_default_gateway
    lines = util.load_file("/proc/net/route").splitlines()
  File "/usr/local/lib/python3.9/site-packages/cloudinit/util.py", line 1539, in load_file
    with open(fname, "rb") as ifh:
FileNotFoundError: [Errno 2] No such file or directory: '/proc/net/route'
2023-06-20 14:29:06,534 - util.py[WARNING]: No instance datasource found! Likely bad things to come!
2023-06-20 14:29:06,534 - util.py[DEBUG]: No instance datasource found! Likely bad things to come!
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/cloudinit/cmd/main.py", line 385, in main_init
    init.fetch(existing=existing)
  File "/usr/local/lib/python3.9/site-packages/cloudinit/stages.py", line 434, in fetch
    return self._get_data_source(existing=existing)
  File "/usr/local/lib/python3.9/site-packages/cloudinit/stages.py", line 325, in _get_data_source
    (ds, dsname) = sources.find_source(
  File "/usr/local/lib/python3.9/site-packages/cloudinit/sources/__init__.py", line 987, in find_source
    raise DataSourceNotFoundException(msg)
cloudinit.sources.DataSourceNotFoundException: Did not find any data source, searched classes: (DataSourceCloudStack)

loth avatar Jun 20 '23 14:06 loth

this is pretty bad, for several reasons, but, first of all: we shouldn't even get there. #2122 should have fixed:

2023-06-20 14:29:06,526 - DataSourceCloudStack.py[DEBUG]: DNS Entry data-server not found
2023-06-20 14:29:06,527 - DataSourceCloudStack.py[DEBUG]: No lease file found, using default gateway

this should be (soon) available in net/cloud-init-devel: https://reviews.freebsd.org/D40593 (watch https://www.freshports.org/net/cloud-init-devel/ for that version)

but, that said, (something like) get_default_gateway should be implemented in https://github.com/canonical/cloud-init/blob/main/cloudinit/distros/networking.py and get_vr_address probably also needs a review.

igalic avatar Jun 20 '23 18:06 igalic

Thanks @loth for reporting this. Could you please attach the full logs?

aciba90 avatar Jun 22 '23 11:06 aciba90