Exemplo n.º 1
0
    def remove_network_from_dhcp_agent(self, context, id, network_id):
        agent = self._get_agent(context, id)
        with context.session.begin(subtransactions=True):
            try:
                query = context.session.query(NetworkDhcpAgentBinding)
                binding = query.filter(
                    NetworkDhcpAgentBinding.network_id == network_id,
                    NetworkDhcpAgentBinding.dhcp_agent_id == id).one()
            except exc.NoResultFound:
                raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                    network_id=network_id, agent_id=id)

            # reserve the port, so the ip is reused on a subsequent add
            device_id = utils.get_dhcp_agent_device_id(network_id,
                                                       agent['host'])
            filters = dict(device_id=[device_id])
            ports = self.get_ports(context, filters=filters)
            for port in ports:
                port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
                self.update_port(context, port['id'], dict(port=port))

            context.session.delete(binding)
        dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
        if dhcp_notifier:
            dhcp_notifier.network_removed_from_agent(
                context, network_id, agent.host)
Exemplo n.º 2
0
    def remove_network_from_dhcp_agent(self, context, id, network_id,
                                       notify=True):
        agent = self._get_agent(context, id)
        try:
            query = context.session.query(NetworkDhcpAgentBinding)
            binding = query.filter(
                NetworkDhcpAgentBinding.network_id == network_id,
                NetworkDhcpAgentBinding.dhcp_agent_id == id).one()
        except exc.NoResultFound:
            raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                network_id=network_id, agent_id=id)

        # reserve the port, so the ip is reused on a subsequent add
        device_id = utils.get_dhcp_agent_device_id(network_id,
                                                   agent['host'])
        filters = dict(device_id=[device_id])
        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:
            port['device_id'] = n_const.DEVICE_ID_RESERVED_DHCP_PORT
            self.update_port(context, port['id'], dict(port=port))
        with context.session.begin():
            context.session.delete(binding)

        if not notify:
            return
        dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
        if dhcp_notifier:
            dhcp_notifier.network_removed_from_agent(
                context, network_id, agent.host)
Exemplo n.º 3
0
    def remove_network_from_dhcp_agent(self, context, id, network_id,
                                       notify=True):
        agent = self._get_agent(context, id)
        with context.session.begin(subtransactions=True):
            try:
                query = context.session.query(NetworkDhcpAgentBinding)
                query = query.filter(
                    NetworkDhcpAgentBinding.network_id == network_id,
                    NetworkDhcpAgentBinding.dhcp_agent_id == id)
                # just ensure the binding exists
                query.one()
            except exc.NoResultFound:
                raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                    network_id=network_id, agent_id=id)

            # reserve the port, so the ip is reused on a subsequent add
            device_id = utils.get_dhcp_agent_device_id(network_id,
                                                       agent['host'])
            filters = dict(device_id=[device_id])
            ports = self.get_ports(context, filters=filters)
            for port in ports:
                port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
                self.update_port(context, port['id'], dict(port=port))
            # avoid issues with query.one() object that was
            # loaded into the session
            query.delete(synchronize_session=False)

        if not notify:
            return
        dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
        if dhcp_notifier:
            dhcp_notifier.network_removed_from_agent(
                context, network_id, agent.host)
Exemplo n.º 4
0
    def remove_network_from_dhcp_agent(self,
                                       context,
                                       id,
                                       network_id,
                                       notify=True):
        agent = self._get_agent(context, id)
        binding_obj = network.NetworkDhcpAgentBinding.get_object(
            context, network_id=network_id, dhcp_agent_id=id)
        if not binding_obj:
            raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                network_id=network_id, agent_id=id)

        # reserve the port, so the ip is reused on a subsequent add
        device_id = utils.get_dhcp_agent_device_id(network_id, agent['host'])
        filters = dict(device_id=[device_id])
        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:
            port['device_id'] = constants.DEVICE_ID_RESERVED_DHCP_PORT
            self.update_port(context, port['id'], dict(port=port))
        binding_obj.delete()

        if not notify:
            return
        dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
        if dhcp_notifier:
            dhcp_notifier.network_removed_from_agent(context, network_id,
                                                     agent.host)
Exemplo n.º 5
0
 def remove_network_from_dhcp_agent(self, context, id, network_id):
     agent = self._get_agent(context, id)
     with context.session.begin(subtransactions=True):
         try:
             query = context.session.query(NetworkDhcpAgentBinding)
             binding = query.filter(
                 NetworkDhcpAgentBinding.network_id == network_id,
                 NetworkDhcpAgentBinding.dhcp_agent_id == id).one()
         except exc.NoResultFound:
             raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                 network_id=network_id, agent_id=id)
         context.session.delete(binding)
     dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
     if dhcp_notifier:
         dhcp_notifier.network_removed_from_agent(context, network_id,
                                                  agent.host)
Exemplo n.º 6
0
    def remove_network_from_dhcp_agent(self, context, id, network_id,
                                       notify=True):
        agent = self._get_agent(context, id)
        try:
            query = context.session.query(ndab_model.NetworkDhcpAgentBinding)
            binding = query.filter(
                ndab_model.NetworkDhcpAgentBinding.network_id == network_id,
                ndab_model.NetworkDhcpAgentBinding.dhcp_agent_id == id).one()
        except exc.NoResultFound:
            raise dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
                network_id=network_id, agent_id=id)

        # reserve the port, so the ip is reused on a subsequent add
        device_id = utils.get_dhcp_agent_device_id(network_id,
                                                   agent['host'])
        filters = dict(network_id=[network_id],
                       device_owner=[constants.DEVICE_OWNER_DHCP])
        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:
            if port['device_id'].startswith(device_id):
                port['device_id'] = n_const.DEVICE_ID_RESERVED_DHCP_PORT
                try:
                    self.update_port(context, port['id'], dict(port=port))
                except n_exc.PortNotFound:
                    LOG.warning("Port %(port)s deleted concurrently "
                                "by agent",
                                {'port': port['id']})
        with context.session.begin():
            context.session.delete(binding)
        LOG.warning("Unbinding network %(network)s from agent %(agent)s",
                    {'network': network_id, 'agent': id})

        if not notify:
            return
        dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
        if dhcp_notifier:
            dhcp_notifier.network_removed_from_agent(
                context, network_id, agent['host'])
Exemplo n.º 7
0
 def test_reschedule_network_from_down_agent_concurrent_removal(self):
     self._test_failed_rescheduling(
         rn_side_effect=dhcpagentscheduler.NetworkNotHostedByDhcpAgent(
             network_id='foo', agent_id='bar'))