From 8795668233faad672cd7b12f6313ad7f20b8d02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 6 Feb 2021 07:30:28 +0100 Subject: [PATCH] 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. --- .../tests/tools/qvm_template_postprocess.py | 12 ++++++------ qubesadmin/tools/qvm_template_postprocess.py | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_template_postprocess.py b/qubesadmin/tests/tools/qvm_template_postprocess.py index 1a77af0..fded880 100644 --- a/qubesadmin/tests/tools/qvm_template_postprocess.py +++ b/qubesadmin/tests/tools/qvm_template_postprocess.py @@ -220,7 +220,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase): vm = self.app.domains['test-vm'] with mock.patch('subprocess.check_call') as mock_proc: 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, [ mock.call(['qvm-appmenus', '--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'] with mock.patch('subprocess.check_call') as mock_proc: 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, [ mock.call(['runuser', '-u', 'user', '--', 'env', 'DISPLAY=:0', 'qvm-appmenus', @@ -316,7 +316,7 @@ class TC_00_qvm_template_postprocess(qubesadmin.tests.QubesTestCase): vm = self.app.domains['test-vm'] with mock.patch('subprocess.check_call') as mock_proc: 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.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[ 'test-vm'], self.source_dir.name) 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: mock_domain_shutdown.assert_called_once_with([self.app.domains[ '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[ 'test-vm']) 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: mock_domain_shutdown.assert_called_once_with([self.app.domains[ '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[ 'test-vm']) 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: self.assertFalse(mock_domain_shutdown.called) self.assertEqual(self.app.service_calls, []) diff --git a/qubesadmin/tools/qvm_template_postprocess.py b/qubesadmin/tools/qvm_template_postprocess.py index b5e04c3..3b1976a 100644 --- a/qubesadmin/tools/qvm_template_postprocess.py +++ b/qubesadmin/tools/qvm_template_postprocess.py @@ -143,8 +143,14 @@ def reset_private_img(vm): vm.volumes['private'].clear_data() -def import_appmenus(vm, source_dir): - '''Import appmenus settings into VM object (later: GUI VM)''' +def import_appmenus(vm, source_dir, skip_generate=True): + """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: try: qubes_group = grp.getgrnam('qubes') @@ -171,6 +177,9 @@ def import_appmenus(vm, source_dir): as 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 # implemented try: @@ -283,7 +292,9 @@ def post_install(args): vm.log.info('Clearing private volume') reset_private_img(vm) 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') if os.path.exists(conf_path):