Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from telekom/support/ubuntu2204
Browse files Browse the repository at this point in the history
Added new templating to cope with the behaviour change in ubuntu 22.04
  • Loading branch information
Cellebyte authored Nov 8, 2023
2 parents 1e46efd + 5ad717e commit c659627
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 38 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/python-prerelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python PreRelease
on:
push:
tags:
# only run the release pipeline on semver tags
- '[0-9]+.[0-9]+.[0-9]+-rc\.[0-9]+'

env:
TAG_NAME: ${{ github.ref_name }}
LINUX_AMD64_BINARY: "netplanner-linux-amd64-${{ github.ref_name }}"

jobs:
prerelease:
runs-on: ubuntu-20.04 # use an ancient release for glibc compatibility.
strategy:
fail-fast: true
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
which strip
python -m pip install --upgrade pip poetry
poetry config virtualenvs.in-project true
poetry --version
poetry install --no-root
- name: Build package
run: |
poetry build
- name: Install Package
run: |
poetry run python -m pip install dist/*.whl
echo "PROJECT_VERSION=$(poetry run python -m netplanner --version)" >> $GITHUB_ENV
TAG_VERSION_RAW="${{ env.TAG_NAME }}"
TAG_VERSION_WITHOUT_DOT="${TAG_VERSION_RAW%.*}${TAG_VERSION_RAW##*.}" # replace last dot
TAG_VERSION_WITHOUT_MINUS=${TAG_VERSION_WITHOUT_DOT//-} # replace all occurences of minus
echo "TAG_VERSION=${TAG_VERSION_WITHOUT_MINUS}" >> $GITHUB_ENV
poetry run python -m pip uninstall --yes dist/*.whl
id: version
- name: Break on version mismatch
if: ${{ env.TAG_VERSION != env.PROJECT_VERSION }}
run: |
echo "::error::We found a version mismatch GIT:[${{ env.TAG_VERSION }}] != PROJECT:[${{ env.PROJECT_VERSION }}]"
exit 1
- name: Lint with black
run: |
poetry run black -t py310 --check .
- name: Type Lint with mypy
run: |
poetry run mypy .
- name: Build package
run: |
poetry build
- name: Build dynamically linked binary
run: |
poetry run pyoxidizer build --release
mkdir -p bin/
cp build/x86_64-unknown-linux-gnu/release/install/netplanner "bin/${LINUX_AMD64_BINARY}"
chmod 0644 "bin/${LINUX_AMD64_BINARY}"
strip "bin/${LINUX_AMD64_BINARY}"
cd bin/ && sha256sum "${LINUX_AMD64_BINARY}" > "${LINUX_AMD64_BINARY}.sha256" && cd ..
- name: E2E Tests
run: |
chmod 0755 "bin/${LINUX_AMD64_BINARY}"
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/worker-config-old.yaml --output /run/systemd/networkd/worker-old configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/worker-config-new.yaml --output /run/systemd/networkd/worker-new configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/master-config-old.yaml --output /run/systemd/networkd/master-old configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/master-config-new.yaml --output /run/systemd/networkd/master-new configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/veth-trial.yaml --output /run/systemd/networkd/veth-trial configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/5g-worker --output /run/systemd/networkd/folder/5g-worker configure
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/5g-worker.yaml --output /run/systemd/networkd/5g-worker configure
# enable the netplan apply command
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/vm-config --output /run/systemd/networkd/folder/vm-config apply
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/vm-config.yaml --output /run/systemd/networkd/vm-config apply
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/vm-config-v6.yaml --output /run/systemd/networkd/vm-config-v6 apply
# this should fail
bin/${LINUX_AMD64_BINARY} --debug --local --only-networkd --config examples/empty --output /run/systemd/networkd/empty configure || true
- name: Unit Tests
run: |
echo "This should later run the unit tests."
- name: Release on GitHub
uses: softprops/action-gh-release@v1
with:
draft: false
prerelease: true
generate_release_notes: true
fail_on_unmatched_files: true
files: |
./bin/${{ env.LINUX_AMD64_BINARY }}
./bin/${{ env.LINUX_AMD64_BINARY }}.sha256
./dist/*
./build/x86_64-unknown-linux-gnu/release/install/COPYING.txt
- name: Release on PyPi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
cp build/x86_64-unknown-linux-gnu/release/install/netplanner "bin/${LINUX_AMD64_BINARY}"
chmod 0644 "bin/${LINUX_AMD64_BINARY}"
strip "bin/${LINUX_AMD64_BINARY}"
cd bin/ && sha256sum "${LINUX_AMD64_BINARY}" > "${LINUX_AMD64_BINARY}.sha256" && cd ..
- name: E2E Tests
run: |
Expand Down Expand Up @@ -93,6 +94,7 @@ jobs:
fail_on_unmatched_files: true
files: |
./bin/${{ env.LINUX_AMD64_BINARY }}
./bin/${{ env.LINUX_AMD64_BINARY }}.sha256
./dist/*
./build/x86_64-unknown-linux-gnu/release/install/COPYING.txt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.10"]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
43 changes: 16 additions & 27 deletions netplanner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,33 +158,22 @@ def main():
else:
output_path = DEFAULT_OUTPUT_PATH
## Python 3.10
# match args.command:
# case ("configure" | "apply" | "generate"):
# configure(
# configuration,
# output_path,
# local=bool(args.local),
# reload=bool(args.reload),
# only_sriov=bool(args.only_sriov),
# only_networkd=bool(args.only_networkd),
# )
# case _:
# raise Exception(f"Unknown subcommand: {'<empty>' if args.command is None else args.command}")
if args.command in ("configure", "apply", "generate"):
configure(
configuration,
output_path,
local=bool(args.local),
reload=bool(args.reload),
only_sriov=bool(args.only_sriov),
only_networkd=bool(args.only_networkd),
)
elif args.command == "rebind":
rebind(args.pci_addresses)
else:
raise Exception(
f"Unknown subcommand: {'<empty>' if args.command is None else args.command}"
)
match args.command:
case ("configure" | "apply" | "generate"):
configure(
configuration,
output_path,
local=bool(args.local),
reload=bool(args.reload),
only_sriov=bool(args.only_sriov),
only_networkd=bool(args.only_networkd),
)
case "rebind":
rebind(args.pci_addresses)
case _:
raise Exception(
f"Unknown subcommand: {'<empty>' if args.command is None else args.command}"
)
except Exception as e:
parser.print_help()
if args.debug:
Expand Down
29 changes: 21 additions & 8 deletions netplanner/providers/networkd/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ def render_networks(self):
for name, config in self.config.network.bridges.items()
if interface_name in config.interfaces
}

case Bridge():
child_interfaces = {
name: config
for name, config in self.config.network.vxlans.items()
if name in interface_config.interfaces
}
if parent_interface is not None and len(parent_interface) > 1:
raise ValueError(
f"Cannot have more than one parent interface for {interface_name}"
Expand Down Expand Up @@ -233,14 +238,21 @@ def render_netdevs(self):
| self.config.network.veths
).items():
peer_interface = None
child_interfaces = {}
# Check if interface is veth and handle only one side of it
if isinstance(interface_config, Veth):
if interface_name not in handled_veth_pairs:
handled_veth_pairs.append(interface_config.link)
else:
continue
peer_interface = self.config.network.veths[interface_config.link]

match interface_config:
case Veth():
if interface_name not in handled_veth_pairs:
handled_veth_pairs.append(interface_config.link)
else:
continue
peer_interface = self.config.network.veths[interface_config.link]
case Bridge():
child_interfaces = {
name: config
for name, config in self.config.network.vxlans.items()
if name in interface_config.interfaces
}
file_name = f"{NetworkdProvider.get_priority(interface_config)}-{interface_name}.netdev"
with open(self.path / file_name, "w") as file:
self.logger.info(f"Write: {self.path / file_name}")
Expand All @@ -249,6 +261,7 @@ def render_netdevs(self):
interface_name=interface_name,
interface=interface_config,
peer_interface=peer_interface,
child_interfaces=child_interfaces,
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{%- if interface.mtu is defined and interface.mtu != None or interface.macaddress is defined and interface.macaddress != None %}
{%- if interface.mtu is defined and interface.mtu != None or interface.macaddress is defined and interface.macaddress != None or interface.object_name == "Bridge" and (interface.interfaces | length) == 1 and child_interfaces is defined and child_interfaces %}
[Link]
{%- if interface.mtu != None %}
MTUBytes={{ interface.mtu }}
{%- endif %}
{%- if interface.macaddress != None %}
MACAddress={{ interface.macaddress }}
{%- elif interface.object_name == "Bridge" and (interface.interfaces | length) == 1 and child_interfaces is defined and child_interfaces %}
{%- set child_interface_name = interface.interfaces[0] %}
{%- set child_interface_config = child_interfaces[child_interface_name] %}
{%- if child_interface_config.macaddress is defined and child_interface_config.macaddress != None %}
MACAddress={{ child_interface_config.macaddress }}
{%- endif %}
{%- endif %}
{%- endif %}
{#-
Expand Down
6 changes: 6 additions & 0 deletions netplanner/providers/networkd/templates/systemd.netdev.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ MTUBytes={{ interface.mtu }}
{%- endif %}
{%- if interface.macaddress is defined and interface.macaddress != None %}
MACAddress={{ interface.macaddress }}
{%- elif interface.object_name == "Bridge" and (interface.interfaces | length) == 1 and child_interfaces is defined and child_interfaces %}
{%- set child_interface_name = interface.interfaces[0] %}
{%- set child_interface_config = child_interfaces[child_interface_name] %}
{%- if child_interface_config.macaddress is defined and child_interface_config.macaddress != None %}
MACAddress={{ child_interface_config.macaddress }}
{%- endif %}
{%- endif %}

{% if interface.object_name not in ["Dummy", "Veth"] %}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "netplanner"
version = "0.14.6"
version = "0.14.7-rc.5"
description = "Mimir the Netplanner is the ground of all network wisdöm"
authors = ["Marcel Fest <[email protected]>", "Christopher Dziomba <[email protected]>"]
license = "GPL-3.0-only"
Expand Down

0 comments on commit c659627

Please sign in to comment.