Skip to content

Instantly share code, notes, and snippets.

@igalic
Created October 26, 2022 22:25
Show Gist options
  • Save igalic/ee97505d7b297237efbcfbe40563fd38 to your computer and use it in GitHub Desktop.
Save igalic/ee97505d7b297237efbcfbe40563fd38 to your computer and use it in GitHub Desktop.
diff --git a/cloudinit/distros/networking.py b/cloudinit/distros/networking.py
index ea966283..877887b4 100644
--- a/cloudinit/distros/networking.py
+++ b/cloudinit/distros/networking.py
@@ -195,8 +195,9 @@ class BSDNetworking(Networking):
self._update_ifs()
def _update_ifs(self):
- ifs_txt, _ = subp.subp(["ifconfig", "-a"])
- self.ifs = self.ifc.parse(ifs_txt)
+ ifconf = subp.subp(["ifconfig", "-a"])
+ if ifconf[0]:
+ self.ifs = self.ifc.parse(ifconf[0])
def apply_network_config_names(self, netcfg: NetworkConfig) -> None:
LOG.debug("Cannot rename network interface.")
diff --git a/tests/unittests/config/test_cc_power_state_change.py b/tests/unittests/config/test_cc_power_state_change.py
index 82824306..5bcc5cb5 100644
--- a/tests/unittests/config/test_cc_power_state_change.py
+++ b/tests/unittests/config/test_cc_power_state_change.py
@@ -12,7 +12,7 @@ from cloudinit.config.schema import (
validate_cloudconfig_schema,
)
from tests.unittests import helpers as t_help
-from tests.unittests.helpers import mock, skipUnlessJsonSchema
+from tests.unittests.helpers import mock, readResource, skipUnlessJsonSchema
class TestLoadPowerState(t_help.TestCase):
@@ -86,12 +86,17 @@ class TestLoadPowerState(t_help.TestCase):
self.assertEqual(cond, True)
def test_freebsd_poweroff_uses_lowercase_p(self):
- cls = distros.fetch("freebsd")
- paths = helpers.Paths({})
- freebsd = cls("freebsd", {}, paths)
- cfg = {"power_state": {"mode": "poweroff"}}
- ret = psc.load_power_state(cfg, freebsd)
- self.assertIn("-p", ret[0])
+ ifs_txt = readResource("netinfo/freebsd-ifconfig-output")
+ with mock.patch(
+ "cloudinit.distros.networking.subp.subp",
+ return_value=(ifs_txt, None),
+ ):
+ cls = distros.fetch("freebsd")
+ paths = helpers.Paths({})
+ freebsd = cls("freebsd", {}, paths)
+ cfg = {"power_state": {"mode": "poweroff"}}
+ ret = psc.load_power_state(cfg, freebsd)
+ self.assertIn("-p", ret[0])
def test_alpine_delay(self):
# alpine takes delay in seconds.
diff --git a/tests/unittests/distros/test_networking.py b/tests/unittests/distros/test_networking.py
index fffaf22e..4a93268a 100644
--- a/tests/unittests/distros/test_networking.py
+++ b/tests/unittests/distros/test_networking.py
@@ -49,7 +49,7 @@ def generic_networking_cls():
@pytest.fixture
def bsd_networking_cls(asset="netinfo/freebsd-ifconfig-output"):
"""Returns a patched BSDNetworking class which already comes pre-loaded
- with output for ``ifconfig -``"""
+ with output for ``ifconfig -a``"""
ifs_txt = readResource(asset)
with mock.patch("cloudinit.subp.subp", return_value=(ifs_txt, None)):
yield BSDNetworking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment