Exemple #1
0
    def test_delete_vm_port_namespace_already_deleted(self):
        ns_to_delete = {
            'host': 'myhost',
            'agent_id': 'vm_l3_agent',
            'router_id': 'my_router'
        }

        with contextlib.nested(
                mock.patch.object(manager.NeutronManager,
                                  'get_service_plugins',
                                  return_value=self.service_plugins),
                self.port(do_delete=False, device_owner='compute:None'),
                mock.patch.object(self.l3plugin,
                                  'dvr_deletens_if_no_port',
                                  return_value=[ns_to_delete]),
                mock.patch.object(
                    self.l3plugin,
                    'remove_router_from_l3_agent',
                    side_effect=l3agentscheduler.RouterNotHostedByL3Agent(
                        router_id=ns_to_delete['router_id'],
                        agent_id=ns_to_delete['agent_id']))) as (
                            get_service_plugin, port, dvr_delns_ifno_port,
                            remove_router_from_l3_agent):

            self.plugin.delete_port(self.context, port['port']['id'])
            remove_router_from_l3_agent.assert_called_once_with(
                self.context, ns_to_delete['agent_id'],
                ns_to_delete['router_id'])
 def _unbind_router(self, context, router_id, agent_id):
     with context.session.begin(subtransactions=True):
         query = context.session.query(RouterL3AgentBinding)
         query = query.filter(RouterL3AgentBinding.router_id == router_id,
                              RouterL3AgentBinding.l3_agent_id == agent_id)
         try:
             binding = query.one()
         except exc.NoResultFound:
             raise l3agentscheduler.RouterNotHostedByL3Agent(
                 router_id=router_id, agent_id=agent_id)
         context.session.delete(binding)
    def remove_router_from_l3_agent(self, context, agent_id, router_id):
        """Remove the router from l3 agent.

        After removal, the router will be non-hosted until there is update
        which leads to re-schedule or be added to another agent manually.
        """
        agent = self._get_agent(context, agent_id)
        with context.session.begin(subtransactions=True):
            query = context.session.query(RouterL3AgentBinding)
            query = query.filter(RouterL3AgentBinding.router_id == router_id,
                                 RouterL3AgentBinding.l3_agent_id == agent_id)
            try:
                binding = query.one()
            except exc.NoResultFound:
                raise l3agentscheduler.RouterNotHostedByL3Agent(
                    router_id=router_id, agent_id=agent_id)
            context.session.delete(binding)
        l3_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_L3)
        if l3_notifier:
            l3_notifier.router_removed_from_agent(context, router_id,
                                                  agent.host)