Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement optional-addresses (LP: #1880029) #339

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion tests/generator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def get_network_config_for_link(self, link_name):
def get_optional_addresses(self, eth_name):
config = self.get_network_config_for_link(eth_name)
r = set()
prefix = "OptionalAddresses="
prefix = "RequiredFamilyForOnline="
for line in config.splitlines():
if line.startswith(prefix):
r.add(line[len(prefix):])
Expand Down
71 changes: 67 additions & 4 deletions tests/generator/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,26 @@ def config_with_optional_addresses(self, eth_name, optional_addresses):

def test_optional_addresses(self):
eth_name = self.eth_name()
self.generate(self.config_with_optional_addresses(eth_name, '["dhcp4"]'))
self.assertEqual(self.get_optional_addresses(eth_name), set(["dhcp4"]))
self.generate(self.config_with_optional_addresses(eth_name, '["ipv4"]'))
self.assertEqual(self.get_optional_addresses(eth_name), set())

def test_optional_addresses_multiple(self):
eth_name = self.eth_name()
self.generate(self.config_with_optional_addresses(eth_name, '[dhcp4, ipv4-ll, ipv6-ra, dhcp6, dhcp4, static]'))
self.generate(self.config_with_optional_addresses(eth_name, '["ipv4", "ipv6", "ipv4"]'))
slyon marked this conversation as resolved.
Show resolved Hide resolved
self.assertEqual(
self.get_optional_addresses(eth_name),
set(["ipv4-ll", "ipv6-ra", "dhcp4", "dhcp6", "static"]))
set())

def test_optional_addresses_none(self):
eth_name = self.eth_name()
self.generate(self.config_with_optional_addresses(eth_name, '["none"]'))
self.assertEqual(self.get_optional_addresses(eth_name), set(["both"]))

def test_optional_addresses_deprecated_flags(self):
flags = '["ipv4-ll", "ipv6-ra", "dhcp4", "dhcp6", "static"]'
eth_name = self.eth_name()
self.generate(self.config_with_optional_addresses(eth_name, flags))
self.assertEqual(self.get_optional_addresses(eth_name), set())

def test_optional_addresses_invalid(self):
eth_name = self.eth_name()
Expand Down Expand Up @@ -1322,6 +1333,58 @@ def test_nameserver(self):
method=ignore
'''})

def test_optional_addresses(self):
self.generate('''network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
optional-addresses: [ipv4, ipv6]''')

self.assert_nm({'eth0': '''[connection]
id=netplan-eth0
type=ethernet
interface-name=eth0

[ethernet]
wake-on-lan=0

[ipv4]
method=link-local
may-fail=true

[ipv6]
method=ignore
may-fail=true
'''})
self.assert_networkd({})

def test_optional_addresses_none(self):
self.generate('''network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
optional-addresses: [none]''')

self.assert_nm({'eth0': '''[connection]
id=netplan-eth0
type=ethernet
interface-name=eth0

[ethernet]
wake-on-lan=0

[ipv4]
method=link-local
may-fail=false

[ipv6]
method=ignore
may-fail=false
'''})
self.assert_networkd({})


class TestForwardDeclaration(TestBase):

Expand Down