Skip to content

Commit

Permalink
tests: verify if update.qubes-vm works
Browse files Browse the repository at this point in the history
This salt state is (currently) rather important for qubes to work, so
besides basic salt tests, verify this one explicitly too.

This allows detecting bugs like QubesOS/qubes-issues#7891
  • Loading branch information
marmarek committed Nov 18, 2022
1 parent 921cc8e commit 79e3ddb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions qubes/tests/integ/salt.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,37 @@ def test_002_grans_id(self):
self.assertTrue(state_output_single['result'])
self.assertNotEqual(state_output_single['changes'], {})

def test_003_update(self):
vmname = self.make_vm_name('target')
self.vm = self.app.add_new_vm('AppVM', name=vmname, label='red')
self.loop.run_until_complete(self.vm.create_on_disk())
# start the VM manually, so it stays running after applying salt state
self.loop.run_until_complete(self.vm.start())
state_output = self.salt_call(
['--skip-dom0', '--show-output', '--targets=' + vmname,
'state.sls', 'update.qubes-vm'])
expected_output = vmname + ':\n'
self.assertTrue(state_output.startswith(expected_output),
'Full output: ' + state_output)
json_data = state_output[len(expected_output):]
# workaround for https://github.com/saltstack/salt/issues/60476
# (fixed upstream, but hasen't flowed into Fedora yet)
if "Setuptools is replacing distutils" in json_data:
json_data = "\n".join(
l for l in json_data.splitlines()
if "Setuptools is replacing distutils" not in l)
try:
state_output_json = json.loads(json_data)
except json.decoder.JSONDecodeError as e:
self.fail('{}: {}'.format(e, json_data))
self.assertIn(vmname, state_output_json)
self.assertNotEqual(state_output_json[vmname], {})
for state, result in state_output_json[vmname].items():
self.assertTrue(
result['result'],
"State {} failed: {!r}".format(state, result))


def create_testcases_for_templates():
return qubes.tests.create_testcases_for_templates('TC_10_VMSalt',
SaltVMTestMixin, qubes.tests.SystemTestCase,
Expand Down

0 comments on commit 79e3ddb

Please sign in to comment.