diff options
-rwxr-xr-x | cloudinit/net/cmdline.py | 6 | ||||
-rw-r--r-- | tests/unittests/test_net.py | 50 |
2 files changed, 54 insertions, 2 deletions
diff --git a/cloudinit/net/cmdline.py b/cloudinit/net/cmdline.py index cc8dc17b..7cdd428d 100755 --- a/cloudinit/net/cmdline.py +++ b/cloudinit/net/cmdline.py @@ -12,6 +12,7 @@ import gzip import io import logging import os +import shlex from cloudinit import util @@ -72,8 +73,9 @@ class KlibcNetworkConfigSource(InitramfsNetworkConfigSource): (ii) an open-iscsi interface file is present in the system """ if self._files: - if 'ip=' in self._cmdline or 'ip6=' in self._cmdline: - return True + for item in shlex.split(self._cmdline): + if item.startswith('ip=') or item.startswith('ip6='): + return True if os.path.exists(_OPEN_ISCSI_INTERFACE_FILE): # iBft can configure networking without ip= return True diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index cb636f41..2bd50e72 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -4387,6 +4387,56 @@ class TestCmdlineKlibcNetworkConfigSource(FilesystemMockingTestCase): ) self.assertFalse(src.is_applicable()) + def test_with_faux_ip(self): + content = {'net6-eno1.conf': DHCP6_CONTENT_1} + files = sorted(populate_dir(self.tmp_dir(), content)) + src = cmdline.KlibcNetworkConfigSource( + _files=files, + _cmdline='foo iscsi_target_ip=root=/dev/sda', + _mac_addrs=self.macs, + ) + self.assertFalse(src.is_applicable()) + + def test_empty_cmdline(self): + content = {'net6-eno1.conf': DHCP6_CONTENT_1} + files = sorted(populate_dir(self.tmp_dir(), content)) + src = cmdline.KlibcNetworkConfigSource( + _files=files, + _cmdline='', + _mac_addrs=self.macs, + ) + self.assertFalse(src.is_applicable()) + + def test_whitespace_cmdline(self): + content = {'net6-eno1.conf': DHCP6_CONTENT_1} + files = sorted(populate_dir(self.tmp_dir(), content)) + src = cmdline.KlibcNetworkConfigSource( + _files=files, + _cmdline=' ', + _mac_addrs=self.macs, + ) + self.assertFalse(src.is_applicable()) + + def test_cmdline_no_lhand(self): + content = {'net6-eno1.conf': DHCP6_CONTENT_1} + files = sorted(populate_dir(self.tmp_dir(), content)) + src = cmdline.KlibcNetworkConfigSource( + _files=files, + _cmdline='=wut', + _mac_addrs=self.macs, + ) + self.assertFalse(src.is_applicable()) + + def test_cmdline_embedded_ip(self): + content = {'net6-eno1.conf': DHCP6_CONTENT_1} + files = sorted(populate_dir(self.tmp_dir(), content)) + src = cmdline.KlibcNetworkConfigSource( + _files=files, + _cmdline='opt="some things and ip=foo"', + _mac_addrs=self.macs, + ) + self.assertFalse(src.is_applicable()) + def test_with_both_ip_ip6(self): content = { '/run/net-eth0.conf': DHCP_CONTENT_1, |