Skip to content

Commit

Permalink
fix(net): klibc ipconfig PROTO compatibility (#5437)
Browse files Browse the repository at this point in the history
klibc's ipconfig format [1] states that PROTO values 'none', 'off',
'static' and blank all mean no autoconfiguration, but cloud-init parser
is too strict and accepts only the first.

LP: #2065787

[1] https://git.kernel.org/pub/scm/libs/klibc/klibc.git/plain/usr/kinit/ipconfig/README.ipconfig
  • Loading branch information
alexsander-souza authored Jun 27, 2024
1 parent 5250260 commit 2c09f69
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cloudinit/net/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def _klibc_to_config_entry(content, mac_addrs=None):
else:
proto = "none"

if proto in ("static", "off"):
proto = "none"

if proto not in ("none", "dhcp", "dhcp6"):
raise ValueError("Unexpected value for PROTO: %s" % proto)

Expand Down
39 changes: 37 additions & 2 deletions tests/unittests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@
],
}

STATIC_CONTENT_2 = """
DEVICE='eth1'
PROTO='static'
IPV4ADDR='10.0.0.2'
IPV4BROADCAST='10.0.0.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='10.0.0.1'
IPV4DNS0='10.0.1.1'
IPV4DNS1='0.0.0.0'
HOSTNAME='foohost'
UPTIME='21'
DHCPLEASETIME='3600'
DOMAINSEARCH='foo.com'
"""

STATIC_CONTENT_3 = """
DEVICE='eth1'
PROTO='off'
IPV4ADDR='10.0.0.2'
IPV4BROADCAST='10.0.0.255'
IPV4NETMASK='255.255.255.0'
IPV4GATEWAY='10.0.0.1'
IPV4DNS0='10.0.1.1'
IPV4DNS1='0.0.0.0'
HOSTNAME='foohost'
UPTIME='21'
DHCPLEASETIME='3600'
DOMAINSEARCH='foo.com'
"""


V1_NAMESERVER_ALIAS = """
config:
- id: eno1
Expand Down Expand Up @@ -3763,8 +3794,12 @@ def test_cmdline_convert_dhcp6(self):
assert found == ("eno1", DHCP6_EXPECTED_1)

def test_cmdline_convert_static(self):
found = cmdline._klibc_to_config_entry(STATIC_CONTENT_1)
assert found == ("eth1", STATIC_EXPECTED_1)
found1 = cmdline._klibc_to_config_entry(STATIC_CONTENT_1)
assert found1 == ("eth1", STATIC_EXPECTED_1)
found2 = cmdline._klibc_to_config_entry(STATIC_CONTENT_2)
assert found2 == ("eth1", STATIC_EXPECTED_1)
found3 = cmdline._klibc_to_config_entry(STATIC_CONTENT_3)
assert found3 == ("eth1", STATIC_EXPECTED_1)

def test_config_from_cmdline_net_cfg(self):
files = []
Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ afbjorklund
ajmyyra
akutz
AlexBaranowski
alexsander-souza
AlexSv04047
AliyevH
Aman306
Expand Down

0 comments on commit 2c09f69

Please sign in to comment.