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
This commit is contained in:
Eugene Nikanorov 2013-08-15 02:40:49 +04:00
parent 32c38625d5
commit 8db51da1e2
3 changed files with 50 additions and 7 deletions

View File

@ -145,9 +145,8 @@ class HealthMonitor(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
admin_state_up = sa.Column(sa.Boolean(), nullable=False) admin_state_up = sa.Column(sa.Boolean(), nullable=False)
pools = orm.relationship( pools = orm.relationship(
"PoolMonitorAssociation", "PoolMonitorAssociation", backref="healthmonitor",
backref="healthmonitor", cascade="all", lazy="joined"
cascade="all"
) )
@ -679,7 +678,10 @@ class LoadBalancerPluginDb(LoadBalancerPluginBase,
if res['type'] in ['HTTP', 'HTTPS']: if res['type'] in ['HTTP', 'HTTPS']:
for attr in ['url_path', 'http_method', 'expected_codes']: for attr in ['url_path', 'http_method', 'expected_codes']:
res[attr] = health_monitor[attr] 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) return self._fields(res, fields)
def create_health_monitor(self, context, health_monitor): def create_health_monitor(self, context, health_monitor):

View File

@ -258,6 +258,8 @@ RESOURCE_ATTRIBUTE_MAP = {
'status': {'allow_post': False, 'allow_put': False, 'status': {'allow_post': False, 'allow_put': False,
'is_visible': True}, 'is_visible': True},
'status_description': {'allow_post': False, 'allow_put': False, 'status_description': {'allow_post': False, 'allow_put': False,
'is_visible': True},
'pools': {'allow_post': False, 'allow_put': False,
'is_visible': True} 'is_visible': True}
} }
} }

View File

@ -1200,16 +1200,55 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
self.pool(), self.pool(),
self.health_monitor() self.health_monitor()
) as (pool, hm): ) as (pool, hm):
data = {"health_monitor": { data = {'health_monitor': {
"id": hm['health_monitor']['id'], 'id': hm['health_monitor']['id'],
'tenant_id': self._tenant_id}} 'tenant_id': self._tenant_id}}
self.plugin.create_pool_health_monitor( self.plugin.create_pool_health_monitor(
context.get_admin_context(), context.get_admin_context(),
data, pool['pool']['id'] 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( driver_call.assert_called_once_with(
mock.ANY, hm['health_monitor'], pool['pool']['id']) 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): def test_create_pool_health_monitor_already_associated(self):
with contextlib.nested( with contextlib.nested(
self.pool(name="pool"), self.pool(name="pool"),