Skip to content

Commit 97c6161

Browse files
committed
Run the code checkers on the whole repository
Signed-off-by: Gaëtan Lehmann <gaetan.lehmann@vates.tech>
1 parent 39750db commit 97c6161

File tree

15 files changed

+53
-38
lines changed

15 files changed

+53
-38
lines changed

.github/workflows/code-checkers.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ jobs:
1414
- uses: ./.github/actions/uv-setup
1515
- name: Create a dummy data.py
1616
run: cp data.py-dist data.py
17-
- run: mypy --install-types --non-interactive lib/ conftest.py pkgfixtures.py tests/
17+
- name: Create a dummy vm_data.py
18+
run: cp vm_data.py-dist vm_data.py
19+
- run: mypy --install-types --non-interactive .
1820

1921
pyright:
2022
runs-on: ubuntu-latest
@@ -25,7 +27,9 @@ jobs:
2527
- uses: ./.github/actions/uv-setup/
2628
- name: Create a dummy data.py
2729
run: cp data.py-dist data.py
28-
- run: pyright lib/ conftest.py pkgfixtures.py # tests/
30+
- name: Create a dummy vm_data.py
31+
run: cp vm_data.py-dist vm_data.py
32+
- run: pyright .
2933

3034
ruff:
3135
runs-on: ubuntu-latest
@@ -38,7 +42,7 @@ jobs:
3842
- uses: ./.github/actions/uv-setup/
3943
- name: Create a dummy data.py
4044
run: cp data.py-dist data.py
41-
- run: ruff check lib/ tests/
45+
- run: ruff check
4246

4347
flake8:
4448
runs-on: ubuntu-latest

conftest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import lib.config as global_config
1414
from lib import pxe
1515
from lib.common import (
16-
callable_marker,
1716
DiskDevName,
1817
HostAddress,
18+
callable_marker,
1919
is_uuid,
2020
prefix_object_name,
2121
setup_formatted_and_mounted_disk,
@@ -24,8 +24,8 @@
2424
vm_image,
2525
wait_for,
2626
)
27-
from lib.netutil import is_ipv6
2827
from lib.host import Host
28+
from lib.netutil import is_ipv6
2929
from lib.pool import Pool
3030
from lib.sr import SR
3131
from lib.vm import VM, vm_cache_key_from_def
@@ -321,7 +321,7 @@ def xfail_on_xcpng_8_3(host, request):
321321
@pytest.fixture(scope='session')
322322
def host_no_ipv6(host):
323323
if is_ipv6(host.hostname_or_ip):
324-
pytest.skip(f"This test requires an IPv4 XCP-ng")
324+
pytest.skip("This test requires an IPv4 XCP-ng")
325325

326326
@pytest.fixture(scope="session")
327327
def shared_sr(host):
@@ -442,9 +442,7 @@ def vm_ref(request):
442442
logging.info(">> No VM specified on CLI, and no default found in test definition. Using global default.")
443443
ref = 'mini-linux-x86_64-bios'
444444

445-
if is_uuid(ref):
446-
return ref
447-
elif ref.startswith('http'):
445+
if is_uuid(ref) or ref.startswith('http'):
448446
return ref
449447
else:
450448
return vm_image(ref)

data.py-dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ HOST_DEFAULT_PASSWORD = ""
1717

1818
def hash_password(password):
1919
"""Hash password for /etc/password."""
20-
salt = crypt.mksalt(crypt.METHOD_SHA512)
20+
salt = crypt.mksalt(crypt.METHOD_SHA512) # type: ignore
2121
return crypt.crypt(password, salt)
2222

2323
HOST_DEFAULT_PASSWORD_HASH = hash_password(HOST_DEFAULT_PASSWORD)

lib/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
8686
opts.append(f'-o "ControlPath ~/.ssh/control-{os.getpid()}:%h:%p:%r"')
8787
opts.append('-o "ControlPersist 10m"')
8888
opts.append('-o "ServerAliveInterval 10s"')
89+
opts.append('-o "LogLevel ERROR"')
8990
else:
9091
opts.append('-o "ControlMaster no"')
9192

pkgfixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from __future__ import annotations
22

33
import pytest
4-
from typing import TYPE_CHECKING, Generator
54

65
import logging
76

87
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
98

9+
from typing import TYPE_CHECKING, Generator
10+
1011
if TYPE_CHECKING:
1112
from lib.common import DiskDevName
1213
from lib.host import Host

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pydocstyle.convention = "pep257"
8686
"F401", # F401 unused-import
8787
"F811", # F811 redefined-while-unused
8888
]
89+
"conftest.py" = [
90+
"F401", # F401 unused-import
91+
"F811", # F811 redefined-while-unused
92+
]
8993

9094
[tool.ruff.lint.isort.sections]
9195
testing = ["pytest*"]

scripts/install_xcpng.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# flake8: noqa: E402
1818
sys.path.append(f"{os.path.abspath(os.path.dirname(__file__))}/..")
1919
from lib import pxe
20-
from lib.commands import SSHCommandFailed, scp, ssh
20+
from lib.commands import SSHCommandFailed, ssh
2121
from lib.common import is_uuid, wait_for
2222
from lib.host import host_data
2323
from lib.pool import Pool
@@ -62,7 +62,7 @@ def generate_answerfile(directory, installer, hostname_or_ip, target_hostname, a
6262
</installation>
6363
""")
6464
elif action == 'restore':
65-
answerfile.write(f"""<?xml version="1.0"?>
65+
answerfile.write("""<?xml version="1.0"?>
6666
<restore>
6767
</restore>
6868
""")
@@ -160,7 +160,7 @@ def main():
160160
try:
161161
pool = Pool(args.host) # will fail if host is not XCP-ng or XAPI doesn't respond yet
162162
except Exception as e:
163-
raise Exception(f"Host `{args.host}` isn't ready or isn't an XCP-ng host")
163+
raise Exception(f"Host `{args.host}` isn't ready or isn't an XCP-ng host") from e
164164

165165
host = pool.master
166166
assert host.is_enabled()
@@ -178,6 +178,7 @@ def main():
178178
vm = VM(args.vm_uuid, host)
179179
vif = vm.vifs()[0]
180180
mac_address = vif.param_get('MAC')
181+
assert mac_address is not None
181182
with tempfile.TemporaryDirectory(suffix=mac_address) as tmp_local_path:
182183
logging.info('Generate files: answerfile.xml and boot.conf')
183184
hdd = 'nvme0n1' if vm.is_uefi else 'sda'
@@ -201,11 +202,12 @@ def main():
201202
"Waiting for the installation process to complete and the VM to reboot and be up", 3600, 10
202203
)
203204
vm_ip_address = get_new_host_ip(mac_address)
205+
assert vm_ip_address is not None
204206
logging.info('The IP address of the installed XCP-ng is: ' + vm_ip_address)
205207
wait_for(lambda: is_new_host_ready(vm_ip_address), "Waiting for XAPI to be ready", 600, 10)
206208
pool2 = Pool(vm_ip_address)
207209
host2 = pool2.master
208-
host2.inventory = host2._get_xensource_inventory()
210+
host2.inventory = host2._get_xensource_inventory() # noqa: SLF001
209211
check_mac_address(host2, mac_address)
210212
logging.info(f'Target host is started and enabled in version: {host2.xcp_version}')
211213
if args.action == 'restore' and host2.xcp_version >= version.parse(xcp_version):

scripts/xcpng-fs-diff.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ class DataType(StrEnum):
5656
PACKAGE = auto()
5757

5858
def ignore_file(filename, ignored_files):
59-
for i in ignored_files:
60-
if fnmatch(filename, i):
61-
return True
62-
63-
return False
59+
return any(fnmatch(filename, i) for i in ignored_files)
6460

6561
def ssh_cmd(host, cmd):
6662
args = ["ssh", f"root@{host}", cmd]
@@ -155,9 +151,9 @@ def sftp_get(host, remote_file, local_file):
155151
return res
156152

157153
def remote_diff(host_ref, host_test, filename):
154+
file_ref = None
155+
file_test = None
158156
try:
159-
file_ref = None
160-
file_test = None
161157

162158
# check remote files are text files
163159
cmd = f"file -b {shlex.quote(filename)}"

scripts/xva_bridge.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import os
99
from xml.dom import minidom
1010

11-
import libarchive
12-
import libarchive.ffi
11+
import libarchive # type: ignore
12+
import libarchive.ffi # type: ignore
1313

1414
class XvaHeaderMember:
1515
def __init__(self, member: minidom.Element):
@@ -124,10 +124,10 @@ def set_bridge(self, bridge: str):
124124
setattr(new_entry, attr, getattr(entry, attr))
125125

126126
# ArchiveEntry doesn't expose block copying, so write the entry manually via the FFI interface
127-
libarchive.ffi.write_header(output_file._pointer, new_entry._entry_p)
127+
libarchive.ffi.write_header(output_file._pointer, new_entry._entry_p) # type: ignore # noqa: SLF001
128128
for block in entry.get_blocks():
129-
libarchive.ffi.write_data(output_file._pointer, block, len(block))
130-
libarchive.ffi.write_finish_entry(output_file._pointer)
129+
libarchive.ffi.write_data(output_file._pointer, block, len(block)) # type: ignore # noqa: SLF001
130+
libarchive.ffi.write_finish_entry(output_file._pointer) # type: ignore # noqa: SLF001
131131

132132
if args.in_place:
133133
backup_path = args.backup_path

tests/install/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class TestNested:
8585
.top_append(
8686
{"iso": {"TAG": "source", "type": "local"},
8787
"net": {"TAG": "source", "type": "url",
88-
"CONTENTS": ISO_IMAGES[iso_version]['net-url']},
88+
"CONTENTS": ISO_IMAGES[iso_version]['net-url']}, # type: ignore
8989
}[package_source],
9090
{"TAG": "admin-interface", "name": "eth0", "proto": "dhcp"},
9191
{"TAG": "primary-disk",
@@ -339,7 +339,7 @@ def test_boot_inst(self, create_vms,
339339
lambda system_disks_names, package_source, iso_version: AnswerFile("UPGRADE").top_append(
340340
{"iso": {"TAG": "source", "type": "local"},
341341
"net": {"TAG": "source", "type": "url",
342-
"CONTENTS": ISO_IMAGES[iso_version]['net-url']},
342+
"CONTENTS": ISO_IMAGES[iso_version]['net-url']}, # type: ignore
343343
}[package_source],
344344
{"TAG": "existing-installation",
345345
"CONTENTS": system_disks_names[0]},

0 commit comments

Comments
 (0)