diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 436e9de3..6f8b55bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,6 +55,8 @@ jobs: build: name: Build ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.name || inputs.name }} ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.target || inputs.target }} runs-on: [ self-hosted, latest ] + env: + PARALLEL: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.parallel == 'true' || github.event_name != 'workflow_dispatch' && inputs.parallel == true }} strategy: fail-fast: false outputs: @@ -126,7 +128,7 @@ jobs: id: parallel run: | - if [ "${{ ((github.event.inputs.parallel == 'true' && github.event_name == 'workflow_dispatch') || (github.ref_name != 'main' && github.event_name != 'workflow_dispatch')) }}" == "true" ]; then + if [ "$PARALLEL" == "true" ]; then echo "BR2_PER_PACKAGE_DIRECTORIES=y" >> output/.config MAKE="make -j$((`getconf _NPROCESSORS_ONLN` / 2 + 2))" echo "Building in parallel with -j$((`getconf _NPROCESSORS_ONLN` / 2 + 2))" diff --git a/.github/workflows/generic-x86-build.yml b/.github/workflows/generic-x86-build.yml new file mode 100644 index 00000000..3272d52a --- /dev/null +++ b/.github/workflows/generic-x86-build.yml @@ -0,0 +1,74 @@ +name: Generic X86 GitHub Build + +on: + push: + +jobs: + build: + if: github.repository != 'kernelkit/infix' + name: Infix x86_64 + runs-on: ubuntu-latest + + steps: + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + bc binutils build-essential bzip2 cpio \ + diffutils file findutils git gzip \ + libncurses-dev libssl-dev perl patch \ + python3 rsync sed tar unzip wget \ + autopoint bison flex autoconf automake \ + mtools + + - name: Checkout infix repo + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }} + ref: ${{ github.ref }} + fetch-depth: 0 + submodules: recursive + + - name: Set Build Variables + id: vars + run: | + echo "INFIX_BUILD_ID=${{ github.run_id }}" >> $GITHUB_OUTPUT + echo "dir=Infix-x86_64" >> $GITHUB_OUTPUT + echo "tgz=Infix-x86_64.tar.gz" >> $GITHUB_OUTPUT + echo "flv=_minimal" >> $GITHUB_OUTPUT + + - name: Configure x86_64_minimal + run: | + make x86_64_minimal_defconfig + + - name: Unit Test x86_64 + run: | + make test-unit + + - name: Build x86_64_minimal + run: | + make + + - name: Check SBOM + run: | + make legal-info + + - name: Report Build Size + run: | + du -sh . + du -sh output + du -sh dl || true + ls -l output/images/ + + - name: Prepare Artifact + run: | + cd output/ + mv images Infix-x86_64 + ln -s Infix-x86_64 images + tar cfz Infix-x86_64.tar.gz Infix-x86_64 + + - uses: actions/upload-artifact@v4 + with: + path: output/Infix-x86_64.tar.gz + name: artifact-x86_64 + diff --git a/.github/workflows/trigger.yml b/.github/workflows/trigger.yml index 125a6162..8fe5d0ba 100644 --- a/.github/workflows/trigger.yml +++ b/.github/workflows/trigger.yml @@ -1,4 +1,4 @@ -name: Self Trigger +name: Kernelkit Trigger on: pull_request: @@ -11,6 +11,7 @@ on: jobs: build-x86_64: + if: startsWith(github.repository, 'kernelkit/') uses: ./.github/workflows/build.yml with: target: "x86_64" @@ -18,6 +19,7 @@ jobs: flavor: "_minimal" build-aarch64: + if: startsWith(github.repository, 'kernelkit/') uses: ./.github/workflows/build.yml with: target: "aarch64" @@ -25,6 +27,7 @@ jobs: flavor: "_minimal" test-run-x86_64: + if: startsWith(github.repository, 'kernelkit/') needs: build-x86_64 uses: ./.github/workflows/test.yml with: @@ -32,6 +35,7 @@ jobs: name: "infix" test-publish-x86_64: + if: startsWith(github.repository, 'kernelkit/') needs: test-run-x86_64 uses: ./.github/workflows/publish.yml diff --git a/src/statd/python/yanger/host.py b/src/statd/python/yanger/host.py index 1fcceb90..8fd4f01c 100644 --- a/src/statd/python/yanger/host.py +++ b/src/statd/python/yanger/host.py @@ -116,6 +116,11 @@ class Localhost(Host): return None + def exists(self, path: str) -> bool: + try: + return os.path.exists(path) + except OSError: + return False class Remotehost(Localhost): def __init__(self, prefix, capdir): @@ -159,6 +164,18 @@ class Remotehost(Localhost): return out + def exists(self, path: str) -> bool: + if not self._run(("ls", path), default="", log=False): + return False + + if self.capdir: + dirname = os.path.join(self.capdir, "rootfs", os.path.dirname(path[1:])) + filname = os.path.join(self.capdir, "rootfs", path[1:]) + os.makedirs(dirname, exist_ok=True) + open(filname, "w", encoding='utf-8').close() # Create empty file + + return True + def read(self, path): out = self._run(("cat", path), default="", log=False) @@ -199,6 +216,13 @@ class Replayhost(Host): common.LOG.error(f"No recording found for run \"{path}\"") raise + def exists(self, path: str) -> bool: + path = os.path.join(self.replaydir, "rootfs", path[1:]) + try: + return os.path.exists(path) + except OSError: + return False + def read(self, path): path = os.path.join(self.replaydir, "rootfs", path[1:]) try: diff --git a/src/statd/python/yanger/ietf_hardware.py b/src/statd/python/yanger/ietf_hardware.py index 70a4aa29..94a74f65 100644 --- a/src/statd/python/yanger/ietf_hardware.py +++ b/src/statd/python/yanger/ietf_hardware.py @@ -61,18 +61,16 @@ def usb_port_components(systemjson): path = usb_port["path"] if os.path.basename(path) == "authorized_default": - # TODO: Untestable. Should be done via the host API - if os.path.exists(path): - with open(path, "r") as f: - names.append(usb_port["name"]) - data = int(f.readline().strip()) - enabled = "unlocked" if data == 1 else "locked" - port["state"] = {} - port["state"]["admin-state"] = enabled - port["name"] = usb_port["name"] - port["class"] = "infix-hardware:usb" - port["state"]["oper-state"] = "enabled" - ports.append(port) + if HOST.exists(path): + names.append(usb_port["name"]) + data = int(HOST.read(path)) + enabled = "unlocked" if data == 1 else "locked" + port["state"] = {} + port["state"]["admin-state"] = enabled + port["name"] = usb_port["name"] + port["class"] = "infix-hardware:usb" + port["state"]["oper-state"] = "enabled" + ports.append(port) return ports diff --git a/test/case/statd/system/cli/show-hardware b/test/case/statd/system/cli/show-hardware index 29460a6c..a598d096 100644 --- a/test/case/statd/system/cli/show-hardware +++ b/test/case/statd/system/cli/show-hardware @@ -1,4 +1,4 @@ USB PORTS  NAME STATE  -USB unlocked -USB2 unlocked +USB locked +USB2 locked diff --git a/test/case/statd/system/ietf-hardware.json b/test/case/statd/system/ietf-hardware.json index c8153af6..cea9cbe9 100644 --- a/test/case/statd/system/ietf-hardware.json +++ b/test/case/statd/system/ietf-hardware.json @@ -7,7 +7,7 @@ }, { "state": { - "admin-state": "unlocked", + "admin-state": "locked", "oper-state": "enabled" }, "name": "USB", @@ -15,7 +15,7 @@ }, { "state": { - "admin-state": "unlocked", + "admin-state": "locked", "oper-state": "enabled" }, "name": "USB2", diff --git a/test/case/statd/system/operational.json b/test/case/statd/system/operational.json index 31826b87..1cb94407 100644 --- a/test/case/statd/system/operational.json +++ b/test/case/statd/system/operational.json @@ -9,7 +9,7 @@ "class": "infix-hardware:usb", "name": "USB", "state": { - "admin-state": "unlocked", + "admin-state": "locked", "oper-state": "enabled" } }, @@ -17,7 +17,7 @@ "class": "infix-hardware:usb", "name": "USB2", "state": { - "admin-state": "unlocked", + "admin-state": "locked", "oper-state": "enabled" } } diff --git a/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb1/authorized_default b/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb1/authorized_default new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb1/authorized_default @@ -0,0 +1 @@ +0 diff --git a/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb2/authorized_default b/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb2/authorized_default new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/test/case/statd/system/system/rootfs/sys/bus/usb/devices/usb2/authorized_default @@ -0,0 +1 @@ +0