]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add list of pool ids to HealthMonitor dict
authorEugene Nikanorov <enikanorov@mirantis.com>
Wed, 14 Aug 2013 22:40:49 +0000 (02:40 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Tue, 20 Aug 2013 09:49:41 +0000 (13:49 +0400)
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
neutron/extensions/loadbalancer.py
neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py

index 8b890fc00cf9d321c46bf14cd856be8d508ae349..103699534b35d6aca469a9a53465f4f4399b3a8e 100644 (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)
 
     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):
index 084a7c4555adb7610bf9583a5d25f8b198155428..90050ee3a81cc0ea3c43a926bf14fe654fb118ca 100644 (file)
@@ -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}
     }
 }
 
index c4ee714f995a0d38a6b9f3600da31928566ca5b9..f0bfd3c2c319267182188694ee4a4a370144dee5 100644 (file)
@@ -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"),