Skip to content

Commit

Permalink
backup/restore: improve error message about restoring tags
Browse files Browse the repository at this point in the history
Before reporting a tag as not restored, verify if it really wasn't
restored. Generally created-by-* tags cannot be created manually. But
when restoring a backup in dom0, created-by-dom0 tag is added, which in
many cases will match what want to be restored.

Adjust tests to check this too.
  • Loading branch information
marmarek committed Aug 4, 2020
1 parent 2b6b4e7 commit 114f6fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 3 additions & 2 deletions qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2035,8 +2035,9 @@ def _restore_vms_metadata(self, restore_info):
try:
new_vm.tags.add(tag)
except Exception as err: # pylint: disable=broad-except
self.log.error('Error adding tag %s to %s: %s',
tag, vm.name, err)
if tag not in new_vm.tags:
self.log.error('Error adding tag %s to %s: %s',
tag, vm.name, err)

for bus in vm.devices:
for backend_domain, ident in vm.devices[bus]:
Expand Down
22 changes: 16 additions & 6 deletions qubesadmin/tests/backup/backupcompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,8 +1440,14 @@ def setup_expected_calls(self, parsed_qubes_xml, templates_map=None):
str(value).encode())] = b'0\0'

for tag in vm['tags']:
self.app.expected_calls[
(name, 'admin.vm.tag.Set', tag, None)] = b'0\0'
if tag.startswith('created-by-'):
self.app.expected_calls[
(name, 'admin.vm.tag.Set', tag, None)] = b''
self.app.expected_calls[
(name, 'admin.vm.tag.Get', tag, None)] = b'0\0001'
else:
self.app.expected_calls[
(name, 'admin.vm.tag.Set', tag, None)] = b'0\0'

if vm['backup_path']:
appmenus = (
Expand Down Expand Up @@ -1727,7 +1733,8 @@ def test_230_r4(self):
# retrieve calls from other multiprocess.Process instances
while not qubesd_calls_queue.empty():
call_args = qubesd_calls_queue.get()
self.app.qubesd_call(*call_args)
with contextlib.suppress(qubesadmin.exc.QubesException):
self.app.qubesd_call(*call_args)
qubesd_calls_queue.close()

self.assertAllCalled()
Expand Down Expand Up @@ -1797,7 +1804,8 @@ def test_230_r4_compressed(self):
# retrieve calls from other multiprocess.Process instances
while not qubesd_calls_queue.empty():
call_args = qubesd_calls_queue.get()
self.app.qubesd_call(*call_args)
with contextlib.suppress(qubesadmin.exc.QubesException):
self.app.qubesd_call(*call_args)
qubesd_calls_queue.close()

self.assertAllCalled()
Expand Down Expand Up @@ -1867,7 +1875,8 @@ def test_230_r4_custom_cmpression(self):
# retrieve calls from other multiprocess.Process instances
while not qubesd_calls_queue.empty():
call_args = qubesd_calls_queue.get()
self.app.qubesd_call(*call_args)
with contextlib.suppress(qubesadmin.exc.QubesException):
self.app.qubesd_call(*call_args)
qubesd_calls_queue.close()

self.assertAllCalled()
Expand Down Expand Up @@ -1968,7 +1977,8 @@ def test_230_r4_uncommon_cmpression_forced(self):
# retrieve calls from other multiprocess.Process instances
while not qubesd_calls_queue.empty():
call_args = qubesd_calls_queue.get()
self.app.qubesd_call(*call_args)
with contextlib.suppress(qubesadmin.exc.QubesException):
self.app.qubesd_call(*call_args)
qubesd_calls_queue.close()

self.assertAllCalled()
Expand Down

0 comments on commit 114f6fb

Please sign in to comment.