Skip to content

Commit

Permalink
updater: get default value of '--update-if-stale' from dom0 settings
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrbartman committed Jun 11, 2024
1 parent 35a9ae0 commit ad50c1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions vmupdate/tests/test_vmupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
12 changes: 9 additions & 3 deletions vmupdate/vmupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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.')
Expand Down

0 comments on commit ad50c1b

Please sign in to comment.