Merge "Don't update DHCP ports in a transaction"
This commit is contained in:
commit
f2785fc797
@ -374,14 +374,11 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
|
|||||||
def remove_network_from_dhcp_agent(self, context, id, network_id,
|
def remove_network_from_dhcp_agent(self, context, id, network_id,
|
||||||
notify=True):
|
notify=True):
|
||||||
agent = self._get_agent(context, id)
|
agent = self._get_agent(context, id)
|
||||||
with context.session.begin(subtransactions=True):
|
|
||||||
try:
|
try:
|
||||||
query = context.session.query(NetworkDhcpAgentBinding)
|
query = context.session.query(NetworkDhcpAgentBinding)
|
||||||
query = query.filter(
|
binding = query.filter(
|
||||||
NetworkDhcpAgentBinding.network_id == network_id,
|
NetworkDhcpAgentBinding.network_id == network_id,
|
||||||
NetworkDhcpAgentBinding.dhcp_agent_id == id)
|
NetworkDhcpAgentBinding.dhcp_agent_id == id).one()
|
||||||
# just ensure the binding exists
|
|
||||||
query.one()
|
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
|
raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
|
||||||
network_id=network_id, agent_id=id)
|
network_id=network_id, agent_id=id)
|
||||||
@ -391,12 +388,14 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
|
|||||||
agent['host'])
|
agent['host'])
|
||||||
filters = dict(device_id=[device_id])
|
filters = dict(device_id=[device_id])
|
||||||
ports = self.get_ports(context, filters=filters)
|
ports = self.get_ports(context, filters=filters)
|
||||||
|
# NOTE(kevinbenton): there should only ever be one port per
|
||||||
|
# DHCP agent per network so we don't have to worry about one
|
||||||
|
# update_port passing and another failing
|
||||||
for port in ports:
|
for port in ports:
|
||||||
port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
|
port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
|
||||||
self.update_port(context, port['id'], dict(port=port))
|
self.update_port(context, port['id'], dict(port=port))
|
||||||
# avoid issues with query.one() object that was
|
with context.session.begin():
|
||||||
# loaded into the session
|
context.session.delete(binding)
|
||||||
query.delete(synchronize_session=False)
|
|
||||||
|
|
||||||
if not notify:
|
if not notify:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user