]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
OOP naming cleanup in l3_dvr_db
authorEugene Nikanorov <enikanorov@mirantis.com>
Wed, 22 Apr 2015 00:14:42 +0000 (04:14 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Wed, 22 Apr 2015 00:18:24 +0000 (04:18 +0400)
Start protected method names with underscore.

Closes-Bug: #1446911
Change-Id: Iddf4f467118e40eb5b4bfe18bde00aa9d34b2ec4

neutron/db/l3_dvr_db.py
neutron/db/l3_dvrscheduler_db.py
neutron/db/l3_hamode_db.py
neutron/tests/unit/db/test_l3_dvr_db.py

index c8d8356014b5e4b64805705b86dc692ba858bd72..4f8d50c47979c2a62243a950a683c29c04fd8940 100644 (file)
@@ -130,7 +130,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                     # router, make sure to create corresponding
                     # snat interface ports that are to be consumed by
                     # the Service Node.
-                    if not self.create_snat_intf_ports_if_not_exists(
+                    if not self._create_snat_intf_ports_if_not_exists(
                         context.elevated(), router_db):
                         LOG.debug("SNAT interface ports not created: %s",
                                   router_db['id'])
@@ -157,7 +157,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         # Make sure that the gateway port exists before creating the
         # snat interface ports for distributed router.
         if router.extra_attributes.distributed and router.gw_port:
-            snat_p_list = self.create_snat_intf_ports_if_not_exists(
+            snat_p_list = self._create_snat_intf_ports_if_not_exists(
                 context.elevated(), router)
             if not snat_p_list:
                 LOG.debug("SNAT interface ports not created: %s", snat_p_list)
@@ -199,7 +199,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             # Check if distributed router and then delete the
             # FloatingIP agent gateway port
             if router_dict.get('distributed'):
-                self.clear_unused_fip_agent_gw_port(
+                self._clear_unused_fip_agent_gw_port(
                     admin_ctx, floatingip_db)
         super(L3_NAT_with_dvr_db_mixin, self)._update_fip_assoc(
             context, fip, floatingip_db, external_port)
@@ -211,7 +211,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             # Check if distributed router and then create the
             # FloatingIP agent gateway port
             if router_dict.get('distributed'):
-                vm_hostid = self.get_vm_port_hostid(
+                vm_hostid = self._get_vm_port_hostid(
                     context, fip_port)
                 if vm_hostid:
                     # FIXME (Swami): This FIP Agent Gateway port should be
@@ -225,7 +225,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                             vm_hostid))
                     LOG.debug("FIP Agent gateway port: %s", fip_agent_port)
 
-    def clear_unused_fip_agent_gw_port(
+    def _clear_unused_fip_agent_gw_port(
             self, context, floatingip_db):
         """Helper function to check for fip agent gw port and delete.
 
@@ -235,20 +235,20 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         the FIP agent gateway port. If even a single VM is using the
         port it will not delete.
         """
-        fip_hostid = self.get_vm_port_hostid(
+        fip_hostid = self._get_vm_port_hostid(
             context, floatingip_db['fixed_port_id'])
-        if fip_hostid and self.check_fips_availability_on_host_ext_net(
+        if fip_hostid and self._check_fips_availability_on_host_ext_net(
             context, fip_hostid, floatingip_db['floating_network_id']):
             LOG.debug('Deleting the Agent GW Port for ext-net: '
                       '%s', floatingip_db['floating_network_id'])
-            self.delete_floatingip_agent_gateway_port(
+            self._delete_floatingip_agent_gateway_port(
                 context, fip_hostid, floatingip_db['floating_network_id'])
 
     def delete_floatingip(self, context, id):
         floatingip = self._get_floatingip(context, id)
         if floatingip['fixed_port_id']:
             admin_ctx = context.elevated()
-            self.clear_unused_fip_agent_gw_port(
+            self._clear_unused_fip_agent_gw_port(
                 admin_ctx, floatingip)
         super(L3_NAT_with_dvr_db_mixin,
               self).delete_floatingip(context, id)
@@ -266,7 +266,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 context, port_id=port_id)
             if fip:
                 admin_ctx = context.elevated()
-                self.clear_unused_fip_agent_gw_port(
+                self._clear_unused_fip_agent_gw_port(
                     admin_ctx, fip)
         return super(L3_NAT_with_dvr_db_mixin,
                      self).disassociate_floatingips(context,
@@ -298,7 +298,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 context.session.add(router_port)
 
             if router.extra_attributes.distributed and router.gw_port:
-                self.add_csnat_router_interface_port(
+                self._add_csnat_router_interface_port(
                     context.elevated(), router, port['network_id'],
                     port['fixed_ips'][-1]['subnet_id'])
 
@@ -349,7 +349,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             context, router_interface_info, 'remove')
         return router_interface_info
 
-    def get_snat_sync_interfaces(self, context, router_ids):
+    def _get_snat_sync_interfaces(self, context, router_ids):
         """Query router interfaces that relate to list of router_ids."""
         if not router_ids:
             return []
@@ -401,7 +401,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             routers_dict[router['id']] = router
             router_ids = [router['id']]
             if router['gw_port_id']:
-                snat_router_intfs = self.get_snat_sync_interfaces(context,
+                snat_router_intfs = self._get_snat_sync_interfaces(context,
                                                                   router_ids)
                 LOG.debug("SNAT ports returned: %s ", snat_router_intfs)
                 router[SNAT_ROUTER_INTF_KEY] = snat_router_intfs
@@ -422,13 +422,13 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 router_floatingips.append(floating_ip)
                 router[l3_const.FLOATINGIP_KEY] = router_floatingips
                 if not fip_sync_interfaces:
-                    fip_sync_interfaces = self.get_fip_sync_interfaces(
+                    fip_sync_interfaces = self._get_fip_sync_interfaces(
                         context, agent.id)
                     LOG.debug("FIP Agent ports: %s", fip_sync_interfaces)
                 router[l3_const.FLOATINGIP_AGENT_INTF_KEY] = (
                     fip_sync_interfaces)
 
-    def get_fip_sync_interfaces(self, context, fip_agent_id):
+    def _get_fip_sync_interfaces(self, context, fip_agent_id):
         """Query router interfaces that relate to list of router_ids."""
         if not fip_agent_id:
             return []
@@ -440,7 +440,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             self._populate_subnets_for_ports(context, interfaces)
         return interfaces
 
-    def get_dvr_sync_data(self, context, host, agent, router_ids=None,
+    def _get_dvr_sync_data(self, context, host, agent, router_ids=None,
                           active=None):
         routers, interfaces, floating_ips = self._get_router_info_list(
             context, router_ids=router_ids, active=active,
@@ -452,7 +452,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         for fip in floating_ips:
             vm_port = port_dict.get(fip['port_id'], None)
             if vm_port:
-                fip['host'] = self.get_vm_port_hostid(context, fip['port_id'],
+                fip['host'] = self._get_vm_port_hostid(context, fip['port_id'],
                                                       port=vm_port)
         routers_dict = self._process_routers(context, routers)
         self._process_floating_ips_dvr(context, routers_dict,
@@ -460,7 +460,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         self._process_interfaces(routers_dict, interfaces)
         return routers_dict.values()
 
-    def get_vm_port_hostid(self, context, port_id, port=None):
+    def _get_vm_port_hostid(self, context, port_id, port=None):
         """Return the portbinding host_id."""
         vm_port_db = port or self._core_plugin.get_port(context, port_id)
         device_owner = vm_port_db['device_owner'] if vm_port_db else ""
@@ -468,7 +468,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             device_owner == DEVICE_OWNER_AGENT_GW):
             return vm_port_db[portbindings.HOST_ID]
 
-    def get_agent_gw_ports_exist_for_network(
+    def _get_agent_gw_ports_exist_for_network(
             self, context, network_id, host, agent_id):
         """Return agent gw port if exist, or None otherwise."""
         if not network_id:
@@ -484,7 +484,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         if ports:
             return ports[0]
 
-    def check_fips_availability_on_host_ext_net(
+    def _check_fips_availability_on_host_ext_net(
         self, context, host_id, fip_ext_net_id):
         """Query all floating_ips and filter on host and external net."""
         fip_count_on_host = 0
@@ -494,7 +494,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             floating_ips = self._get_sync_floating_ips(context, router_ids)
             # Check for the active floatingip in the host
             for fip in floating_ips:
-                f_host = self.get_vm_port_hostid(context, fip['port_id'])
+                f_host = self._get_vm_port_hostid(context, fip['port_id'])
                 if (f_host == host_id and
                     (fip['floating_network_id'] == fip_ext_net_id)):
                     fip_count_on_host += 1
@@ -505,7 +505,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 return True
             return False
 
-    def delete_floatingip_agent_gateway_port(
+    def _delete_floatingip_agent_gateway_port(
         self, context, host_id, ext_net_id):
         """Function to delete FIP gateway port with given ext_net_id."""
         # delete any fip agent gw port
@@ -514,7 +514,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         ports = self._core_plugin.get_ports(context,
                                             filters=device_filter)
         for p in ports:
-            if self.get_vm_port_hostid(context, p['id'], p) == host_id:
+            if self._get_vm_port_hostid(context, p['id'], p) == host_id:
                 self._core_plugin._delete_port(context, p['id'])
                 return
 
@@ -531,7 +531,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             context, l3_const.AGENT_TYPE_L3, host)
         if l3_agent_db:
             LOG.debug("Agent ID exists: %s", l3_agent_db['id'])
-            f_port = self.get_agent_gw_ports_exist_for_network(
+            f_port = self._get_agent_gw_ports_exist_for_network(
                 context, network_id, host, l3_agent_db['id'])
             if not f_port:
                 LOG.info(_LI('Agent Gateway port does not exist,'
@@ -556,7 +556,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 self._populate_subnets_for_ports(context, [f_port])
                 return f_port
 
-    def get_snat_interface_ports_for_router(self, context, router_id):
+    def _get_snat_interface_ports_for_router(self, context, router_id):
         """Return all existing snat_router_interface ports."""
         qry = context.session.query(l3_db.RouterPort)
         qry = qry.filter_by(
@@ -568,7 +568,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                  for rp in qry]
         return ports
 
-    def add_csnat_router_interface_port(
+    def _add_csnat_router_interface_port(
             self, context, router, network_id, subnet_id, do_pop=True):
         """Add SNAT interface to the specified router and subnet."""
         snat_port = self._core_plugin.create_port(
@@ -597,14 +597,14 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             return self._populate_subnets_for_ports(context, [snat_port])
         return snat_port
 
-    def create_snat_intf_ports_if_not_exists(self, context, router):
+    def _create_snat_intf_ports_if_not_exists(self, context, router):
         """Function to return the snat interface port list.
 
         This function will return the snat interface port list
         if it exists. If the port does not exist it will create
         new ports and then return the list.
         """
-        port_list = self.get_snat_interface_ports_for_router(
+        port_list = self._get_snat_interface_ports_for_router(
             context, router.id)
         if port_list:
             self._populate_subnets_for_ports(context, port_list)
@@ -624,7 +624,7 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
                 # Passing the subnet for the port to make sure the IP's
                 # are assigned on the right subnet if multiple subnet
                 # exists
-                snat_port = self.add_csnat_router_interface_port(
+                snat_port = self._add_csnat_router_interface_port(
                     context, router, intf['network_id'],
                     intf['fixed_ips'][0]['subnet_id'], do_pop=False)
                 port_list.append(snat_port)
index 6dd4e7807ef0868a22bb1dd62ee3105e74ea0ed5..ff664f9112292105c6705aa0222ef423fb088d18 100644 (file)
@@ -324,8 +324,8 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
             return self.get_ha_sync_data_for_host(context, host,
                                                   router_ids=router_ids,
                                                   active=True)
-        return self.get_dvr_sync_data(context, host, agent,
-                                      router_ids=router_ids, active=True)
+        return self._get_dvr_sync_data(context, host, agent,
+                                       router_ids=router_ids, active=True)
 
 
 def _notify_l3_agent_new_port(resource, event, trigger, **kwargs):
index 74884d2dfa15edebabd47704ba2fd057ce74f6ea..8553d00c5981560f4903a8333816ab5931c27fea 100644 (file)
@@ -471,8 +471,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
             agent = self._get_agent_by_type_and_host(context,
                                                      constants.AGENT_TYPE_L3,
                                                      host)
-            sync_data = self.get_dvr_sync_data(context, host, agent,
-                                               router_ids, active)
+            sync_data = self._get_dvr_sync_data(context, host, agent,
+                                                router_ids, active)
         else:
             sync_data = super(L3_HA_NAT_db_mixin, self).get_sync_data(context,
                                                             router_ids, active)
index 7e1f369276319be0d831cab53e9a2f7861c9f9ee..46fa775179bfdfcfb9fa3375ce1f797cbc6386e0 100644 (file)
@@ -144,12 +144,12 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         router = {'id': 'foo_router_id', 'distributed': True}
         self._test__is_distributed_router(router, True)
 
-    def test_get_agent_gw_ports_exist_for_network(self):
+    def test__get_agent_gw_ports_exist_for_network(self):
         with mock.patch.object(manager.NeutronManager, 'get_plugin') as gp:
             plugin = mock.Mock()
             gp.return_value = plugin
             plugin.get_ports.return_value = []
-            self.mixin.get_agent_gw_ports_exist_for_network(
+            self.mixin._get_agent_gw_ports_exist_for_network(
                 self.ctx, 'network_id', 'host', 'agent_id')
         plugin.get_ports.assert_called_with(self.ctx, {
             'network_id': ['network_id'],
@@ -166,7 +166,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
                               self.ctx,
                               port['id'])
 
-    def test_prevent_delete_floatingip_agent_gateway_port(self):
+    def test_prevent__delete_floatingip_agent_gateway_port(self):
         port = {
             'id': 'my_port_id',
             'fixed_ips': mock.ANY,
@@ -195,7 +195,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               '_create_gw_port'),
             mock.patch.object(self.mixin,
-                              'create_snat_intf_ports_if_not_exists')
+                              '_create_snat_intf_ports_if_not_exists')
                               ) as (cw, cs):
             self.mixin._create_gw_port(
                 self.ctx, router_id, router_db, mock.ANY,
@@ -208,7 +208,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         routers = self.mixin._build_routers_list(self.ctx, routers, gw_ports)
         self.assertIsNone(routers[0].get('gw_port'))
 
-    def test_clear_unused_fip_agent_gw_port(self):
+    def test__clear_unused_fip_agent_gw_port(self):
         floatingip = {
             'id': _uuid(),
             'fixed_port_id': _uuid(),
@@ -218,22 +218,22 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               '_get_floatingip'),
             mock.patch.object(self.mixin,
-                              'get_vm_port_hostid'),
+                              '_get_vm_port_hostid'),
             mock.patch.object(self.mixin,
-                              'check_fips_availability_on_host_ext_net'),
+                              '_check_fips_availability_on_host_ext_net'),
             mock.patch.object(self.mixin,
-                              'delete_floatingip_agent_gateway_port')
+                              '_delete_floatingip_agent_gateway_port')
                              ) as (gfips, gvm, cfips, dfips):
             gfips.return_value = floatingip
             gvm.return_value = 'my-host'
             cfips.return_value = True
-            self.mixin.clear_unused_fip_agent_gw_port(
+            self.mixin._clear_unused_fip_agent_gw_port(
                 self.ctx, floatingip)
             self.assertTrue(dfips.called)
             self.assertTrue(cfips.called)
             self.assertTrue(gvm.called)
 
-    def test_delete_floatingip_agent_gateway_port(self):
+    def test__delete_floatingip_agent_gateway_port(self):
         port = {
             'id': 'my_port_id',
             'binding:host_id': 'foo_host',
@@ -243,12 +243,12 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         with contextlib.nested(
             mock.patch.object(manager.NeutronManager, 'get_plugin'),
             mock.patch.object(self.mixin,
-                              'get_vm_port_hostid')) as (gp, vm_host):
+                              '_get_vm_port_hostid')) as (gp, vm_host):
             plugin = mock.Mock()
             gp.return_value = plugin
             plugin.get_ports.return_value = [port]
             vm_host.return_value = 'foo_host'
-            self.mixin.delete_floatingip_agent_gateway_port(
+            self.mixin._delete_floatingip_agent_gateway_port(
                 self.ctx, 'foo_host', 'network_id')
         plugin.get_ports.assert_called_with(self.ctx, filters={
             'network_id': ['network_id'],
@@ -261,7 +261,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               '_get_floatingip'),
             mock.patch.object(self.mixin,
-                              'clear_unused_fip_agent_gw_port'),
+                              '_clear_unused_fip_agent_gw_port'),
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               'delete_floatingip')) as (gf, vf, df):
             gf.return_value = floatingip
@@ -272,7 +272,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         with contextlib.nested(
             mock.patch.object(self.mixin, '_get_floatingip_on_port'),
             mock.patch.object(self.mixin,
-                              'clear_unused_fip_agent_gw_port'),
+                              '_clear_unused_fip_agent_gw_port'),
                               ) as (gf, vf):
             gf.return_value = floatingip
             self.mixin.disassociate_floatingips(
@@ -332,10 +332,10 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         # NOTE: mock.patch is not needed here since self.mixin is created fresh
         # for each test.  It doesn't work with some methods since the mixin is
         # tested in isolation (e.g. _get_agent_by_type_and_host).
-        self.mixin.get_vm_port_hostid = mock.Mock(return_value=hostid)
+        self.mixin._get_vm_port_hostid = mock.Mock(return_value=hostid)
         self.mixin._get_agent_by_type_and_host = mock.Mock(
             return_value=fipagent)
-        self.mixin.get_fip_sync_interfaces = mock.Mock(
+        self.mixin._get_fip_sync_interfaces = mock.Mock(
             return_value='fip_interface')
         agent = mock.Mock()
         agent.id = fipagent['id']
@@ -353,7 +353,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
     def test_floatingip_on_port_with_host(self):
         router, fip = self._floatingip_on_port_test_setup(_uuid())
 
-        self.assertTrue(self.mixin.get_fip_sync_interfaces.called)
+        self.assertTrue(self.mixin._get_fip_sync_interfaces.called)
 
         self.assertIn(l3_const.FLOATINGIP_KEY, router)
         self.assertIn(l3_const.FLOATINGIP_AGENT_INTF_KEY, router)
@@ -376,7 +376,7 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
             mock.patch.object(self.mixin,
                               'get_router'),
             mock.patch.object(self.mixin,
-                              'clear_unused_fip_agent_gw_port'),
+                              '_clear_unused_fip_agent_gw_port'),
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,
                               '_update_fip_assoc'),
                  ) as (grtr, vf, cf):
@@ -397,9 +397,9 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
             mock.patch.object(self.mixin,
                               'get_router'),
             mock.patch.object(self.mixin,
-                              'get_vm_port_hostid'),
+                              '_get_vm_port_hostid'),
             mock.patch.object(self.mixin,
-                              'clear_unused_fip_agent_gw_port'),
+                              '_clear_unused_fip_agent_gw_port'),
             mock.patch.object(self.mixin,
                               'create_fip_agent_gw_port_if_not_exists'),
             mock.patch.object(l3_dvr_db.l3_db.L3_NAT_db_mixin,