Update python test suite to use pytest rather than nose#187
Open
mpenny-github wants to merge 22 commits into
Open
Update python test suite to use pytest rather than nose#187mpenny-github wants to merge 22 commits into
mpenny-github wants to merge 22 commits into
Conversation
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…run on arm64 hosts. Pin to a specific focal version to harden security
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the repository’s Python-based test suites from the EOL nose framework to pytest to keep tests runnable on newer Ubuntu/Python versions (notably Ubuntu Noble), while also improving local/CI ergonomics for environments that lack required kernel/network infrastructure.
Changes:
- Replace
noseassertions/attributes withpytestidioms (plainassert,pytest.mark.*) acrossglb-directorandglb-redirecttests. - Add pytest marker configuration (
pytest.ini) and update test runner scripts to select DPDK vs XDP tests via markers. - Improve containerized/local test behavior by adding skip mechanisms for missing infrastructure (e.g., vagrant backends, hugepages, KNI, XDP attach) and add/adjust CI + Docker image dependencies.
Show a summary per file
| File | Description |
|---|---|
| src/scapy-glb-gue/glb_scapy/glb_gue_scapy.py | Fix integer division for header length calculation under Py3. |
| src/scapy-glb-gue/glb_scapy/init.py | Use relative import for package correctness. |
| src/glb-redirect/tests/test_glb_redirect_v6_on_v4.py | Convert assertions/prints from nose/Py2 style to pytest/Py3 style. |
| src/glb-redirect/tests/test_glb_redirect_v4_on_v4.py | Convert assertions/prints from nose/Py2 style to pytest/Py3 style. |
| src/glb-redirect/tests/glb_test_utils.py | Add pytest-compatible skipping when vagrant backend network is unavailable. |
| src/glb-redirect/tests/glb_test_remote_snoop.py | Minor Py3 print adjustment for debug output. |
| src/glb-redirect/script/test | Switch test runner from nosetests to pytest. |
| src/glb-redirect/pytest.ini | Define runtime markers for selecting DPDK vs XDP tests. |
| src/glb-healthcheck/test/test-basic.sh | Add conditional skips for missing vagrant backends; use python3 http server. |
| src/glb-healthcheck/test/lib.sh | Add a skip mechanism and a backend reachability probe; bind local backend IP in docker. |
| src/glb-director/tests/test-config.json | Reformat test config JSON (ordering/whitespace) for Py3-era tooling usage. |
| src/glb-director/tests/test_rendezvous_table.py | Replace Py2 hex encode/decode + nose asserts with Py3/pytest style. |
| src/glb-director/tests/test_director_metrics.py | Convert nose attrs to pytest markers for backend selection. |
| src/glb-director/tests/test_director_kni.py | Convert nose attrs/asserts to pytest markers/asserts. |
| src/glb-director/tests/test_director_hash_fields.py | Convert nose asserts to pytest-style asserts. |
| src/glb-director/tests/test_director_classify_v6.py | Convert nose asserts to pytest-style asserts; update prints. |
| src/glb-director/tests/test_director_classify_v4.py | Convert nose asserts to pytest-style asserts. |
| src/glb-director/tests/test_director_classify_ranges_v6.py | Convert nose attrs/asserts to pytest markers/asserts. |
| src/glb-director/tests/test_director_classify_ranges_v4.py | Convert nose asserts to pytest style; adjust SkipTest import. |
| src/glb-director/tests/test_cli_tool.py | Convert Py2 hex/map/bytes handling and nose asserts to Py3 + pytest-style asserts. |
| src/glb-director/tests/pcap_tests.sh | Add skips when hugepages aren’t available to avoid false failures. |
| src/glb-director/tests/lib/testlib.sh | Add a skip mechanism and hugepage availability detection. |
| src/glb-director/tests/glb_test_utils.py | Add runtime/environment probes to skip incompatible setups; improve Py3 byte/string handling. |
| src/glb-director/script/test | Switch test runner from nosetests to pytest with marker-based selection. |
| src/glb-director/pytest.ini | Define runtime markers for selecting DPDK vs XDP tests. |
| src/glb-director-xdp/script/test | Run glb-director pytest suite under XDP mode using marker filtering. |
| script/test-local | Add local helper to build per-distro images and run all suite scripts in containers. |
| script/helpers/folding.sh | Update fold output to GitHub Actions log grouping syntax. |
| script/Dockerfile.focal | Pin base image digest; add python/pytest deps and GOFLAGS -buildvcs=false for container builds. |
| script/cibuild-create-packages-focal | Remove focal-only package build script (replaced by parameterized script). |
| script/cibuild-create-packages | Parameterize package build by distro and update docker build invocation. |
| requirements.txt | Replace nose dependency with pytest version range. |
| .github/workflows/test.yml | Add workflow to build docker images and run each suite in a privileged container. |
| .github/workflows/ci.yml | Update package-build job to use parameterized package script and distro matrix. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
src/glb-director/tests/glb_test_utils.py:232
stdout=open('director-output.txt', 'ab')leaves a file handle open in the parent process. Use awith open(...):aroundPopen(...)(or close the file object right after spawning) to avoid leaking file descriptors, especially since XDP tests can relaunch the director during reloads.
def setup(self, iface):
notify_shim = SystemdNotify('/tmp/glb-notify-shim.sock')
self.xdp_root = subprocess.Popen(
[
'../glb-director-xdp/xdp-root-shim/xdp-root-shim',
os.path.abspath('../glb-director-xdp/bpf/tailcall.o'),
'/sys/fs/bpf/root_array@' + iface,
iface,
],
stdout=open('director-output.txt', 'ab'),
stderr=subprocess.STDOUT,
env=notify_shim.updated_env(),
)
notify_shim.wait()
- Files reviewed: 33/34 changed files
- Comments generated: 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the third PR in a series to add support for running glb-director on ubuntu noble.
Previous PR: https://github.com/github/glb-director/pull/186/changes
It's a semi-optional pull request. The existing testing framework is functional for ubuntu focal, but it's based upon nose test library which are end of life. It won't be compatible with the version of python that ships with ubuntu noble.
There is a replacement library nose2 (https://github.com/nose-devs/nose2), but it doesn't support the older python the will come with ubuntu focal. Rather then trying to run the two tests in parallel, it made more sense to use pytest, which is supported on both platforms. The syntax is nearly identical, which allows for a relatively simple replacements.