|
| 1 | +# coding=utf-8 |
| 2 | +# |
| 3 | +# The Qubes OS Project, https://www.qubes-os.org |
| 4 | +# |
| 5 | +# Copyright (C) 2026 |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License |
| 9 | +# as published by the Free Software Foundation; either version 2 |
| 10 | +# of the License, or (at your option) any later version. |
| 11 | +# |
| 12 | +from unittest.mock import Mock, patch |
| 13 | + |
| 14 | +from vmupdate.qube_connection import QubeConnection |
| 15 | + |
| 16 | + |
| 17 | +@patch("vmupdate.qube_connection.wait_for_domain_shutdown") |
| 18 | +@patch("vmupdate.qube_connection.asyncio.run") |
| 19 | +def test_wait_for_shutdown_when_vm_started_by_update(_arun, wait_shutdown): |
| 20 | + vm = Mock() |
| 21 | + vm.name = "hvm1" |
| 22 | + vm.is_running.side_effect = [False, True] |
| 23 | + status_notifier = Mock() |
| 24 | + logger = Mock() |
| 25 | + |
| 26 | + with QubeConnection( |
| 27 | + vm, "/tmp/qubes-update", cleanup=False, logger=logger, |
| 28 | + show_progress=False, status_notifier=status_notifier): |
| 29 | + pass |
| 30 | + |
| 31 | + vm.shutdown.assert_called_once_with() |
| 32 | + wait_shutdown.assert_called_once_with([vm]) |
| 33 | + _arun.assert_called_once() |
| 34 | + |
| 35 | + |
| 36 | +@patch("vmupdate.qube_connection.wait_for_domain_shutdown") |
| 37 | +@patch("vmupdate.qube_connection.asyncio.run") |
| 38 | +def test_do_not_shutdown_if_vm_was_already_running(_arun, wait_shutdown): |
| 39 | + vm = Mock() |
| 40 | + vm.name = "hvm2" |
| 41 | + vm.is_running.return_value = True |
| 42 | + status_notifier = Mock() |
| 43 | + logger = Mock() |
| 44 | + |
| 45 | + with QubeConnection( |
| 46 | + vm, "/tmp/qubes-update", cleanup=False, logger=logger, |
| 47 | + show_progress=False, status_notifier=status_notifier): |
| 48 | + pass |
| 49 | + |
| 50 | + vm.shutdown.assert_not_called() |
| 51 | + wait_shutdown.assert_not_called() |
| 52 | + _arun.assert_not_called() |
0 commit comments