[v3.30] Migrate k8st tests from nose to pytest for Python 3.12 compatibility#11772
[v3.30] Migrate k8st tests from nose to pytest for Python 3.12 compatibility#11772nelljerram wants to merge 3 commits intoprojectcalico:release-v3.30from
Conversation
…vert-python2-to-python3 Migrate k8st tests from nose to pytest for Python 3.12 compatibility (cherry picked from commit f89d869)
There was a problem hiding this comment.
Pull request overview
This PR modernizes the k8st test infrastructure for Python 3.12+ compatibility by migrating from the deprecated nose test runner to pytest and updating all associated dependencies and code.
Changes:
- Converted Python 2 code to Python 3 (cmp(), integer division, subprocess output decoding)
- Updated Docker base image from 18.09 to 25 and Python 2 to Python 3
- Migrated from nose to pytest test runner with updated assertion methods
- Updated Python dependencies to Python 3-compatible versions
- Cleaned up unused variables and whitespace
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| node/tests/k8st/utils/utils.py | Added decode() calls to handle subprocess output as strings in Python 3 |
| node/tests/k8st/tests/test_local_bgp_peer.py | Replaced deprecated assertRegexpMatches/assertNotRegexpMatches with assertRegex/assertNotRegex; fixed raw string literals for regex patterns; refactored test method to support inheritance pattern |
| node/tests/k8st/tests/test_bgp_filter.py | Fixed raw string literals for regex patterns; removed unused cluster_route_regex variables; cleaned up trailing whitespace |
| node/tests/k8st/test_base.py | Updated import path for pytest compatibility; replaced cmp() with == operator; fixed integer division for Python 3 |
| node/calico_test/requirements.txt | Updated all dependencies to Python 3-compatible versions; removed Python 2 backports; removed nose dependencies and kept pytest |
| node/calico_test/Dockerfile | Updated base image to docker:25; migrated from Python 2 to Python 3 packages; updated comments to reference pytest |
| node/Makefile | Replaced nosetests command with pytest command and updated arguments |
| RUN curl -sfL https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-${TARGETARCH}.tar.gz | \ | ||
| tar xz --strip-components 1 -C /usr/local/bin etcd-${ETCD_VERSION}-linux-${TARGETARCH}/etcdctl |
There was a problem hiding this comment.
The RUN curl ... | tar pipeline downloads and extracts a remote etcdctl binary from GitHub without any checksum or signature verification, creating a supply-chain risk if the release asset or network traffic is compromised. An attacker who can tamper with that tarball could supply a malicious binary that will be installed into /usr/local/bin and executed with the container’s privileges. To mitigate this, fetch and verify a published checksum or signature for the archive (or use a package-managed etcdctl), and fail the build if verification does not match.
There was a problem hiding this comment.
Yes, but:
- This is an old-ish release branch.
- This is only relevant to our own CI, running in a Semaphore VM.
- CI does not have write access to our GitHub repos.
…1349) * Fix nested retry loop in service advertisement tests * Remove DS env updates * Fix extra spaces
Cherry-pick history
Python 2 to Python 3 Conversion & Test Runner Migration - Complete ✅
This PR comprehensively modernizes the node/tests/k8st test infrastructure by:
Part 1: Python Test Code Conversion
Files Modified
node/tests/k8st/test_base.py- Fixedcmp()and integer divisionnode/tests/k8st/tests/test_local_bgp_peer.py- Fixed 18 regex escapesnode/tests/k8st/tests/test_bgp_filter.py- Fixed 8 regex escapes, removed unused variablesPart 2: Test Container Update
Files Modified
node/calico_test/Dockerfile- Docker 18.09→25, Python 2→3node/calico_test/requirements.txt- Removed Python 2 backportsPart 3: nose → pytest Migration
Problem Solved
The
nosetest runner is incompatible with Python 3.12 because it imports theimpmodule which was removed.Changes Made
Test Assertion Updates
assertRegexpMatches→assertRegex(22 occurrences)assertNotRegexpMatches→assertNotRegex(2 occurrences)Dependency Changes
Removed:
nose==1.3.7nose-parameterized==0.6.0nose-timer==1.0.1Kept:
pytest==9.0.2Test Runner Changes (Makefile)
Part 4: Code Cleanup
Changes Made
cluster_route_regex_v4andcluster_route_regex_v6variables from test functionsComplete PR Summary
Total Impact
Verification
Benefits
✅ Python 3.12 compatible
✅ Modern, maintained dependencies
✅ Industry-standard test runner (pytest)
✅ Minimal, surgical changes
✅ No test functionality lost
✅ Clean code without unused variables
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.