Commit 6dd208cd authored by Łukasz Nowak's avatar Łukasz Nowak

kvm/test: Improve sanity check

Calling makeModuleSetUpAndTestCaseClass results already with preparing some
environment and also test classes will run the promises, so they would never
execute test_kvm_sanity_check.

So create a method sanityCheck to check the environment and depending of the
result call or not makeModuleSetUpAndTestCaseClass and skipIf test cases
when environment is not sane enough.
parent e5fcbd31
Pipeline #6745 failed with stage
......@@ -28,24 +28,19 @@
import httplib
import json
import os
import re
import requests
import slapos.util
import subprocess
import sqlite3
import urlparse
import unittest
from slapos.recipe.librecipe import generateHashFromFiles
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
setUpModule, InstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
class SanityCheckedInstanceTestCase(InstanceTestCase):
def test_kvm_sanity_check(self):
"""Sanity check - if fails, machine is not able to run KVM tests"""
def sanityCheck():
try:
output = subprocess.check_output("lsmod | grep kvm_intel", shell=True)
except subprocess.CalledProcessError as e:
......@@ -53,10 +48,26 @@ class SanityCheckedInstanceTestCase(InstanceTestCase):
output = e.output
else:
state = True
self.assertTrue(state)
self.assertRegexpMatches(output, r'kvm.*kvm_intel')
if state is True and re.search(r'kvm.*kvm_intel', output):
return True
if sanityCheck():
setUpModule, InstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
else:
setUpModule, InstanceTestCase = None, unittest.TestCase
class SanityCheckTestCase(unittest.TestCase):
def test_kvm_sanity_check(self):
if not(sanityCheck()):
self.fail('This environment is not usable for kvm testing, as it '
'lacks kvm_intel kernel module')
class ServicesTestCase(SanityCheckedInstanceTestCase):
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module')
class ServicesTestCase(InstanceTestCase):
def test_hashes(self):
hash_files = [
'software_release/buildout.cfg',
......@@ -151,7 +162,8 @@ class MonitorAccessMixin(object):
)
class TestAccessDefault(MonitorAccessMixin, SanityCheckedInstanceTestCase):
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module')
class TestAccessDefault(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'ad'
expected_partition_with_monitor_base_url_count = 1
......@@ -167,7 +179,8 @@ class TestAccessDefault(MonitorAccessMixin, SanityCheckedInstanceTestCase):
self.assertFalse('url-additional' in connection_parameter_dict)
class TestAccessDefaultAdditional(MonitorAccessMixin, SanityCheckedInstanceTestCase):
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module')
class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'ada'
expected_partition_with_monitor_base_url_count = 1
......@@ -197,7 +210,8 @@ class TestAccessDefaultAdditional(MonitorAccessMixin, SanityCheckedInstanceTestC
self.assertTrue('<title>noVNC</title>' in result.text)
class TestAccessKvmCluster(MonitorAccessMixin, SanityCheckedInstanceTestCase):
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module')
class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'akc'
expected_partition_with_monitor_base_url_count = 2
......@@ -227,7 +241,8 @@ class TestAccessKvmCluster(MonitorAccessMixin, SanityCheckedInstanceTestCase):
self.assertFalse('kvm0-url-additional' in connection_parameter_dict)
class TestAccessKvmClusterAdditional(MonitorAccessMixin, SanityCheckedInstanceTestCase):
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module')
class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'akca'
expected_partition_with_monitor_base_url_count = 2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment