Don't delete DVR namespace if there are still ports on this node
Skip deleting DVR namespaces if they contain ports in the BUILD or DOWN status. Change-Id: I026f2014ede800c0f4532ca15f1fccdaa59d5b61 Closes-bug: #1464527
This commit is contained in:
parent
345ffb99ef
commit
e3710f5948
|
@ -144,19 +144,19 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
|
|||
subnet_ids.add(int_subnet)
|
||||
return subnet_ids
|
||||
|
||||
def check_ports_active_on_host_and_subnet(self, context, host,
|
||||
port_id, subnet_id):
|
||||
def check_ports_on_host_and_subnet(self, context, host,
|
||||
port_id, subnet_id):
|
||||
"""Check if there is any dvr serviceable port on the subnet_id."""
|
||||
filter_sub = {'fixed_ips': {'subnet_id': [subnet_id]}}
|
||||
ports = self._core_plugin.get_ports(context, filters=filter_sub)
|
||||
for port in ports:
|
||||
if (n_utils.is_dvr_serviced(port['device_owner'])
|
||||
and port['status'] == 'ACTIVE'
|
||||
and port['binding:host_id'] == host
|
||||
and port['id'] != port_id):
|
||||
LOG.debug('DVR: Active port exists for subnet %(subnet_id)s '
|
||||
'on host %(host)s', {'subnet_id': subnet_id,
|
||||
'host': host})
|
||||
LOG.debug('DVR: %(port_status)s port exists for subnet '
|
||||
'%(subnet_id)s on host %(host)s',
|
||||
{'port_status': port['status'],
|
||||
'subnet_id': subnet_id, 'host': host})
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -177,10 +177,10 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
|
|||
router_id)
|
||||
port_exists_on_subnet = False
|
||||
for subnet in subnet_ids:
|
||||
if self.check_ports_active_on_host_and_subnet(admin_context,
|
||||
port_host,
|
||||
port_id,
|
||||
subnet):
|
||||
if self.check_ports_on_host_and_subnet(admin_context,
|
||||
port_host,
|
||||
port_id,
|
||||
subnet):
|
||||
port_exists_on_subnet = True
|
||||
break
|
||||
|
||||
|
|
|
@ -1016,11 +1016,11 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
|
|||
self.assertEqual(sub_ids.pop(),
|
||||
dvr_port.get('fixed_ips').pop(0).get('subnet_id'))
|
||||
|
||||
def test_check_ports_active_on_host_and_subnet(self):
|
||||
def _test_check_ports_on_host_and_subnet_base(self, port_status):
|
||||
dvr_port = {
|
||||
'id': 'dvr_port1',
|
||||
'id': 'fake_id',
|
||||
'device_id': 'r1',
|
||||
'status': 'ACTIVE',
|
||||
'status': port_status,
|
||||
'binding:host_id': 'thisHost',
|
||||
'device_owner': 'compute:nova',
|
||||
'fixed_ips': [
|
||||
|
@ -1046,16 +1046,25 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
|
|||
'.L3AgentNotifyAPI'):
|
||||
sub_ids = self.dut.get_subnet_ids_on_router(self.adminContext,
|
||||
r1['id'])
|
||||
result = self.dut.check_ports_active_on_host_and_subnet(
|
||||
result = self.dut.check_ports_on_host_and_subnet(
|
||||
self.adminContext,
|
||||
'thisHost', 'dvr_port1',
|
||||
sub_ids)
|
||||
self.assertFalse(result)
|
||||
self.assertTrue(result)
|
||||
|
||||
def test_check_ports_on_host_and_subnet_with_active_port(self):
|
||||
self._test_check_ports_on_host_and_subnet_base('ACTIVE')
|
||||
|
||||
def test_check_ports_on_host_and_subnet_with_build_port(self):
|
||||
self._test_check_ports_on_host_and_subnet_base('BUILD')
|
||||
|
||||
def test_check_ports_on_host_and_subnet_with_down_port(self):
|
||||
self._test_check_ports_on_host_and_subnet_base('DOWN')
|
||||
|
||||
def _test_dvr_serviced_port_exists_on_subnet(self, port):
|
||||
with mock.patch('neutron.db.db_base_plugin_v2.NeutronDbPluginV2.'
|
||||
'get_ports', return_value=[port]):
|
||||
result = self.dut.check_ports_active_on_host_and_subnet(
|
||||
result = self.dut.check_ports_on_host_and_subnet(
|
||||
self.adminContext,
|
||||
'thisHost',
|
||||
'dvr1-intf-id',
|
||||
|
|
Loading…
Reference in New Issue