Skip to content

Commit 497d467

Browse files
committed
Merge remote-tracking branch 'origin/pr/215'
* origin/pr/215: ci: add vmupdate black and pylint checks style: format vmupdate with black Pull request description: This extends the existing GitLab test job so vmupdate changes are checked with black and pylint after the unit tests run. The patch also formats the current vmupdate files so the new black check starts from a clean baseline, and adds a focused pylint configuration for the checks that are actionable in this tree. Mypy is intentionally not enabled in this PR because current upstream still has existing typing errors that need a separate cleanup before it can be a blocking CI check. fixes: #213 (comment)
2 parents 6786ad4 + 3176257 commit 497d467

9 files changed

Lines changed: 95 additions & 35 deletions

File tree

.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
include:
2+
- file: /common.yml
3+
project: QubesOS/qubes-continuous-integration
24
- file: /r4.3/gitlab-base.yml
35
project: QubesOS/qubes-continuous-integration
46
- file: /r4.3/gitlab-host.yml
57
project: QubesOS/qubes-continuous-integration
68

9+
lint:
10+
extends: .lint
11+
stage: checks
12+
variables:
13+
DIR: vmupdate
14+
715
checks:tests:
816
stage: checks
917
variables:

.pylintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[MASTER]
2+
init-hook='import sys; sys.path.append("vmupdate/agent")'
3+
4+
[MESSAGES CONTROL]
5+
disable=
6+
broad-exception-caught,
7+
duplicate-code,
8+
import-error,
9+
invalid-name,
10+
line-too-long,
11+
missing-class-docstring,
12+
missing-function-docstring,
13+
missing-module-docstring,
14+
possibly-used-before-assignment,
15+
too-few-public-methods,
16+
too-many-arguments,
17+
too-many-branches,
18+
too-many-instance-attributes,
19+
too-many-locals,
20+
too-many-positional-arguments,
21+
too-many-return-statements,
22+
too-many-statements,
23+
unspecified-encoding,
24+
consider-using-with,
25+
f-string-without-interpolation,
26+
implicit-str-concat,
27+
unused-argument,
28+
unused-import

setup.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
# with this program; if not, see <http://www.gnu.org/licenses/>.
1717
import setuptools
1818

19-
if __name__ == '__main__':
19+
if __name__ == "__main__":
2020
setuptools.setup(
21-
name='qubes-vmupdate',
22-
version=open('version').read().strip(),
23-
author='Invisible Things Lab',
24-
author_email='qubes-devel@googlegroups.com',
25-
description='Qubes VM updater',
26-
license='GPL2+',
27-
url='https://www.qubes-os.org/',
21+
name="qubes-vmupdate",
22+
version=open("version").read().strip(),
23+
author="Invisible Things Lab",
24+
author_email="qubes-devel@googlegroups.com",
25+
description="Qubes VM updater",
26+
license="GPL2+",
27+
url="https://www.qubes-os.org/",
2828
packages=setuptools.find_packages(include=("vmupdate", "vmupdate*")),
2929
entry_points={
30-
'console_scripts':
31-
'qubes-vm-update = vmupdate.vmupdate:main',
30+
"console_scripts": "qubes-vm-update = vmupdate.vmupdate:main",
3231
},
33-
)
32+
)

vmupdate/agent/source/common/package_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
2020
# USA.
2121
"""package manager for VMs"""
22+
2223
import io
2324
import logging
2425
import subprocess

vmupdate/agent/source/plugins/whonix17_key.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,14 @@
176176
# sub:e:4096:1:10FDAC53119B3FD6:1389913402:1769172143:::
177177
# sub:e:4096:1:CB8D50BB77BB3C48:1389913659:1769172143:::
178178

179+
179180
def whonix17_key(os_data, log, **kwargs):
180181
"""
181182
Update kicksecure signing key - https://www.kicksecure.com/wiki/EXPKEYSIG
182183
"""
183-
if os_data.get("codename", "") != "bookworm" or not os.path.exists(KEYFILE_PATH):
184+
if os_data.get("codename", "") != "bookworm" or not os.path.exists(
185+
KEYFILE_PATH
186+
):
184187
return
185188

186189
# check if key is expire

vmupdate/qube_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
9595
if self.qube.is_running() and not self._initially_running:
9696
if self._has_assigned_pci_devices(self.qube):
9797
self.logger.info(
98-
'Waiting for full shutdown %s (PCI devices assigned)',
99-
self.qube.name)
98+
"Waiting for full shutdown %s (PCI devices assigned)",
99+
self.qube.name,
100+
)
100101
shutdown_domains([self.qube], self.logger)
101102
else:
102-
self.logger.info('Shutdown %s', self.qube.name)
103+
self.logger.info("Shutdown %s", self.qube.name)
103104
self.qube.shutdown()
104105

105106
self.__connected = False
@@ -108,7 +109,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
108109
def _has_assigned_pci_devices(vm) -> bool:
109110
"""Return True when VM has assigned PCI devices."""
110111
try:
111-
return any(vm.devices['pci'].get_assigned_devices())
112+
return any(vm.devices["pci"].get_assigned_devices())
112113
except qubesadmin.exc.QubesDaemonAccessError:
113114
return False
114115

vmupdate/tests/test_qube_connection.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ def test_wait_for_shutdown_when_vm_started_by_update(shutdown_domains):
2828
vm = Mock()
2929
vm.name = "hvm1"
3030
vm.is_running.side_effect = [False, True]
31-
vm.devices = {'pci': Mock()}
32-
vm.devices['pci'].get_assigned_devices.return_value = ["00_1f.2"]
31+
vm.devices = {"pci": Mock()}
32+
vm.devices["pci"].get_assigned_devices.return_value = ["00_1f.2"]
3333
status_notifier = Mock()
3434
logger = Mock()
3535

3636
with QubeConnection(
37-
vm, "/tmp/qubes-update", cleanup=False, logger=logger,
38-
show_progress=False, status_notifier=status_notifier):
37+
vm,
38+
"/tmp/qubes-update",
39+
cleanup=False,
40+
logger=logger,
41+
show_progress=False,
42+
status_notifier=status_notifier,
43+
):
3944
pass
4045

4146
shutdown_domains.assert_called_once_with([vm], logger)
@@ -47,14 +52,19 @@ def test_do_not_wait_for_shutdown_without_assigned_pci(shutdown_domains):
4752
vm = Mock()
4853
vm.name = "hvm2"
4954
vm.is_running.side_effect = [False, True]
50-
vm.devices = {'pci': Mock()}
51-
vm.devices['pci'].get_assigned_devices.return_value = []
55+
vm.devices = {"pci": Mock()}
56+
vm.devices["pci"].get_assigned_devices.return_value = []
5257
status_notifier = Mock()
5358
logger = Mock()
5459

5560
with QubeConnection(
56-
vm, "/tmp/qubes-update", cleanup=False, logger=logger,
57-
show_progress=False, status_notifier=status_notifier):
61+
vm,
62+
"/tmp/qubes-update",
63+
cleanup=False,
64+
logger=logger,
65+
show_progress=False,
66+
status_notifier=status_notifier,
67+
):
5868
pass
5969

6070
vm.shutdown.assert_called_once_with()
@@ -66,14 +76,19 @@ def test_do_not_shutdown_if_vm_was_already_running(shutdown_domains):
6676
vm = Mock()
6777
vm.name = "hvm3"
6878
vm.is_running.return_value = True
69-
vm.devices = {'pci': Mock()}
70-
vm.devices['pci'].get_assigned_devices.return_value = ["00_1f.2"]
79+
vm.devices = {"pci": Mock()}
80+
vm.devices["pci"].get_assigned_devices.return_value = ["00_1f.2"]
7181
status_notifier = Mock()
7282
logger = Mock()
7383

7484
with QubeConnection(
75-
vm, "/tmp/qubes-update", cleanup=False, logger=logger,
76-
show_progress=False, status_notifier=status_notifier):
85+
vm,
86+
"/tmp/qubes-update",
87+
cleanup=False,
88+
logger=logger,
89+
show_progress=False,
90+
status_notifier=status_notifier,
91+
):
7792
pass
7893

7994
vm.shutdown.assert_not_called()

vmupdate/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ def is_stale(vm, expiration_period):
7070
"""Return True if VM has not been checked for updates recently."""
7171
today = datetime.today()
7272
try:
73-
if not ('qrexec' in vm.features.keys()
74-
and vm.features.get('os', '') == 'Linux'):
73+
if not (
74+
"qrexec" in vm.features.keys()
75+
and vm.features.get("os", "") == "Linux"
76+
):
7577
return False
7678

7779
last_update_str = vm.features.check_with_template(
78-
'last-updates-check',
79-
datetime.fromtimestamp(0).strftime('%Y-%m-%d %H:%M:%S')
80+
"last-updates-check",
81+
datetime.fromtimestamp(0).strftime("%Y-%m-%d %H:%M:%S"),
8082
)
8183
last_update = datetime.fromisoformat(last_update_str)
8284
if (today - last_update).days > expiration_period:

vmupdate/vmupdate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
import qubesadmin.exc
1515
from vmupdate.agent.source.status import FinalStatus
1616
from vmupdate.agent.source.common.exit_codes import EXIT
17-
from vmupdate.utils import shutdown_domains, get_feature, get_boolean_feature, \
18-
is_stale
17+
from vmupdate.utils import (
18+
shutdown_domains,
19+
get_feature,
20+
get_boolean_feature,
21+
is_stale,
22+
)
1923
from . import update_manager
2024
from .agent.source.args import AgentArgs
2125

@@ -492,7 +496,6 @@ def get_derived_vm_to_apply(templates, derived_statuses):
492496
return to_restart, to_shutdown
493497

494498

495-
496499
def restart_vms(to_restart, log):
497500
"""
498501
Try to restart vms.

0 commit comments

Comments
 (0)