This patch makes use of the constant defined in the extension.
In addition to this having value of debing defined in one place it
also enables the caller to understand that the portbindings
extension is required.
Note: the constant is not used in the API tests. This has import
issues so it is not relevant.
TrivialFix
Change-Id: I7bfe2528dbbd8017ddbdcf949dbb6264ce1eb5d8
from neutron.agent.linux import keepalived
from neutron.common import constants as n_consts
from neutron.common import utils as common_utils
+from neutron.extensions import portbindings
LOG = logging.getLogger(__name__)
HA_DEV_PREFIX = 'ha-'
def _get_filtered_dict(d, ignore):
return {k: v for k, v in d.items() if k not in ignore}
- keys_to_ignore = set(['binding:host_id'])
+ keys_to_ignore = set([portbindings.HOST_ID])
port1_filtered = _get_filtered_dict(port1, keys_to_ignore)
port2_filtered = _get_filtered_dict(port2, keys_to_ignore)
return port1_filtered == port2_filtered
from neutron.db import l3_attrs_db
from neutron.db import model_base
from neutron.extensions import l3agentscheduler
+from neutron.extensions import portbindings
from neutron.extensions import router_availability_zone as router_az
from neutron import manager
from neutron.plugins.common import constants as service_constants
ports = core_plugin.get_ports(context, filters=filter)
for port in ports:
if (n_utils.is_dvr_serviced(port['device_owner']) and
- l3_agent['host'] == port['binding:host_id']):
+ l3_agent['host'] == port[portbindings.HOST_ID]):
return True
return False
'network_id': network_id,
'device_id': l3_agent_db['id'],
'device_owner': l3_const.DEVICE_OWNER_AGENT_GW,
- 'binding:host_id': host,
+ portbindings.HOST_ID: host,
'admin_state_up': True,
'name': ''}
agent_port = p_utils.create_port(self._core_plugin, context,
from neutron.db import model_base
from neutron.db import models_v2
from neutron.extensions import l3agentscheduler
+from neutron.extensions import portbindings
from neutron import manager
from neutron.plugins.common import constants as service_constants
from neutron.plugins.ml2 import db as ml2_db
def dvr_update_router_addvm(self, context, port):
port_dict = self._core_plugin.get_port(context, port['id'])
- port_host = port_dict['binding:host_id']
+ port_host = port_dict[portbindings.HOST_ID]
l3_agent_on_host = (self.get_l3_agents(
context, filters={'host': [port_host]}) or [None])[0]
if not l3_agent_on_host:
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['binding:host_id'] == host
+ and port[portbindings.HOST_ID] == host
and port['id'] != port_id):
LOG.debug('DVR: %(port_status)s port exists for subnet '
'%(subnet_id)s on host %(host)s',
n_utils.is_dvr_serviced(original_device_owner) and
not n_utils.is_dvr_serviced(new_device_owner))
is_port_moved = (
- original_port['binding:host_id'] and
- original_port['binding:host_id'] != new_port['binding:host_id'])
+ original_port[portbindings.HOST_ID] and
+ original_port[portbindings.HOST_ID] !=
+ new_port[portbindings.HOST_ID])
if is_port_no_longer_serviced or is_port_moved:
l3plugin = manager.NeutronManager.get_service_plugins().get(
service_constants.L3_ROUTER_NAT)
removed_routers = l3plugin.dvr_deletens_if_no_port(
context,
original_port['id'],
- port_host=original_port['binding:host_id'])
+ port_host=original_port[portbindings.HOST_ID])
if removed_routers:
removed_router_args = {
'context': context,
from neutron.agent.linux import dhcp
from neutron.agent.linux import ip_lib
from neutron.common import constants
-
+from neutron.extensions import portbindings
LOG = logging.getLogger(__name__)
'device_id': '%s' % socket.gethostname(),
'device_owner': '%s:probe' % device_owner,
'tenant_id': network.tenant_id,
- 'binding:host_id': host,
+ portbindings.HOST_ID: host,
'fixed_ips': [dict(subnet_id=s.id)
for s in network.subnets]}}
port_dict = self.client.create_port(body)['port']
import fixtures
from neutronclient.common import exceptions
+from neutron.extensions import portbindings
from neutron.tests import base
spec = {
'network_id': network_id,
'tenant_id': tenant_id,
- 'binding:host_id': hostname,
+ portbindings.HOST_ID: hostname,
}
if qos_policy_id:
spec['qos_policy_id'] = qos_policy_id
from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils
from neutron.common import constants as l3_constants
+from neutron.extensions import portbindings
from neutron.tests.common import l3_test_common
from neutron.tests.common import net_helpers
from neutron.tests.functional.agent.l3 import framework
internal_ports = router.get(l3_constants.INTERFACE_KEY, [])
router['distributed'] = True
router['gw_port_host'] = agent.conf.host
- router['gw_port']['binding:host_id'] = agent.conf.host
+ router['gw_port'][portbindings.HOST_ID] = agent.conf.host
floating_ip = router['_floatingips'][0]
floating_ip['floating_network_id'] = router['gw_port']['network_id']
floating_ip['host'] = agent.conf.host
'network_id': external_gw_port['network_id'],
'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW,
'mac_address': 'fa:16:3e:80:8d:89',
- 'binding:host_id': self.agent.conf.host,
+ portbindings.HOST_ID: self.agent.conf.host,
'fixed_ips': [{'subnet_id': fixed_ip['subnet_id'],
'ip_address': fip_gw_port_ip,
'prefixlen': prefixlen}],
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.extensions import external_net
+from neutron.extensions import portbindings
from neutron.tests.common import helpers
from neutron.tests.unit.plugins.ml2 import base as ml2_test_base
'fixed_ips': attributes.ATTR_NOT_SPECIFIED,
'device_id': self.l3_agent['id'],
'device_owner': constants.DEVICE_OWNER_AGENT_GW,
- 'binding:host_id': '',
+ portbindings.HOST_ID: '',
'admin_state_up': True,
'name': ''}})
return network_id, port
if dvr:
l3_notif.routers_updated_on_host.assert_called_once_with(
self.context, [router['id']],
- int_port['port']['binding:host_id'])
+ int_port['port'][portbindings.HOST_ID])
self.assertFalse(l3_notif.routers_updated.called)
else:
l3_notif.routers_updated.assert_called_once_with(
# locate internal ports on different hosts
self.core_plugin.update_port(
self.context, int_port1['port']['id'],
- {'port': {'binding:host_id': 'host1'}})
+ {'port': {portbindings.HOST_ID: 'host1'}})
self.core_plugin.update_port(
self.context, int_port2['port']['id'],
- {'port': {'binding:host_id': 'host2'}})
+ {'port': {portbindings.HOST_ID: 'host2'}})
# and create l3 agents on corresponding hosts
helpers.register_l3_agent(host='host1',
agent_mode=constants.L3_AGENT_MODE_DVR)
if dvr:
l3_notif.routers_updated_on_host.assert_called_once_with(
self.context, [router['id']],
- int_port['port']['binding:host_id'])
+ int_port['port'][portbindings.HOST_ID])
self.assertFalse(l3_notif.routers_updated.called)
else:
l3_notif.routers_updated.assert_called_once_with(
constants.AGENT_TYPE_L3] = l3_notifier
self.core_plugin.update_port(
self.context, port['port']['id'],
- {'port': {'binding:host_id': HOST1}})
+ {'port': {portbindings.HOST_ID: HOST1}})
# now router should be scheduled to dvr_snat agent and
# dvr agent on host1
l3_notifier.reset_mock()
self.core_plugin.update_port(
self.context, port['port']['id'],
- {'port': {'binding:host_id': HOST2}})
+ {'port': {portbindings.HOST_ID: HOST2}})
# now router should be scheduled to dvr_snat agent and
# dvr agent on host2
agents = self.l3_plugin.list_l3_agents_hosting_router(
from neutron.common import config as base_config
from neutron.common import constants as l3_constants
from neutron.common import exceptions as n_exc
+from neutron.extensions import portbindings
from neutron.plugins.common import constants as p_const
from neutron.tests import base
from neutron.tests.common import l3_test_common
'subnets': [{'gateway_ip': '20.0.0.1'}],
'extra_subnets': [{'cidr': '172.16.0.0/24'}],
'id': _uuid(),
- 'binding:host_id': HOSTNAME,
+ portbindings.HOST_ID: HOSTNAME,
'network_id': _uuid(),
'mac_address': 'ca:fe:de:ad:be:ef'}
ri.snat_ports = sn_port
from neutron.common import config as base_config
from neutron.common import constants as l3_constants
from neutron.common import utils as common_utils
+from neutron.extensions import portbindings
from neutron.tests import base
from neutron.tests.common import l3_test_common
'cidr': '20.0.0.0/24',
'gateway_ip': '20.0.0.1'}],
'id': _uuid(),
- 'binding:host_id': 'myhost',
+ portbindings.HOST_ID: 'myhost',
'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW,
'network_id': fake_network_id,
'mac_address': 'ca:fe:de:ad:be:ef'}]
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import utils
+from neutron.extensions import portbindings
from neutron.tests import base
}
expected_port = {'port': {'network_id': 'foo_network_id',
'device_owner': constants.DEVICE_OWNER_DHCP,
- 'binding:host_id': 'foo_host',
+ portbindings.HOST_ID: 'foo_host',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]
},
'id': 'foo_port_id'
}
expected_port = {'port': {'network_id': 'foo_network_id',
'device_owner': constants.DEVICE_OWNER_DHCP,
- 'binding:host_id': 'foo_host',
+ portbindings.HOST_ID: 'foo_host',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]
},
'id': 'foo_port_id'
}
expected_port = {'port': {'network_id': 'foo_network_id',
'device_owner': constants.DEVICE_OWNER_DHCP,
- 'binding:host_id': 'foo_host',
+ portbindings.HOST_ID: 'foo_host',
'fixed_ips': [{'subnet_id': 'foo_subnet_id'}]
},
'id': 'foo_port_id'
from neutron.db import common_db_mixin
from neutron.db import l3_agentschedulers_db
from neutron.db import l3_dvr_db
+from neutron.extensions import portbindings
from neutron import manager
from neutron.plugins.common import constants as plugin_const
from neutron.tests.unit.db import test_db_base_plugin_v2
def _helper_delete_floatingip_agent_gateway_port(self, port_host):
ports = [{
'id': 'my_port_id',
- 'binding:host_id': 'foo_host',
+ portbindings.HOST_ID: 'foo_host',
'network_id': 'ext_network_id',
'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW
},
{
'id': 'my_new_port_id',
- 'binding:host_id': 'my_foo_host',
+ portbindings.HOST_ID: 'my_foo_host',
'network_id': 'ext_network_id',
'device_owner': l3_const.DEVICE_OWNER_ROUTER_GW
}]
self, fip, floatingip_db, router_db):
port = {
'id': '1234',
- 'binding:host_id': 'myhost',
+ portbindings.HOST_ID: 'myhost',
'network_id': 'external_net'
}
from neutron.common import config as common_config
from neutron.debug import commands
from neutron.debug import debug_agent
+from neutron.extensions import portbindings
from neutron.tests import base
'admin_state_up': True,
'network_id': 'fake_net',
'tenant_id': 'fake_tenant',
- 'binding:host_id': cfg.CONF.host,
+ portbindings.HOST_ID: cfg.CONF.host,
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
'device_id': socket.gethostname()}}
namespace = 'qprobe-fake_port'
'admin_state_up': True,
'network_id': 'fake_net',
'tenant_id': 'fake_tenant',
- 'binding:host_id': cfg.CONF.host,
+ portbindings.HOST_ID: cfg.CONF.host,
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
'device_id': socket.gethostname()}}
namespace = 'qprobe-fake_port'
'admin_state_up': True,
'network_id': 'fake_net',
'tenant_id': 'fake_tenant',
- 'binding:host_id': cfg.CONF.host,
+ portbindings.HOST_ID: cfg.CONF.host,
'fixed_ips': [{'subnet_id': 'fake_subnet'}],
'device_id': socket.gethostname()}}
expected = [mock.call.show_network('fake_net'),
self.l3_rpc_cb._ensure_host_set_on_port(
mock.ANY, mock.ANY, port, router_id)
self.l3_rpc_cb.plugin.update_port.assert_called_once_with(
- mock.ANY, port_id, {'port': {'binding:host_id': mock.ANY}})
+ mock.ANY, port_id, {'port': {portbindings.HOST_ID: mock.ANY}})
self.assertTrue(mock_log.call_count)
expected_message = ('Port foo_port_id not found while updating '
'agent binding for router foo_router_id.')
self.assertEqual(port_id, details['port_id'])
def _update_and_check_portbinding(self, port_id, host_id):
- data = {'port': {'binding:host_id': host_id}}
+ data = {'port': {portbindings.HOST_ID: host_id}}
req = self.new_update_request('ports', data, port_id)
res = self.deserialize(self.fmt,
req.get_response(self.api))
- self.assertEqual(host_id, res['port']['binding:host_id'])
+ self.assertEqual(host_id, res['port'][portbindings.HOST_ID])
def _test_host_changed(self, twice):
self._register_ml2_agents()
plugin = manager.NeutronManager.get_plugin()
port = {
'id': 'foo_port_id',
- 'binding:host_id': 'foo_host',
+ portbindings.HOST_ID: 'foo_host',
}
with mock.patch.object(ml2_db, 'ensure_dvr_port_binding') as mock_dvr:
plugin.update_dvr_port_binding(
from neutron.db import l3_hascheduler_db
from neutron.extensions import l3_ext_ha_mode as l3_ha
from neutron.extensions import l3agentscheduler as l3agent
+from neutron.extensions import portbindings
from neutron import manager
from neutron.scheduler import l3_agent_scheduler
from neutron.tests import base
l3_agent = self._prepare_check_ports_exist_tests()
# matching subnet
port = {'subnet_id': str(uuid.uuid4()),
- 'binding:host_id': 'host_1',
+ portbindings.HOST_ID: 'host_1',
'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX,
'id': 1234}
subnet = {'id': str(uuid.uuid4()),
'port': None,
'original_port': {
'id': port_id,
- 'binding:host_id': 'vm-host',
+ portbindings.HOST_ID: 'vm-host',
'device_id': 'vm-id',
'device_owner': DEVICE_OWNER_COMPUTE,
'mac_address': '02:04:05:17:18:19'
'context': self.adminContext,
'port': {
'id': port_id,
- 'binding:host_id': None,
+ portbindings.HOST_ID: None,
'device_id': '',
'device_owner': ''
},
'mac_address_updated': False,
'original_port': {
'id': port_id,
- 'binding:host_id': 'vm-host',
+ portbindings.HOST_ID: 'vm-host',
'device_id': 'vm-id',
'device_owner': DEVICE_OWNER_COMPUTE
}
'id': 'port1',
'device_id': 'abcd',
'device_owner': DEVICE_OWNER_COMPUTE_NOVA,
- 'binding:host_id': 'host1',
+ portbindings.HOST_ID: 'host1',
'fixed_ips': [
{
'subnet_id': '80947d4a-fbc8-484b-9f92-623a6bfcf3e0',
self.dut.dvr_update_router_addvm(self.adminContext, port)
get_l3_agents.assert_called_once_with(
- self.adminContext, filters={'host': [port['binding:host_id']]})
+ self.adminContext,
+ filters={'host': [port[portbindings.HOST_ID]]})
(self.dut.l3_rpc_notifier.routers_updated_on_host.
assert_called_once_with(
self.adminContext, {'r1', 'r2'}, 'host1'))
'id': 'fake_id',
'device_id': 'r1',
'status': port_status,
- 'binding:host_id': 'thisHost',
+ portbindings.HOST_ID: 'thisHost',
'device_owner': DEVICE_OWNER_COMPUTE_NOVA,
'fixed_ips': [
{
'id': 'lbaas-vip-port1',
'device_id': 'vip-pool-id',
'status': 'ACTIVE',
- 'binding:host_id': 'thisHost',
+ portbindings.HOST_ID: 'thisHost',
'device_owner': device_owner,
'fixed_ips': [
{
'device_id': port_name,
'device_owner': device_owner,
'status': status,
- 'binding:host_id': host,
+ portbindings.HOST_ID: host,
'fixed_ips': [
{
'subnet_id': subnet_id,
'id': 'dhcp-port1',
'device_id': 'dhcp-net-id',
'status': 'ACTIVE',
- 'binding:host_id': 'thisHost',
+ portbindings.HOST_ID: 'thisHost',
'device_owner': constants.DEVICE_OWNER_DHCP,
'fixed_ips': [
{