From ad50c1b45dca4cdba3198506981fdbebf0dae55c Mon Sep 17 00:00:00 2001 From: Piotr Bartman-Szwarc Date: Tue, 11 Jun 2024 11:30:35 +0200 Subject: [PATCH] updater: get default value of '--update-if-stale' from dom0 settings --- vmupdate/tests/test_vmupdate.py | 5 +++-- vmupdate/vmupdate.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/vmupdate/tests/test_vmupdate.py b/vmupdate/tests/test_vmupdate.py index 6b8ab53..2147d16 100644 --- a/vmupdate/tests/test_vmupdate.py +++ b/vmupdate/tests/test_vmupdate.py @@ -22,7 +22,7 @@ from unittest.mock import patch -from vmupdate.tests.conftest import generate_vm_variations +from vmupdate.tests.conftest import generate_vm_variations, TestVM from vmupdate.agent.source.status import FinalStatus from vmupdate.vmupdate import main from vmupdate import vmupdate @@ -34,7 +34,8 @@ @patch('logging.getLogger') def test_no_options_do_nothing(_logger, _log_file, _chmod, _chown, test_qapp): args = [] - test_qapp.domains = () + test_qapp.domains = test_qapp.Domains() + TestVM("dom0", test_qapp, klass="AdminVM") assert main(args, test_qapp) == 100 diff --git a/vmupdate/vmupdate.py b/vmupdate/vmupdate.py index e46e768..9ae8caf 100644 --- a/vmupdate/vmupdate.py +++ b/vmupdate/vmupdate.py @@ -18,6 +18,7 @@ from . import update_manager from .agent.source.args import AgentArgs +DEFAULT_UPDATE_IF_STALE = 7 LOGPATH = '/var/log/qubes/qubes-vm-update.log' LOG_FORMAT = '%(asctime)s %(message)s' @@ -28,7 +29,7 @@ class ArgumentError(Exception): def main(args=None, app=qubesadmin.Qubes()): - args = parse_args(args) + args = parse_args(args, app) log_handler = logging.FileHandler(LOGPATH, encoding='utf-8') log_formatter = logging.Formatter(LOG_FORMAT) @@ -79,8 +80,13 @@ def main(args=None, app=qubesadmin.Qubes()): return ret_code -def parse_args(args): +def parse_args(args, app): parser = argparse.ArgumentParser() + try: + default_update_if_stale = int(app.domains["dom0"].features.get( + "qubes-vm-update-update-if-stale", DEFAULT_UPDATE_IF_STALE)) + except qubesadmin.exc.QubesDaemonAccessError: + default_update_if_stale = DEFAULT_UPDATE_IF_STALE parser.add_argument('--max-concurrency', '-x', action='store', @@ -116,7 +122,7 @@ def parse_args(args): 'Attempt to update targeted VMs with known updates available ' 'or for which last update check was more than N days ago. ' '(default: %(default)d)', - type=int, default=7) + type=int, default=default_update_if_stale) update_state.add_argument( '--update-if-available', action='store_true', help='Update targeted VMs with known updates available.')