Skip to content

Commit

Permalink
Revert to red label while restoring on missing labels
Browse files Browse the repository at this point in the history
If we allow users to create custom labels and they backup such qubes,
restore operation will fail on new systems without those custom labels.
Fix this by reverting to red label and allow users to restore their
backup.

fixes: QubesOS/qubes-issues#9781
  • Loading branch information
alimirjamali committed Feb 23, 2025
1 parent c3759ad commit 5f4fbaf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions qubesadmin/backup/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,12 @@ def _restore_vms_metadata(self, restore_info):
# can't create vm, but need backup info
new_vm = self.backup_app.domains[vm_name]
else:
# do not fail if VM had a custom label. revert to red label
if not vm.label in self.app.labels:
self.log.warning(
'Reverting to red label while restoring %s ' \
'since %s label does not exist', vm.name, vm.label)
vm.label = "red"
try:
# first only create VMs, later setting may require other VMs
# be already created
Expand Down
12 changes: 9 additions & 3 deletions qubesadmin/tests/backup/backupcompatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@
},
'test-net': {
'klass': 'AppVM',
'label': 'red',
'label': 'scarlet',
'properties': {
'maxmem': '300',
'memory': '300',
Expand Down Expand Up @@ -749,8 +749,11 @@ def assertCorrectlyConverted(self, backup_app, expected_data):
expected_data['domains'][vm]['template'], vm)
self.assertEqual(backup_app.domains[vm].klass,
expected_data['domains'][vm]['klass'], vm)
self.assertEqual(backup_app.domains[vm].label,
expected_data['domains'][vm]['label'], vm)
if expected_data['domains'][vm]['label'] == 'scarlet':
self.assertEqual(backup_app.domains[vm].label, 'red', vm)
else:
self.assertEqual(backup_app.domains[vm].label,
expected_data['domains'][vm]['label'], vm)
self.assertEqual(backup_app.domains[vm].backup_path,
expected_data['domains'][vm]['backup_path'], vm)
self.assertEqual(backup_app.domains[vm].included_in_backup,
Expand Down Expand Up @@ -1487,6 +1490,9 @@ def setup_expected_calls(self, parsed_qubes_xml, templates_map=None):
[orig_admin_vm_list] + \
[orig_admin_vm_list + b''.join(extra_vm_list_lines)] * \
len(extra_vm_list_lines)
self.app.expected_calls[('dom0', 'admin.label.List', None, None)] = (
b'0\0red\norange\nyellow\ngreen\ngray\nblue\npurple\nblack\n'
)

def mock_appmenus(self, queue, vm, stream):
queue.put((vm.name, 'appmenus', None, stream.read()))
Expand Down

0 comments on commit 5f4fbaf

Please sign in to comment.