From 8db51da1e25f1c148fbe8d8f27d144a39d1850f3 Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Thu, 15 Aug 2013 02:40:49 +0400 Subject: [PATCH] Add list of pool ids to HealthMonitor dict List of pool ids will allow users (and horizon dashboard) to show associations between pools and monitors more conveniently. fixes bug 1212258 Change-Id: Ie1e48e554382a6a4df9e1ba6312c505ba2ca8c02 --- neutron/db/loadbalancer/loadbalancer_db.py | 10 +++-- neutron/extensions/loadbalancer.py | 4 +- .../db/loadbalancer/test_db_loadbalancer.py | 43 ++++++++++++++++++- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/neutron/db/loadbalancer/loadbalancer_db.py b/neutron/db/loadbalancer/loadbalancer_db.py index 8b890fc00..103699534 100644 --- a/neutron/db/loadbalancer/loadbalancer_db.py +++ b/neutron/db/loadbalancer/loadbalancer_db.py @@ -145,9 +145,8 @@ class HealthMonitor(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant): admin_state_up = sa.Column(sa.Boolean(), nullable=False) pools = orm.relationship( - "PoolMonitorAssociation", - backref="healthmonitor", - cascade="all" + "PoolMonitorAssociation", backref="healthmonitor", + cascade="all", lazy="joined" ) @@ -679,7 +678,10 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase, if res['type'] in ['HTTP', 'HTTPS']: for attr in ['url_path', 'http_method', 'expected_codes']: res[attr] = health_monitor[attr] - + res['pools'] = [{'pool_id': p['pool_id'], + 'status': p['status'], + 'status_description': p['status_description']} + for p in health_monitor.pools] return self._fields(res, fields) def create_health_monitor(self, context, health_monitor): diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index 084a7c455..90050ee3a 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -258,7 +258,9 @@ RESOURCE_ATTRIBUTE_MAP = { 'status': {'allow_post': False, 'allow_put': False, 'is_visible': True}, 'status_description': {'allow_post': False, 'allow_put': False, - 'is_visible': True} + 'is_visible': True}, + 'pools': {'allow_post': False, 'allow_put': False, + 'is_visible': True} } } diff --git a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py index c4ee714f9..f0bfd3c2c 100644 --- a/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py +++ b/neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py @@ -1200,16 +1200,55 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase): self.pool(), self.health_monitor() ) as (pool, hm): - data = {"health_monitor": { - "id": hm['health_monitor']['id'], + data = {'health_monitor': { + 'id': hm['health_monitor']['id'], 'tenant_id': self._tenant_id}} self.plugin.create_pool_health_monitor( context.get_admin_context(), data, pool['pool']['id'] ) + hm['health_monitor']['pools'] = [ + {'pool_id': pool['pool']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None}] driver_call.assert_called_once_with( mock.ANY, hm['health_monitor'], pool['pool']['id']) + def test_pool_monitor_list_of_pools(self): + with contextlib.nested( + self.pool(), + self.pool(), + self.health_monitor() + ) as (p1, p2, hm): + ctx = context.get_admin_context() + data = {'health_monitor': { + 'id': hm['health_monitor']['id'], + 'tenant_id': self._tenant_id}} + self.plugin.create_pool_health_monitor( + ctx, data, p1['pool']['id']) + self.plugin.create_pool_health_monitor( + ctx, data, p2['pool']['id']) + healthmon = self.plugin.get_health_monitor( + ctx, hm['health_monitor']['id']) + pool_data = [{'pool_id': p1['pool']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None}, + {'pool_id': p2['pool']['id'], + 'status': 'PENDING_CREATE', + 'status_description': None}] + self.assertEqual(sorted(healthmon['pools']), + sorted(pool_data)) + req = self.new_show_request( + 'health_monitors', + hm['health_monitor']['id'], + fmt=self.fmt) + hm = self.deserialize( + self.fmt, + req.get_response(self.ext_api) + ) + self.assertEqual(sorted(hm['health_monitor']['pools']), + sorted(pool_data)) + def test_create_pool_health_monitor_already_associated(self): with contextlib.nested( self.pool(name="pool"), -- 2.45.2