Skip to content

Commit

Permalink
Merge pull request #18 from packethost/debian10-to-udev
Browse files Browse the repository at this point in the history
convert debian 10 to persistent names
  • Loading branch information
dustinmiller authored Mar 31, 2020
2 parents 7c7d96b + 79e645a commit 61a99e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packetnetworking/distros/debian/bonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def build_tasks(self):
self.task_template("etc/network/interfaces", "bonded/etc_network_interfaces.j2")
self.task_template("etc/modules", "bonded/etc_modules.j2", write_mode="a")

if self.metadata.operating_system.version in ["14.04", "19.04", "19.10"]:
os = self.metadata.operating_system

if os.distro == "debian" and os.version == "10":
self.tasks.update(generate_persistent_names())
elif os.distro == "ubuntu" and os.version in ["14.04", "19.04", "19.10"]:
self.tasks.update(generate_persistent_names())
return self.tasks
6 changes: 5 additions & 1 deletion packetnetworking/distros/debian/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def build_tasks(self):
"etc/network/interfaces", "individual/etc_network_interfaces.j2"
)

if self.metadata.operating_system.version in ["14.04", "19.04", "19.10"]:
os = self.metadata.operating_system

if os.distro == "debian" and os.version == "10":
self.tasks.update(generate_persistent_names())
elif os.distro == "ubuntu" and os.version in ["14.04", "19.04", "19.10"]:
self.tasks.update(generate_persistent_names())
return self.tasks
19 changes: 17 additions & 2 deletions packetnetworking/distros/debian/test_debian_10_bonded.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,26 @@ def test_debian_10_etc_hosts_configured(debian_10_bonded_network):
assert tasks["etc/hosts"] == result


def test_debian_10_no_persistent_interface_names(debian_10_bonded_network):
# pylama:ignore=E501
def test_debian_10_persistent_interface_names(debian_10_bonded_network):
"""
When using certain operating systems, we want to bypass driver interface name,
here we make sure the /etc/udev/rules.d/70-persistent-net.rules is generated.
"""
builder = debian_10_bonded_network()
tasks = builder.render()
assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks
result = dedent(
"""\
# This file was automatically generated by the packet.net installation environment.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device (custom name provided by external tool to mimic Predictable Network Interface Names)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface0.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface0.name}"
# PCI device (custom name provided by external tool to mimic Predictable Network Interface Names)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}"
"""
).format(iface0=builder.network.interfaces[0], iface1=builder.network.interfaces[1])
assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result
19 changes: 17 additions & 2 deletions packetnetworking/distros/debian/test_debian_10_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,26 @@ def test_debian_10_etc_hosts_configured(debian_10_individual_network):
assert tasks["etc/hosts"] == result


def test_debian_10_no_persistent_interface_names(debian_10_individual_network):
# pylama:ignore=E501
def test_debian_10_persistent_interface_names(debian_10_individual_network):
"""
When using certain operating systems, we want to bypass driver interface name,
here we make sure the /etc/udev/rules.d/70-persistent-net.rules is generated.
"""
builder = debian_10_individual_network()
tasks = builder.render()
assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks
result = dedent(
"""\
# This file was automatically generated by the packet.net installation environment.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device (custom name provided by external tool to mimic Predictable Network Interface Names)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface0.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface0.name}"
# PCI device (custom name provided by external tool to mimic Predictable Network Interface Names)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{{address}}=="{iface1.mac}", ATTR{{dev_id}}=="0x0", ATTR{{type}}=="1", NAME="{iface1.name}"
"""
).format(iface0=builder.network.interfaces[0], iface1=builder.network.interfaces[1])
assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result

0 comments on commit 61a99e0

Please sign in to comment.