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
version = '0.0.1.dev0'
name = 'slapos.test.erp5'
long_description = open("README.md").read()
with open("README.md") as f:
long_description = f.read()
setup(name=name,
version=version,
......
......@@ -25,15 +25,24 @@
#
##############################################################################
import json
import os
import unittest
import logging
if os.environ.get('DEBUG'):
raise ValueError("Don't set DEBUG - it breaks postfix compilation - set SLAPOS_TEST_DEBUG instead.")
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
debug_mode = os.environ.get('SLAPOS_TEST_DEBUG')
# for development: debugging logs and install Ctrl+C handler
if debug_mode:
logging.basicConfig(level=logging.DEBUG)
unittest.installHandler()
setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', '..', 'software.cfg')))
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
import json
import glob
import urlparse
import logging
import socket
import time
import psutil
import requests
from utils import SlapOSInstanceTestCase
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()['_'])
from . import ERP5InstanceTestCase
from . import setUpModule
setUpModule # pyflakes
class TestPublishedURLIsReachableMixin(object):
......@@ -91,13 +78,13 @@ class TestPublishedURLIsReachableMixin(object):
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
"""
__partition_reference__ = 'defp'
class TestMedusa(ERP5TestCase, TestPublishedURLIsReachableMixin):
class TestMedusa(ERP5InstanceTestCase, TestPublishedURLIsReachableMixin):
"""Test ERP5 Medusa server
"""
__partition_reference__ = 'medusa'
......@@ -107,7 +94,7 @@ class TestMedusa(ERP5TestCase, TestPublishedURLIsReachableMixin):
return {'_': json.dumps({'wsgi': False})}
class TestApacheBalancerPorts(ERP5TestCase):
class TestApacheBalancerPorts(ERP5InstanceTestCase):
"""Instanciate with two zope families, this should create for each family:
- a balancer entry point with corresponding haproxy
- a balancer entry point for test runner
......@@ -159,8 +146,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_zope_listen(self):
# we requested 3 zope in family1 and 5 zopes in family2, we should have 8 zope running.
all_process_info = self.getSupervisorRPCServer(
).supervisor.getAllProcessInfo()
with self.slap.instance_supervisor_rpc as supervisor:
all_process_info = supervisor.getAllProcessInfo()
self.assertEqual(
3 + 5,
len([p for p in all_process_info if p['name'].startswith('zope-')]))
......@@ -168,8 +155,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_apache_listen(self):
# 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
all_process_info = self.getSupervisorRPCServer(
).supervisor.getAllProcessInfo()
with self.slap.instance_supervisor_rpc as supervisor:
all_process_info = supervisor.getAllProcessInfo()
process_info, = [p for p in all_process_info if p['name'] == 'apache']
apache_process = psutil.Process(process_info['pid'])
self.assertEqual(
......@@ -182,8 +169,8 @@ class TestApacheBalancerPorts(ERP5TestCase):
def test_haproxy_listen(self):
# There is one haproxy per family
all_process_info = self.getSupervisorRPCServer(
).supervisor.getAllProcessInfo()
with self.slap.instance_supervisor_rpc as supervisor:
all_process_info = supervisor.getAllProcessInfo()
process_info, = [
p for p in all_process_info if p['name'].startswith('haproxy-')
]
......@@ -193,7 +180,7 @@ class TestApacheBalancerPorts(ERP5TestCase):
])
class TestDisableTestRunner(ERP5TestCase, TestPublishedURLIsReachableMixin):
class TestDisableTestRunner(ERP5InstanceTestCase, TestPublishedURLIsReachableMixin):
"""Test ERP5 can be instanciated without test runner.
"""
__partition_reference__ = 'distr'
......@@ -215,8 +202,8 @@ class TestDisableTestRunner(ERP5TestCase, TestPublishedURLIsReachableMixin):
def test_no_apache_testrunner_port(self):
# Apache only listen on two ports, there is no apache ports allocated for test runner
all_process_info = self.getSupervisorRPCServer(
).supervisor.getAllProcessInfo()
with self.slap.instance_supervisor_rpc as supervisor:
all_process_info = supervisor.getAllProcessInfo()
process_info, = [p for p in all_process_info if p['name'] == 'apache']
apache_process = psutil.Process(process_info['pid'])
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