Create scenario tests for listeners

This patch implements listener tests for the Octavia
Tempest Plugin.

Change-Id: I5c0d3a737ff4cc929573c6fb7fbb5d46f1159d80
This commit is contained in:
Jude Cross 2017-08-09 15:21:04 -07:00
parent c211636552
commit 15f1920bb1
6 changed files with 174 additions and 4 deletions

View File

@ -15,6 +15,8 @@
from tempest import clients
from tempest import config
from octavia_tempest_plugin.services.load_balancer.v2 import (
listener_client)
from octavia_tempest_plugin.services.load_balancer.v2 import (
loadbalancer_client)
@ -29,3 +31,6 @@ class Manager(clients.Manager):
self.lb_client = loadbalancer_client.LoadbalancerClient(
self.auth_provider, SERVICE_TYPE, CONF.identity.region)
self.li_client = listener_client.ListenerClient(
self.auth_provider, SERVICE_TYPE, CONF.identity.region)

View File

@ -80,4 +80,3 @@ def wait_for_error(client, error, resource):
except error:
LOG.info('{name} errored successfully'.format(
name=client.resource_name))
return

View File

@ -0,0 +1,70 @@
# Copyright 2017 GoDaddy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
import json
from tempest import config
from tempest.lib.common import rest_client
CONF = config.CONF
class ListenerClient(rest_client.RestClient):
_uri = '/v2.0/lbaas/listeners'
def __init__(self, auth_provider, service, region):
super(ListenerClient, self).__init__(auth_provider, service, region)
self.timeout = CONF.octavia.build_timeout
self.build_interval = CONF.octavia.build_interval
self.resource_name = 'listener'
self.get_status = self.get_listener
def list_listeners(self):
response, body = self.get(self._uri)
self.expected_success(200, response.status)
return json.loads(body)
def create_listener(self, payload):
response, body = self.post(self._uri, json.dumps(payload))
self.expected_success(201, response.status)
return json.loads(body)['listener']
def delete_listener(self, listener_id, ignore_errors=None):
uri = self._uri + '/{}'.format(listener_id)
if ignore_errors:
try:
response, body = self.delete(uri)
except ignore_errors:
return
else:
response, body = self.delete(uri)
self.expected_success(204, response.status)
return response.status
def get_listener(self, listener_id):
uri = self._uri + '/{}'.format(listener_id)
response, body = self.get(uri)
self.expected_success(200, response.status)
return json.loads(body)['listener']
def update_listener(self, listener_id, payload):
uri = self._uri + '/{}'.format(listener_id)
response, body = self.put(uri, json.dumps(payload))
self.expected_success(200, response.status)
return json.loads(body)['listener']

View File

@ -0,0 +1,75 @@
# Copyright 2017 GoDaddy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from oslo_log import log as logging
from tempest.common import credentials_factory as common_creds
from tempest import config
from tempest.lib import exceptions as lib_exc
from tempest import test
from octavia_tempest_plugin import clients
from octavia_tempest_plugin.services.load_balancer.common import waiters
LOG = logging.getLogger(__name__)
CONF = config.CONF
class BaseListenerTest(test.BaseTestCase):
identity_version = 'v3'
credential_type = 'identity_admin'
@classmethod
def setup_clients(cls):
super(BaseListenerTest, cls).setup_clients()
credentials = common_creds.get_configured_admin_credentials(
cls.credential_type, identity_version=cls.identity_version)
cls.clients = clients.Manager(credentials)
cls.li_client = cls.clients.li_client
def create_listener(self, lb_id):
payload = {'listener': {
'protocol': 'HTTP',
'description': 'Listener for tempest tests',
'admin_state_up': True,
'connection_limit': 200,
'protocol_port': '80',
'loadbalancer_id': lb_id,
'name': 'TEMPEST_TEST_LISTENER'}
}
LOG.info('Creating listener')
listener = self.li_client.create_listener(payload)
# Make sure we responded correctly
self.assertEqual('PENDING_CREATE', listener['provisioning_status'])
self.assertEqual(True, listener['admin_state_up'])
# Wait for listener to become active
waiters.wait_for_status(self.li_client, 'ACTIVE', listener,
'provisioning_status')
listener = self.li_client.get_listener(listener['id'])
self.assertEqual('ACTIVE', listener['provisioning_status'])
return listener
def delete_listener(self, li_id, ignore_errors=None):
listener = self.li_client.get_listener(li_id)
LOG.info('Deleting listener')
self.li_client.delete_listener(li_id, ignore_errors)
waiters.wait_for_error(self.li_client, lib_exc.NotFound, listener)
self.assertRaises(lib_exc.NotFound, self.li_client.get_listener, li_id)

View File

@ -46,7 +46,7 @@ class BaseLoadbalancerTest(test.BaseTestCase):
'name': 'TEMPEST_TEST_LB',
'description': 'LB for Tempest tests'}
}
LOG.info('Creating load balancer')
lb = self.lb_client.create_loadbalancer(payload)
# Make sure we responded correctly
@ -64,6 +64,10 @@ class BaseLoadbalancerTest(test.BaseTestCase):
def delete_loadbalancer(self, lb_id, ignore_errors=None):
lb = self.lb_client.get_loadbalancer(lb_id)
LOG.info('Waiting for loadbalncer to be mutable')
waiters.wait_for_status(self.lb_client, 'ACTIVE', lb,
'provisioning_status')
LOG.info('Deleting load balancer')
self.lb_client.delete_loadbalancer(lb_id, ignore_errors)
waiters.wait_for_status(self.lb_client, 'DELETED', lb,
'provisioning_status')

View File

@ -22,6 +22,7 @@ from tempest import test
from octavia_tempest_plugin import clients
from octavia_tempest_plugin.services.load_balancer.common import waiters
from octavia_tempest_plugin.tests.scenario.v2.base import base_listener
from octavia_tempest_plugin.tests.scenario.v2.base import base_loadbalancer
LOG = logging.getLogger(__name__)
@ -85,7 +86,8 @@ class TestLoadbalancerSmoke(test.BaseTestCase):
self.assertEqual('DELETED', lb['provisioning_status'])
class TestOctaviaFull(base_loadbalancer.BaseLoadbalancerTest):
class TestOctaviaFull(base_loadbalancer.BaseLoadbalancerTest,
base_listener.BaseListenerTest):
@test.services('network', 'image', 'compute')
@decorators.attr(type='slow')
@ -95,5 +97,20 @@ class TestOctaviaFull(base_loadbalancer.BaseLoadbalancerTest):
# Create load balancer for end to end tests.
lb = self.create_loadbalancer()
self.addCleanup(self.lb_client.delete_loadbalancer, lb['id'],
lib_exc.Conflict)
self.addCleanup(self.delete_loadbalancer, lb['id'], lib_exc.Conflict)
# Create listener for load balancer
listener = self.create_listener(lb['id'])
self.addCleanup(self.li_client.delete_listener, listener['id'],
lib_exc.NotFound)
# Wait for load balancer to update
waiters.wait_for_status(self.lb_client, 'ACTIVE', lb,
'provisioning_status')
# Delete listener
self.delete_listener(listener['id'])
# Delete load balancer
self.delete_loadbalancer(lb['id'])