Skip to content

Commit

Permalink
add package_changes.py
Browse files Browse the repository at this point in the history
This file allows to modify package changes based on release, target and
version. At some point it could become a YAML file but works for now.

Signed-off-by: Paul Spooren <[email protected]>
  • Loading branch information
aparcar committed Oct 27, 2023
1 parent a3442a0 commit d4b7b56
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 21 deletions.
23 changes: 2 additions & 21 deletions asu/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
report_error,
run_container,
)
from asu.package_changes import appy_package_changes

log = logging.getLogger("rq.worker")
log.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -90,27 +91,7 @@ def build(req: dict, job=None):
.split()
)

if req["target"] == "mediatek/mt7622" and req["version"].startswith("23.05"):
req["packages"].append("kmod-mt7622-firmware")
log.debug(f"Added kmod-mt7622-firmware to packages")

if req["target"] == "ath79/generic" and req["version"].startswith("23.05"):
if req["profile"] in {
"buffalo_wzr-hp-g300nh-s",
"dlink_dir-825-b1",
"netgear_wndr3700",
"netgear_wndr3700-v2",
"netgear_wndr3800",
"netgear_wndr3800ch",
"netgear_wndrmac-v1",
"netgear_wndrmac-v2",
"trendnet_tew-673gru",
}:
req["packages"].append("kmod-switch-rtl8366s")
log.debug("Added kmod-switch-rtl8366s to packages")
if req["profile"] == "buffalo_wzr-hp-g300nh-rb":
req["packages"].append("kmod-switch-rtl8366rb")
log.debug("Added kmod-switch-rtl8366rb to packages")
appy_package_changes(req)

if req.get("diff_packages"):
req["build_cmd_packages"] = diff_packages(
Expand Down
45 changes: 45 additions & 0 deletions asu/package_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import logging

log = logging.getLogger("rq.worker")


def appy_package_changes(req):
"""
Apply package changes to the request
Args:
req (dict): The image request
log (logging.Logger): The logger to use
"""

def _add_if_missing(package):
if package not in req["packages"]:
req["packages"].append(package)
log.debug(f"Added {package} to packages")

# 23.05 specific changes
if req["version"].startswith("23.05"):
# mediatek/mt7622 specific changes
if req["target"] == "mediatek/mt7622":
_add_if_missing("kmod-mt7622-firmware")
log.debug("Added kmod-mt7622-firmware to packages")

# ath79/generic specific changes
elif req["target"] == "ath79/generic":
if req["profile"] in {
"buffalo_wzr-hp-g300nh-s",
"dlink_dir-825-b1",
"netgear_wndr3700",
"netgear_wndr3700-v2",
"netgear_wndr3800",
"netgear_wndr3800ch",
"netgear_wndrmac-v1",
"netgear_wndrmac-v2",
"trendnet_tew-673gru",
}:
_add_if_missing("kmod-switch-rtl8366s")
log.debug("Added kmod-switch-rtl8366s to packages")

elif req["profile"] == "buffalo_wzr-hp-g300nh-rb":
_add_if_missing("kmod-switch-rtl8366rb")
log.debug("Added kmod-switch-rtl8366rb to packages")
64 changes: 64 additions & 0 deletions tests/test_package_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest

from asu.package_changes import appy_package_changes


def test_apply_package_changes_adds_kmod_switch_rtl8366s():
req = {
"version": "23.05",
"target": "ath79/generic",
"profile": "buffalo_wzr-hp-g300nh-s",
"packages": ["kmod-ath9k-htc"],
}
appy_package_changes(req)

assert "kmod-switch-rtl8366s" in req["packages"]


def test_apply_package_changes_does_not_add_duplicate_packages():
req = {
"version": "23.05",
"target": "ath79/generic",
"profile": "buffalo_wzr-hp-g300nh-s",
"packages": ["kmod-ath9k-htc", "kmod-switch-rtl8366s"],
}
appy_package_changes(req)

assert req["packages"] == ["kmod-ath9k-htc", "kmod-switch-rtl8366s"]


def test_apply_package_changes_does_not_modify_input_dict():
req = {
"version": "23.05",
"target": "ath79/generic",
"profile": "buffalo_wzr-hp-g300nh-s",
"packages": ["kmod-ath9k-htc"],
}
original_req = req.copy()
appy_package_changes(req)

assert req == original_req


def test_apply_package_changes_release():
req = {
"version": "21.02.0-rc1",
"target": "ath79/generic",
"profile": "buffalo_wzr-hp-g300nh-s",
"packages": ["kmod-ath9k-htc"],
}
appy_package_changes(req)

original_req = req.copy()
appy_package_changes(req)

def test_apply_package_changes_mediatek():
req = {
"version": "23.05",
"target": "mediatek/mt7622",
"profile": "foobar",
"packages": ["ubus"],
}
appy_package_changes(req)

assert "kmod-mt7622-firmware" in req["packages"]

0 comments on commit d4b7b56

Please sign in to comment.