Commit ee979773 authored by Julien Muchembled's avatar Julien Muchembled

kvm: fix how the test checs if kvm module is loaded and allowed

- lsmod is wrong because kvm_intel may be built inside the kernel
- kvm_intel is wrong because it only works for Intel CPUs
  (for exemple, there exists kvm_amd)
- /dev/kvm may have wrong permissions
parent 17d8fe38
...@@ -28,10 +28,8 @@ ...@@ -28,10 +28,8 @@
import httplib import httplib
import json import json
import os import os
import re
import requests import requests
import slapos.util import slapos.util
import subprocess
import sqlite3 import sqlite3
import urlparse import urlparse
import unittest import unittest
...@@ -39,20 +37,10 @@ import unittest ...@@ -39,20 +37,10 @@ import unittest
from slapos.recipe.librecipe import generateHashFromFiles from slapos.recipe.librecipe import generateHashFromFiles
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
has_kvm = os.access('/dev/kvm', os.R_OK|os.W_OK)
skipUnlessKvm = unittest.skipUnless(has_kvm, 'kvm not loaded or not allowed')
def sanityCheck(): if has_kvm:
try:
output = subprocess.check_output("lsmod | grep kvm_intel", shell=True)
except subprocess.CalledProcessError as e:
state = False
output = e.output
else:
state = True
if state is True and re.search(r'kvm.*kvm_intel', output):
return True
if sanityCheck():
setUpModule, InstanceTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, InstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath( os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'software.cfg'))) os.path.join(os.path.dirname(__file__), '..', 'software.cfg')))
...@@ -61,12 +49,11 @@ else: ...@@ -61,12 +49,11 @@ else:
class SanityCheckTestCase(unittest.TestCase): class SanityCheckTestCase(unittest.TestCase):
def test_kvm_sanity_check(self): def test_kvm_sanity_check(self):
if not(sanityCheck()): self.fail('This environment is not usable for kvm testing,'
self.fail('This environment is not usable for kvm testing, as it ' ' as it lacks kvm_intel kernel module')
'lacks kvm_intel kernel module')
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class ServicesTestCase(InstanceTestCase): class ServicesTestCase(InstanceTestCase):
def test_hashes(self): def test_hashes(self):
hash_files = [ hash_files = [
...@@ -162,7 +149,7 @@ class MonitorAccessMixin(object): ...@@ -162,7 +149,7 @@ class MonitorAccessMixin(object):
) )
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestAccessDefault(MonitorAccessMixin, InstanceTestCase): class TestAccessDefault(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'ad' __partition_reference__ = 'ad'
expected_partition_with_monitor_base_url_count = 1 expected_partition_with_monitor_base_url_count = 1
...@@ -179,7 +166,7 @@ class TestAccessDefault(MonitorAccessMixin, InstanceTestCase): ...@@ -179,7 +166,7 @@ class TestAccessDefault(MonitorAccessMixin, InstanceTestCase):
self.assertFalse('url-additional' in connection_parameter_dict) self.assertFalse('url-additional' in connection_parameter_dict)
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase): class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'ada' __partition_reference__ = 'ada'
expected_partition_with_monitor_base_url_count = 1 expected_partition_with_monitor_base_url_count = 1
...@@ -210,7 +197,7 @@ class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase): ...@@ -210,7 +197,7 @@ class TestAccessDefaultAdditional(MonitorAccessMixin, InstanceTestCase):
self.assertTrue('<title>noVNC</title>' in result.text) self.assertTrue('<title>noVNC</title>' in result.text)
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase): class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'akc' __partition_reference__ = 'akc'
expected_partition_with_monitor_base_url_count = 2 expected_partition_with_monitor_base_url_count = 2
...@@ -241,7 +228,7 @@ class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase): ...@@ -241,7 +228,7 @@ class TestAccessKvmCluster(MonitorAccessMixin, InstanceTestCase):
self.assertFalse('kvm0-url-additional' in connection_parameter_dict) self.assertFalse('kvm0-url-additional' in connection_parameter_dict)
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase): class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase):
__partition_reference__ = 'akca' __partition_reference__ = 'akca'
expected_partition_with_monitor_base_url_count = 2 expected_partition_with_monitor_base_url_count = 2
...@@ -282,7 +269,7 @@ class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase): ...@@ -282,7 +269,7 @@ class TestAccessKvmClusterAdditional(MonitorAccessMixin, InstanceTestCase):
self.assertTrue('<title>noVNC</title>' in result.text) self.assertTrue('<title>noVNC</title>' in result.text)
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestInstanceResilient(InstanceTestCase): class TestInstanceResilient(InstanceTestCase):
__partition_reference__ = 'ir' __partition_reference__ = 'ir'
instance_max_retry = 20 instance_max_retry = 20
...@@ -309,7 +296,7 @@ class TestInstanceResilient(InstanceTestCase): ...@@ -309,7 +296,7 @@ class TestInstanceResilient(InstanceTestCase):
'takeover-kvm-1-url', 'takeover-kvm-1-url',
'url'])) 'url']))
@unittest.skipIf(not sanityCheck(), 'missing kvm_intel module') @skipUnlessKvm
class TestAccessResilientAdditional(InstanceTestCase): class TestAccessResilientAdditional(InstanceTestCase):
__partition_reference__ = 'ara' __partition_reference__ = 'ara'
expected_partition_with_monitor_base_url_count = 1 expected_partition_with_monitor_base_url_count = 1
......
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