Skip to content

Commit

Permalink
Validate default_kernel global property on set
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Aug 18, 2024
1 parent a1a023b commit 029ae55
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,3 +1593,13 @@ def on_property_set_default_dispvm(self, event, name, newvalue,
# resetting dispvm to its default value
vm.fire_event('property-reset:default_dispvm',
name='default_dispvm', oldvalue=oldvalue)

@qubes.events.handler('property-pre-set:default_kernel')
# pylint: disable-next=invalid-name
def on_property_pre_set_default_kernel(self, event, name, newvalue,
oldvalue=None):
# pylint: disable=unused-argument
kernels = [kernel.vid for kernel in self.pools['linux-kernel'].volumes]
if not newvalue in kernels:
raise qubes.exc.QubesException(
'Invalid kernel: {} !'.format(newvalue))
7 changes: 7 additions & 0 deletions qubes/tests/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,13 @@ def setUp(self):
super(TC_90_Qubes, self).setUp()
self.app = qubes.Qubes('/tmp/qubestest.xml', load=False,
offline_mode=True)
self.pools['linux-kernel'].dir_path = '/tmp/qubes-test-kernel'
dummy_kernel = os.path.join(self.pools['linux-kernel'].dir_path,
'dummy')
os.makedirs(dummy_kernel)
open(os.path.join(dummy_kernel, 'vmlinuz'), 'w').close()
open(os.path.join(dummy_kernel, 'modules.img'), 'w').close()
open(os.path.join(dummy_kernel, 'initramfs'), 'w').close()
self.app.default_kernel = 'dummy'
self.addCleanup(self.cleanup_qubes)
self.app.load_initial_values()
Expand Down
12 changes: 12 additions & 0 deletions run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ if sudo --non-interactive "$name/ci/lvm-manage" setup-lvm vg$$/pool; then
CLEANUP_LVM=yes
fi

CLEANUP_KERNEL_POOL=
if [ ! -d "/var/lib/qubes/vm-kernels" ]; then
sudo mkdir --parents /var/lib/qubes/vm-kernels/dummy
sudo mkdir --parents /var/lib/qubes/vm-kernels/1.0
CLEANUP_KERNEL_POOL=yes
fi

: "${PYTHON:=python3}"
: "${TESTPYTHONPATH:=test-packages}"

Expand All @@ -32,6 +39,11 @@ export PYTHONPATH
"${PYTHON}" setup.py egg_info --egg-base "${TESTPYTHONPATH}"
"${PYTHON}" -m coverage run --rcfile=ci/coveragerc -m qubes.tests.run "$@"
retcode=$?
if [ -n "$CLEANUP_KERNEL_POOL" ]; then
sudo rmdir /var/lib/qubes/vm-kernels/dummy
sudo rmdir /var/lib/qubes/vm-kernels/1.0
sudo rmdir /var/lib/qubes/vm-kernels
fi
if [ -n "$CLEANUP_LVM" ]; then
sudo --non-interactive $(dirname "$0")/ci/lvm-manage cleanup-lvm "$DEFAULT_LVM_POOL"
fi
Expand Down

0 comments on commit 029ae55

Please sign in to comment.