qubes.tests.list_templates(), and .close() the app

This commit is contained in:
Wojtek Porczyk 2017-08-28 14:28:17 +02:00
parent de8ff20976
commit 25670fbd61
7 changed files with 32 additions and 48 deletions

View File

@ -52,6 +52,7 @@ import gc
import lxml.etree
import pkg_resources
import qubes
import qubes.api
import qubes.api.admin
import qubes.api.internal
@ -61,6 +62,7 @@ import qubes.devices
import qubes.events
import qubes.exc
import qubes.vm.standalonevm
import qubes.vm.templatevm
XMLPATH = '/var/lib/qubes/qubes-test.xml'
CLASS_XMLPATH = '/var/lib/qubes/qubes-class-test.xml'
@ -992,6 +994,22 @@ class SystemTestCase(QubesTestCase):
timeout=30)
_templates = None
def list_templates():
'''Returns tuple of template names available in the system.'''
global _templates
if _templates is None:
try:
app = qubes.Qubes()
_templates = tuple(vm.name for vm in app.domains
if isinstance(vm, qubes.vm.templatevm.TemplateVM))
app.close()
del app
except OSError:
_templates = ()
return _templates
def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
# discard any tests from this module, because it hosts base classes
tests = unittest.TestSuite()

View File

@ -23,7 +23,6 @@ import sys
import pkg_resources
import qubes.tests
import qubes.vm.appvm
import qubes.vm.templatevm
class ExtraTestCase(qubes.tests.SystemTestCase):
@ -80,18 +79,11 @@ def load_tests(loader, tests, pattern):
{entry.name: runTest})
tests.addTest(ExtraLoadFailure(entry.name))
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for entry in pkg_resources.iter_entry_points(
'qubes.tests.extra.for_template'):
try:
for test_case in entry.load()():
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'{}_{}_{}'.format(

View File

@ -541,13 +541,7 @@ class TC_10_BackupVMMixin(BackupTestsMixin):
def load_tests(loader, tests, pattern):
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'TC_10_BackupVM_' + template,

View File

@ -19,13 +19,15 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
from distutils import spawn
import qubes.tests
import os
import subprocess
import tempfile
import unittest
import os
import time
import unittest
from distutils import spawn
import qubes.tests
class TC_04_DispVM(qubes.tests.SystemTestCase):
@ -254,13 +256,7 @@ class TC_20_DispVMMixin(object):
self.assertEqual(test_txt_content, b"Test test 2\ntest1\n")
def load_tests(loader, tests, pattern):
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'TC_20_DispVM_' + template,

View File

@ -26,6 +26,7 @@ import tempfile
import unittest
import qubes
import qubes.tests
VM_PREFIX = "test-"
@ -359,13 +360,7 @@ Test package
def load_tests(loader, tests, pattern):
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'TC_00_Dom0Upgrade_' + template,

View File

@ -934,13 +934,7 @@ SHA256:
'{}: {}\n{}'.format(self.update_cmd, stdout, stderr))
def load_tests(loader, tests, pattern):
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'VmNetworking_' + template,

View File

@ -25,6 +25,7 @@ import multiprocessing
import os
import subprocess
import unittest
from distutils import spawn
import qubes.config
@ -1001,13 +1002,7 @@ class TC_10_Generic(qubes.tests.SystemTestCase):
def load_tests(loader, tests, pattern):
try:
app = qubes.Qubes()
templates = [vm.name for vm in app.domains if
isinstance(vm, qubes.vm.templatevm.TemplateVM)]
except OSError:
templates = []
for template in templates:
for template in qubes.tests.list_templates():
tests.addTests(loader.loadTestsFromTestCase(
type(
'TC_00_AppVM_' + template,