From c3fc4062d8293053932271998ca10e0b4845e6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sat, 14 Jan 2017 04:56:19 +0100 Subject: [PATCH] tests: add basic test for qvm-features --- qubes/tests/__init__.py | 1 + qubes/tests/integ/tools/qvm_features.py | 70 +++++++++++++++++++++++++ rpm_spec/core-dom0.spec | 1 + 3 files changed, 72 insertions(+) create mode 100644 qubes/tests/integ/tools/qvm_features.py diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index e0073fa7..b05a2ce5 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -908,6 +908,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument # tool tests 'qubes.tests.integ.tools.qubes_create', 'qubes.tests.integ.tools.qvm_check', + 'qubes.tests.integ.tools.qvm_features', 'qubes.tests.integ.tools.qvm_firewall', 'qubes.tests.integ.tools.qvm_prefs', 'qubes.tests.integ.tools.qvm_run', diff --git a/qubes/tests/integ/tools/qvm_features.py b/qubes/tests/integ/tools/qvm_features.py new file mode 100644 index 00000000..5a72b209 --- /dev/null +++ b/qubes/tests/integ/tools/qvm_features.py @@ -0,0 +1,70 @@ +#!/usr/bin/python2 +# -*- encoding: utf8 -*- +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2017 Marek Marczykowski-Górecki +# +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import qubes +import qubes.tools.qvm_features + +import qubes.tests +import qubes.tests.tools +import qubes.vm.appvm + + +class TC_00_qvm_features(qubes.tests.SystemTestsMixin, + qubes.tests.QubesTestCase): + def setUp(self): + super(TC_00_qvm_features, self).setUp() + self.init_default_template() + + self.sharedopts = ['--qubesxml', qubes.tests.XMLPATH] + + self.vm1 = self.app.add_new_vm(qubes.vm.appvm.AppVM, + name=self.make_vm_name('vm1'), + template=self.app.default_template, + label='red') + self.app.save() + + def test_000_list(self): + self.assertEqual(0, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name])) + + with self.assertRaises(SystemExit): + qubes.tools.qvm_features.main( + self.sharedopts + ['test-no-such-vm']) + + def test_001_get_missing(self): + self.assertEqual(1, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name, 'no-such-feature'])) + + def test_002_set_and_get(self): + self.assertEqual(0, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name, 'test-feature', 'true'])) + with qubes.tests.tools.StdoutBuffer() as buf: + self.assertEqual(0, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name, 'test-feature'])) + self.assertEqual('true\n', buf.getvalue()) + + def test_003_set_and_list(self): + self.assertEqual(0, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name, 'test-feature', 'true'])) + with qubes.tests.tools.StdoutBuffer() as buf: + self.assertEqual(0, qubes.tools.qvm_features.main( + self.sharedopts + [self.vm1.name])) + self.assertEqual('test-feature true\n', buf.getvalue()) diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 9b0354ab..610bf4c2 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -358,6 +358,7 @@ fi %{python3_sitelib}/qubes/tests/integ/tools/__pycache__/* %{python3_sitelib}/qubes/tests/integ/tools/__init__.py %{python3_sitelib}/qubes/tests/integ/tools/qubes_create.py +%{python3_sitelib}/qubes/tests/integ/tools/qvm_features.py* %{python3_sitelib}/qubes/tests/integ/tools/qvm_firewall.py %{python3_sitelib}/qubes/tests/integ/tools/qvm_check.py %{python3_sitelib}/qubes/tests/integ/tools/qvm_prefs.py