Commit 7a988a85 authored by Jérome Perrin's avatar Jérome Perrin

erp5/test: use slapos.testing

parent f986e3ba
...@@ -28,7 +28,8 @@ from setuptools import setup, find_packages ...@@ -28,7 +28,8 @@ from setuptools import setup, find_packages
version = '0.0.1.dev0' version = '0.0.1.dev0'
name = 'slapos.test.erp5' name = 'slapos.test.erp5'
long_description = open("README.md").read() with open("README.md") as f:
long_description = f.read()
setup(name=name, setup(name=name,
version=version, version=version,
......
...@@ -25,15 +25,24 @@ ...@@ -25,15 +25,24 @@
# #
############################################################################## ##############################################################################
import json
import os import os
import unittest
import logging
if os.environ.get('DEBUG'): from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
raise ValueError("Don't set DEBUG - it breaks postfix compilation - set SLAPOS_TEST_DEBUG instead.")
debug_mode = os.environ.get('SLAPOS_TEST_DEBUG') setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
# for development: debugging logs and install Ctrl+C handler os.path.abspath(
if debug_mode: os.path.join(os.path.dirname(__file__), '..', '..', 'software.cfg')))
logging.basicConfig(level=logging.DEBUG)
unittest.installHandler()
class ERP5InstanceTestCase(SlapOSInstanceTestCase):
"""ERP5 base test case
"""
# ERP5 instanciation needs to run several times before being ready, as
# the root instance request more instances.
instance_max_retry = 7 # XXX how many times ?
def getRootPartitionConnectionParameterDict(self):
"""Return the output paramters from the root partition"""
return json.loads(
self.computer_partition.getConnectionParameterDict()['_'])
...@@ -29,28 +29,15 @@ import os ...@@ -29,28 +29,15 @@ import os
import json import json
import glob import glob
import urlparse import urlparse
import logging
import socket import socket
import time import time
import psutil import psutil
import requests import requests
from utils import SlapOSInstanceTestCase from . import ERP5InstanceTestCase
from . import setUpModule
setUpModule # pyflakes
class ERP5TestCase(SlapOSInstanceTestCase):
"""Test the remote driver on a minimal web server.
"""
logger = logging.getLogger(__name__)
@classmethod
def getSoftwareURLList(cls):
return (os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'software.cfg')), )
def getRootPartitionConnectionParameterDict(self):
"""Return the output paramters from the root partition"""
return json.loads(
self.computer_partition.getConnectionParameterDict()['_'])
class TestPublishedURLIsReachableMixin(object): class TestPublishedURLIsReachableMixin(object):
...@@ -91,13 +78,13 @@ class TestPublishedURLIsReachableMixin(object): ...@@ -91,13 +78,13 @@ class TestPublishedURLIsReachableMixin(object):
urlparse.urljoin(param_dict['family-default'], param_dict['site-id'])) urlparse.urljoin(param_dict['family-default'], param_dict['site-id']))
class TestDefaultParameters(ERP5TestCase, TestPublishedURLIsReachableMixin): class TestDefaultParameters(ERP5InstanceTestCase, TestPublishedURLIsReachableMixin):
"""Test ERP5 can be instanciated with no parameters """Test ERP5 can be instanciated with no parameters
""" """
__partition_reference__ = 'defp' __partition_reference__ = 'defp'
class TestMedusa(ERP5TestCase, TestPublishedURLIsReachableMixin): class TestMedusa(ERP5InstanceTestCase, TestPublishedURLIsReachableMixin):
"""Test ERP5 Medusa server """Test ERP5 Medusa server
""" """
__partition_reference__ = 'medusa' __partition_reference__ = 'medusa'
...@@ -107,7 +94,7 @@ class TestMedusa(ERP5TestCase, TestPublishedURLIsReachableMixin): ...@@ -107,7 +94,7 @@ class TestMedusa(ERP5TestCase, TestPublishedURLIsReachableMixin):
return {'_': json.dumps({'wsgi': False})} return {'_': json.dumps({'wsgi': False})}
class TestApacheBalancerPorts(ERP5TestCase): class TestApacheBalancerPorts(ERP5InstanceTestCase):
"""Instanciate with two zope families, this should create for each family: """Instanciate with two zope families, this should create for each family:
- a balancer entry point with corresponding haproxy - a balancer entry point with corresponding haproxy
- a balancer entry point for test runner - a balancer entry point for test runner
...@@ -159,8 +146,8 @@ class TestApacheBalancerPorts(ERP5TestCase): ...@@ -159,8 +146,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_zope_listen(self): def test_zope_listen(self):
# we requested 3 zope in family1 and 5 zopes in family2, we should have 8 zope running. # we requested 3 zope in family1 and 5 zopes in family2, we should have 8 zope running.
all_process_info = self.getSupervisorRPCServer( with self.slap.instance_supervisor_rpc as supervisor:
).supervisor.getAllProcessInfo() all_process_info = supervisor.getAllProcessInfo()
self.assertEqual( self.assertEqual(
3 + 5, 3 + 5,
len([p for p in all_process_info if p['name'].startswith('zope-')])) len([p for p in all_process_info if p['name'].startswith('zope-')]))
...@@ -168,8 +155,8 @@ class TestApacheBalancerPorts(ERP5TestCase): ...@@ -168,8 +155,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_apache_listen(self): def test_apache_listen(self):
# We have 2 families, apache should listen to a total of 3 ports per family # We have 2 families, apache should listen to a total of 3 ports per family
# normal access on ipv4 and ipv6 and test runner access on ipv4 only # normal access on ipv4 and ipv6 and test runner access on ipv4 only
all_process_info = self.getSupervisorRPCServer( with self.slap.instance_supervisor_rpc as supervisor:
).supervisor.getAllProcessInfo() all_process_info = supervisor.getAllProcessInfo()
process_info, = [p for p in all_process_info if p['name'] == 'apache'] process_info, = [p for p in all_process_info if p['name'] == 'apache']
apache_process = psutil.Process(process_info['pid']) apache_process = psutil.Process(process_info['pid'])
self.assertEqual( self.assertEqual(
...@@ -182,8 +169,8 @@ class TestApacheBalancerPorts(ERP5TestCase): ...@@ -182,8 +169,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_haproxy_listen(self): def test_haproxy_listen(self):
# There is one haproxy per family # There is one haproxy per family
all_process_info = self.getSupervisorRPCServer( with self.slap.instance_supervisor_rpc as supervisor:
).supervisor.getAllProcessInfo() all_process_info = supervisor.getAllProcessInfo()
process_info, = [ process_info, = [
p for p in all_process_info if p['name'].startswith('haproxy-') p for p in all_process_info if p['name'].startswith('haproxy-')
] ]
...@@ -193,7 +180,7 @@ class TestApacheBalancerPorts(ERP5TestCase): ...@@ -193,7 +180,7 @@ class TestApacheBalancerPorts(ERP5TestCase):
]) ])
class TestDisableTestRunner(ERP5TestCase, TestPublishedURLIsReachableMixin): class TestDisableTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMixin):
"""Test ERP5 can be instanciated without test runner. """Test ERP5 can be instanciated without test runner.
""" """
__partition_reference__ = 'distr' __partition_reference__ = 'distr'
...@@ -215,8 +202,8 @@ class TestDisableTestRunner(ERP5TestCase, TestPublishedURLIsReachableMixin): ...@@ -215,8 +202,8 @@ class TestDisableTestRunner(ERP5TestCase, TestPublishedURLIsReachableMixin):
def test_no_apache_testrunner_port(self): def test_no_apache_testrunner_port(self):
# Apache only listen on two ports, there is no apache ports allocated for test runner # Apache only listen on two ports, there is no apache ports allocated for test runner
all_process_info = self.getSupervisorRPCServer( with self.slap.instance_supervisor_rpc as supervisor:
).supervisor.getAllProcessInfo() all_process_info = supervisor.getAllProcessInfo()
process_info, = [p for p in all_process_info if p['name'] == 'apache'] process_info, = [p for p in all_process_info if p['name'] == 'apache']
apache_process = psutil.Process(process_info['pid']) apache_process = psutil.Process(process_info['pid'])
self.assertEqual( self.assertEqual(
......
This diff is collapsed.
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