diff options
author | Chad Smith <chad.smith@canonical.com> | 2023-01-11 16:28:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-11 16:28:58 -0700 |
commit | a85f103e2c59dd80157e535354d41f03545d7314 (patch) | |
tree | 207ce4333e8aaf44f6091380fcee37b4a91a1f70 | |
parent | eb22a2426d4df1d1870dbef04f5edf7f58356ee1 (diff) | |
download | cloud-init-git-a85f103e2c59dd80157e535354d41f03545d7314.tar.gz |
lxd: handle 404 from missing devices route for LXD 4.0
LXD 4.0 will not get a backport of the devices route on LXD socket
API. This prevented launching Jammy from hosts with LXD 4.0.
Allow cloud-init to support LXD backplanes without the "devices"
route and use fallback network config when absent.
LP: #2001737
-rw-r--r-- | cloudinit/sources/DataSourceLXD.py | 12 | ||||
-rw-r--r-- | tests/unittests/sources/test_lxd.py | 12 |
2 files changed, 19 insertions, 5 deletions
diff --git a/cloudinit/sources/DataSourceLXD.py b/cloudinit/sources/DataSourceLXD.py index 49a7567c..eea1e294 100644 --- a/cloudinit/sources/DataSourceLXD.py +++ b/cloudinit/sources/DataSourceLXD.py @@ -277,6 +277,14 @@ def _get_json_response( session: requests.Session, url: str, do_raise: bool = True ): url_response = _do_request(session, url, do_raise) + if not url_response.ok: + LOG.debug( + "Skipping %s on [HTTP:%d]:%s", + url, + url_response.status_code, + url_response.text, + ) + return {} try: return url_response.json() except JSONDecodeError as exc: @@ -386,7 +394,9 @@ class _MetaDataReader: md.update(self._process_config(session)) if MetaDataKeys.DEVICES in metadata_keys: url = url_helper.combine_url(self._version_url, "devices") - md["devices"] = _get_json_response(session, url) + devices = _get_json_response(session, url, do_raise=False) + if devices: + md["devices"] = devices return md diff --git a/tests/unittests/sources/test_lxd.py b/tests/unittests/sources/test_lxd.py index b02ed177..8f6db3fe 100644 --- a/tests/unittests/sources/test_lxd.py +++ b/tests/unittests/sources/test_lxd.py @@ -440,18 +440,22 @@ class TestReadMetadata: "[GET] [HTTP:200] http://lxd/1.0/config", ], ), - ( # Assert 404 on devices + ( # Assert 404 on devices logs about skipping True, { "http://lxd/1.0/meta-data": "local-hostname: md\n", "http://lxd/1.0/config": "[]", + # No devices URL response, so 404 raised + }, + { + "_metadata_api_version": lxd.LXD_SOCKET_API_VERSION, + "config": {}, + "meta-data": "local-hostname: md\n", }, - InvalidMetaDataException( - "Invalid HTTP response [404] from http://lxd/1.0/devices" - ), [ "[GET] [HTTP:200] http://lxd/1.0/meta-data", "[GET] [HTTP:200] http://lxd/1.0/config", + "Skipping http://lxd/1.0/devices on [HTTP:404]", ], ), ( # Assert non-JSON format from devices |