qvm-template-postprocess: do not generate appmenus twice

Skip initial generate, as it's done before actual menu entries are
extracted from the template. But do call it if we aren't going to
extract menu entries initially - it will create just "settings" menu
entry.
This commit is contained in:
Marek Marczykowski-Górecki 2021-02-06 07:30:28 +01:00
parent b7446afe3b
commit 8795668233
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 20 additions and 9 deletions

View File

@ -220,7 +220,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
vm = self.app.domains['test-vm'] vm = self.app.domains['test-vm']
with mock.patch('subprocess.check_call') as mock_proc: with mock.patch('subprocess.check_call') as mock_proc:
qubesadmin.tools.qvm_template_postprocess.import_appmenus( qubesadmin.tools.qvm_template_postprocess.import_appmenus(
vm, self.source_dir.name) vm, self.source_dir.name, skip_generate=False)
self.assertEqual(mock_proc.mock_calls, [ self.assertEqual(mock_proc.mock_calls, [
mock.call(['qvm-appmenus', mock.call(['qvm-appmenus',
'--set-default-whitelist=' + os.path.join(self.source_dir.name, '--set-default-whitelist=' + os.path.join(self.source_dir.name,
@ -282,7 +282,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
vm = self.app.domains['test-vm'] vm = self.app.domains['test-vm']
with mock.patch('subprocess.check_call') as mock_proc: with mock.patch('subprocess.check_call') as mock_proc:
qubesadmin.tools.qvm_template_postprocess.import_appmenus( qubesadmin.tools.qvm_template_postprocess.import_appmenus(
vm, self.source_dir.name) vm, self.source_dir.name, skip_generate=False)
self.assertEqual(mock_proc.mock_calls, [ self.assertEqual(mock_proc.mock_calls, [
mock.call(['runuser', '-u', 'user', '--', 'env', 'DISPLAY=:0', mock.call(['runuser', '-u', 'user', '--', 'env', 'DISPLAY=:0',
'qvm-appmenus', 'qvm-appmenus',
@ -316,7 +316,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
vm = self.app.domains['test-vm'] vm = self.app.domains['test-vm']
with mock.patch('subprocess.check_call') as mock_proc: with mock.patch('subprocess.check_call') as mock_proc:
qubesadmin.tools.qvm_template_postprocess.import_appmenus( qubesadmin.tools.qvm_template_postprocess.import_appmenus(
vm, self.source_dir.name) vm, self.source_dir.name, skip_generate=False)
self.assertEqual(mock_proc.mock_calls, []) self.assertEqual(mock_proc.mock_calls, [])
self.assertAllCalled() self.assertAllCalled()
@ -373,7 +373,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
mock_import_root_img.assert_called_once_with(self.app.domains[ mock_import_root_img.assert_called_once_with(self.app.domains[
'test-vm'], self.source_dir.name) 'test-vm'], self.source_dir.name)
mock_import_appmenus.assert_called_once_with(self.app.domains[ mock_import_appmenus.assert_called_once_with(self.app.domains[
'test-vm'], self.source_dir.name) 'test-vm'], self.source_dir.name, skip_generate=True)
if qubesadmin.tools.qvm_template_postprocess.have_events: if qubesadmin.tools.qvm_template_postprocess.have_events:
mock_domain_shutdown.assert_called_once_with([self.app.domains[ mock_domain_shutdown.assert_called_once_with([self.app.domains[
'test-vm']]) 'test-vm']])
@ -428,7 +428,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
mock_reset_private_img.assert_called_once_with(self.app.domains[ mock_reset_private_img.assert_called_once_with(self.app.domains[
'test-vm']) 'test-vm'])
mock_import_appmenus.assert_called_once_with(self.app.domains[ mock_import_appmenus.assert_called_once_with(self.app.domains[
'test-vm'], self.source_dir.name) 'test-vm'], self.source_dir.name, skip_generate=True)
if qubesadmin.tools.qvm_template_postprocess.have_events: if qubesadmin.tools.qvm_template_postprocess.have_events:
mock_domain_shutdown.assert_called_once_with([self.app.domains[ mock_domain_shutdown.assert_called_once_with([self.app.domains[
'test-vm']]) 'test-vm']])
@ -469,7 +469,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase):
mock_reset_private_img.assert_called_once_with(self.app.domains[ mock_reset_private_img.assert_called_once_with(self.app.domains[
'test-vm']) 'test-vm'])
mock_import_appmenus.assert_called_once_with(self.app.domains[ mock_import_appmenus.assert_called_once_with(self.app.domains[
'test-vm'], self.source_dir.name) 'test-vm'], self.source_dir.name, skip_generate=False)
if qubesadmin.tools.qvm_template_postprocess.have_events: if qubesadmin.tools.qvm_template_postprocess.have_events:
self.assertFalse(mock_domain_shutdown.called) self.assertFalse(mock_domain_shutdown.called)
self.assertEqual(self.app.service_calls, []) self.assertEqual(self.app.service_calls, [])

View File

@ -143,8 +143,14 @@ def reset_private_img(vm):
vm.volumes['private'].clear_data() vm.volumes['private'].clear_data()
def import_appmenus(vm, source_dir): def import_appmenus(vm, source_dir, skip_generate=True):
'''Import appmenus settings into VM object (later: GUI VM)''' """Import appmenus settings into VM object (later: GUI VM)
:param vm: QubesVM object of just imported template
:param source_dir: directory with source files
:param skip_generate: do not generate actual menu entries,
only set item lists
"""
if os.getuid() == 0: if os.getuid() == 0:
try: try:
qubes_group = grp.getgrnam('qubes') qubes_group = grp.getgrnam('qubes')
@ -171,6 +177,9 @@ def import_appmenus(vm, source_dir):
as fd: as fd:
vm.features['netvm-menu-items'] = ' '.join([x.rstrip() for x in fd]) vm.features['netvm-menu-items'] = ' '.join([x.rstrip() for x in fd])
if skip_generate:
return
# TODO: change this to qrexec calls to GUI VM, when GUI VM will be # TODO: change this to qrexec calls to GUI VM, when GUI VM will be
# implemented # implemented
try: try:
@ -283,7 +292,9 @@ def post_install(args):
vm.log.info('Clearing private volume') vm.log.info('Clearing private volume')
reset_private_img(vm) reset_private_img(vm)
vm.installed_by_rpm = not args.no_installed_by_rpm vm.installed_by_rpm = not args.no_installed_by_rpm
import_appmenus(vm, args.dir) # do not generate actual menu entries, if post-install service will be
# executed anyway
import_appmenus(vm, args.dir, skip_generate=not args.skip_start)
conf_path = os.path.join(args.dir, 'template.conf') conf_path = os.path.join(args.dir, 'template.conf')
if os.path.exists(conf_path): if os.path.exists(conf_path):