diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c16161d..cfbf3aa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,63 +20,24 @@ jobs: with: nix_path: nixpkgs=channel:nixos-unstable - run: nix-shell --run "pylama packetnetworking setup.py" - test-python-35: + pytests: runs-on: ubuntu-latest - needs: [format, lint] + strategy: + matrix: + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: - python-version: '3.5' + python-version: "${{matrix.python-version}}" - run: pip install tox - - run: tox -e py35 - test-python-36: - runs-on: ubuntu-latest - needs: [format, lint] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.6' - - run: pip install tox - - run: tox -e py36 - test-python-37: - runs-on: ubuntu-latest - needs: [format, lint] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.7' - - run: pip install tox - - run: tox -e py37 - test-python-38: - runs-on: ubuntu-latest - needs: [format, lint] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - run: pip install tox - - run: tox -e py38 - test-python-39: - runs-on: ubuntu-latest - needs: [format, lint] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - run: pip install tox - - run: tox -e py39 - test-python-310: - runs-on: ubuntu-latest - needs: [format, lint] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - run: pip install tox - - run: tox -e py310 + - name: Test on Python ${{matrix.python-version}} + run: | + pyversion=py${{matrix.python-version}} + pyversion=${pyversion//./} + tox -e "$pyversion" diff --git a/packetnetworking/distros/__init__.py b/packetnetworking/distros/__init__.py index d1c0756..99c0944 100644 --- a/packetnetworking/distros/__init__.py +++ b/packetnetworking/distros/__init__.py @@ -3,7 +3,6 @@ from .alpine import AlpineBuilder from .debian import DebianBuilder from .redhat import RedhatBuilder -from .suse import SuseBuilder __all__ = [ "DistroBuilder", @@ -12,5 +11,4 @@ "AlpineBuilder", "DebianBuilder", "RedhatBuilder", - "SuseBuilder", ] diff --git a/packetnetworking/distros/alpine/templates/bonded/etc_network_interfaces.j2 b/packetnetworking/distros/alpine/templates/bonded/etc_network_interfaces.j2 index 5f2e47a..9f19042 100644 --- a/packetnetworking/distros/alpine/templates/bonded/etc_network_interfaces.j2 +++ b/packetnetworking/distros/alpine/templates/bonded/etc_network_interfaces.j2 @@ -12,29 +12,25 @@ iface bond0 inet static netmask {{ ip4priv.netmask }} gateway {{ ip4priv.gateway }} {% endif %} + dns-nameservers {{ resolvers | join(" ") }} use bond - requires{% for iface in interfaces %} {{ iface.meta_name }}{% endfor %} - - bond-members{% for iface in interfaces %} {{ iface.meta_name }}{% endfor %} - + requires {{ interfaces | map(attribute="meta_name") | join(" ") }} + bond-members {{ interfaces | map(attribute="meta_name") | join(" ") }} bond-mode {{ net.bonding.mode }} - bond-downdelay 200 bond-miimon 100 bond-updelay 200 bond-xmit_hash_policy layer3+4 - - dns-nameservers{% for dns in resolvers %} {{ dns }}{% endfor %} - {% if ip6pub %} + iface bond0 inet6 static address {{ ip6pub.address }} netmask {{ ip6pub.cidr }} gateway {{ ip6pub.gateway }} {% endif %} - {% if ip4pub %} + auto bond0:0 iface bond0:0 inet static address {{ ip4priv.address }} diff --git a/packetnetworking/distros/alpine/templates/individual/etc_network_interfaces.j2 b/packetnetworking/distros/alpine/templates/individual/etc_network_interfaces.j2 index 4f6fb05..7aa6385 100644 --- a/packetnetworking/distros/alpine/templates/individual/etc_network_interfaces.j2 +++ b/packetnetworking/distros/alpine/templates/individual/etc_network_interfaces.j2 @@ -12,17 +12,16 @@ iface {{ iface0.meta_name }} inet static netmask {{ ip4priv.netmask }} gateway {{ ip4priv.gateway }} {% endif %} - - dns-nameservers{% for dns in resolvers %} {{ dns }}{% endfor %} - + dns-nameservers {{ resolvers | join(" ") }} {% if ip6pub %} + iface {{ iface0.meta_name }} inet6 static address {{ ip6pub.address }} netmask {{ ip6pub.cidr }} gateway {{ ip6pub.gateway }} {% endif %} - {% if ip4pub %} + auto {{ iface0.meta_name }}:0 iface {{ iface0.meta_name }}:0 inet static address {{ ip4priv.address }} diff --git a/packetnetworking/distros/alpine/test_alpine_3_bonded.py b/packetnetworking/distros/alpine/test_alpine_3_bonded.py index 8604a23..bcdb63e 100644 --- a/packetnetworking/distros/alpine/test_alpine_3_bonded.py +++ b/packetnetworking/distros/alpine/test_alpine_3_bonded.py @@ -26,18 +26,17 @@ def test_alpine_3_public_bonded_task_etc_network_interfaces(alpine_3_bonded_netw address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} use bond requires {iface0.meta_name} {iface1.meta_name} bond-members {iface0.meta_name} {iface1.meta_name} bond-mode {bonding_mode} - bond-downdelay 200 bond-miimon 100 bond-updelay 200 bond-xmit_hash_policy layer3+4 - dns-nameservers {dns1} {dns2} iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -80,19 +79,16 @@ def test_alpine_3_private_bonded_task_etc_network_interfaces(alpine_3_bonded_net address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} use bond requires {iface0.meta_name} {iface1.meta_name} bond-members {iface0.meta_name} {iface1.meta_name} bond-mode {bonding_mode} - bond-downdelay 200 bond-miimon 100 bond-updelay 200 bond-xmit_hash_policy layer3+4 - - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -122,18 +118,17 @@ def test_alpine_3_public_bonded_task_etc_network_interfaces_with_custom_private_ address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} use bond requires {iface0.meta_name} {iface1.meta_name} bond-members {iface0.meta_name} {iface1.meta_name} bond-mode {bonding_mode} - bond-downdelay 200 bond-miimon 100 bond-updelay 200 bond-xmit_hash_policy layer3+4 - dns-nameservers {dns1} {dns2} iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -181,19 +176,16 @@ def test_alpine_3_private_bonded_task_etc_network_interfaces_with_custom_private address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} use bond requires {iface0.meta_name} {iface1.meta_name} bond-members {iface0.meta_name} {iface1.meta_name} bond-mode {bonding_mode} - bond-downdelay 200 bond-miimon 100 bond-updelay 200 bond-xmit_hash_policy layer3+4 - - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/alpine/test_alpine_3_individual.py b/packetnetworking/distros/alpine/test_alpine_3_individual.py index 978caf0..932adda 100644 --- a/packetnetworking/distros/alpine/test_alpine_3_individual.py +++ b/packetnetworking/distros/alpine/test_alpine_3_individual.py @@ -28,8 +28,8 @@ def test_alpine_3_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface eth0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -71,9 +71,7 @@ def test_alpine_3_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -100,8 +98,8 @@ def test_alpine_3_public_individual_task_etc_network_interfaces_with_custom_priv address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface eth0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -146,9 +144,7 @@ def test_alpine_3_private_individual_task_etc_network_interfaces_with_custom_pri address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/bonded.py b/packetnetworking/distros/debian/bonded.py index f6ff08c..7ca5958 100644 --- a/packetnetworking/distros/debian/bonded.py +++ b/packetnetworking/distros/debian/bonded.py @@ -13,20 +13,5 @@ def build(self): 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") - - os = self.metadata.operating_system - - if os.distro == "debian" and os.version not in ["7", "8"]: - self.tasks.update(generate_persistent_names_udev()) - elif os.distro == "ubuntu" and os.version in [ - "14.04", - "18.04", - "19.04", - "19.10", - "20.04", - "20.10", - "21.04", - "22.04", - ]: - self.tasks.update(generate_persistent_names_udev()) + self.tasks.update(generate_persistent_names_udev()) return self.tasks diff --git a/packetnetworking/distros/debian/individual.py b/packetnetworking/distros/debian/individual.py index de70f03..f015592 100644 --- a/packetnetworking/distros/debian/individual.py +++ b/packetnetworking/distros/debian/individual.py @@ -22,13 +22,8 @@ def build_tasks(self): if os.distro == "debian" and os.version in ["10", "11"]: self.tasks.update(generate_persistent_names_udev()) elif os.distro == "ubuntu" and os.version in [ - "14.04", "18.04", - "19.04", - "19.10", "20.04", - "20.10", - "21.04", "22.04", ]: self.tasks.update(generate_persistent_names_udev()) diff --git a/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 b/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 index 4b01642..cde6e56 100644 --- a/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 +++ b/packetnetworking/distros/debian/templates/bonded/etc_network_interfaces.j2 @@ -23,6 +23,8 @@ iface bond0 inet static netmask {{ ip4priv.netmask }} gateway {{ ip4priv.gateway }} {% endif %} + dns-nameservers {{ resolvers | join(" ") }} + bond-downdelay 200 bond-miimon 100 bond-mode {{ net.bonding.mode }} @@ -31,18 +33,16 @@ iface bond0 inet static {% if osinfo.distro == 'ubuntu' and net.bonding.mode == 4 %} bond-lacp-rate 1 {% endif %} - bond-slaves{% for iface in interfaces %} {{ iface.name }}{% endfor %} - - dns-nameservers{% for dns in resolvers %} {{ dns }}{% endfor %} - + bond-slaves {{ interfaces | map(attribute='name') | join(' ')}} {% if ip6pub %} + iface bond0 inet6 static address {{ ip6pub.address }} netmask {{ ip6pub.cidr }} gateway {{ ip6pub.gateway }} {% endif %} - {% if ip4pub %} + auto bond0:0 iface bond0:0 inet static address {{ ip4priv.address }} diff --git a/packetnetworking/distros/debian/templates/individual/etc_network_interfaces.j2 b/packetnetworking/distros/debian/templates/individual/etc_network_interfaces.j2 index f4a9eb1..d7a140f 100644 --- a/packetnetworking/distros/debian/templates/individual/etc_network_interfaces.j2 +++ b/packetnetworking/distros/debian/templates/individual/etc_network_interfaces.j2 @@ -12,17 +12,16 @@ iface {{ iface0.name }} inet static netmask {{ ip4priv.netmask }} gateway {{ ip4priv.gateway }} {% endif %} - - dns-nameservers{% for dns in resolvers %} {{ dns }}{% endfor %} - + dns-nameservers {{ resolvers | join(" ") }} {% if ip6pub %} + iface {{ iface0.name }} inet6 static address {{ ip6pub.address }} netmask {{ ip6pub.cidr }} gateway {{ ip6pub.gateway }} {% endif %} - {% if ip4pub %} + auto {{ iface0.name }}:0 iface {{ iface0.name }}:0 inet static address {{ ip4priv.address }} diff --git a/packetnetworking/distros/debian/test_debian_10_bonded.py b/packetnetworking/distros/debian/test_debian_10_bonded.py index 17f9ef9..93f5072 100644 --- a/packetnetworking/distros/debian/test_debian_10_bonded.py +++ b/packetnetworking/distros/debian/test_debian_10_bonded.py @@ -26,13 +26,15 @@ def test_debian_10_public_bonded_task_etc_network_interfaces(debian_10_bonded_ne address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -75,14 +77,14 @@ def test_debian_10_private_bonded_task_etc_network_interfaces(debian_10_bonded_n address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -112,13 +114,15 @@ def test_debian_10_public_bonded_task_etc_network_interfaces_with_custom_private address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -166,14 +170,14 @@ def test_debian_10_private_bonded_task_etc_network_interfaces_with_custom_privat address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_debian_10_individual.py b/packetnetworking/distros/debian/test_debian_10_individual.py index d46e27d..afd6d06 100644 --- a/packetnetworking/distros/debian/test_debian_10_individual.py +++ b/packetnetworking/distros/debian/test_debian_10_individual.py @@ -28,8 +28,8 @@ def test_debian_10_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -71,9 +71,7 @@ def test_debian_10_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -100,8 +98,8 @@ def test_debian_10_public_individual_task_etc_network_interfaces_with_custom_pri address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -146,9 +144,7 @@ def test_debian_10_private_individual_task_etc_network_interfaces_with_custom_pr address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_debian_11_bonded.py b/packetnetworking/distros/debian/test_debian_11_bonded.py index 18606a8..fd12ce3 100644 --- a/packetnetworking/distros/debian/test_debian_11_bonded.py +++ b/packetnetworking/distros/debian/test_debian_11_bonded.py @@ -26,13 +26,15 @@ def test_debian_11_public_bonded_task_etc_network_interfaces(debian_11_bonded_ne address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -75,14 +77,14 @@ def test_debian_11_private_bonded_task_etc_network_interfaces(debian_11_bonded_n address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -112,13 +114,15 @@ def test_debian_11_public_bonded_task_etc_network_interfaces_with_custom_private address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -166,14 +170,14 @@ def test_debian_11_private_bonded_task_etc_network_interfaces_with_custom_privat address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} bond-updelay 200 bond-xmit_hash_policy layer3+4 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_debian_11_individual.py b/packetnetworking/distros/debian/test_debian_11_individual.py index 93bb0a6..9ec4f6e 100644 --- a/packetnetworking/distros/debian/test_debian_11_individual.py +++ b/packetnetworking/distros/debian/test_debian_11_individual.py @@ -28,8 +28,8 @@ def test_debian_11_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -71,9 +71,7 @@ def test_debian_11_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -100,8 +98,8 @@ def test_debian_11_public_individual_task_etc_network_interfaces_with_custom_pri address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -146,9 +144,7 @@ def test_debian_11_private_individual_task_etc_network_interfaces_with_custom_pr address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_debian_7_bonded.py b/packetnetworking/distros/debian/test_debian_7_bonded.py deleted file mode 100644 index 43c5c77..0000000 --- a/packetnetworking/distros/debian/test_debian_7_bonded.py +++ /dev/null @@ -1,259 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def debian_7_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("debian", "7", **kwargs) - - return _builder - - -def test_debian_7_public_bonded_task_etc_network_interfaces(debian_7_bonded_network): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_private_bonded_task_etc_network_interfaces(debian_7_bonded_network): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_7_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_7_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_7_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_7_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_7_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_task_etc_modules(debian_7_bonded_network): - """Validates /etc/modules for a public bond""" - builder = debian_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_debian_7_etc_resolvers_configured(debian_7_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_7_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_7_etc_hostname_configured(debian_7_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_7_etc_hosts_configured(debian_7_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_7_no_persistent_interface_names(debian_7_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_7_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/debian/test_debian_7_individual.py b/packetnetworking/distros/debian/test_debian_7_individual.py deleted file mode 100644 index 7c50106..0000000 --- a/packetnetworking/distros/debian/test_debian_7_individual.py +++ /dev/null @@ -1,248 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def debian_7_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("debian", "7", **kwargs) - - return _builder - - -def test_debian_7_public_individual_task_etc_network_interfaces( - debian_7_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_7_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_private_individual_task_etc_network_interfaces( - debian_7_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_7_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_7_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_7_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_7_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_7_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_etc_resolvers_configured(debian_7_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_7_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_7_etc_hostname_configured(debian_7_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_7_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_7_etc_hosts_configured(debian_7_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_7_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_7_no_persistent_interface_names(debian_7_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_7_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks - - -def test_debian_7_public_individual_dhcp_task_etc_network_interfaces( - debian_7_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = debian_7_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_debian_7_etc_resolvers_dhcp( - debian_7_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = debian_7_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_debian_8_bonded.py b/packetnetworking/distros/debian/test_debian_8_bonded.py deleted file mode 100644 index fa2f4b6..0000000 --- a/packetnetworking/distros/debian/test_debian_8_bonded.py +++ /dev/null @@ -1,259 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def debian_8_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("debian", "8", **kwargs) - - return _builder - - -def test_debian_8_public_bonded_task_etc_network_interfaces(debian_8_bonded_network): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_8_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_private_bonded_task_etc_network_interfaces(debian_8_bonded_network): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_8_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_8_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_8_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_8_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_8_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_task_etc_modules(debian_8_bonded_network): - """Validates /etc/modules for a public bond""" - builder = debian_8_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_debian_8_etc_resolvers_configured(debian_8_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_8_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_8_etc_hostname_configured(debian_8_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_8_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_8_etc_hosts_configured(debian_8_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_8_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_8_no_persistent_interface_names(debian_8_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_8_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/debian/test_debian_8_individual.py b/packetnetworking/distros/debian/test_debian_8_individual.py deleted file mode 100644 index 618a752..0000000 --- a/packetnetworking/distros/debian/test_debian_8_individual.py +++ /dev/null @@ -1,248 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def debian_8_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("debian", "8", **kwargs) - - return _builder - - -def test_debian_8_public_individual_task_etc_network_interfaces( - debian_8_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_8_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_private_individual_task_etc_network_interfaces( - debian_8_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_8_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_8_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_8_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_8_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_8_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_etc_resolvers_configured(debian_8_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_8_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_8_etc_hostname_configured(debian_8_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_8_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_8_etc_hosts_configured(debian_8_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_8_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_8_no_persistent_interface_names(debian_8_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_8_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks - - -def test_debian_8_public_individual_dhcp_task_etc_network_interfaces( - debian_8_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = debian_8_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_debian_8_etc_resolvers_dhcp( - debian_8_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = debian_8_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_debian_9_bonded.py b/packetnetworking/distros/debian/test_debian_9_bonded.py deleted file mode 100644 index 5be17b2..0000000 --- a/packetnetworking/distros/debian/test_debian_9_bonded.py +++ /dev/null @@ -1,278 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def debian_9_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("debian", "9", **kwargs) - - return _builder - - -def test_debian_9_public_bonded_task_etc_network_interfaces(debian_9_bonded_network): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_9_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_private_bonded_task_etc_network_interfaces(debian_9_bonded_network): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_9_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_9_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_9_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - debian_9_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_9_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_task_etc_modules(debian_9_bonded_network): - """Validates /etc/modules for a public bond""" - builder = debian_9_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_debian_9_etc_resolvers_configured(debian_9_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_9_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_9_etc_hostname_configured(debian_9_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_9_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_9_etc_hosts_configured(debian_9_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_9_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_9_persistent_interface_names(debian_9_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_9_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_debian_9_individual.py b/packetnetworking/distros/debian/test_debian_9_individual.py deleted file mode 100644 index 630cc35..0000000 --- a/packetnetworking/distros/debian/test_debian_9_individual.py +++ /dev/null @@ -1,248 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def debian_9_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("debian", "9", **kwargs) - - return _builder - - -def test_debian_9_public_individual_task_etc_network_interfaces( - debian_9_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = debian_9_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_private_individual_task_etc_network_interfaces( - debian_9_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = debian_9_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_9_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_9_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - debian_9_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = debian_9_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_etc_resolvers_configured(debian_9_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = debian_9_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_debian_9_etc_hostname_configured(debian_9_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = debian_9_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_debian_9_etc_hosts_configured(debian_9_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = debian_9_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_debian_9_no_persistent_interface_names(debian_9_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_9_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks - - -def test_debian_9_public_individual_dhcp_task_etc_network_interfaces( - debian_9_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = debian_9_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_debian_9_etc_resolvers_dhcp( - debian_9_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = debian_9_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_1404_bonded.py b/packetnetworking/distros/debian/test_ubuntu_1404_bonded.py deleted file mode 100644 index 06150ad..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1404_bonded.py +++ /dev/null @@ -1,322 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1404_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "14.04", **kwargs) - - return _builder - - -def test_ubuntu_1404_public_bonded_task_etc_network_interfaces( - ubuntu_1404_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1404_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_private_bonded_task_etc_network_interfaces( - ubuntu_1404_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1404_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1404_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1404_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1404_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1404_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_task_etc_modules(ubuntu_1404_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_1404_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_1404_etc_resolvers_configured(ubuntu_1404_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1404_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1404_etc_hostname_configured(ubuntu_1404_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1404_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1404_etc_hosts_configured(ubuntu_1404_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1404_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1404_persistent_interface_names(ubuntu_1404_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 = ubuntu_1404_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_ubuntu_1404_individual.py b/packetnetworking/distros/debian/test_ubuntu_1404_individual.py deleted file mode 100644 index ee047ac..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1404_individual.py +++ /dev/null @@ -1,267 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1404_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "14.04", **kwargs) - - return _builder - - -def test_ubuntu_1404_public_individual_task_etc_network_interfaces( - ubuntu_1404_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1404_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_private_individual_task_etc_network_interfaces( - ubuntu_1404_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1404_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1404_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1404_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1404_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1404_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_etc_resolvers_configured(ubuntu_1404_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1404_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1404_etc_hostname_configured(ubuntu_1404_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1404_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1404_etc_hosts_configured(ubuntu_1404_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1404_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1404_persistent_interface_names(ubuntu_1404_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 = ubuntu_1404_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result - - -def test_ubuntu_1404_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_1404_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_1404_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1404_etc_resolvers_dhcp( - ubuntu_1404_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_1404_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_1604_bonded.py b/packetnetworking/distros/debian/test_ubuntu_1604_bonded.py deleted file mode 100644 index 44fa48f..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1604_bonded.py +++ /dev/null @@ -1,303 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def ubuntu_1604_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "16.04", **kwargs) - - return _builder - - -def test_ubuntu_1604_public_bonded_task_etc_network_interfaces( - ubuntu_1604_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1604_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_private_bonded_task_etc_network_interfaces( - ubuntu_1604_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1604_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1604_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1604_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1604_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1604_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_task_etc_modules(ubuntu_1604_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_1604_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_1604_etc_resolvers_configured(ubuntu_1604_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1604_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1604_etc_hostname_configured(ubuntu_1604_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1604_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1604_etc_hosts_configured(ubuntu_1604_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1604_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1604_no_persistent_interface_names(ubuntu_1604_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 = ubuntu_1604_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/debian/test_ubuntu_1604_individual.py b/packetnetworking/distros/debian/test_ubuntu_1604_individual.py deleted file mode 100644 index 862f8af..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1604_individual.py +++ /dev/null @@ -1,248 +0,0 @@ -from textwrap import dedent -import pytest - - -@pytest.fixture -def ubuntu_1604_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "16.04", **kwargs) - - return _builder - - -def test_ubuntu_1604_public_individual_task_etc_network_interfaces( - ubuntu_1604_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1604_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_private_individual_task_etc_network_interfaces( - ubuntu_1604_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1604_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1604_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1604_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1604_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1604_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_etc_resolvers_configured(ubuntu_1604_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1604_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1604_etc_hostname_configured(ubuntu_1604_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1604_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1604_etc_hosts_configured(ubuntu_1604_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1604_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1604_no_persistent_interface_names(ubuntu_1604_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 = ubuntu_1604_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks - - -def test_ubuntu_1604_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_1604_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_1604_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1604_etc_resolvers_dhcp( - ubuntu_1604_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_1604_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_1804_bonded.py b/packetnetworking/distros/debian/test_ubuntu_1804_bonded.py index 2e32d1e..d92a15b 100644 --- a/packetnetworking/distros/debian/test_ubuntu_1804_bonded.py +++ b/packetnetworking/distros/debian/test_ubuntu_1804_bonded.py @@ -37,6 +37,8 @@ def test_ubuntu_1804_public_bonded_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -44,7 +46,7 @@ def test_ubuntu_1804_public_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -98,6 +100,8 @@ def test_ubuntu_1804_private_bonded_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -105,8 +109,6 @@ def test_ubuntu_1804_private_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -145,6 +147,8 @@ def test_ubuntu_1804_public_bonded_task_etc_network_interfaces_with_custom_priva address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -152,7 +156,7 @@ def test_ubuntu_1804_public_bonded_task_etc_network_interfaces_with_custom_priva bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -209,6 +213,8 @@ def test_ubuntu_1804_private_bonded_task_etc_network_interfaces_with_custom_priv address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -216,8 +222,6 @@ def test_ubuntu_1804_private_bonded_task_etc_network_interfaces_with_custom_priv bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_ubuntu_1804_individual.py b/packetnetworking/distros/debian/test_ubuntu_1804_individual.py index 3d51585..eaf8a3e 100644 --- a/packetnetworking/distros/debian/test_ubuntu_1804_individual.py +++ b/packetnetworking/distros/debian/test_ubuntu_1804_individual.py @@ -28,8 +28,8 @@ def test_ubuntu_1804_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -71,9 +71,7 @@ def test_ubuntu_1804_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -100,8 +98,8 @@ def test_ubuntu_1804_public_individual_task_etc_network_interfaces_with_custom_p address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -146,9 +144,7 @@ def test_ubuntu_1804_private_individual_task_etc_network_interfaces_with_custom_ address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_ubuntu_1904_bonded.py b/packetnetworking/distros/debian/test_ubuntu_1904_bonded.py deleted file mode 100644 index c2ee7c8..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1904_bonded.py +++ /dev/null @@ -1,322 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1904_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "19.04", **kwargs) - - return _builder - - -def test_ubuntu_1904_public_bonded_task_etc_network_interfaces( - ubuntu_1904_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1904_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_private_bonded_task_etc_network_interfaces( - ubuntu_1904_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1904_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1904_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1904_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1904_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1904_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_task_etc_modules(ubuntu_1904_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_1904_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_1904_etc_resolvers_configured(ubuntu_1904_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1904_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1904_etc_hostname_configured(ubuntu_1904_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1904_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1904_etc_hosts_configured(ubuntu_1904_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1904_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1904_persistent_interface_names(ubuntu_1904_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 = ubuntu_1904_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_ubuntu_1904_individual.py b/packetnetworking/distros/debian/test_ubuntu_1904_individual.py deleted file mode 100644 index 9ac4a36..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1904_individual.py +++ /dev/null @@ -1,267 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1904_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "19.04", **kwargs) - - return _builder - - -def test_ubuntu_1904_public_individual_task_etc_network_interfaces( - ubuntu_1904_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1904_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_private_individual_task_etc_network_interfaces( - ubuntu_1904_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1904_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1904_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1904_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1904_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1904_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_etc_resolvers_configured(ubuntu_1904_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1904_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1904_etc_hostname_configured(ubuntu_1904_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1904_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1904_etc_hosts_configured(ubuntu_1904_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1904_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1904_persistent_interface_names(ubuntu_1904_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 = ubuntu_1904_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result - - -def test_ubuntu_1904_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_1904_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_1904_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1904_etc_resolvers_dhcp( - ubuntu_1904_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_1904_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_1910_bonded.py b/packetnetworking/distros/debian/test_ubuntu_1910_bonded.py deleted file mode 100644 index 08a55de..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1910_bonded.py +++ /dev/null @@ -1,322 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1910_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "19.10", **kwargs) - - return _builder - - -def test_ubuntu_1910_public_bonded_task_etc_network_interfaces( - ubuntu_1910_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1910_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_private_bonded_task_etc_network_interfaces( - ubuntu_1910_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1910_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1910_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1910_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1910_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1910_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_task_etc_modules(ubuntu_1910_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_1910_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_1910_etc_resolvers_configured(ubuntu_1910_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1910_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1910_etc_hostname_configured(ubuntu_1910_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1910_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1910_etc_hosts_configured(ubuntu_1910_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1910_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1910_persistent_interface_names(ubuntu_1910_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 = ubuntu_1910_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_ubuntu_1910_individual.py b/packetnetworking/distros/debian/test_ubuntu_1910_individual.py deleted file mode 100644 index 4f0599d..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_1910_individual.py +++ /dev/null @@ -1,267 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_1910_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "19.10", **kwargs) - - return _builder - - -def test_ubuntu_1910_public_individual_task_etc_network_interfaces( - ubuntu_1910_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_1910_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_private_individual_task_etc_network_interfaces( - ubuntu_1910_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_1910_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1910_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1910_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_1910_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_1910_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_etc_resolvers_configured(ubuntu_1910_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_1910_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_1910_etc_hostname_configured(ubuntu_1910_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_1910_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_1910_etc_hosts_configured(ubuntu_1910_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_1910_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_1910_persistent_interface_names(ubuntu_1910_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 = ubuntu_1910_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result - - -def test_ubuntu_1910_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_1910_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_1910_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_1910_etc_resolvers_dhcp( - ubuntu_1910_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_1910_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_2004_bonded.py b/packetnetworking/distros/debian/test_ubuntu_2004_bonded.py index 931b066..936cc38 100644 --- a/packetnetworking/distros/debian/test_ubuntu_2004_bonded.py +++ b/packetnetworking/distros/debian/test_ubuntu_2004_bonded.py @@ -37,6 +37,8 @@ def test_ubuntu_2004_public_bonded_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -44,7 +46,7 @@ def test_ubuntu_2004_public_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -98,6 +100,8 @@ def test_ubuntu_2004_private_bonded_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -105,8 +109,6 @@ def test_ubuntu_2004_private_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -145,6 +147,8 @@ def test_ubuntu_2004_public_bonded_task_etc_network_interfaces_with_custom_priva address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -152,7 +156,7 @@ def test_ubuntu_2004_public_bonded_task_etc_network_interfaces_with_custom_priva bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -209,6 +213,8 @@ def test_ubuntu_2004_private_bonded_task_etc_network_interfaces_with_custom_priv address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -216,8 +222,6 @@ def test_ubuntu_2004_private_bonded_task_etc_network_interfaces_with_custom_priv bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_ubuntu_2004_individual.py b/packetnetworking/distros/debian/test_ubuntu_2004_individual.py index 8f84f75..8ae6fd1 100644 --- a/packetnetworking/distros/debian/test_ubuntu_2004_individual.py +++ b/packetnetworking/distros/debian/test_ubuntu_2004_individual.py @@ -28,8 +28,8 @@ def test_ubuntu_2004_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -71,9 +71,7 @@ def test_ubuntu_2004_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -100,8 +98,8 @@ def test_ubuntu_2004_public_individual_task_etc_network_interfaces_with_custom_p address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -146,9 +144,7 @@ def test_ubuntu_2004_private_individual_task_etc_network_interfaces_with_custom_ address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_ubuntu_2010_bonded.py b/packetnetworking/distros/debian/test_ubuntu_2010_bonded.py deleted file mode 100644 index 2623b08..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_2010_bonded.py +++ /dev/null @@ -1,322 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_2010_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "20.10", **kwargs) - - return _builder - - -def test_ubuntu_2010_public_bonded_task_etc_network_interfaces( - ubuntu_2010_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_2010_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_private_bonded_task_etc_network_interfaces( - ubuntu_2010_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_2010_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2010_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2010_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2010_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2010_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_task_etc_modules(ubuntu_2010_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_2010_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_2010_etc_resolvers_configured(ubuntu_2010_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_2010_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_2010_etc_hostname_configured(ubuntu_2010_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_2010_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_2010_etc_hosts_configured(ubuntu_2010_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_2010_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_2010_persistent_interface_names(ubuntu_2010_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 = ubuntu_2010_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_ubuntu_2010_individual.py b/packetnetworking/distros/debian/test_ubuntu_2010_individual.py deleted file mode 100644 index 0c3a2f7..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_2010_individual.py +++ /dev/null @@ -1,267 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_2010_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "20.10", **kwargs) - - return _builder - - -def test_ubuntu_2010_public_individual_task_etc_network_interfaces( - ubuntu_2010_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_2010_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_private_individual_task_etc_network_interfaces( - ubuntu_2010_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_2010_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2010_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2010_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2010_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2010_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_etc_resolvers_configured(ubuntu_2010_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_2010_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_2010_etc_hostname_configured(ubuntu_2010_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_2010_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_2010_etc_hosts_configured(ubuntu_2010_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_2010_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_2010_persistent_interface_names(ubuntu_2010_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 = ubuntu_2010_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result - - -def test_ubuntu_2010_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_2010_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_2010_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2010_etc_resolvers_dhcp( - ubuntu_2010_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_2010_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_2104_bonded.py b/packetnetworking/distros/debian/test_ubuntu_2104_bonded.py deleted file mode 100644 index 5849b75..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_2104_bonded.py +++ /dev/null @@ -1,322 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_2104_bonded_network(generic_debian_bonded_network): - def _builder(**kwargs): - return generic_debian_bonded_network("ubuntu", "21.04", **kwargs) - - return _builder - - -def test_ubuntu_2104_public_bonded_task_etc_network_interfaces( - ubuntu_2104_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_2104_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_private_bonded_task_etc_network_interfaces( - ubuntu_2104_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_2104_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_public_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_bonded_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - iface bond0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto bond0:0 - iface bond0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_private_bonded_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_bonded_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto {iface0.name} - iface {iface0.name} inet manual - bond-master bond0 - - auto {iface1.name} - iface {iface1.name} inet manual - pre-up sleep 4 - bond-master bond0 - - auto bond0 - iface bond0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - bond-downdelay 200 - bond-miimon 100 - bond-mode {bonding_mode} - bond-updelay 200 - bond-xmit_hash_policy layer3+4 - bond-lacp-rate 1 - bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_task_etc_modules(ubuntu_2104_bonded_network): - """Validates /etc/modules for a public bond""" - builder = ubuntu_2104_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - bonding - """ - ) - assert tasks["etc/modules"]["file_mode"] == "a" - assert tasks["etc/modules"]["content"] == result - - -def test_ubuntu_2104_etc_resolvers_configured(ubuntu_2104_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_2104_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_2104_etc_hostname_configured(ubuntu_2104_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_2104_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_2104_etc_hosts_configured(ubuntu_2104_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_2104_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_2104_persistent_interface_names(ubuntu_2104_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 = ubuntu_2104_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/debian/test_ubuntu_2104_individual.py b/packetnetworking/distros/debian/test_ubuntu_2104_individual.py deleted file mode 100644 index 7f84c30..0000000 --- a/packetnetworking/distros/debian/test_ubuntu_2104_individual.py +++ /dev/null @@ -1,267 +0,0 @@ -from textwrap import dedent -from ... import utils -import pytest - - -@pytest.fixture -def ubuntu_2104_individual_network(generic_debian_individual_network): - def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "21.04", **kwargs) - - return _builder - - -def test_ubuntu_2104_public_individual_task_etc_network_interfaces( - ubuntu_2104_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - - builder = ubuntu_2104_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 10.0.0.0/8 gw {ipv4priv.gateway} - post-down route del -net 10.0.0.0/8 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_private_individual_task_etc_network_interfaces( - ubuntu_2104_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - builder = ubuntu_2104_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_individual_network, -): - """Validates /etc/network/interfaces for a public bond""" - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4pub.address} - netmask {ipv4pub.netmask} - gateway {ipv4pub.gateway} - - dns-nameservers {dns1} {dns2} - iface enp0 inet6 static - address {ipv6pub.address} - netmask {ipv6pub.cidr} - gateway {ipv6pub.gateway} - - auto enp0:0 - iface enp0:0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - post-up route add -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-down route del -net 192.168.5.0/24 gw {ipv4priv.gateway} - post-up route add -net 172.16.0.0/12 gw {ipv4priv.gateway} - post-down route del -net 172.16.0.0/12 gw {ipv4priv.gateway} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/network/interfaces file. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_individual_network(public=False, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - auto lo - iface lo inet loopback - - auto enp0 - iface enp0 inet static - address {ipv4priv.address} - netmask {ipv4priv.netmask} - gateway {ipv4priv.gateway} - - dns-nameservers {dns1} {dns2} - - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_etc_resolvers_configured(ubuntu_2104_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = ubuntu_2104_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_ubuntu_2104_etc_hostname_configured(ubuntu_2104_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = ubuntu_2104_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_ubuntu_2104_etc_hosts_configured(ubuntu_2104_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = ubuntu_2104_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost {hostname} - - # The following lines are desirable for IPv6 capable hosts - ::1 localhost ip6-localhost ip6-loopback - ff02::1 ip6-allnodes - ff02::2 ip6-allrouters - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hosts"] == result - - -def test_ubuntu_2104_persistent_interface_names(ubuntu_2104_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 = ubuntu_2104_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result - - -def test_ubuntu_2104_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_2104_individual_network, - make_interfaces_dhcp_metadata, - expected_file_etc_network_interfaces_dhcp_2, -): - """Validates /etc/network/interfaces for a public dhcp interfaces""" - - builder = ubuntu_2104_individual_network( - public=True, post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - - result = expected_file_etc_network_interfaces_dhcp_2 - - assert tasks["etc/network/interfaces"] == result - - -def test_ubuntu_2104_etc_resolvers_dhcp( - ubuntu_2104_individual_network, make_interfaces_dhcp_metadata -): - """ - Validates /etc/resolv.conf is skipped - """ - builder = ubuntu_2104_individual_network( - post_gen_metadata=make_interfaces_dhcp_metadata - ) - tasks = builder.render() - assert tasks["etc/resolv.conf"] is None diff --git a/packetnetworking/distros/debian/test_ubuntu_2204_bonded.py b/packetnetworking/distros/debian/test_ubuntu_2204_bonded.py index bfb6b7d..34a6bce 100644 --- a/packetnetworking/distros/debian/test_ubuntu_2204_bonded.py +++ b/packetnetworking/distros/debian/test_ubuntu_2204_bonded.py @@ -37,6 +37,8 @@ def test_ubuntu_2204_public_bonded_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -44,7 +46,7 @@ def test_ubuntu_2204_public_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -98,6 +100,8 @@ def test_ubuntu_2204_private_bonded_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -105,8 +109,6 @@ def test_ubuntu_2204_private_bonded_task_etc_network_interfaces( bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -145,6 +147,8 @@ def test_ubuntu_2204_public_bonded_task_etc_network_interfaces_with_custom_priva address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -152,7 +156,7 @@ def test_ubuntu_2204_public_bonded_task_etc_network_interfaces_with_custom_priva bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} + iface bond0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -209,6 +213,8 @@ def test_ubuntu_2204_private_bonded_task_etc_network_interfaces_with_custom_priv address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} + dns-nameservers {dns1} {dns2} + bond-downdelay 200 bond-miimon 100 bond-mode {bonding_mode} @@ -216,8 +222,6 @@ def test_ubuntu_2204_private_bonded_task_etc_network_interfaces_with_custom_priv bond-xmit_hash_policy layer3+4 bond-lacp-rate 1 bond-slaves {iface0.name} {iface1.name} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, diff --git a/packetnetworking/distros/debian/test_ubuntu_2204_individual.py b/packetnetworking/distros/debian/test_ubuntu_2204_individual.py index 7f84c30..f33cd95 100644 --- a/packetnetworking/distros/debian/test_ubuntu_2204_individual.py +++ b/packetnetworking/distros/debian/test_ubuntu_2204_individual.py @@ -4,19 +4,19 @@ @pytest.fixture -def ubuntu_2104_individual_network(generic_debian_individual_network): +def ubuntu_2204_individual_network(generic_debian_individual_network): def _builder(**kwargs): - return generic_debian_individual_network("ubuntu", "21.04", **kwargs) + return generic_debian_individual_network("ubuntu", "22.04", **kwargs) return _builder -def test_ubuntu_2104_public_individual_task_etc_network_interfaces( - ubuntu_2104_individual_network, +def test_ubuntu_2204_public_individual_task_etc_network_interfaces( + ubuntu_2204_individual_network, ): """Validates /etc/network/interfaces for a public bond""" - builder = ubuntu_2104_individual_network(public=True) + builder = ubuntu_2204_individual_network(public=True) tasks = builder.render() result = dedent( """\ @@ -28,8 +28,8 @@ def test_ubuntu_2104_public_individual_task_etc_network_interfaces( address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -52,14 +52,14 @@ def test_ubuntu_2104_public_individual_task_etc_network_interfaces( assert tasks["etc/network/interfaces"] == result -def test_ubuntu_2104_private_individual_task_etc_network_interfaces( - ubuntu_2104_individual_network, +def test_ubuntu_2204_private_individual_task_etc_network_interfaces( + ubuntu_2204_individual_network, ): """ When no public ip is assigned, we should see the private ip details in the /etc/network/interfaces file. """ - builder = ubuntu_2104_individual_network(public=False) + builder = ubuntu_2204_individual_network(public=False) tasks = builder.render() result = dedent( """\ @@ -71,9 +71,7 @@ def test_ubuntu_2104_private_individual_task_etc_network_interfaces( address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -83,12 +81,12 @@ def test_ubuntu_2104_private_individual_task_etc_network_interfaces( assert tasks["etc/network/interfaces"] == result -def test_ubuntu_2104_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_individual_network, +def test_ubuntu_2204_public_individual_task_etc_network_interfaces_with_custom_private_ip_space( + ubuntu_2204_individual_network, ): """Validates /etc/network/interfaces for a public bond""" subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_individual_network(public=True, metadata=subnets) + builder = ubuntu_2204_individual_network(public=True, metadata=subnets) tasks = builder.render() result = dedent( """\ @@ -100,8 +98,8 @@ def test_ubuntu_2104_public_individual_task_etc_network_interfaces_with_custom_p address {ipv4pub.address} netmask {ipv4pub.netmask} gateway {ipv4pub.gateway} - dns-nameservers {dns1} {dns2} + iface enp0 inet6 static address {ipv6pub.address} netmask {ipv6pub.cidr} @@ -126,15 +124,15 @@ def test_ubuntu_2104_public_individual_task_etc_network_interfaces_with_custom_p assert tasks["etc/network/interfaces"] == result -def test_ubuntu_2104_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( - ubuntu_2104_individual_network, +def test_ubuntu_2204_private_individual_task_etc_network_interfaces_with_custom_private_ip_space( + ubuntu_2204_individual_network, ): """ When no public ip is assigned, we should see the private ip details in the /etc/network/interfaces file. """ subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = ubuntu_2104_individual_network(public=False, metadata=subnets) + builder = ubuntu_2204_individual_network(public=False, metadata=subnets) tasks = builder.render() result = dedent( """\ @@ -146,9 +144,7 @@ def test_ubuntu_2104_private_individual_task_etc_network_interfaces_with_custom_ address {ipv4priv.address} netmask {ipv4priv.netmask} gateway {ipv4priv.gateway} - dns-nameservers {dns1} {dns2} - """ ).format( ipv4priv=builder.ipv4priv.first, @@ -158,11 +154,11 @@ def test_ubuntu_2104_private_individual_task_etc_network_interfaces_with_custom_ assert tasks["etc/network/interfaces"] == result -def test_ubuntu_2104_etc_resolvers_configured(ubuntu_2104_individual_network, fake): +def test_ubuntu_2204_etc_resolvers_configured(ubuntu_2204_individual_network, fake): """ Validates /etc/resolv.conf is configured correctly """ - builder = ubuntu_2104_individual_network() + builder = ubuntu_2204_individual_network() resolver1 = fake.ipv4() resolver2 = fake.ipv4() builder.network.resolvers = (resolver1, resolver2) @@ -176,11 +172,11 @@ def test_ubuntu_2104_etc_resolvers_configured(ubuntu_2104_individual_network, fa assert tasks["etc/resolv.conf"] == result -def test_ubuntu_2104_etc_hostname_configured(ubuntu_2104_individual_network): +def test_ubuntu_2204_etc_hostname_configured(ubuntu_2204_individual_network): """ Validates /etc/hostname is configured correctly """ - builder = ubuntu_2104_individual_network() + builder = ubuntu_2204_individual_network() tasks = builder.render() result = dedent( """\ @@ -190,11 +186,11 @@ def test_ubuntu_2104_etc_hostname_configured(ubuntu_2104_individual_network): assert tasks["etc/hostname"] == result -def test_ubuntu_2104_etc_hosts_configured(ubuntu_2104_individual_network): +def test_ubuntu_2204_etc_hosts_configured(ubuntu_2204_individual_network): """ Validates /etc/hosts is configured correctly """ - builder = ubuntu_2104_individual_network() + builder = ubuntu_2204_individual_network() tasks = builder.render() result = dedent( """\ @@ -209,12 +205,12 @@ def test_ubuntu_2104_etc_hosts_configured(ubuntu_2104_individual_network): assert tasks["etc/hosts"] == result -def test_ubuntu_2104_persistent_interface_names(ubuntu_2104_individual_network): +def test_ubuntu_2204_persistent_interface_names(ubuntu_2204_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 = ubuntu_2104_individual_network() + builder = ubuntu_2204_individual_network() tasks = builder.render() result = dedent( """\ @@ -237,14 +233,14 @@ def test_ubuntu_2104_persistent_interface_names(ubuntu_2104_individual_network): assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result -def test_ubuntu_2104_public_individual_dhcp_task_etc_network_interfaces( - ubuntu_2104_individual_network, +def test_ubuntu_2204_public_individual_dhcp_task_etc_network_interfaces( + ubuntu_2204_individual_network, make_interfaces_dhcp_metadata, expected_file_etc_network_interfaces_dhcp_2, ): """Validates /etc/network/interfaces for a public dhcp interfaces""" - builder = ubuntu_2104_individual_network( + builder = ubuntu_2204_individual_network( public=True, post_gen_metadata=make_interfaces_dhcp_metadata ) tasks = builder.render() @@ -254,13 +250,13 @@ def test_ubuntu_2104_public_individual_dhcp_task_etc_network_interfaces( assert tasks["etc/network/interfaces"] == result -def test_ubuntu_2104_etc_resolvers_dhcp( - ubuntu_2104_individual_network, make_interfaces_dhcp_metadata +def test_ubuntu_2204_etc_resolvers_dhcp( + ubuntu_2204_individual_network, make_interfaces_dhcp_metadata ): """ Validates /etc/resolv.conf is skipped """ - builder = ubuntu_2104_individual_network( + builder = ubuntu_2204_individual_network( post_gen_metadata=make_interfaces_dhcp_metadata ) tasks = builder.render() diff --git a/packetnetworking/distros/redhat/bonded.py b/packetnetworking/distros/redhat/bonded.py index 390c96f..e832076 100644 --- a/packetnetworking/distros/redhat/bonded.py +++ b/packetnetworking/distros/redhat/bonded.py @@ -51,7 +51,6 @@ def build_tasks(self): ) if self.metadata.operating_system.distro not in ( - "scientificcernslc", "redhatenterpriseserver", "redhatenterprise", ): diff --git a/packetnetworking/distros/redhat/builder.py b/packetnetworking/distros/redhat/builder.py index 48c2fae..e2a7471 100644 --- a/packetnetworking/distros/redhat/builder.py +++ b/packetnetworking/distros/redhat/builder.py @@ -7,11 +7,9 @@ class RedhatBuilder(DistroBuilder): distros = [ "almalinux", "centos", - "fedora", "redhatenterprise", "redhatenterpriseserver", "rocky", - "scientificcernslc", ] network_builders = [RedhatBondedNetwork, RedhatIndividualNetwork] diff --git a/packetnetworking/distros/redhat/individual.py b/packetnetworking/distros/redhat/individual.py index efcafa7..adc61ef 100644 --- a/packetnetworking/distros/redhat/individual.py +++ b/packetnetworking/distros/redhat/individual.py @@ -39,7 +39,6 @@ def build_tasks(self): ) if self.metadata.operating_system.distro not in ( - "scientificcernslc", "redhatenterpriseserver", "redhatenterprise", ): diff --git a/packetnetworking/distros/redhat/test_fedora_31_bonded.py b/packetnetworking/distros/redhat/test_fedora_31_bonded.py deleted file mode 100644 index 5ac8989..0000000 --- a/packetnetworking/distros/redhat/test_fedora_31_bonded.py +++ /dev/null @@ -1,340 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_31_bonded_network(generic_redhat_bonded_network): - def _builder(**kwargs): - return generic_redhat_bonded_network("fedora", "31", **kwargs) - - return _builder - - -def test_fedora_31_public_bonded_task_etc_sysconfig_network(fedora_31_bonded_network): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_31_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_fedora_31_private_bonded_task_etc_sysconfig_network(fedora_31_bonded_network): - """Validates /etc/sysconfig/network for a private only bond""" - builder = fedora_31_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4priv.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 -def test_fedora_31_bonded_task_etc_modprobe_d_bonding(fedora_31_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = fedora_31_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_fedora_31_public_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_31_bonded_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-bond0 for a public bond""" - builder = fedora_31_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_31_private_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_31_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-bond0 interface file. - """ - builder = fedora_31_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_31_private_alias_task_etc_sysconfig_network_scripts_ifcfg_bond0_0( - fedora_31_bonded_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-bond0:0 alias - has been created for the private ip - """ - builder = fedora_31_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0:0 - NAME=bond0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0:0"] == result - - -def test_fedora_31_private_alias_task_missing_for_private_only_bond( - fedora_31_bonded_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-bond0:0 should not exist. - """ - builder = fedora_31_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-bond0:0" not in tasks - - -def test_fedora_31_private_route_task_etc_sysconfig_network_scripts_route_bond0( - fedora_31_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - builder = fedora_31_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -# pylama:ignore=E501 -def test_fedora_31_private_route_task_etc_sysconfig_network_scripts_route_bond0_with_custom_private_subnets( - fedora_31_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_31_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev bond0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_fedora_31_private_route_task_missing_for_private_only_bond( - fedora_31_bonded_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-bond0 should not exist. - """ - builder = fedora_31_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-bond0" not in tasks - - -def test_fedora_31_individual_interface_files_created(fedora_31_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network-scripts/ifcfg-* - """ - builder = fedora_31_bonded_network(public=True) - tasks = builder.render() - for interface in builder.network.interfaces: - result = dedent( - """\ - DEVICE={iface} - ONBOOT=yes - HWADDR={mac} - MASTER=bond0 - SLAVE=yes - BOOTPROTO=none - """ - ).format(iface=interface.name, mac=interface.mac) - assert tasks["etc/sysconfig/network-scripts/ifcfg-" + interface.name] == result - - -def test_fedora_31_etc_resolvers_configured(fedora_31_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_31_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_31_etc_hostname_configured(fedora_31_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_31_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_31_etc_hosts_configured(fedora_31_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_31_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_31_sbin_ifup_pre_local(fedora_31_bonded_network): - """ - Validates /sbin/ifup-pre-local is created correctly - """ - builder = fedora_31_bonded_network() - tasks = builder.render() - result = dedent( - """\ - #!/bin/bash - - set -o errexit -o nounset -o pipefail -o xtrace - - iface=${{1#*-}} - case "$iface" in - bond0 | {interface0.name}) ip link set "$iface" address {interface0.mac} ;; - {interface1.name}) ip link set "$iface" address {interface1.mac} && sleep 4 ;; - *) echo "ignoring unknown interface $iface" && exit 0 ;; - esac - """ - ).format( - interface0=builder.network.interfaces[0], - interface1=builder.network.interfaces[1], - ) - assert tasks["sbin/ifup-pre-local"]["content"] == result - assert tasks["sbin/ifup-pre-local"]["mode"] == 0o755 - - -def test_fedora_31_network_manager_is_disabled(fedora_31_bonded_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_31_bonded_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_31_persistent_interface_names_does_not_exist(fedora_31_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 = fedora_31_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_31_individual.py b/packetnetworking/distros/redhat/test_fedora_31_individual.py deleted file mode 100644 index f50e2c7..0000000 --- a/packetnetworking/distros/redhat/test_fedora_31_individual.py +++ /dev/null @@ -1,263 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_31_individual_network(generic_redhat_individual_network): - def _builder(**kwargs): - return generic_redhat_individual_network("fedora", "31", **kwargs) - - return _builder - - -def test_fedora_31_public_individual_task_etc_sysconfig_network( - fedora_31_individual_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_31_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=enp0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 - - -def test_fedora_31_public_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_31_individual_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-enp0 for a public bond""" - builder = fedora_31_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_31_private_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_31_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-enp0 interface file. - """ - builder = fedora_31_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_31_private_alias_task_etc_sysconfig_network_scripts_ifcfg_enp0_0( - fedora_31_individual_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-enp0:0 alias - has been created for the private ip - """ - builder = fedora_31_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0:0 - NAME=enp0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0:0"] == result - - -def test_fedora_31_private_alias_task_missing_for_private_only_enp( - fedora_31_individual_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-enp0:0 should not exist. - """ - builder = fedora_31_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-enp0:0" not in tasks - - -def test_fedora_31_private_route_task_etc_sysconfig_network_scripts_route_enp0( - fedora_31_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - builder = fedora_31_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -# pylama:ignore=E501 -def test_fedora_31_private_route_task_etc_sysconfig_network_scripts_route_enp0_with_custom_private_subnets( - fedora_31_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_31_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev enp0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_fedora_31_private_route_task_missing_for_private_only_enp( - fedora_31_individual_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-enp0 should not exist. - """ - builder = fedora_31_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-enp0" not in tasks - - -def test_fedora_31_etc_resolvers_configured(fedora_31_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_31_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_31_etc_hostname_configured(fedora_31_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_31_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_31_etc_hosts_configured(fedora_31_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_31_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_31_network_manager_is_disabled(fedora_31_individual_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_31_individual_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_31_persistent_interface_names_does_not_exist( - fedora_31_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 = fedora_31_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_32_bonded.py b/packetnetworking/distros/redhat/test_fedora_32_bonded.py deleted file mode 100644 index ec20c4c..0000000 --- a/packetnetworking/distros/redhat/test_fedora_32_bonded.py +++ /dev/null @@ -1,340 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_32_bonded_network(generic_redhat_bonded_network): - def _builder(**kwargs): - return generic_redhat_bonded_network("fedora", "32", **kwargs) - - return _builder - - -def test_fedora_32_public_bonded_task_etc_sysconfig_network(fedora_32_bonded_network): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_32_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_fedora_32_private_bonded_task_etc_sysconfig_network(fedora_32_bonded_network): - """Validates /etc/sysconfig/network for a private only bond""" - builder = fedora_32_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4priv.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 -def test_fedora_32_bonded_task_etc_modprobe_d_bonding(fedora_32_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = fedora_32_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_fedora_32_public_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_32_bonded_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-bond0 for a public bond""" - builder = fedora_32_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_32_private_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_32_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-bond0 interface file. - """ - builder = fedora_32_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_32_private_alias_task_etc_sysconfig_network_scripts_ifcfg_bond0_0( - fedora_32_bonded_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-bond0:0 alias - has been created for the private ip - """ - builder = fedora_32_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0:0 - NAME=bond0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0:0"] == result - - -def test_fedora_32_private_alias_task_missing_for_private_only_bond( - fedora_32_bonded_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-bond0:0 should not exist. - """ - builder = fedora_32_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-bond0:0" not in tasks - - -def test_fedora_32_private_route_task_etc_sysconfig_network_scripts_route_bond0( - fedora_32_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - builder = fedora_32_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -# pylama:ignore=E501 -def test_fedora_32_private_route_task_etc_sysconfig_network_scripts_route_bond0_with_custom_private_subnets( - fedora_32_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_32_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev bond0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_fedora_32_private_route_task_missing_for_private_only_bond( - fedora_32_bonded_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-bond0 should not exist. - """ - builder = fedora_32_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-bond0" not in tasks - - -def test_fedora_32_individual_interface_files_created(fedora_32_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network-scripts/ifcfg-* - """ - builder = fedora_32_bonded_network(public=True) - tasks = builder.render() - for interface in builder.network.interfaces: - result = dedent( - """\ - DEVICE={iface} - ONBOOT=yes - HWADDR={mac} - MASTER=bond0 - SLAVE=yes - BOOTPROTO=none - """ - ).format(iface=interface.name, mac=interface.mac) - assert tasks["etc/sysconfig/network-scripts/ifcfg-" + interface.name] == result - - -def test_fedora_32_etc_resolvers_configured(fedora_32_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_32_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_32_etc_hostname_configured(fedora_32_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_32_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_32_etc_hosts_configured(fedora_32_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_32_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_32_sbin_ifup_pre_local(fedora_32_bonded_network): - """ - Validates /sbin/ifup-pre-local is created correctly - """ - builder = fedora_32_bonded_network() - tasks = builder.render() - result = dedent( - """\ - #!/bin/bash - - set -o errexit -o nounset -o pipefail -o xtrace - - iface=${{1#*-}} - case "$iface" in - bond0 | {interface0.name}) ip link set "$iface" address {interface0.mac} ;; - {interface1.name}) ip link set "$iface" address {interface1.mac} && sleep 4 ;; - *) echo "ignoring unknown interface $iface" && exit 0 ;; - esac - """ - ).format( - interface0=builder.network.interfaces[0], - interface1=builder.network.interfaces[1], - ) - assert tasks["sbin/ifup-pre-local"]["content"] == result - assert tasks["sbin/ifup-pre-local"]["mode"] == 0o755 - - -def test_fedora_32_network_manager_is_disabled(fedora_32_bonded_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_32_bonded_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_32_persistent_interface_names_does_not_exist(fedora_32_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 = fedora_32_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_32_individual.py b/packetnetworking/distros/redhat/test_fedora_32_individual.py deleted file mode 100644 index 703fef5..0000000 --- a/packetnetworking/distros/redhat/test_fedora_32_individual.py +++ /dev/null @@ -1,263 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_32_individual_network(generic_redhat_individual_network): - def _builder(**kwargs): - return generic_redhat_individual_network("fedora", "32", **kwargs) - - return _builder - - -def test_fedora_32_public_individual_task_etc_sysconfig_network( - fedora_32_individual_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_32_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=enp0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 - - -def test_fedora_32_public_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_32_individual_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-enp0 for a public bond""" - builder = fedora_32_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_32_private_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_32_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-enp0 interface file. - """ - builder = fedora_32_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_32_private_alias_task_etc_sysconfig_network_scripts_ifcfg_enp0_0( - fedora_32_individual_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-enp0:0 alias - has been created for the private ip - """ - builder = fedora_32_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0:0 - NAME=enp0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0:0"] == result - - -def test_fedora_32_private_alias_task_missing_for_private_only_enp( - fedora_32_individual_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-enp0:0 should not exist. - """ - builder = fedora_32_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-enp0:0" not in tasks - - -def test_fedora_32_private_route_task_etc_sysconfig_network_scripts_route_enp0( - fedora_32_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - builder = fedora_32_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -# pylama:ignore=E501 -def test_fedora_32_private_route_task_etc_sysconfig_network_scripts_route_enp0_with_custom_private_subnets( - fedora_32_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_32_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev enp0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_fedora_32_private_route_task_missing_for_private_only_enp( - fedora_32_individual_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-enp0 should not exist. - """ - builder = fedora_32_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-enp0" not in tasks - - -def test_fedora_32_etc_resolvers_configured(fedora_32_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_32_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_32_etc_hostname_configured(fedora_32_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_32_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_32_etc_hosts_configured(fedora_32_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_32_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_32_network_manager_is_disabled(fedora_32_individual_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_32_individual_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_32_persistent_interface_names_does_not_exist( - fedora_32_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 = fedora_32_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_33_bonded.py b/packetnetworking/distros/redhat/test_fedora_33_bonded.py deleted file mode 100644 index 684329b..0000000 --- a/packetnetworking/distros/redhat/test_fedora_33_bonded.py +++ /dev/null @@ -1,340 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_33_bonded_network(generic_redhat_bonded_network): - def _builder(**kwargs): - return generic_redhat_bonded_network("fedora", "33", **kwargs) - - return _builder - - -def test_fedora_33_public_bonded_task_etc_sysconfig_network(fedora_33_bonded_network): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_33_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_fedora_33_private_bonded_task_etc_sysconfig_network(fedora_33_bonded_network): - """Validates /etc/sysconfig/network for a private only bond""" - builder = fedora_33_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4priv.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 -def test_fedora_33_bonded_task_etc_modprobe_d_bonding(fedora_33_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = fedora_33_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_fedora_33_public_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_33_bonded_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-bond0 for a public bond""" - builder = fedora_33_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_33_private_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_33_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-bond0 interface file. - """ - builder = fedora_33_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_33_private_alias_task_etc_sysconfig_network_scripts_ifcfg_bond0_0( - fedora_33_bonded_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-bond0:0 alias - has been created for the private ip - """ - builder = fedora_33_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0:0 - NAME=bond0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0:0"] == result - - -def test_fedora_33_private_alias_task_missing_for_private_only_bond( - fedora_33_bonded_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-bond0:0 should not exist. - """ - builder = fedora_33_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-bond0:0" not in tasks - - -def test_fedora_33_private_route_task_etc_sysconfig_network_scripts_route_bond0( - fedora_33_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - builder = fedora_33_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -# pylama:ignore=E501 -def test_fedora_33_private_route_task_etc_sysconfig_network_scripts_route_bond0_with_custom_private_subnets( - fedora_33_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_33_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev bond0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_fedora_33_private_route_task_missing_for_private_only_bond( - fedora_33_bonded_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-bond0 should not exist. - """ - builder = fedora_33_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-bond0" not in tasks - - -def test_fedora_33_individual_interface_files_created(fedora_33_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network-scripts/ifcfg-* - """ - builder = fedora_33_bonded_network(public=True) - tasks = builder.render() - for interface in builder.network.interfaces: - result = dedent( - """\ - DEVICE={iface} - ONBOOT=yes - HWADDR={mac} - MASTER=bond0 - SLAVE=yes - BOOTPROTO=none - """ - ).format(iface=interface.name, mac=interface.mac) - assert tasks["etc/sysconfig/network-scripts/ifcfg-" + interface.name] == result - - -def test_fedora_33_etc_resolvers_configured(fedora_33_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_33_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_33_etc_hostname_configured(fedora_33_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_33_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_33_etc_hosts_configured(fedora_33_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_33_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_33_sbin_ifup_pre_local(fedora_33_bonded_network): - """ - Validates /sbin/ifup-pre-local is created correctly - """ - builder = fedora_33_bonded_network() - tasks = builder.render() - result = dedent( - """\ - #!/bin/bash - - set -o errexit -o nounset -o pipefail -o xtrace - - iface=${{1#*-}} - case "$iface" in - bond0 | {interface0.name}) ip link set "$iface" address {interface0.mac} ;; - {interface1.name}) ip link set "$iface" address {interface1.mac} && sleep 4 ;; - *) echo "ignoring unknown interface $iface" && exit 0 ;; - esac - """ - ).format( - interface0=builder.network.interfaces[0], - interface1=builder.network.interfaces[1], - ) - assert tasks["sbin/ifup-pre-local"]["content"] == result - assert tasks["sbin/ifup-pre-local"]["mode"] == 0o755 - - -def test_fedora_33_network_manager_is_disabled(fedora_33_bonded_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_33_bonded_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_33_persistent_interface_names_does_not_exist(fedora_33_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 = fedora_33_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_33_individual.py b/packetnetworking/distros/redhat/test_fedora_33_individual.py deleted file mode 100644 index a714eb4..0000000 --- a/packetnetworking/distros/redhat/test_fedora_33_individual.py +++ /dev/null @@ -1,263 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_33_individual_network(generic_redhat_individual_network): - def _builder(**kwargs): - return generic_redhat_individual_network("fedora", "33", **kwargs) - - return _builder - - -def test_fedora_33_public_individual_task_etc_sysconfig_network( - fedora_33_individual_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_33_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=enp0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 - - -def test_fedora_33_public_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_33_individual_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-enp0 for a public bond""" - builder = fedora_33_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_33_private_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_33_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-enp0 interface file. - """ - builder = fedora_33_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_33_private_alias_task_etc_sysconfig_network_scripts_ifcfg_enp0_0( - fedora_33_individual_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-enp0:0 alias - has been created for the private ip - """ - builder = fedora_33_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0:0 - NAME=enp0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0:0"] == result - - -def test_fedora_33_private_alias_task_missing_for_private_only_enp( - fedora_33_individual_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-enp0:0 should not exist. - """ - builder = fedora_33_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-enp0:0" not in tasks - - -def test_fedora_33_private_route_task_etc_sysconfig_network_scripts_route_enp0( - fedora_33_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - builder = fedora_33_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -# pylama:ignore=E501 -def test_fedora_33_private_route_task_etc_sysconfig_network_scripts_route_enp0_with_custom_private_subnets( - fedora_33_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_33_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev enp0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_fedora_33_private_route_task_missing_for_private_only_enp( - fedora_33_individual_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-enp0 should not exist. - """ - builder = fedora_33_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-enp0" not in tasks - - -def test_fedora_33_etc_resolvers_configured(fedora_33_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_33_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_33_etc_hostname_configured(fedora_33_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_33_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_33_etc_hosts_configured(fedora_33_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_33_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_33_network_manager_is_disabled(fedora_33_individual_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_33_individual_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_33_persistent_interface_names_does_not_exist( - fedora_33_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 = fedora_33_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_34_bonded.py b/packetnetworking/distros/redhat/test_fedora_34_bonded.py deleted file mode 100644 index 1e17936..0000000 --- a/packetnetworking/distros/redhat/test_fedora_34_bonded.py +++ /dev/null @@ -1,340 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_34_bonded_network(generic_redhat_bonded_network): - def _builder(**kwargs): - return generic_redhat_bonded_network("fedora", "34", **kwargs) - - return _builder - - -def test_fedora_34_public_bonded_task_etc_sysconfig_network(fedora_34_bonded_network): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_34_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_fedora_34_private_bonded_task_etc_sysconfig_network(fedora_34_bonded_network): - """Validates /etc/sysconfig/network for a private only bond""" - builder = fedora_34_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4priv.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 -def test_fedora_34_bonded_task_etc_modprobe_d_bonding(fedora_34_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = fedora_34_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_fedora_34_public_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_34_bonded_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-bond0 for a public bond""" - builder = fedora_34_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_34_private_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - fedora_34_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-bond0 interface file. - """ - builder = fedora_34_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_fedora_34_private_alias_task_etc_sysconfig_network_scripts_ifcfg_bond0_0( - fedora_34_bonded_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-bond0:0 alias - has been created for the private ip - """ - builder = fedora_34_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0:0 - NAME=bond0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0:0"] == result - - -def test_fedora_34_private_alias_task_missing_for_private_only_bond( - fedora_34_bonded_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-bond0:0 should not exist. - """ - builder = fedora_34_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-bond0:0" not in tasks - - -def test_fedora_34_private_route_task_etc_sysconfig_network_scripts_route_bond0( - fedora_34_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - builder = fedora_34_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -# pylama:ignore=E501 -def test_fedora_34_private_route_task_etc_sysconfig_network_scripts_route_bond0_with_custom_private_subnets( - fedora_34_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_34_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev bond0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_fedora_34_private_route_task_missing_for_private_only_bond( - fedora_34_bonded_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-bond0 should not exist. - """ - builder = fedora_34_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-bond0" not in tasks - - -def test_fedora_34_individual_interface_files_created(fedora_34_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network-scripts/ifcfg-* - """ - builder = fedora_34_bonded_network(public=True) - tasks = builder.render() - for interface in builder.network.interfaces: - result = dedent( - """\ - DEVICE={iface} - ONBOOT=yes - HWADDR={mac} - MASTER=bond0 - SLAVE=yes - BOOTPROTO=none - """ - ).format(iface=interface.name, mac=interface.mac) - assert tasks["etc/sysconfig/network-scripts/ifcfg-" + interface.name] == result - - -def test_fedora_34_etc_resolvers_configured(fedora_34_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_34_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_34_etc_hostname_configured(fedora_34_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_34_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_34_etc_hosts_configured(fedora_34_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_34_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_34_sbin_ifup_pre_local(fedora_34_bonded_network): - """ - Validates /sbin/ifup-pre-local is created correctly - """ - builder = fedora_34_bonded_network() - tasks = builder.render() - result = dedent( - """\ - #!/bin/bash - - set -o errexit -o nounset -o pipefail -o xtrace - - iface=${{1#*-}} - case "$iface" in - bond0 | {interface0.name}) ip link set "$iface" address {interface0.mac} ;; - {interface1.name}) ip link set "$iface" address {interface1.mac} && sleep 4 ;; - *) echo "ignoring unknown interface $iface" && exit 0 ;; - esac - """ - ).format( - interface0=builder.network.interfaces[0], - interface1=builder.network.interfaces[1], - ) - assert tasks["sbin/ifup-pre-local"]["content"] == result - assert tasks["sbin/ifup-pre-local"]["mode"] == 0o755 - - -def test_fedora_34_network_manager_is_disabled(fedora_34_bonded_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_34_bonded_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_34_persistent_interface_names_does_not_exist(fedora_34_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 = fedora_34_bonded_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_fedora_34_individual.py b/packetnetworking/distros/redhat/test_fedora_34_individual.py deleted file mode 100644 index 430dc3d..0000000 --- a/packetnetworking/distros/redhat/test_fedora_34_individual.py +++ /dev/null @@ -1,263 +0,0 @@ -from textwrap import dedent -import os -import pytest - - -@pytest.fixture -def fedora_34_individual_network(generic_redhat_individual_network): - def _builder(**kwargs): - return generic_redhat_individual_network("fedora", "34", **kwargs) - - return _builder - - -def test_fedora_34_public_individual_task_etc_sysconfig_network( - fedora_34_individual_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = fedora_34_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=enp0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -# pylama:ignore=E501 - - -def test_fedora_34_public_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_34_individual_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-enp0 for a public bond""" - builder = fedora_34_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_34_private_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - fedora_34_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-enp0 interface file. - """ - builder = fedora_34_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_fedora_34_private_alias_task_etc_sysconfig_network_scripts_ifcfg_enp0_0( - fedora_34_individual_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-enp0:0 alias - has been created for the private ip - """ - builder = fedora_34_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0:0 - NAME=enp0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0:0"] == result - - -def test_fedora_34_private_alias_task_missing_for_private_only_enp( - fedora_34_individual_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-enp0:0 should not exist. - """ - builder = fedora_34_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-enp0:0" not in tasks - - -def test_fedora_34_private_route_task_etc_sysconfig_network_scripts_route_enp0( - fedora_34_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - builder = fedora_34_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -# pylama:ignore=E501 -def test_fedora_34_private_route_task_etc_sysconfig_network_scripts_route_enp0_with_custom_private_subnets( - fedora_34_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = fedora_34_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev enp0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_fedora_34_private_route_task_missing_for_private_only_enp( - fedora_34_individual_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-enp0 should not exist. - """ - builder = fedora_34_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-enp0" not in tasks - - -def test_fedora_34_etc_resolvers_configured(fedora_34_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = fedora_34_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_fedora_34_etc_hostname_configured(fedora_34_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = fedora_34_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_fedora_34_etc_hosts_configured(fedora_34_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = fedora_34_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_fedora_34_network_manager_is_disabled(fedora_34_individual_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = fedora_34_individual_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert tasks[os.path.join("etc/systemd/system", service + ".service")] is None - - -def test_fedora_34_persistent_interface_names_does_not_exist( - fedora_34_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 = fedora_34_individual_network() - tasks = builder.render() - assert "etc/udev/rules.d/70-persistent-net.rules" not in tasks diff --git a/packetnetworking/distros/redhat/test_scientific_7_bonded.py b/packetnetworking/distros/redhat/test_scientific_7_bonded.py deleted file mode 100644 index 83438fd..0000000 --- a/packetnetworking/distros/redhat/test_scientific_7_bonded.py +++ /dev/null @@ -1,361 +0,0 @@ -from textwrap import dedent -from ... import utils -import os -import pytest - - -@pytest.fixture -def scientific_7_bonded_network(generic_redhat_bonded_network): - def _builder(**kwargs): - return generic_redhat_bonded_network("scientificcernslc", "7", **kwargs) - - return _builder - - -def test_scientific_7_public_bonded_task_etc_sysconfig_network( - scientific_7_bonded_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = scientific_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_scientific_7_private_bonded_task_etc_sysconfig_network( - scientific_7_bonded_network, -): - """Validates /etc/sysconfig/network for a private only bond""" - builder = scientific_7_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=bond0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4priv.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_scientific_7_bonded_task_etc_modprobe_d_bonding(scientific_7_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = scientific_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_scientific_7_public_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - scientific_7_bonded_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-bond0 for a public bond""" - builder = scientific_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_scientific_7_private_bonded_task_etc_sysconfig_network_scripts_ifcfg_bond0( - scientific_7_bonded_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-bond0 interface file. - """ - builder = scientific_7_bonded_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0 - NAME=bond0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - TYPE=Bond - BONDING_OPTS="mode={bonding_mode} miimon=100 downdelay=200 updelay=200" - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - bonding_mode=builder.network.bonding.mode, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0"] == result - - -def test_scientific_7_private_alias_task_etc_sysconfig_network_scripts_ifcfg_bond0_0( - scientific_7_bonded_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-bond0:0 alias - has been created for the private ip - """ - builder = scientific_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=bond0:0 - NAME=bond0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-bond0:0"] == result - - -def test_scientific_7_private_alias_task_missing_for_private_only_bond( - scientific_7_bonded_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-bond0:0 should not exist. - """ - builder = scientific_7_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-bond0:0" not in tasks - - -def test_scientific_7_private_route_task_etc_sysconfig_network_scripts_route_bond0( - scientific_7_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - builder = scientific_7_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_scientific_7_private_route_task_etc_sysconfig_network_scripts_route_bond0_with_custom_private_subnets( - scientific_7_bonded_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-bond0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = scientific_7_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev bond0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev bond0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-bond0"] == result - - -def test_scientific_7_private_route_task_missing_for_private_only_bond( - scientific_7_bonded_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-bond0 should not exist. - """ - builder = scientific_7_bonded_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-bond0" not in tasks - - -def test_scientific_7_individual_interface_files_created(scientific_7_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network-scripts/ifcfg-* - """ - builder = scientific_7_bonded_network(public=True) - tasks = builder.render() - for interface in builder.network.interfaces: - result = dedent( - """\ - DEVICE={iface} - ONBOOT=yes - HWADDR={mac} - MASTER=bond0 - SLAVE=yes - BOOTPROTO=none - """ - ).format(iface=interface.name, mac=interface.mac) - assert tasks["etc/sysconfig/network-scripts/ifcfg-" + interface.name] == result - - -def test_scientific_7_etc_resolvers_configured(scientific_7_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = scientific_7_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_scientific_7_etc_hostname_configured(scientific_7_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = scientific_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_scientific_7_etc_hosts_configured(scientific_7_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = scientific_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_scientific_7_sbin_ifup_pre_local(scientific_7_bonded_network): - """ - Validates /sbin/ifup-pre-local is created correctly - """ - builder = scientific_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - #!/bin/bash - - set -o errexit -o nounset -o pipefail -o xtrace - - iface=${{1#*-}} - case "$iface" in - bond0 | {interface0.name}) ip link set "$iface" address {interface0.mac} ;; - {interface1.name}) ip link set "$iface" address {interface1.mac} && sleep 4 ;; - *) echo "ignoring unknown interface $iface" && exit 0 ;; - esac - """ - ).format( - interface0=builder.network.interfaces[0], - interface1=builder.network.interfaces[1], - ) - assert tasks["sbin/ifup-pre-local"]["content"] == result - assert tasks["sbin/ifup-pre-local"]["mode"] == 0o755 - - -def test_scientific_7_network_manager_is_disabled(scientific_7_bonded_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = scientific_7_bonded_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert os.path.join("etc/systemd/system", service + ".service") not in tasks - - -def test_scientific_7_persistent_interface_names(scientific_7_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 = scientific_7_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/redhat/test_scientific_7_individual.py b/packetnetworking/distros/redhat/test_scientific_7_individual.py deleted file mode 100644 index adcf178..0000000 --- a/packetnetworking/distros/redhat/test_scientific_7_individual.py +++ /dev/null @@ -1,276 +0,0 @@ -from textwrap import dedent -from ... import utils -import os -import pytest - - -@pytest.fixture -def scientific_7_individual_network(generic_redhat_individual_network): - def _builder(**kwargs): - return generic_redhat_individual_network("scientificcernslc", "7", **kwargs) - - return _builder - - -def test_scientific_7_public_individual_task_etc_sysconfig_network( - scientific_7_individual_network, -): - """Validates /etc/sysconfig/network for a public bond""" - builder = scientific_7_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - NETWORKING=yes - HOSTNAME={hostname} - GATEWAY={gateway} - GATEWAYDEV=enp0 - NOZEROCONF=yes - """ - ).format(hostname=builder.metadata.hostname, gateway=builder.ipv4pub.first.gateway) - assert tasks["etc/sysconfig/network"] == result - - -def test_scientific_7_public_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - scientific_7_individual_network, -): - """Validates /etc/sysconfig/network-scripts/ifcfg-enp0 for a public bond""" - builder = scientific_7_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4pub.address} - NETMASK={ipv4pub.netmask} - GATEWAY={ipv4pub.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - IPV6INIT=yes - IPV6ADDR={ipv6pub.address}/{ipv6pub.cidr} - IPV6_DEFAULTGW={ipv6pub.gateway} - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv6pub=builder.ipv6pub.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_scientific_7_private_individual_task_etc_sysconfig_network_scripts_ifcfg_enp0( - scientific_7_individual_network, -): - """ - When no public ip is assigned, we should see the private ip details in the - /etc/sysconfig/network-scripts/ifcfg-enp0 interface file. - """ - builder = scientific_7_individual_network(public=False) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0 - NAME=enp0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0"] == result - - -def test_scientific_7_private_alias_task_etc_sysconfig_network_scripts_ifcfg_enp0_0( - scientific_7_individual_network, -): - """ - When a public ip is assigned, the private ip address should become an - alias, this validates /etc/sysconfig/network-scripts/ifcfg-enp0:0 alias - has been created for the private ip - """ - builder = scientific_7_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - DEVICE=enp0:0 - NAME=enp0:0 - IPADDR={ipv4priv.address} - NETMASK={ipv4priv.netmask} - GATEWAY={ipv4priv.gateway} - BOOTPROTO=none - ONBOOT=yes - USERCTL=no - DNS1={dns1} - DNS2={dns2} - """ - ).format( - ipv4priv=builder.ipv4priv.first, - dns1=builder.network.resolvers[0], - dns2=builder.network.resolvers[1], - ) - assert tasks["etc/sysconfig/network-scripts/ifcfg-enp0:0"] == result - - -def test_scientific_7_private_alias_task_missing_for_private_only_enp( - scientific_7_individual_network, -): - """ - When no public ip is assigned, we should not see an alias created - therefore /etc/sysconfig/network-scripts/ifcfg-enp0:0 should not exist. - """ - builder = scientific_7_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/ifcfg-enp0:0" not in tasks - - -def test_scientific_7_private_route_task_etc_sysconfig_network_scripts_route_enp0( - scientific_7_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - builder = scientific_7_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - 10.0.0.0/8 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_scientific_7_private_route_task_etc_sysconfig_network_scripts_route_enp0_with_custom_private_subnets( - scientific_7_individual_network, -): - """ - When using a public ip, the private ip is assigned as an alias, this - validates the /etc/sysconfig/network-scripts/route-enp0 route is created - for the private subnet. - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = scientific_7_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - 192.168.5.0/24 via {ipv4priv.gateway} dev enp0:0 - 172.16.0.0/12 via {ipv4priv.gateway} dev enp0:0 - """ - ).format(ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network-scripts/route-enp0"] == result - - -def test_scientific_7_private_route_task_missing_for_private_only_enp( - scientific_7_individual_network, -): - """ - When no public ip is assigned, we should not see a route file created - therefore /etc/sysconfig/network-scripts/route-enp0 should not exist. - """ - builder = scientific_7_individual_network(public=False) - tasks = builder.render() - assert "etc/sysconfig/network-scripts/route-enp0" not in tasks - - -def test_scientific_7_etc_resolvers_configured(scientific_7_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = scientific_7_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_scientific_7_etc_hostname_configured(scientific_7_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = scientific_7_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_scientific_7_etc_hosts_configured(scientific_7_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = scientific_7_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result - - -def test_scientific_7_network_manager_is_disabled(scientific_7_individual_network): - """ - When using certain operating systems, we want to disable Network Manager, - here we make sure those distros remove the necessary files - """ - builder = scientific_7_individual_network() - tasks = builder.render() - for service in ( - "dbus-org.freedesktop.NetworkManager", - "dbus-org.freedesktop.nm-dispatcher", - "multi-user.target.wants/NetworkManager", - ): - assert os.path.join("etc/systemd/system", service + ".service") not in tasks - - -def test_scientific_7_persistent_interface_names(scientific_7_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 = scientific_7_individual_network() - tasks = builder.render() - result = dedent( - """\ - {header} - # - # 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( - header=utils.generated_header(), - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - ) - assert tasks["etc/udev/rules.d/70-persistent-net.rules"] == result diff --git a/packetnetworking/distros/suse/__init__.py b/packetnetworking/distros/suse/__init__.py deleted file mode 100644 index b55253e..0000000 --- a/packetnetworking/distros/suse/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from .builder import SuseBuilder -from .bonded import SuseBondedNetwork -from .individual import SuseIndividualNetwork - -__all__ = ["SuseBuilder", "SuseBondedNetwork", "SuseIndividualNetwork"] diff --git a/packetnetworking/distros/suse/bonded.py b/packetnetworking/distros/suse/bonded.py deleted file mode 100644 index 1c88181..0000000 --- a/packetnetworking/distros/suse/bonded.py +++ /dev/null @@ -1,32 +0,0 @@ -from .. import NetworkBuilder - - -class SuseBondedNetwork(NetworkBuilder): - def build(self): - if self.network.bonding.link_aggregation not in ("bonded", "mlag_ha"): - return - - super().build() - self.build_tasks() - - def build_tasks(self): - self.task_template( - "etc/modprobe.d/bonding.conf", "bonded/etc_modprobe.d_bonding.conf.j2" - ) - self.task_template( - "etc/sysconfig/network/ifcfg-bond0", - "bonded/etc_sysconfig_network_ifcfg-bond0.j2", - ) - self.task_template( - "etc/sysconfig/network/routes", "bonded/etc_sysconfig_network_routes.j2" - ) - - for i, iface in enumerate(self.network.interfaces): - name = iface["name"] - self.task_template( - "etc/sysconfig/network/ifcfg-" + name, - "bonded/etc_sysconfig_network_ifcfg-template.j2", - fmt={"iface": name, "i": i}, - ) - - return self.tasks diff --git a/packetnetworking/distros/suse/builder.py b/packetnetworking/distros/suse/builder.py deleted file mode 100644 index 2507cdf..0000000 --- a/packetnetworking/distros/suse/builder.py +++ /dev/null @@ -1,13 +0,0 @@ -from .. import DistroBuilder -from .bonded import SuseBondedNetwork -from .individual import SuseIndividualNetwork - - -class SuseBuilder(DistroBuilder): - distros = ["opensuseproject", "suselinux", "suse"] - network_builders = [SuseBondedNetwork, SuseIndividualNetwork] - - def build_tasks(self): - self.task_template("etc/hostname", "etc_hostname.j2") - self.task_template("etc/resolv.conf", "etc_resolv.conf.j2") - self.task_template("etc/hosts", "etc_hosts.j2") diff --git a/packetnetworking/distros/suse/conftest.py b/packetnetworking/distros/suse/conftest.py deleted file mode 100644 index b537a43..0000000 --- a/packetnetworking/distros/suse/conftest.py +++ /dev/null @@ -1,89 +0,0 @@ -import pytest -from ...builder import Builder -from ... import utils -from .builder import SuseBuilder -from .bonded import SuseBondedNetwork -from .individual import SuseIndividualNetwork - - -@pytest.fixture -def susebuilder(mockit, fake, metadata, patch_dict): - gen_metadata = metadata - - def _builder(metadata=None, public=True): - resolvers = ("1.2.3.4", "2.3.4.5") - meta_interfaces = [ - {"name": "eth0", "mac": "00:0c:29:51:53:a1", "bond": "bond0"}, - {"name": "eth1", "mac": "00:0c:29:51:53:a2", "bond": "bond0"}, - ] - phys_interfaces = [ - {"name": "enp0", "mac": "00:0c:29:51:53:a1"}, - {"name": "enp1", "mac": "00:0c:29:51:53:a2"}, - ] - _metadata = {"network": {"interfaces": meta_interfaces}} - if metadata: - patch_dict(_metadata, metadata) - md = gen_metadata(_metadata, public=public) - with mockit(utils.get_interfaces, return_value=phys_interfaces): - builder_metadata = Builder(md).initialize() - builder_metadata.network.resolvers = resolvers - - return SuseBuilder(builder_metadata) - - return _builder - - -@pytest.fixture(params=["bonded", "mlag_ha"]) -def generic_suse_bonded_network(susebuilder, patch_dict, request): - def _builder(distro, version, public=True, metadata=None): - version = str(version) - slug = "{distro}_{version}".format(distro=distro, version=version) - metadata = patch_dict( - { - "network": {"bonding": {"link_aggregation": request.param}}, - "operating_system": { - "slug": slug, - "distro": distro, - "version": version, - }, - }, - metadata or {}, - ) - builder = susebuilder(metadata, public=public) - builder.build() - builder.builders = [ - builder - for builder in builder.builders - if isinstance(builder, SuseBondedNetwork) - ] - return builder - - return _builder - - -@pytest.fixture -def generic_suse_individual_network(susebuilder, patch_dict): - def _builder(distro, version, public=True, metadata=None): - version = str(version) - slug = "{distro}_{version}".format(distro=distro, version=version) - metadata = patch_dict( - { - "network": {"bonding": {"link_aggregation": "individual"}}, - "operating_system": { - "slug": slug, - "distro": distro, - "version": version, - }, - }, - metadata or {}, - ) - builder = susebuilder(metadata, public=public) - builder.build() - builder.builders = [ - builder - for builder in builder.builders - if isinstance(builder, SuseIndividualNetwork) - ] - return builder - - return _builder diff --git a/packetnetworking/distros/suse/individual.py b/packetnetworking/distros/suse/individual.py deleted file mode 100644 index 0ab778f..0000000 --- a/packetnetworking/distros/suse/individual.py +++ /dev/null @@ -1,33 +0,0 @@ -from .. import NetworkBuilder - - -class SuseIndividualNetwork(NetworkBuilder): - def build(self): - if self.network.bonding.link_aggregation != "individual": - return - - super().build() - self.build_tasks() - - def build_tasks(self): - iface0 = self.network.interfaces[0] - - self.task_template( - "etc/sysconfig/network/ifcfg-" + iface0.name, - "individual/etc_sysconfig_network_ifcfg-iface0.j2", - ) - self.task_template( - "etc/sysconfig/network/routes", "individual/etc_sysconfig_network_routes.j2" - ) - - for i, iface in enumerate(self.network.interfaces): - if iface == iface0: - # skip interface since it is already configured above - continue - self.task_template( - "etc/sysconfig/network/ifcfg-" + iface.name, - "individual/etc_sysconfig_network_ifcfg-template.j2", - fmt={"iface": iface.name, "i": i}, - ) - - return self.tasks diff --git a/packetnetworking/distros/suse/templates/bonded/etc_modprobe.d_bonding.conf.j2 b/packetnetworking/distros/suse/templates/bonded/etc_modprobe.d_bonding.conf.j2 deleted file mode 100644 index fecbe38..0000000 --- a/packetnetworking/distros/suse/templates/bonded/etc_modprobe.d_bonding.conf.j2 +++ /dev/null @@ -1,2 +0,0 @@ -alias bond0 bonding -options bond0 mode={{ net.bonding.mode }} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 diff --git a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-bond0.j2 b/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-bond0.j2 deleted file mode 100644 index 8b5873a..0000000 --- a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-bond0.j2 +++ /dev/null @@ -1,14 +0,0 @@ -STARTMODE='onboot' -BOOTPROTO='static' -IPADDR='{{ ip4pub.address }}/{{ ip4pub.cidr }}' -BONDING_MASTER='yes' -BONDING_SLAVE_0='{{ interfaces[0].name }}' -BONDING_SLAVE_1='{{ interfaces[1].name }}' -BONDING_MODULE_OPTS='mode={{ net.bonding.mode }} miimon=100' -IPADDR1='{{ ip4priv.address }}' -NETMASK1='{{ ip4priv.netmask }}' -GATEWAY1='{{ ip4priv.gateway }}' -LABEL1='0' -IPADDR2='{{ ip6pub.address }}/{{ ip6pub.cidr }}' -GATEWAY2='{{ ip6pub.gateway }}' -LABEL2='1' diff --git a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-template.j2 b/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-template.j2 deleted file mode 100644 index 236c78b..0000000 --- a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_ifcfg-template.j2 +++ /dev/null @@ -1,2 +0,0 @@ -STARTMODE='hotplug' -BOOTPROTO='none' diff --git a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_routes.j2 b/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_routes.j2 deleted file mode 100644 index 35e0af0..0000000 --- a/packetnetworking/distros/suse/templates/bonded/etc_sysconfig_network_routes.j2 +++ /dev/null @@ -1,4 +0,0 @@ -default {{ ip4pub.gateway }} -{% for subnets in private_subnets %} -{{ subnets }} {{ ip4priv.gateway }} -{% endfor %} diff --git a/packetnetworking/distros/suse/templates/etc_hostname.j2 b/packetnetworking/distros/suse/templates/etc_hostname.j2 deleted file mode 100644 index 56baac7..0000000 --- a/packetnetworking/distros/suse/templates/etc_hostname.j2 +++ /dev/null @@ -1 +0,0 @@ -{{ hostname }} diff --git a/packetnetworking/distros/suse/templates/etc_hosts.j2 b/packetnetworking/distros/suse/templates/etc_hosts.j2 deleted file mode 100644 index 849c10d..0000000 --- a/packetnetworking/distros/suse/templates/etc_hosts.j2 +++ /dev/null @@ -1,2 +0,0 @@ -127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 -::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 diff --git a/packetnetworking/distros/suse/templates/etc_resolv.conf.j2 b/packetnetworking/distros/suse/templates/etc_resolv.conf.j2 deleted file mode 100644 index a3a2c65..0000000 --- a/packetnetworking/distros/suse/templates/etc_resolv.conf.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{% for server in resolvers %} -nameserver {{ server }} -{% endfor %} diff --git a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-iface0.j2 b/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-iface0.j2 deleted file mode 100644 index 81f2c1e..0000000 --- a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-iface0.j2 +++ /dev/null @@ -1,10 +0,0 @@ -STARTMODE='onboot' -BOOTPROTO='static' -IPADDR='{{ ip4pub.address }}/{{ ip4pub.cidr }}' -IPADDR1='{{ ip4priv.address }}' -NETMASK1='{{ ip4priv.netmask }}' -GATEWAY1='{{ ip4priv.gateway }}' -LABEL1='0' -IPADDR2='{{ ip6pub.address }}/{{ ip6pub.cidr }}' -GATEWAY2='{{ ip6pub.gateway }}' -LABEL2='1' diff --git a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-template.j2 b/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-template.j2 deleted file mode 100644 index 236c78b..0000000 --- a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_ifcfg-template.j2 +++ /dev/null @@ -1,2 +0,0 @@ -STARTMODE='hotplug' -BOOTPROTO='none' diff --git a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_routes.j2 b/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_routes.j2 deleted file mode 100644 index 6be90f6..0000000 --- a/packetnetworking/distros/suse/templates/individual/etc_sysconfig_network_routes.j2 +++ /dev/null @@ -1,4 +0,0 @@ -default {{ ip4pub.gateway }} -{% for subnet in private_subnets %} -{{ subnet }} {{ ip4priv.gateway }} -{% endfor %} diff --git a/packetnetworking/distros/suse/test_opensuseproject_bonded.py b/packetnetworking/distros/suse/test_opensuseproject_bonded.py deleted file mode 100644 index b8d4bc5..0000000 --- a/packetnetworking/distros/suse/test_opensuseproject_bonded.py +++ /dev/null @@ -1,189 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def opensuseproject_bonded_network(generic_suse_bonded_network): - def _builder(**kwargs): - return generic_suse_bonded_network("opensuseproject", "7", **kwargs) - - return _builder - - -def test_opensuseproject_private_only_throws_error(opensuseproject_bonded_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = opensuseproject_bonded_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_opensuseproject_bonded_task_etc_modprobe_d_bonding( - opensuseproject_bonded_network, -): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = opensuseproject_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_opensuseproject_public_bonded_task_etc_sysconfig_network_ifcfg_bond0( - opensuseproject_bonded_network, -): - """Validates /etc/sysconfig/network/ifcfg-bond0 for a public bond""" - builder = opensuseproject_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - BONDING_MASTER='yes' - BONDING_SLAVE_0='{iface0.name}' - BONDING_SLAVE_1='{iface1.name}' - BONDING_MODULE_OPTS='mode={bonding_mode} miimon=100' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - ) - assert tasks["etc/sysconfig/network/ifcfg-bond0"] == result - - -def test_opensuseproject_public_route_task_etc_sysconfig_network_routes( - opensuseproject_bonded_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = opensuseproject_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_opensuseproject_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - opensuseproject_bonded_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = opensuseproject_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_opensuseproject_public_task_etc_sysconfig_network_ifcfg_enp0( - opensuseproject_bonded_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = opensuseproject_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_opensuseproject_public_task_etc_sysconfig_network_ifcfg_enp1( - opensuseproject_bonded_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = opensuseproject_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_opensuseproject_etc_resolvers_configured(opensuseproject_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = opensuseproject_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_opensuseproject_etc_hostname_configured(opensuseproject_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = opensuseproject_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_opensuseproject_etc_hosts_configured(opensuseproject_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = opensuseproject_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/packetnetworking/distros/suse/test_opensuseproject_individual.py b/packetnetworking/distros/suse/test_opensuseproject_individual.py deleted file mode 100644 index 8273f42..0000000 --- a/packetnetworking/distros/suse/test_opensuseproject_individual.py +++ /dev/null @@ -1,151 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def opensuseproject_individual_network(generic_suse_individual_network): - def _builder(**kwargs): - return generic_suse_individual_network("opensuseproject", "7", **kwargs) - - return _builder - - -def test_opensuseproject_private_only_throws_error(opensuseproject_individual_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = opensuseproject_individual_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_opensuseproject_public_individual_task_etc_sysconfig_network_ifcfg_enp0( - opensuseproject_individual_network, -): - """Validates /etc/sysconfig/network/ifcfg-enp0 file""" - builder = opensuseproject_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_opensuseproject_public_route_task_etc_sysconfig_network_routes( - opensuseproject_individual_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = opensuseproject_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_opensuseproject_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - opensuseproject_individual_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = opensuseproject_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_opensuseproject_public_task_etc_sysconfig_network_ifcfg_enp1( - opensuseproject_individual_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = opensuseproject_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_opensuseproject_etc_resolvers_configured( - opensuseproject_individual_network, fake -): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = opensuseproject_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_opensuseproject_etc_hostname_configured(opensuseproject_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = opensuseproject_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_opensuseproject_etc_hosts_configured(opensuseproject_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = opensuseproject_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/packetnetworking/distros/suse/test_suse_bonded.py b/packetnetworking/distros/suse/test_suse_bonded.py deleted file mode 100644 index 20ed792..0000000 --- a/packetnetworking/distros/suse/test_suse_bonded.py +++ /dev/null @@ -1,179 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def suse_bonded_network(generic_suse_bonded_network): - def _builder(**kwargs): - return generic_suse_bonded_network("suse", "7", **kwargs) - - return _builder - - -def test_suse_private_only_throws_error(suse_bonded_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = suse_bonded_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_suse_bonded_task_etc_modprobe_d_bonding(suse_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = suse_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_suse_public_bonded_task_etc_sysconfig_network_ifcfg_bond0(suse_bonded_network): - """Validates /etc/sysconfig/network/ifcfg-bond0 for a public bond""" - builder = suse_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - BONDING_MASTER='yes' - BONDING_SLAVE_0='{iface0.name}' - BONDING_SLAVE_1='{iface1.name}' - BONDING_MODULE_OPTS='mode={bonding_mode} miimon=100' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - ) - assert tasks["etc/sysconfig/network/ifcfg-bond0"] == result - - -def test_suse_public_route_task_etc_sysconfig_network_routes(suse_bonded_network): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = suse_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suse_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - suse_bonded_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = suse_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suse_public_task_etc_sysconfig_network_ifcfg_enp0(suse_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suse_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_suse_public_task_etc_sysconfig_network_ifcfg_enp1(suse_bonded_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suse_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_suse_etc_resolvers_configured(suse_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = suse_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_suse_etc_hostname_configured(suse_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = suse_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_suse_etc_hosts_configured(suse_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = suse_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/packetnetworking/distros/suse/test_suse_individual.py b/packetnetworking/distros/suse/test_suse_individual.py deleted file mode 100644 index e671e1b..0000000 --- a/packetnetworking/distros/suse/test_suse_individual.py +++ /dev/null @@ -1,145 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def suse_individual_network(generic_suse_individual_network): - def _builder(**kwargs): - return generic_suse_individual_network("suse", "7", **kwargs) - - return _builder - - -def test_suse_private_only_throws_error(suse_individual_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = suse_individual_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_suse_public_individual_task_etc_sysconfig_network_ifcfg_enp0( - suse_individual_network, -): - """Validates /etc/sysconfig/network/ifcfg-enp0 file""" - builder = suse_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_suse_public_route_task_etc_sysconfig_network_routes(suse_individual_network): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = suse_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suse_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - suse_individual_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = suse_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suse_public_task_etc_sysconfig_network_ifcfg_enp1(suse_individual_network): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suse_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_suse_etc_resolvers_configured(suse_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = suse_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_suse_etc_hostname_configured(suse_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = suse_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_suse_etc_hosts_configured(suse_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = suse_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/packetnetworking/distros/suse/test_suselinux_bonded.py b/packetnetworking/distros/suse/test_suselinux_bonded.py deleted file mode 100644 index 5f78b97..0000000 --- a/packetnetworking/distros/suse/test_suselinux_bonded.py +++ /dev/null @@ -1,187 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def suselinux_bonded_network(generic_suse_bonded_network): - def _builder(**kwargs): - return generic_suse_bonded_network("suselinux", "7", **kwargs) - - return _builder - - -def test_suselinux_private_only_throws_error(suselinux_bonded_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = suselinux_bonded_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_suselinux_bonded_task_etc_modprobe_d_bonding(suselinux_bonded_network): - """Validates /etc/modprobe.d/bonding.conf has correct bonding mode""" - builder = suselinux_bonded_network() - tasks = builder.render() - result = dedent( - """\ - alias bond0 bonding - options bond0 mode={mode} miimon=100 downdelay=200 updelay=200 xmit_hash_policy=layer3+4 lacp_rate=1 - """ - ).format(mode=builder.network.bonding.mode) - assert tasks["etc/modprobe.d/bonding.conf"] == result - - -def test_suselinux_public_bonded_task_etc_sysconfig_network_ifcfg_bond0( - suselinux_bonded_network, -): - """Validates /etc/sysconfig/network/ifcfg-bond0 for a public bond""" - builder = suselinux_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - BONDING_MASTER='yes' - BONDING_SLAVE_0='{iface0.name}' - BONDING_SLAVE_1='{iface1.name}' - BONDING_MODULE_OPTS='mode={bonding_mode} miimon=100' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - iface0=builder.network.interfaces[0], - iface1=builder.network.interfaces[1], - bonding_mode=builder.network.bonding.mode, - ) - assert tasks["etc/sysconfig/network/ifcfg-bond0"] == result - - -def test_suselinux_public_route_task_etc_sysconfig_network_routes( - suselinux_bonded_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = suselinux_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suselinux_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - suselinux_bonded_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = suselinux_bonded_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suselinux_public_task_etc_sysconfig_network_ifcfg_enp0( - suselinux_bonded_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suselinux_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_suselinux_public_task_etc_sysconfig_network_ifcfg_enp1( - suselinux_bonded_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suselinux_bonded_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_suselinux_etc_resolvers_configured(suselinux_bonded_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = suselinux_bonded_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_suselinux_etc_hostname_configured(suselinux_bonded_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = suselinux_bonded_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_suselinux_etc_hosts_configured(suselinux_bonded_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = suselinux_bonded_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/packetnetworking/distros/suse/test_suselinux_individual.py b/packetnetworking/distros/suse/test_suselinux_individual.py deleted file mode 100644 index a7cf1db..0000000 --- a/packetnetworking/distros/suse/test_suselinux_individual.py +++ /dev/null @@ -1,149 +0,0 @@ -from textwrap import dedent -import pytest -from jinja2.exceptions import UndefinedError - - -@pytest.fixture -def suselinux_individual_network(generic_suse_individual_network): - def _builder(**kwargs): - return generic_suse_individual_network("suselinux", "7", **kwargs) - - return _builder - - -def test_suselinux_private_only_throws_error(suselinux_individual_network): - """ - Verifies a jinja2 UndefinedError is thrown when providing only - private ip information - """ - builder = suselinux_individual_network(public=False) - with pytest.raises(UndefinedError): - builder.render() - - -def test_suselinux_public_individual_task_etc_sysconfig_network_ifcfg_enp0( - suselinux_individual_network, -): - """Validates /etc/sysconfig/network/ifcfg-enp0 file""" - builder = suselinux_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='onboot' - BOOTPROTO='static' - IPADDR='{ipv4pub.address}/{ipv4pub.cidr}' - IPADDR1='{ipv4priv.address}' - NETMASK1='{ipv4priv.netmask}' - GATEWAY1='{ipv4priv.gateway}' - LABEL1='0' - IPADDR2='{ipv6pub.address}/{ipv6pub.cidr}' - GATEWAY2='{ipv6pub.gateway}' - LABEL2='1' - """ - ).format( - ipv4pub=builder.ipv4pub.first, - ipv4priv=builder.ipv4priv.first, - ipv6pub=builder.ipv6pub.first, - ) - assert tasks["etc/sysconfig/network/ifcfg-enp0"] == result - - -def test_suselinux_public_route_task_etc_sysconfig_network_routes( - suselinux_individual_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - builder = suselinux_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 10.0.0.0/8 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suselinux_public_route_task_etc_sysconfig_network_routes_with_private_subnet_routes( - suselinux_individual_network, -): - """ - Validates /etc/sysconfig/network/routes is configured correctly - """ - subnets = {"private_subnets": ["192.168.5.0/24", "172.16.0.0/12"]} - builder = suselinux_individual_network(public=True, metadata=subnets) - tasks = builder.render() - result = dedent( - """\ - default {ipv4pub.gateway} - 192.168.5.0/24 {ipv4priv.gateway} - 172.16.0.0/12 {ipv4priv.gateway} - """ - ).format(ipv4pub=builder.ipv4pub.first, ipv4priv=builder.ipv4priv.first) - assert tasks["etc/sysconfig/network/routes"] == result - - -def test_suselinux_public_task_etc_sysconfig_network_ifcfg_enp1( - suselinux_individual_network, -): - """ - For each interface, we should see the corresponding ifcfg file - located at /etc/sysconfig/network/ifcfg-* - """ - builder = suselinux_individual_network(public=True) - tasks = builder.render() - result = dedent( - """\ - STARTMODE='hotplug' - BOOTPROTO='none' - """ - ) - assert tasks["etc/sysconfig/network/ifcfg-enp1"] == result - - -def test_suselinux_etc_resolvers_configured(suselinux_individual_network, fake): - """ - Validates /etc/resolv.conf is configured correctly - """ - builder = suselinux_individual_network() - resolver1 = fake.ipv4() - resolver2 = fake.ipv4() - builder.network.resolvers = (resolver1, resolver2) - tasks = builder.render() - result = dedent( - """\ - nameserver {resolver1} - nameserver {resolver2} - """ - ).format(resolver1=resolver1, resolver2=resolver2) - assert tasks["etc/resolv.conf"] == result - - -def test_suselinux_etc_hostname_configured(suselinux_individual_network): - """ - Validates /etc/hostname is configured correctly - """ - builder = suselinux_individual_network() - tasks = builder.render() - result = dedent( - """\ - {hostname} - """ - ).format(hostname=builder.metadata.hostname) - assert tasks["etc/hostname"] == result - - -def test_suselinux_etc_hosts_configured(suselinux_individual_network): - """ - Validates /etc/hosts is configured correctly - """ - builder = suselinux_individual_network() - tasks = builder.render() - result = dedent( - """\ - 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 - ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 - """ - ) - assert tasks["etc/hosts"] == result diff --git a/tox.ini b/tox.ini index f79b7c1..c126355 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,18 @@ [tox] -# yes py35 is eol, but tinkerbell/osie still uses old ubuntu and py3.5... sigh -envlist = py35,py36,py37,py38,py39,py310 +envlist = py37,py38,py39,py310,py311 skip_missing_interpreters=True [testenv] deps = - requests - pytest - pytest-cov - mock faker + mock netaddr + pytest + pytest-cov + requests commands = - py.test -vv --cov {envsitepackagesdir}/packetnetworking --cov-report=term-missing {envsitepackagesdir}/packetnetworking + py.test --cov {envsitepackagesdir}/packetnetworking --cov-report=term-missing {envsitepackagesdir}/packetnetworking [pylama:pycodestyle] max_line_length = 88