Skip to content

Commit bd8ba6b

Browse files
authored
Merge pull request #286 from xcp-ng/mypy
Fixes mypy support
2 parents 96e01d1 + 091f4cb commit bd8ba6b

32 files changed

+39
-19
lines changed

.github/workflows/jobs-check.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,21 @@ jobs:
1919
run: cp data.py-dist data.py
2020
- name: jobs-check
2121
run: ./jobs.py check
22+
23+
mypy:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: 3.8
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install -r requirements/base.txt
35+
pip install mypy
36+
- name: Create a dummy data.py
37+
run: cp data.py-dist data.py
38+
- name: Check with mypy
39+
run: mypy lib/ tests/

data.py-dist

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Any, Dict
2+
13
# Configuration file, to be adapted to one's needs
24

35
# Default user and password to connect to a host through XAPI
@@ -15,7 +17,7 @@ HOST_DEFAULT_PASSWORD = ""
1517
# skip_xo_config allows to not touch XO's configuration regarding the host
1618
# Else the default behaviour is to add the host to XO servers at the beginning
1719
# of the testing session and remove it at the end.
18-
HOSTS = {
20+
HOSTS: Dict[str, Dict[str, Any]] = {
1921
# "10.0.0.1": {"user": "root", "password": ""},
2022
# "testhost1": {"user": "root", "password": "", 'skip_xo_config': True},
2123
}
@@ -106,44 +108,44 @@ DEFAULT_SR = 'default'
106108
CACHE_IMPORTED_VM = False
107109

108110
# Default NFS device config:
109-
NFS_DEVICE_CONFIG = {
111+
NFS_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
110112
# 'server': '10.0.0.2', # URL/Hostname of NFS server
111113
# 'serverpath': '/path/to/shared/mount' # Path to shared mountpoint
112114
}
113115

114116
# Default NFS4+ only device config:
115-
NFS4_DEVICE_CONFIG = {
117+
NFS4_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
116118
# 'server': '10.0.0.2', # URL/Hostname of NFS server
117119
# 'serverpath': '/path_to_shared_mount' # Path to shared mountpoint
118120
# 'nfsversion': '4.1'
119121
}
120122

121123
# Default NFS ISO device config:
122-
NFS_ISO_DEVICE_CONFIG = {
124+
NFS_ISO_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
123125
# 'location': '10.0.0.2:/path/to/shared/mount' # URL/Hostname of NFS server and path to shared mountpoint
124126
}
125127

126128
# Default CIFS ISO device config:
127-
CIFS_ISO_DEVICE_CONFIG = {
129+
CIFS_ISO_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
128130
# 'location': r'\\10.0.0.2\<shared folder name>',
129131
# 'username': '<user>',
130132
# 'cifspassword': '<password>',
131133
# 'type': 'cifs',
132134
# 'vers': '<1.0> or <3.0>'
133135
}
134136

135-
CEPHFS_DEVICE_CONFIG = {
137+
CEPHFS_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
136138
# 'server': '10.0.0.2',
137139
# 'serverpath': '/vms'
138140
}
139141

140-
MOOSEFS_DEVICE_CONFIG = {
142+
MOOSEFS_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
141143
# 'masterhost': 'mfsmaster',
142144
# 'masterport': '9421',
143145
# 'rootpath': '/vms'
144146
}
145147

146-
LVMOISCSI_DEVICE_CONFIG = {
148+
LVMOISCSI_DEVICE_CONFIG: Dict[str, Dict[str, str]] = {
147149
# 'target': '192.168.1.1',
148150
# 'port': '3260',
149151
# 'targetIQN': 'target.example',

jobs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"tests/snapshot",
2929
"tests/system",
3030
"tests/xapi",
31-
"tests/xapi-plugins",
31+
"tests/xapi_plugins",
3232
],
3333
"markers": "(small_vm or no_vm) and not flaky and not reboot and not complex_prerequisites",
3434
},
@@ -333,7 +333,7 @@
333333
"params": {
334334
"--vm": "single/small_vm_unix_tools",
335335
},
336-
"paths": ["tests/guest-tools/unix"],
336+
"paths": ["tests/guest_tools/unix"],
337337
"markers": "",
338338
},
339339
"tools-unix-multi": {
@@ -347,7 +347,7 @@
347347
"params": {
348348
"--vm[]": "multi/tools_unix",
349349
},
350-
"paths": ["tests/guest-tools/unix"],
350+
"paths": ["tests/guest_tools/unix"],
351351
"markers": "multi_vms",
352352
},
353353
"tools-windows": {
@@ -360,7 +360,7 @@
360360
"params": {
361361
"--vm[]": "multi/tools_windows",
362362
},
363-
"paths": ["tests/guest-tools/win"],
363+
"paths": ["tests/guest_tools/win"],
364364
"markers": "multi_vms",
365365
},
366366
"xen": {
@@ -429,7 +429,7 @@
429429
# This test needs 2 hosts that can be from the same pool
430430
"nb_pools": 1,
431431
"params": {},
432-
"paths": ["tests/fs-diff"],
432+
"paths": ["tests/fs_diff"],
433433
},
434434
}
435435

lib/efi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_secure_boot_guid(variable: str) -> GUID:
122122
'KEK': global_variable_guid,
123123
'db': image_security_database_guid,
124124
'dbx': image_security_database_guid,
125-
}.get(variable)
125+
}[variable]
126126

127127

128128
def cert_to_efi_sig_list(cert):
@@ -149,7 +149,7 @@ def cert_to_efi_sig_list(cert):
149149
)
150150

151151

152-
def certs_to_sig_db(certs):
152+
def certs_to_sig_db(certs) -> bytes:
153153
"""Returns a signature database from a list cert file paths."""
154154
if isinstance(certs, str):
155155
certs = [certs]
@@ -380,7 +380,7 @@ def copy(cls, other, name=None):
380380

381381
return obj
382382

383-
def _get_efi_signature_list(self) -> str:
383+
def _get_efi_signature_list(self) -> bytes:
384384
if self.is_null:
385385
return b''
386386

lib/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ def sign_efi_bins(self, db: efi.EFIAuth):
387387
signed = db.sign_image(local_bin)
388388
self.scp(signed, remote_bin)
389389

390-
def set_efi_var(self, var: str, guid: str, attrs: bytes, data: bytes):
390+
def set_efi_var(self, var: str, guid: efi.GUID, attrs: bytes, data: bytes):
391391
"""Sets the data and attrs for an EFI variable and GUID."""
392392
assert len(attrs) == 4
393393

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)