]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Improve lbaas haproxy plugin_driver test coverage
authorOleg Bondarev <obondarev@mirantis.com>
Mon, 1 Jul 2013 13:30:52 +0000 (17:30 +0400)
committerOleg Bondarev <obondarev@mirantis.com>
Mon, 8 Jul 2013 12:17:43 +0000 (16:17 +0400)
 - also removes unnecessary delete_health_monitor() from haproxy plugin_driver

Fixes bug 1191007

Change-Id: Ic9ec1f705a94a2e246d1a4985e72e9c58d48191d

neutron/services/loadbalancer/drivers/haproxy/plugin_driver.py
neutron/tests/unit/services/loadbalancer/drivers/haproxy/test_plugin_driver.py

index cf27dfdd74830e7b3c96296c9892dc12c72d7973..3e16ae7eaa0b1e2ee0b931028df1d75e57c580fc 100644 (file)
@@ -276,10 +276,6 @@ class HaproxyOnHostPluginDriver(abstract_driver.LoadBalancerAbstractDriver):
         # monitors are unused here because agent will fetch what is necessary
         self.agent_rpc.modify_pool(context, pool_id)
 
-    def delete_health_monitor(self, context, healthmon_id, pool_id):
-        # healthmon_id is not used in this driver
-        self.agent_rpc.modify_pool(context, pool_id)
-
     def create_pool_health_monitor(self, context, healthmon, pool_id):
         # healthmon is not used here
         self.agent_rpc.modify_pool(context, pool_id)
index 111956eec034e1702248e14101e92969e37bdb41..ff6d0341b13ff3cbc43e2fb011386a692541b861 100644 (file)
@@ -322,6 +322,122 @@ class TestLoadBalancerPluginNotificationWrapper(TestLoadBalancerPluginBase):
                         vip['vip']['pool_id']
                     )
 
+    def test_create_pool(self):
+        with self.pool():
+            self.assertFalse(self.mock_api.reload_pool.called)
+            self.assertFalse(self.mock_api.modify_pool.called)
+            self.assertFalse(self.mock_api.destroy_pool.called)
+
+    def test_update_pool_non_active(self):
+        with self.pool() as pool:
+            pool['pool']['status'] = 'INACTIVE'
+            ctx = context.get_admin_context()
+            self.plugin_instance.update_pool(ctx, pool['pool']['id'], pool)
+            self.mock_api.destroy_pool.assert_called_once_with(
+                mock.ANY, pool['pool']['id'])
+            self.assertFalse(self.mock_api.reload_pool.called)
+            self.assertFalse(self.mock_api.modify_pool.called)
+
+    def test_update_pool_no_vip_id(self):
+        with self.pool() as pool:
+            ctx = context.get_admin_context()
+            self.plugin_instance.update_pool(ctx, pool['pool']['id'], pool)
+            self.assertFalse(self.mock_api.destroy_pool.called)
+            self.assertFalse(self.mock_api.reload_pool.called)
+            self.assertFalse(self.mock_api.modify_pool.called)
+
+    def test_update_pool_with_vip_id(self):
+        with self.pool() as pool:
+            with self.vip(pool=pool):
+                ctx = context.get_admin_context()
+                self.plugin_instance.update_pool(ctx, pool['pool']['id'], pool)
+                self.mock_api.reload_pool.assert_called_once_with(
+                    mock.ANY, pool['pool']['id'])
+                self.assertFalse(self.mock_api.destroy_pool.called)
+                self.assertFalse(self.mock_api.modify_pool.called)
+
+    def test_delete_pool(self):
+        with self.pool(no_delete=True) as pool:
+            req = self.new_delete_request('pools',
+                                          pool['pool']['id'])
+            res = req.get_response(self.ext_api)
+            self.assertEqual(res.status_int, 204)
+            self.mock_api.destroy_pool.assert_called_once_with(
+                mock.ANY, pool['pool']['id'])
+
+    def test_create_member(self):
+        with self.pool() as pool:
+            pool_id = pool['pool']['id']
+            with self.member(pool_id=pool_id):
+                self.mock_api.modify_pool.assert_called_once_with(
+                    mock.ANY, pool_id)
+
+    def test_update_member(self):
+        with self.pool() as pool:
+            pool_id = pool['pool']['id']
+            with self.member(pool_id=pool_id) as member:
+                ctx = context.get_admin_context()
+                self.mock_api.modify_pool.reset_mock()
+                self.plugin_instance.update_member(
+                    ctx, member['member']['id'], member)
+                self.mock_api.modify_pool.assert_called_once_with(
+                    mock.ANY, pool_id)
+
+    def test_update_member_new_pool(self):
+        with self.pool() as pool1:
+            pool1_id = pool1['pool']['id']
+            with self.pool() as pool2:
+                pool2_id = pool2['pool']['id']
+                with self.member(pool_id=pool1_id) as member:
+                    ctx = context.get_admin_context()
+                    self.mock_api.modify_pool.reset_mock()
+                    member['member']['pool_id'] = pool2_id
+                    self.plugin_instance.update_member(ctx,
+                                                       member['member']['id'],
+                                                       member)
+                    self.assertEqual(2, self.mock_api.modify_pool.call_count)
+                    self.mock_api.modify_pool.assert_has_calls(
+                        [mock.call(mock.ANY, pool1_id),
+                         mock.call(mock.ANY, pool2_id)])
+
+    def test_delete_member(self):
+        with self.pool() as pool:
+            pool_id = pool['pool']['id']
+            with self.member(pool_id=pool_id,
+                             no_delete=True) as member:
+                self.mock_api.modify_pool.reset_mock()
+                req = self.new_delete_request('members',
+                                              member['member']['id'])
+                res = req.get_response(self.ext_api)
+                self.assertEqual(res.status_int, 204)
+                self.mock_api.modify_pool.assert_called_once_with(
+                    mock.ANY, pool_id)
+
+    def test_create_pool_health_monitor(self):
+        with self.pool() as pool:
+            pool_id = pool['pool']['id']
+            with self.health_monitor() as hm:
+                ctx = context.get_admin_context()
+                self.plugin_instance.create_pool_health_monitor(ctx,
+                                                                hm,
+                                                                pool_id)
+                self.mock_api.modify_pool.assert_called_once_with(
+                    mock.ANY, pool_id)
+
+    def test_delete_pool_health_monitor(self):
+        with self.pool() as pool:
+            pool_id = pool['pool']['id']
+            with self.health_monitor() as hm:
+                ctx = context.get_admin_context()
+                self.plugin_instance.create_pool_health_monitor(ctx,
+                                                                hm,
+                                                                pool_id)
+                self.mock_api.modify_pool.reset_mock()
+                self.plugin_instance.delete_pool_health_monitor(
+                    ctx, hm['health_monitor']['id'], pool_id)
+                self.mock_api.modify_pool.assert_called_once_with(
+                    mock.ANY, pool_id)
+
     def test_update_health_monitor_associated_with_pool(self):
         with self.health_monitor(type='HTTP') as monitor:
             with self.pool() as pool:
@@ -357,5 +473,3 @@ class TestLoadBalancerPluginNotificationWrapper(TestLoadBalancerPluginBase):
                     mock.ANY,
                     pool['pool']['id']
                 )
-
-    # TODO(obondarev): improve plugin_driver test coverage (bug 1191007)