Skip to content

Commit de482a0

Browse files
Merge pull request #131 from xenserver-next/private/rossla/CA-392459
CA-392459: Avoid opening /dev/mem when calling biosdevname
2 parents a93599b + 93731d1 commit de482a0

8 files changed

Lines changed: 75 additions & 20 deletions

File tree

.github/workflows/main.yml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ jobs:
3636
os: ubuntu-22.04
3737
runs-on: ${{ matrix.os }}
3838
steps:
39-
- uses: actions/checkout@v3
39+
- uses: actions/checkout@v4
4040
with:
4141
fetch-depth: 0 # Needed by diff-cover to get the changed lines: origin/master..HEAD
4242
- name: Set up Python ${{ matrix.python-version }}
43-
uses: actions/setup-python@v4
43+
uses: actions/setup-python@v5
4444
with:
4545
python-version: ${{ matrix.python-version }}
4646

@@ -73,13 +73,59 @@ jobs:
7373
python3.8 -m pip install 'virtualenv<20.22' 'tox==4.5.1' tox-gh-actions
7474
tox --workdir .github/workflows/.tox --recreate
7575
76-
- name: Upload coverage reports to Codecov
77-
if: ${{ matrix.os == 'ubuntu-20.04' && github.actor != 'nektos/act'}}
76+
77+
# The new reliable Codecov upload requires Codecov to query the GitHub API to check
78+
# the repo and the commit. The repo (or organisation) owner needs to login to
79+
# codev, generated the CODECOV_TOKEN and save it as a secret in the ORG or the repo:
80+
# https://docs.codecov.com/docs/adding-the-codecov-token
81+
82+
# Links to get and set the token:
83+
# Get the CODECOV_TOKEN: https://app.codecov.io/gh/xenserver/python-libs/settings
84+
# Set the CODE_COV_TOKEN: https://github.com/xenserver/python-libs/settings/secrets/actions
85+
86+
# Without it, the API calls are rate-limited by GitHub, and the upload may fail:
87+
# https://github.com/codecov/feedback/issues/126#issuecomment-1932658904
88+
#
89+
- name: Upload coverage reports to Codecov (fallback, legacy Node.js 16 action)
90+
# If CODECOV_TOKEN is not set, use the legacy tokenless Codecov action:
91+
env:
92+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
93+
if: |
94+
!env.CODECOV_TOKEN && !cancelled() &&
95+
matrix.os == 'ubuntu-20.04' && github.actor != 'nektos/act' &&
96+
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
7897
uses: codecov/codecov-action@v3
7998
with:
8099
directory: .github/workflows/.tox/py38-covcombine-check/log
81100
env_vars: OS,PYTHON
82-
fail_ci_if_error: true
101+
# Use fail_ci_if_error: false as explained the big comment above:
102+
# Not failing this job in this case is ok because the tox CI checks also contain
103+
# a diff-cover check which would fail on changed lines missing coverage.
104+
fail_ci_if_error: false
83105
flags: unittest
84106
name: py27-py38-combined
85107
verbose: true
108+
109+
- name: Upload coverage reports to Codecov (used when secrets.CODECOV_TOKEN is set)
110+
# If CODECOV_TOKEN is set, use the new Codecov CLI to upload the coverage reports
111+
env:
112+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
113+
if: |
114+
env.CODECOV_TOKEN && !cancelled() && github.actor != 'nektos/act' &&
115+
( github.event.pull_request.number || github.ref == 'refs/heads/master' )
116+
run: >
117+
set -euxv;
118+
mv .github/workflows/.tox/py38-covcombine-check/log/coverage.xml cov.xml;
119+
curl -O https://cli.codecov.io/latest/linux/codecov; sudo chmod +x codecov;
120+
./codecov upload-process --report-type coverage
121+
--name "CLI Upload for ${{ env.PYTHON_VERSION }}"
122+
--git-service github --fail-on-error --file cov.xml --disable-search
123+
--flag python${{ env.PYTHON_VERSION }}
124+
continue-on-error: false # Fail the job if the upload with CODECOV_TOKEN fails
125+
126+
127+
- name: Upload coverage reports to Coveralls
128+
env:
129+
COVERALLS_FLAG_NAME: ${{ format('python{0}', steps.python.outputs.python-version ) }}
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
run: pip install coveralls && coveralls --service=github && coveralls --finish

.pre-commit-config.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,28 @@ repos:
5353
args: [--branch, master]
5454
always_run: true
5555
- repo: https://github.com/akaihola/darker
56-
rev: 1.7.1
56+
rev: 1.7.3
5757
hooks:
5858
- id: darker
59-
args: [--isort, -tpy33]
59+
args: [--isort, -S, -tpy36]
6060
verbose: true
6161
additional_dependencies:
62-
- black
6362
- isort
63+
64+
65+
- repo: https://github.com/pre-commit/mirrors-mypy
66+
rev: v1.8.0
67+
hooks:
68+
- id: mypy
69+
additional_dependencies:
70+
- pytest-subprocess
71+
- types-mock
72+
- types-six
73+
74+
6475
- repo: https://github.com/rcmdnk/pyproject-pre-commit
6576
rev: v0.0.12
6677
hooks:
67-
- id: mypy
68-
args: [--ignore-missing-imports] # --config-file, "mypy.ini"(config is in pyproject.toml)
69-
pass_filenames: true
7078
- id: shellcheck
7179
- id: mdformat-check
7280
exclude: README-Unicode.md

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# not support ;python_version<=3.0 or ;python_version>3.0. Therefore, it can
1010
# only list plugins available for all tested python versions (2.7, 3.6 ... 3.11):
1111
required_plugins =
12+
pytest_httpserver
1213
pytest-forked
1314
pytest-localftpserver
1415
pytest-pythonpath

tests/test_biosdevname.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def test(self):
4545
# check after the fact that we mocked the proper calls
4646
self.assertEqual(popen_mock.call_count, 2)
4747
calls = popen_mock.call_args_list
48-
self.assertEqual(calls[0].args[0], ['/sbin/biosdevname', '--policy', 'physical', '-d'])
49-
self.assertEqual(calls[1].args[0], ['/sbin/biosdevname', '--policy', 'all_ethN', '-d'])
48+
self.assertEqual(calls[0].args[0], ['/sbin/biosdevname', '--policy', 'physical', '-d', '-x'])
49+
self.assertEqual(calls[1].args[0], ['/sbin/biosdevname', '--policy', 'all_ethN', '-d', '-x'])
5050
popen_kwargs = {"stdout": PIPE, "stderr": PIPE, "universal_newlines": True}
5151
self.assertEqual(calls[0].kwargs, popen_kwargs)
5252
self.assertEqual(calls[1].kwargs, popen_kwargs)

tests/test_httpaccessor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
"""Test xcp.accessor.HTTPAccessor using a local pure-Python http(s)server fixture"""
21
# -*- coding: utf-8 -*-
2+
"""Test xcp.accessor.HTTPAccessor using a local pure-Python http(s)server fixture"""
3+
34
import base64
45
import sys
56
from contextlib import contextmanager
@@ -8,7 +9,7 @@
89

910
from six.moves import urllib # pyright: ignore
1011

11-
from xcp.accessor import createAccessor, HTTPAccessor
12+
from xcp.accessor import HTTPAccessor, createAccessor
1213

1314
from .httpserver_testcase import ErrorHandler, HTTPServerTestCase, Response
1415

@@ -42,6 +43,7 @@ def http_get_request_data(self, url, read_file, error_handler):
4243

4344
def assert_http_get_request_data(self, url, read_file, error_handler):
4445
# type:(str, str, ErrorHandler) -> HTTPAccessor
46+
# pyre-ignore[23]: silence false positive
4547
with self.http_get_request_data(url, read_file, error_handler) as (httpaccessor, ref):
4648
http_accessor_filehandle = httpaccessor.openAddress(read_file)
4749
if sys.version_info >= (3, 0):

tests/test_ifrename_dynamic.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def setUp(self):
2020
openLog(self.logbuf, logging.NOTSET)
2121

2222
def tearDown(self):
23-
self.logbuf.close()
2423
closeLogs()
24+
self.logbuf.close()
2525

2626
def test_null(self):
2727

@@ -91,7 +91,6 @@ def setUp(self):
9191
openLog(self.logbuf, logging.NOTSET)
9292

9393
def tearDown(self):
94-
9594
closeLogs()
9695
self.logbuf.close()
9796

@@ -167,7 +166,6 @@ def setUp(self):
167166
openLog(self.logbuf, logging.NOTSET)
168167

169168
def tearDown(self):
170-
171169
closeLogs()
172170
self.logbuf.close()
173171

tests/test_mountingaccessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def open_text(accessor, location, fs, text):
137137
assert isinstance(accessor, xcp.accessor.MountingAccessorTypes)
138138
name = "textfile"
139139
path = location + "/" + name
140-
assert fs.create_file(path, contents=text)
140+
assert fs.create_file(path, contents=text, encoding="utf-8")
141141
assert accessor.access(name)
142142
with accessor.openText(name) as textfile:
143143
assert not isinstance(textfile, bool)

xcp/net/biosdevname.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __run_all_devices(policy = "physical"):
4040
"""
4141

4242
proc = Popen(["/sbin/biosdevname", "--policy", policy,
43-
"-d"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
43+
"-d", "-x"], stdout=PIPE, stderr=PIPE, universal_newlines=True)
4444

4545
stdout, stderr = proc.communicate()
4646

0 commit comments

Comments
 (0)