From 70902ad4358fee050a4a8ebbc3ff2aa50278058e Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Mon, 2 Sep 2013 13:44:51 +0400 Subject: [PATCH] LBaaS: add status of pool-monitor association to the pool return dict Closes-Bug: #1219692 Change-Id: Icc7ca4a48c43a8462860cdbc42626079bffadc26 --- neutron/db/loadbalancer/loadbalancer_db.py | 5 ++++ neutron/extensions/loadbalancer.py | 3 +++ .../db/loadbalancer/test_db_loadbalancer.py | 24 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/neutron/db/loadbalancer/loadbalancer_db.py b/neutron/db/loadbalancer/loadbalancer_db.py index d9d41cf5e46..c6e35f5263e 100644 --- a/neutron/db/loadbalancer/loadbalancer_db.py +++ b/neutron/db/loadbalancer/loadbalancer_db.py @@ -479,6 +479,11 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase, # Get the associated health_monitors res['health_monitors'] = [ monitor['monitor_id'] for monitor in pool['monitors']] + res['health_monitors_status'] = [ + {'monitor_id': monitor['monitor_id'], + 'status': monitor['status'], + 'status_description': monitor['status_description']} + for monitor in pool['monitors']] return self._fields(res, fields) def update_pool_stats(self, context, pool_id, data=None): diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index 67054fb962a..d2dde8adb7f 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -175,6 +175,8 @@ RESOURCE_ATTRIBUTE_MAP = { 'validate': {'type:uuid_list': None}, 'convert_to': attr.convert_to_list, 'is_visible': True}, + 'health_monitors_status': {'allow_post': False, 'allow_put': False, + 'is_visible': True}, 'admin_state_up': {'allow_post': True, 'allow_put': True, 'default': True, 'convert_to': attr.convert_to_boolean, @@ -308,6 +310,7 @@ class Loadbalancer(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()] + my_plurals.append(('health_monitors_status', 'health_monitor_status')) attr.PLURALS.update(dict(my_plurals)) resources = [] plugin = manager.NeutronManager.get_service_plugins()[ diff --git a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py index 483de340922..0cbadf5ff87 100644 --- a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py +++ b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py @@ -1109,6 +1109,16 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase): res['pool']['health_monitors']) self.assertIn(monitor2['health_monitor']['id'], res['pool']['health_monitors']) + expected = [ + {'monitor_id': monitor1['health_monitor']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None}, + {'monitor_id': monitor2['health_monitor']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None}] + self.assertEqual( + sorted(expected), + sorted(res['pool']['health_monitors_status'])) def test_delete_healthmonitor_of_pool(self): with self.health_monitor(type="TCP") as monitor1: @@ -1161,6 +1171,13 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase): res['pool']['health_monitors']) self.assertIn(monitor2['health_monitor']['id'], res['pool']['health_monitors']) + expected = [ + {'monitor_id': monitor2['health_monitor']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None} + ] + self.assertEqual(expected, + res['pool']['health_monitors_status']) def test_create_loadbalancer(self): vip_name = "vip3" @@ -1221,6 +1238,13 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase): pool_updated['pool']['members']) self.assertIn(health_monitor['health_monitor']['id'], pool_updated['pool']['health_monitors']) + expected = [ + {'monitor_id': health_monitor['health_monitor']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None} + ] + self.assertEqual( + expected, pool_updated['pool']['health_monitors_status']) req = self.new_show_request('vips', vip_id,