Created
October 26, 2022 21:37
-
-
Save igalic/fcefd4a0afee6e156fd7e3f691b0784c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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..d90d795c 100644 | |
--- a/tests/unittests/config/test_cc_power_state_change.py | |
+++ b/tests/unittests/config/test_cc_power_state_change.py | |
@@ -12,7 +12,17 @@ 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 | |
+ | |
+ | |
+@pytest.fixture | |
+def bsd_cls(distro="freebsd", asset="netinfo/freebsd-ifconfig-output"): | |
+ """Returns a patched BSD distro class which already comes pre-loaded | |
+ with output for ``ifconfig -a``""" | |
+ ifs_txt = readResource(asset) | |
+ with mock.patch("cloudinit.subp.subp", return_value=(ifs_txt, None)): | |
+ cls = distros.fetch("freebsd") | |
+ yield cls | |
class TestLoadPowerState(t_help.TestCase): | |
@@ -85,8 +95,8 @@ class TestLoadPowerState(t_help.TestCase): | |
_cmd, _timeout, cond = psc.load_power_state(cfg, self.dist) | |
self.assertEqual(cond, True) | |
- def test_freebsd_poweroff_uses_lowercase_p(self): | |
- cls = distros.fetch("freebsd") | |
+ def test_freebsd_poweroff_uses_lowercase_p(self, bsd_cls): | |
+ cls = bsd_cls() | |
paths = helpers.Paths({}) | |
freebsd = cls("freebsd", {}, paths) | |
cfg = {"power_state": {"mode": "poweroff"}} | |
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