Enable congress HA tests

This commit enables the congress HA tests.

Change-Id: I3507d77203f9b86d81e1b1293aeb8f58171ed6b4
This commit is contained in:
Anusha Ramineni 2015-12-22 15:36:33 +05:30
parent 22e02a3176
commit 7d91734baf
3 changed files with 40 additions and 26 deletions

View File

@ -15,7 +15,7 @@
import json
from tempest_lib.common import rest_client
from tempest.lib.common import rest_client
class PolicyClient(rest_client.RestClient):

View File

@ -19,14 +19,14 @@ import subprocess
import tempfile
from oslo_log import log as logging
from tempest.common import cred_provider
from tempest.common import credentials_factory as credentials
from tempest import config
from tempest.lib import decorators
from tempest.lib import exceptions
from tempest import manager as tempestmanager
from tempest import test
from congress_tempest_tests.services.policy import policy_client
from congress_tempest_tests.tests.scenario import helper
from congress_tempest_tests.tests.scenario import manager_congress
CONF = config.CONF
@ -40,25 +40,27 @@ class TestHA(manager_congress.ScenarioPolicyBase):
self.keypairs = {}
self.servers = []
self.replicas = {}
self.services_client = self.admin_manager.identity_services_client
self.endpoints_client = self.admin_manager.endpoints_client
def _prepare_replica(self, port_num):
replica_url = "http://127.0.0.1:%d" % port_num
ksclient = self.admin_manager.identity_client
resp = ksclient.create_service('congressha',
CONF.congressha.replica_type,
description='policy ha service')
self.replica_service_id = resp['id']
resp = ksclient.create_endpoint(self.replica_service_id,
CONF.identity.region,
publicurl=replica_url,
adminurl=replica_url,
internalurl=replica_url)
self.replica_endpoint_id = resp['id']
resp = self.services_client.create_service(
'congressha',
CONF.congressha.replica_type,
description='policy ha service')
self.replica_service_id = resp['OS-KSADM:service']['id']
resp = self.endpoints_client.create_endpoint(
self.replica_service_id,
CONF.identity.region,
publicurl=replica_url,
adminurl=replica_url,
internalurl=replica_url)
self.replica_endpoint_id = resp['endpoint']['id']
def _cleanup_replica(self):
ksclient = self.admin_manager.identity_client
ksclient.delete_endpoint(self.replica_endpoint_id)
ksclient.delete_service(self.replica_service_id)
self.endpoints_client.delete_endpoint(self.replica_endpoint_id)
self.services_client.delete_service(self.replica_service_id)
def start_replica(self, port_num):
self._prepare_replica(port_num)
@ -68,10 +70,14 @@ class TestHA(manager_congress.ScenarioPolicyBase):
conf_file = f.name
template = open('/etc/congress/congress.conf')
conf = template.read()
conf = conf.replace('# bind_port = 1789',
'bind_port = %d\n' % port_num)
conf = conf.replace('# datasource_sync_period = 60',
'datasource_sync_period = 5')
# Add 'bind_port' and 'datasource_sync_period' to conf file.
index = conf.find('[DEFAULT]') + len('[DEFAULT]\n')
conf = (conf[:index] + 'bind_port = %d\n' % port_num +
'datasource_sync_period = 5\n' + conf[index:])
sindex = conf.find('signing_dir')
conf = conf[:sindex] + '#' + conf[sindex:]
f.write(conf)
f.close()
@ -79,7 +85,6 @@ class TestHA(manager_congress.ScenarioPolicyBase):
'bin/congress-server',
'--config-file',
conf_file]
out = tempfile.NamedTemporaryFile(mode='w', suffix='.out',
prefix='congress%d-' % port_num,
dir='/tmp', delete=False)
@ -87,7 +92,7 @@ class TestHA(manager_congress.ScenarioPolicyBase):
prefix='congress%d-' % port_num,
dir='/tmp', delete=False)
p = subprocess.Popen(args, stdout=out, stderr=err,
cwd='/opt/stack/congress')
cwd=helper.root_path())
assert port_num not in self.replicas
self.replicas[port_num] = (p, conf_file)
@ -102,7 +107,7 @@ class TestHA(manager_congress.ScenarioPolicyBase):
self._cleanup_replica()
def create_client(self, client_type):
creds = cred_provider.get_configured_credentials('identity_admin')
creds = credentials.get_configured_credentials('identity_admin')
auth_prov = tempestmanager.get_auth_provider(creds)
return policy_client.PolicyClient(
@ -172,7 +177,6 @@ class TestHA(manager_congress.ScenarioPolicyBase):
LOG.debug('created fake driver: %s', str(ret['id']))
return ret['id']
@decorators.skip_because(bug='1486246')
@test.attr(type='smoke')
def test_datasource_db_sync_add(self):
# Verify that a replica adds a datasource when a datasource
@ -243,7 +247,6 @@ class TestHA(manager_congress.ScenarioPolicyBase):
if need_to_delete_fake:
self.admin_manager.congress_client.delete_datasource(fake_id)
@decorators.skip_because(bug='1486246')
@test.attr(type='smoke')
def test_datasource_db_sync_remove(self):
# Verify that a replica removes a datasource when a datasource

View File

@ -13,6 +13,7 @@
# under the License.
#
import os
import retrying
@ -34,3 +35,13 @@ def retry_on_exception(f):
except Exception:
return False
return wrapper
def root_path():
"""Return path to root of source code."""
x = os.path.realpath(__file__)
x, y = os.path.split(x) # drop "helper.py"
x, y = os.path.split(x) # drop "scenario"
x, y = os.path.split(x) # drop "tests"
x, y = os.path.split(x) # drop "congress_tempest_tests"
return x