Commit 5568bbf9 authored by Xavier Thompson's avatar Xavier Thompson

software/theia: Add basic tests

parent 5e156b8f
...@@ -45,13 +45,53 @@ from slapos.grid.svcbackend import getSupervisorRPC ...@@ -45,13 +45,53 @@ from slapos.grid.svcbackend import getSupervisorRPC
from slapos.grid.svcbackend import _getSupervisordSocketPath from slapos.grid.svcbackend import _getSupervisordSocketPath
# Base classes
# ------------
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass( setUpModule, SlapOSInstanceTestCase = 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')))
class TestTheia(SlapOSInstanceTestCase): class TheiaTestCase(SlapOSInstanceTestCase):
__partition_reference__ = 'T' # for sockets in included slapos # Theia uses unix sockets, so it needs short paths.
__partition_reference__ = 'T'
# Utils
# -----
class SQLiteDB(object):
def __init__(self, sqlitedb_file):
self.sqlitedb_file = sqlitedb_file
def select(self, fields, table, where={}):
connection = sqlite3.connect(self.sqlitedb_file)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
connection.row_factory = dict_factory
cursor = connection.cursor()
condition = " AND ".join("%s='%s'" % (k, v) for k, v in where.items())
cursor.execute(
"SELECT %s FROM %s%s"
% (
", ".join(fields),
table,
" WHERE %s" % condition if where else "",
)
)
return cursor.fetchall()
# Tests
# -----
class TestTheiaInterface(TheiaTestCase):
def setUp(self): def setUp(self):
self.connection_parameters = self.computer_partition.getConnectionParameterDict() self.connection_parameters = self.computer_partition.getConnectionParameterDict()
...@@ -153,9 +193,7 @@ class TestTheia(SlapOSInstanceTestCase): ...@@ -153,9 +193,7 @@ class TestTheia(SlapOSInstanceTestCase):
self.assertTrue(os.path.exists(test_file)) self.assertTrue(os.path.exists(test_file))
class TestTheiaEmbeddedSlapOSShutdown(SlapOSInstanceTestCase): class TestTheiaEmbeddedSlapOSShutdown(TheiaTestCase):
__partition_reference__ = 'T' # for sockets in included slapos
def test_stopping_instance_stops_embedded_slapos(self): def test_stopping_instance_stops_embedded_slapos(self):
embedded_slapos_supervisord_socket = _getSupervisordSocketPath( embedded_slapos_supervisord_socket = _getSupervisordSocketPath(
os.path.join( os.path.join(
...@@ -187,36 +225,7 @@ class TestTheiaEmbeddedSlapOSShutdown(SlapOSInstanceTestCase): ...@@ -187,36 +225,7 @@ class TestTheiaEmbeddedSlapOSShutdown(SlapOSInstanceTestCase):
self.assertFalse(embedded_slapos_process.is_running()) self.assertFalse(embedded_slapos_process.is_running())
class SQLiteDB(object): class TestTheiaWithSR(TheiaTestCase):
def __init__(self, sqlitedb_file):
self.sqlitedb_file = sqlitedb_file
def select(self, fields, table, where={}):
connection = sqlite3.connect(self.sqlitedb_file)
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
connection.row_factory = dict_factory
cursor = connection.cursor()
condition = " AND ".join("%s='%s'" % (k, v) for k, v in where.items())
cursor.execute(
"SELECT %s FROM %s%s"
% (
", ".join(fields),
table,
" WHERE %s" % condition if where else "",
)
)
return cursor.fetchall()
class TestTheiaWithSR(SlapOSInstanceTestCase):
__partition_reference__ = 'T' # for sockets in included slapos
srurl = 'bogus/software.cfg' srurl = 'bogus/software.cfg'
srtype = 'bogus' srtype = 'bogus'
...@@ -241,3 +250,31 @@ class TestTheiaWithSR(SlapOSInstanceTestCase): ...@@ -241,3 +250,31 @@ class TestTheiaWithSR(SlapOSInstanceTestCase):
where={'software_release': self.srurl, 'software_type': self.srtype} where={'software_release': self.srurl, 'software_type': self.srtype}
) )
self.assertEqual(len(requested), 1) self.assertEqual(len(requested), 1)
class TestTheiaResilientInterface(TestTheiaInterface):
instance_max_retry = 30
@classmethod
def getInstanceSoftwareType(cls):
return 'resilient'
@classmethod
def setUpClass(cls):
super(TestTheiaResilientInterface, cls).setUpClass()
# Patch the computer root path to that of the export theia instance
cls.computer_partition_root_path = os.path.join(cls.slap._instance_root, "T2")
class TestTheiaResilientWithSR(TestTheiaWithSR):
instance_max_retry = 30
@classmethod
def getInstanceSoftwareType(cls):
return 'resilient'
@classmethod
def setUpClass(cls):
super(TestTheiaResilientWithSR, cls).setUpClass()
# Patch the computer root path to that of the export theia instance
cls.computer_partition_root_path = os.path.join(cls.slap._instance_root, "T2")
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