Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cloudinit/sources/DataSourceDigitalOcean.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# https://developers.digitalocean.com/documentation/metadata/

import logging
from typing import Any, Dict, Optional

import cloudinit.sources.helpers.digitalocean as do_helper
from cloudinit import lifecycle, sources, util
Expand Down Expand Up @@ -48,7 +49,7 @@ def __init__(self, sys_cfg, distro, paths):
self.use_ip4LL = self.ds_cfg.get("use_ip4LL", MD_USE_IPV4LL)
self.wait_retry = self.ds_cfg.get("wait_retry", MD_WAIT_RETRY)
self._network_config = None
self.metadata_full = None
self.metadata_full: Optional[Dict[str, Any]] = None

def _unpickle(self, ci_pkl_version: int) -> None:
super()._unpickle(ci_pkl_version)
Expand Down Expand Up @@ -115,7 +116,7 @@ def network_config(self):

interfaces = self.metadata.get("interfaces")
LOG.debug(interfaces)
if not interfaces:
if not interfaces or self.metadata_full is None:
raise RuntimeError("Unable to get meta-data from server....")

nameservers = self.metadata_full["dns"]["nameservers"]
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module = [
"cloudinit.netinfo",
"cloudinit.sources.DataSourceCloudStack",
"cloudinit.sources.DataSourceConfigDrive",
"cloudinit.sources.DataSourceDigitalOcean",
"cloudinit.sources.DataSourceEc2",
"cloudinit.sources.DataSourceExoscale",
"cloudinit.sources.DataSourceGCE",
Expand Down
9 changes: 9 additions & 0 deletions tests/unittests/sources/test_digitalocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ def test_multiple_ssh_keys(self, mock_readmd, get_ds):
assert metadata["public_keys"] == ds.get_public_ssh_keys()
assert isinstance(ds.get_public_ssh_keys(), list)

def test_network_config_requires_full_metadata(self, get_ds):
ds = get_ds()
ds.metadata["interfaces"] = DO_META["interfaces"]

with pytest.raises(
RuntimeError, match="Unable to get meta-data from server"
):
_ = ds.network_config


class TestNetworkConvert:
def _get_networking(self):
Expand Down
Loading