Tests for extension, db and plugin for LBaaS V2

Adding needed driver interface changes for tests.
Adding LoggingNoop driver needed changes for tests.
Adding extension, plugin, and db unit tests.

Partially-implements: blueprint lbaas-api-and-objmodel-improvement

Change-Id: I1f7762bf3c9484b8bf46ce32ab78574aa081324b
Co-authored-by: Brandon Logan <brandon.logan@rackspace.com>
Co-authored-by: Phillip Toohill <phillip.toohill@rackspace.com>
Co-authored-by: Doug Wiegley <dougw@a10networks.com>
This commit is contained in:
Brandon Logan 2014-07-08 17:30:45 -05:00
parent 635a4aa6e0
commit 55bac1ffc1
5 changed files with 2421 additions and 60 deletions

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from neutron.db.loadbalancer import loadbalancer_db as lb_db from neutron.db.loadbalancer import models
from neutron.services.loadbalancer.drivers import driver_mixins from neutron.services.loadbalancer.drivers import driver_mixins
@ -46,42 +46,63 @@ class LoadBalancerBaseDriver(object):
def __init__(self, plugin): def __init__(self, plugin):
self.plugin = plugin self.plugin = plugin
def activate_cascade(self, context, obj):
self.plugin.activate_linked_entities(context, obj)
class BaseLoadBalancerManager(driver_mixins.BaseRefreshMixin, class BaseLoadBalancerManager(driver_mixins.BaseRefreshMixin,
driver_mixins.BaseStatsMixin, driver_mixins.BaseStatsMixin,
driver_mixins.BaseStatusUpdateMixin, driver_mixins.BaseStatusUpdateMixin,
driver_mixins.BaseDeleteHelperMixin,
driver_mixins.BaseManagerMixin): driver_mixins.BaseManagerMixin):
model_class = models.LoadBalancer
def __init__(self, driver): @property
super(BaseLoadBalancerManager, self).__init__(driver) def db_delete_method(self):
# TODO(dougw), use lb_db.LoadBalancer when v2 lbaas return self.driver.plugin.db.delete_loadbalancer
# TODO(dougw), get rid of __init__() in StatusHelperManager, and
# the if is not None clauses; after fixing this next line,
# it can become a mandatory variable for that subclass.
self.model_class = None
class BaseListenerManager(driver_mixins.BaseManagerMixin): class BaseListenerManager(driver_mixins.BaseStatusUpdateMixin,
pass driver_mixins.BaseDeleteHelperMixin,
driver_mixins.BaseManagerMixin):
model_class = models.Listener
@property
def db_delete_method(self):
return self.driver.plugin.db.delete_listener
def defer_cascade(self, context, listener):
self.driver.plugin.defer_listener(context, listener)
class BasePoolManager(driver_mixins.BaseStatusUpdateMixin, class BasePoolManager(driver_mixins.BaseStatusUpdateMixin,
driver_mixins.BaseDeleteHelperMixin,
driver_mixins.BaseManagerMixin): driver_mixins.BaseManagerMixin):
model_class = models.PoolV2
def __init__(self, driver): @property
super(BasePoolManager, self).__init__(driver) def db_delete_method(self):
self.model_class = lb_db.Pool return self.driver.plugin.db.delete_pool
def defer_cascade(self, context, pool):
self.driver.plugin.defer_pool(context, pool)
class BaseMemberManager(driver_mixins.BaseStatusUpdateMixin, class BaseMemberManager(driver_mixins.BaseStatusUpdateMixin,
driver_mixins.BaseDeleteHelperMixin,
driver_mixins.BaseManagerMixin): driver_mixins.BaseManagerMixin):
model_class = models.MemberV2
def __init__(self, driver): @property
super(BaseMemberManager, self).__init__(driver) def db_delete_method(self):
self.model_class = lb_db.Member return self.driver.plugin.delete_member
class BaseHealthMonitorManager( class BaseHealthMonitorManager(driver_mixins.BaseStatusUpdateMixin,
driver_mixins.BaseHealthMonitorStatusUpdateMixin, driver_mixins.BaseDeleteHelperMixin,
driver_mixins.BaseManagerMixin): driver_mixins.BaseManagerMixin):
pass model_class = models.HealthMonitorV2
@property
def db_delete_method(self):
return self.driver.plugin.db.delete_healthmonitor

View File

@ -56,30 +56,26 @@ class BaseStatsMixin(object):
class BaseStatusUpdateMixin(object): class BaseStatusUpdateMixin(object):
# Status update helpers # Status update helpers
# Note: You must set self.model_class to an appropriate neutron model # Note: You must set model_class to an appropriate neutron model
# in your base manager class. # in your base manager class.
def active(self, context, model_id): def active(self, context, model_id):
if self.model_class is not None: self.driver.plugin.db.update_status(context, self.model_class,
self.driver.plugin.update_status(context, self.model_class, model_id, constants.ACTIVE)
model_id, constants.ACTIVE)
def failed(self, context, model_id): def failed(self, context, model_id):
if self.model_class is not None: self.driver.plugin.db.update_status(context, self.model_class,
self.driver.plugin.update_status(context, self.model_class, model_id, constants.ERROR)
model_id, constants.ERROR)
def defer(self, context, model_id):
self.driver.plugin.db.update_status(context, self.model_class,
model_id, constants.DEFERRED)
class BaseHealthMonitorStatusUpdateMixin(object): class BaseDeleteHelperMixin(object):
def active(self, context, health_monitor_id, pool_id): # DB delete helper
self.driver.plugin.update_pool_health_monitor(context, # Must define appropriate db delete function
health_monitor_id,
pool_id,
constants.ACTIVE)
def failed(self, context, health_monitor_id, pool_id): def db_delete(self, context, model_id):
self.driver.plugin.update_pool_health_monitor(context, self.db_delete_method(context, model_id)
health_monitor_id,
pool_id,
constants.ERROR)

View File

@ -70,26 +70,25 @@ class LoggingNoopLoadBalancerManager(LoggingNoopCommonManager,
def create(self, context, loadbalancer): def create(self, context, loadbalancer):
super(LoggingNoopLoadBalancerManager, self).create(context, super(LoggingNoopLoadBalancerManager, self).create(context,
loadbalancer) loadbalancer)
self.driver.plugin.activate_linked_entities(context, self.driver.activate_cascade(context, loadbalancer)
loadbalancer)
def update(self, context, old_loadbalancer, loadbalancer): def update(self, context, old_loadbalancer, loadbalancer):
super(LoggingNoopLoadBalancerManager, self).update(context, super(LoggingNoopLoadBalancerManager, self).update(context,
old_loadbalancer, old_loadbalancer,
loadbalancer) loadbalancer)
self.driver.plugin.activate_linked_entities(context, loadbalancer) self.driver.activate_cascade(context, loadbalancer)
def delete(self, context, loadbalancer): def delete(self, context, loadbalancer):
super(LoggingNoopLoadBalancerManager, self).delete(context, super(LoggingNoopLoadBalancerManager, self).delete(context,
loadbalancer) loadbalancer)
self.driver.plugin._delete_db_loadbalancer(context, loadbalancer.id) self.db_delete(context, loadbalancer.id)
class LoggingNoopListenerManager(LoggingNoopCommonManager, class LoggingNoopListenerManager(LoggingNoopCommonManager,
driver_base.BaseListenerManager): driver_base.BaseListenerManager):
def create(self, context, obj): def create(self, context, obj):
super(LoggingNoopListenerManager, self).create(context, obj) super(LoggingNoopListenerManager, self).create(context, obj)
self.driver.plugin.activate_linked_entities(context, obj) self.driver.activate_cascade(context, obj)
def update(self, context, old_listener, new_listener): def update(self, context, old_listener, new_listener):
super(LoggingNoopListenerManager, self).update(context, old_listener, super(LoggingNoopListenerManager, self).update(context, old_listener,
@ -97,22 +96,22 @@ class LoggingNoopListenerManager(LoggingNoopCommonManager,
if new_listener.attached_to_loadbalancer(): if new_listener.attached_to_loadbalancer():
# Always activate listener and its children if attached to # Always activate listener and its children if attached to
# loadbalancer # loadbalancer
self.driver.plugin.activate_linked_entities(context, new_listener) self.driver.activate_cascade(context, new_listener)
elif old_listener.attached_to_loadbalancer(): elif old_listener.attached_to_loadbalancer():
# If listener has just been detached from loadbalancer # If listener has just been detached from loadbalancer
# defer listener and its children # defer listener and its children
self.driver.plugin.defer_listener(context, new_listener) self.defer_cascade(context, new_listener)
if not new_listener.default_pool and old_listener.default_pool: if not new_listener.default_pool and old_listener.default_pool:
# if listener's pool has been detached then defer the pool # if listener's pool has been detached then defer the pool
# and its children # and its children
self.driver.plugin.defer_pool(context, old_listener.default_pool) self.driver.pool.defer_cascade(context, old_listener.default_pool)
def delete(self, context, listener): def delete(self, context, listener):
super(LoggingNoopListenerManager, self).delete(context, listener) super(LoggingNoopListenerManager, self).delete(context, listener)
if listener.default_pool: if listener.default_pool:
self.driver.plugin.defer_pool(context, listener.default_pool) self.driver.pool.defer_cascade(context, listener.default_pool)
self.driver.plugin._delete_db_listener(context, listener.id) self.db_delete(context, listener.id)
class LoggingNoopPoolManager(LoggingNoopCommonManager, class LoggingNoopPoolManager(LoggingNoopCommonManager,
@ -121,36 +120,36 @@ class LoggingNoopPoolManager(LoggingNoopCommonManager,
super(LoggingNoopPoolManager, self).create(context, pool) super(LoggingNoopPoolManager, self).create(context, pool)
# This shouldn't be called since a pool cannot be created and linked # This shouldn't be called since a pool cannot be created and linked
# to a loadbalancer at the same time # to a loadbalancer at the same time
self.driver.plugin.activate_linked_entities(context, pool) self.driver.activate_cascade(context, pool)
def update(self, context, old_pool, pool): def update(self, context, old_pool, pool):
super(LoggingNoopPoolManager, self).update(context, old_pool, pool) super(LoggingNoopPoolManager, self).update(context, old_pool, pool)
self.driver.plugin.activate_linked_entities(context, pool) self.driver.activate_cascade(context, pool)
if not pool.healthmonitor and old_pool.healthmonitor: if not pool.healthmonitor and old_pool.healthmonitor:
self.driver.plugin.defer_healthmonitor(context, self.driver.health_monitor.defer(context,
old_pool.healthmonitor) old_pool.healthmonitor.id)
def delete(self, context, pool): def delete(self, context, pool):
super(LoggingNoopPoolManager, self).delete(context, pool) super(LoggingNoopPoolManager, self).delete(context, pool)
if pool.healthmonitor: if pool.healthmonitor:
self.driver.plugin.defer_healthmonitor(context, pool.healthmonitor) self.driver.health_monitor.defer(context, pool.healthmonitor.id)
self.driver.plugin._delete_db_pool(context, pool.id) self.db_delete(context, pool.id)
class LoggingNoopMemberManager(LoggingNoopCommonManager, class LoggingNoopMemberManager(LoggingNoopCommonManager,
driver_base.BaseMemberManager): driver_base.BaseMemberManager):
def create(self, context, member): def create(self, context, member):
super(LoggingNoopMemberManager, self).create(context, member) super(LoggingNoopMemberManager, self).create(context, member)
self.driver.plugin.activate_linked_entities(context, member) self.driver.activate_cascade(context, member)
def update(self, context, old_member, member): def update(self, context, old_member, member):
super(LoggingNoopMemberManager, self).update(context, old_member, super(LoggingNoopMemberManager, self).update(context, old_member,
member) member)
self.driver.plugin.activate_linked_entities(context, member) self.driver.activate_cascade(context, member)
def delete(self, context, member): def delete(self, context, member):
super(LoggingNoopMemberManager, self).delete(context, member) super(LoggingNoopMemberManager, self).delete(context, member)
self.driver.plugin._delete_db_pool_member(context, member.id) self.db_delete(context, member.id)
class LoggingNoopHealthMonitorManager(LoggingNoopCommonManager, class LoggingNoopHealthMonitorManager(LoggingNoopCommonManager,
@ -159,15 +158,15 @@ class LoggingNoopHealthMonitorManager(LoggingNoopCommonManager,
def create(self, context, healthmonitor): def create(self, context, healthmonitor):
super(LoggingNoopHealthMonitorManager, self).create(context, super(LoggingNoopHealthMonitorManager, self).create(context,
healthmonitor) healthmonitor)
self.driver.plugin.activate_linked_entities(context, healthmonitor) self.driver.activate_cascade(context, healthmonitor)
def update(self, context, old_healthmonitor, healthmonitor): def update(self, context, old_healthmonitor, healthmonitor):
super(LoggingNoopHealthMonitorManager, self).update(context, super(LoggingNoopHealthMonitorManager, self).update(context,
old_healthmonitor, old_healthmonitor,
healthmonitor) healthmonitor)
self.driver.plugin.activate_linked_entities(context, healthmonitor) self.driver.activate_cascade(context, healthmonitor)
def delete(self, context, healthmonitor): def delete(self, context, healthmonitor):
super(LoggingNoopHealthMonitorManager, self).delete(context, super(LoggingNoopHealthMonitorManager, self).delete(context,
healthmonitor) healthmonitor)
self.driver.plugin._delete_db_pool_member(context, healthmonitor.id) self.db_delete(context, healthmonitor.id)

File diff suppressed because it is too large Load Diff

View File

@ -20,6 +20,7 @@ from webob import exc
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.extensions import loadbalancer from neutron.extensions import loadbalancer
from neutron.extensions import loadbalancerv2
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants from neutron.plugins.common import constants
from neutron.tests.unit import test_api_v2 from neutron.tests.unit import test_api_v2
@ -460,3 +461,523 @@ class LoadBalancerExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
class LoadBalancerExtensionTestCaseXML(LoadBalancerExtensionTestCase): class LoadBalancerExtensionTestCaseXML(LoadBalancerExtensionTestCase):
fmt = 'xml' fmt = 'xml'
class LoadBalancerExtensionV2TestCase(test_api_v2_extension.ExtensionTestCase):
fmt = 'json'
def setUp(self):
super(LoadBalancerExtensionV2TestCase, self).setUp()
self._setUpExtension(
'neutron.extensions.loadbalancerv2.LoadBalancerPluginBaseV2',
constants.LOADBALANCERV2, loadbalancerv2.RESOURCE_ATTRIBUTE_MAP,
loadbalancerv2.Loadbalancerv2, 'lbaas', use_quota=True)
def test_loadbalancer_create(self):
lb_id = _uuid()
data = {'loadbalancer': {'name': 'lb1',
'description': 'descr_lb1',
'tenant_id': _uuid(),
'vip_subnet_id': _uuid(),
'admin_state_up': True,
'vip_address': '127.0.0.1'}}
return_value = copy.copy(data['loadbalancer'])
return_value.update({'status': 'ACTIVE', 'id': lb_id})
instance = self.plugin.return_value
instance.create_loadbalancer.return_value = return_value
res = self.api.post(_get_path('lbaas/loadbalancers', fmt=self.fmt),
self.serialize(data),
content_type='application/{0}'.format(self.fmt))
instance.create_loadbalancer.assert_called_with(mock.ANY,
loadbalancer=data)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('loadbalancer', res)
self.assertEqual(res['loadbalancer'], return_value)
def test_loadbalancer_list(self):
lb_id = _uuid()
return_value = [{'name': 'lb1',
'admin_state_up': True,
'tenant_id': _uuid(),
'id': lb_id}]
instance = self.plugin.return_value
instance.get_loadbalancers.return_value = return_value
res = self.api.get(_get_path('lbaas/loadbalancers', fmt=self.fmt))
instance.get_loadbalancers.assert_called_with(mock.ANY,
fields=mock.ANY,
filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_loadbalancer_update(self):
lb_id = _uuid()
update_data = {'loadbalancer': {'admin_state_up': False}}
return_value = {'name': 'lb1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': lb_id}
instance = self.plugin.return_value
instance.update_loadbalancer.return_value = return_value
res = self.api.put(_get_path('lbaas/loadbalancers',
id=lb_id,
fmt=self.fmt),
self.serialize(update_data))
instance.update_loadbalancer.assert_called_with(
mock.ANY, lb_id, loadbalancer=update_data)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('loadbalancer', res)
self.assertEqual(res['loadbalancer'], return_value)
def test_loadbalancer_get(self):
lb_id = _uuid()
return_value = {'name': 'lb1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': lb_id}
instance = self.plugin.return_value
instance.get_loadbalancer.return_value = return_value
res = self.api.get(_get_path('lbaas/loadbalancers',
id=lb_id,
fmt=self.fmt))
instance.get_loadbalancer.assert_called_with(mock.ANY, lb_id,
fields=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('loadbalancer', res)
self.assertEqual(res['loadbalancer'], return_value)
def test_loadbalancer_delete(self):
self._test_entity_delete('loadbalancer')
def test_listener_create(self):
listener_id = _uuid()
data = {'listener': {'tenant_id': _uuid(),
'name': 'listen-name-1',
'description': 'listen-1-desc',
'protocol': 'HTTP',
'protocol_port': 80,
'connection_limit': 100,
'admin_state_up': True,
'loadbalancer_id': _uuid(),
'default_pool_id': _uuid()}}
return_value = copy.copy(data['listener'])
return_value.update({'status': 'ACTIVE', 'id': listener_id})
instance = self.plugin.return_value
instance.create_listener.return_value = return_value
res = self.api.post(_get_path('lbaas/listeners', fmt=self.fmt),
self.serialize(data),
content_type='application/{0}'.format(self.fmt))
instance.create_listener.assert_called_with(mock.ANY,
listener=data)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('listener', res)
self.assertEqual(res['listener'], return_value)
def test_listener_list(self):
listener_id = _uuid()
return_value = [{'admin_state_up': True,
'tenant_id': _uuid(),
'id': listener_id}]
instance = self.plugin.return_value
instance.get_listeners.return_value = return_value
res = self.api.get(_get_path('lbaas/listeners', fmt=self.fmt))
instance.get_listeners.assert_called_with(mock.ANY,
fields=mock.ANY,
filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_listener_update(self):
listener_id = _uuid()
update_data = {'listener': {'admin_state_up': False}}
return_value = {'name': 'listener1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': listener_id}
instance = self.plugin.return_value
instance.update_listener.return_value = return_value
res = self.api.put(_get_path('lbaas/listeners',
id=listener_id,
fmt=self.fmt),
self.serialize(update_data))
instance.update_listener.assert_called_with(
mock.ANY, listener_id, listener=update_data)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('listener', res)
self.assertEqual(res['listener'], return_value)
def test_listener_get(self):
listener_id = _uuid()
return_value = {'name': 'listener1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': listener_id}
instance = self.plugin.return_value
instance.get_listener.return_value = return_value
res = self.api.get(_get_path('lbaas/listeners',
id=listener_id,
fmt=self.fmt))
instance.get_listener.assert_called_with(mock.ANY, listener_id,
fields=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('listener', res)
self.assertEqual(res['listener'], return_value)
def test_listener_delete(self):
self._test_entity_delete('listener')
def test_pool_create(self):
pool_id = _uuid()
hm_id = _uuid()
data = {'pool': {'name': 'pool1',
'description': 'descr_pool1',
'protocol': 'HTTP',
'lb_algorithm': 'ROUND_ROBIN',
'healthmonitor_id': hm_id,
'admin_state_up': True,
'tenant_id': _uuid(),
'session_persistence': {}}}
return_value = copy.copy(data['pool'])
return_value.update({'status': "ACTIVE", 'id': pool_id})
instance = self.plugin.return_value
instance.create_pool.return_value = return_value
res = self.api.post(_get_path('lbaas/pools', fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt)
instance.create_pool.assert_called_with(mock.ANY,
pool=data)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('pool', res)
self.assertEqual(res['pool'], return_value)
def test_pool_list(self):
pool_id = _uuid()
return_value = [{'name': 'pool1',
'admin_state_up': True,
'tenant_id': _uuid(),
'id': pool_id}]
instance = self.plugin.return_value
instance.get_pools.return_value = return_value
res = self.api.get(_get_path('lbaas/pools', fmt=self.fmt))
instance.get_pools.assert_called_with(mock.ANY, fields=mock.ANY,
filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_pool_update(self):
pool_id = _uuid()
update_data = {'pool': {'admin_state_up': False}}
return_value = {'name': 'pool1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': pool_id}
instance = self.plugin.return_value
instance.update_pool.return_value = return_value
res = self.api.put(_get_path('lbaas/pools', id=pool_id,
fmt=self.fmt),
self.serialize(update_data))
instance.update_pool.assert_called_with(mock.ANY, pool_id,
pool=update_data)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('pool', res)
self.assertEqual(res['pool'], return_value)
def test_pool_get(self):
pool_id = _uuid()
return_value = {'name': 'pool1',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': pool_id}
instance = self.plugin.return_value
instance.get_pool.return_value = return_value
res = self.api.get(_get_path('lbaas/pools', id=pool_id,
fmt=self.fmt))
instance.get_pool.assert_called_with(mock.ANY, pool_id,
fields=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('pool', res)
self.assertEqual(res['pool'], return_value)
def test_pool_delete(self):
self._test_entity_delete('pool')
def test_pool_member_create(self):
subnet_id = _uuid()
member_id = _uuid()
data = {'member': {'address': '10.0.0.1',
'protocol_port': 80,
'weight': 1,
'subnet_id': subnet_id,
'admin_state_up': True,
'tenant_id': _uuid()}}
return_value = copy.copy(data['member'])
return_value.update({'status': "ACTIVE", 'id': member_id})
instance = self.plugin.return_value
instance.create_pool_member.return_value = return_value
res = self.api.post(_get_path('lbaas/pools/pid1/members',
fmt=self.fmt),
self.serialize(data),
content_type='application/%s'
% self.fmt)
instance.create_pool_member.assert_called_with(mock.ANY,
pool_id='pid1',
member=data)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('member', res)
self.assertEqual(res['member'], return_value)
def test_pool_member_list(self):
member_id = _uuid()
return_value = [{'name': 'member1',
'admin_state_up': True,
'tenant_id': _uuid(),
'id': member_id}]
instance = self.plugin.return_value
instance.get_pools.return_value = return_value
res = self.api.get(_get_path('lbaas/pools/pid1/members',
fmt=self.fmt))
instance.get_pool_members.assert_called_with(mock.ANY,
fields=mock.ANY,
filters=mock.ANY,
pool_id='pid1')
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_pool_member_update(self):
self.skipTest('mock autospec bug causes false negative.'
'Similar bug: '
'https://code.google.com/p/mock/issues/detail?id=224')
member_id = _uuid()
update_data = {'member': {'admin_state_up': False}}
return_value = {'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': member_id}
instance = self.plugin.return_value
instance.update_pool_member.return_value = return_value
res = self.api.put(_get_path('lbaas/pools/pid1/members',
id=member_id,
fmt=self.fmt),
self.serialize(update_data),
content_type='application/%s'
% self.fmt)
instance.update_pool_member.assert_called_with(mock.ANY,
member_id,
member=update_data,
pool_id='pid1')
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('member', res)
self.assertEqual(res['member'], return_value)
def test_pool_member_get(self):
member_id = _uuid()
return_value = {'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': member_id}
instance = self.plugin.return_value
instance.get_pool_member.return_value = return_value
res = self.api.get(_get_path('lbaas/pools/pid1/members',
id=member_id, fmt=self.fmt))
instance.get_pool_member.assert_called_with(mock.ANY,
member_id,
fields=mock.ANY,
pool_id='pid1')
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('member', res)
self.assertEqual(res['member'], return_value)
def test_pool_member_delete(self):
entity_id = _uuid()
res = self.api.delete(
test_api_v2._get_path('lbaas/pools/pid1/members',
id=entity_id, fmt=self.fmt))
delete_entity = getattr(self.plugin.return_value,
"delete_pool_member")
delete_entity.assert_called_with(mock.ANY, entity_id,
pool_id='pid1')
self.assertEqual(res.status_int, exc.HTTPNoContent.code)
def test_health_monitor_create(self):
health_monitor_id = _uuid()
data = {'healthmonitor': {'type': 'HTTP',
'delay': 2,
'timeout': 1,
'max_retries': 3,
'http_method': 'GET',
'url_path': '/path',
'expected_codes': '200-300',
'admin_state_up': True,
'tenant_id': _uuid()}}
return_value = copy.copy(data['healthmonitor'])
return_value.update({'status': "ACTIVE", 'id': health_monitor_id})
instance = self.plugin.return_value
instance.create_healthmonitor.return_value = return_value
res = self.api.post(_get_path('lbaas/healthmonitors',
fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt)
instance.create_healthmonitor.assert_called_with(mock.ANY,
healthmonitor=data)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('healthmonitor', res)
self.assertEqual(res['healthmonitor'], return_value)
def test_health_monitor_create_with_timeout_negative(self):
data = {'healthmonitor': {'type': 'HTTP',
'delay': 2,
'timeout': -1,
'max_retries': 3,
'http_method': 'GET',
'url_path': '/path',
'expected_codes': '200-300',
'admin_state_up': True,
'tenant_id': _uuid()}}
res = self.api.post(_get_path('lbaas/healthmonitors',
fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(400, res.status_int)
def test_health_monitor_list(self):
health_monitor_id = _uuid()
return_value = [{'type': 'HTTP',
'admin_state_up': True,
'tenant_id': _uuid(),
'id': health_monitor_id}]
instance = self.plugin.return_value
instance.get_healthmonitors.return_value = return_value
res = self.api.get(_get_path('lbaas/healthmonitors', fmt=self.fmt))
instance.get_healthmonitors.assert_called_with(
mock.ANY, fields=mock.ANY, filters=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_health_monitor_update(self):
health_monitor_id = _uuid()
update_data = {'healthmonitor': {'admin_state_up': False}}
return_value = {'type': 'HTTP',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': health_monitor_id}
instance = self.plugin.return_value
instance.update_healthmonitor.return_value = return_value
res = self.api.put(_get_path('lbaas/healthmonitors',
id=health_monitor_id,
fmt=self.fmt),
self.serialize(update_data))
instance.update_healthmonitor.assert_called_with(
mock.ANY, health_monitor_id, healthmonitor=update_data)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('healthmonitor', res)
self.assertEqual(res['healthmonitor'], return_value)
def test_health_monitor_get(self):
health_monitor_id = _uuid()
return_value = {'type': 'HTTP',
'admin_state_up': False,
'tenant_id': _uuid(),
'status': "ACTIVE",
'id': health_monitor_id}
instance = self.plugin.return_value
instance.get_healthmonitor.return_value = return_value
res = self.api.get(_get_path('lbaas/healthmonitors',
id=health_monitor_id,
fmt=self.fmt))
instance.get_healthmonitor.assert_called_with(
mock.ANY, health_monitor_id, fields=mock.ANY)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('healthmonitor', res)
self.assertEqual(res['healthmonitor'], return_value)
def test_health_monitor_delete(self):
self._test_entity_delete('healthmonitor')
def test_load_balancer_stats(self):
load_balancer_id = _uuid()
stats = {'stats': 'dummy'}
instance = self.plugin.return_value
instance.stats.return_value = stats
path = _get_path('lbaas/loadbalancers', id=load_balancer_id,
action="stats", fmt=self.fmt)
res = self.api.get(path)
instance.stats.assert_called_with(mock.ANY, load_balancer_id)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('stats', res)
self.assertEqual(res['stats'], stats['stats'])