def test_no_down_agents(self, _client):
     self.NetworkServiceContext.return_value = \
         DummyNetworkServiceContext(return_value=network_context)
     dummy_client = MagicMock()
     dummy_client.list_agents.side_effect = agents_all_alive.itervalues()
     _client.return_value = dummy_client
     neutron_utils.reassign_agent_resources()
     dummy_client.add_router_to_l3_agent.assert_not_called()
     dummy_client.remove_router_from_l3_agent.assert_not_called()
     dummy_client.add_network_to_dhcp_agent.assert_not_called()
     dummy_client.remove_network_from_dhcp_agent.assert_not_called()
def cluster_departed():
    if config('plugin') in ['nvp', 'nsx']:
        log('Unable to re-assign agent resources for'
            ' failed nodes with nvp|nsx',
            level=WARNING)
        return
    if config('plugin') == 'n1kv':
        log('Unable to re-assign agent resources for failed nodes with n1kv',
            level=WARNING)
        return
    if not config('ha-legacy-mode') and eligible_leader(None):
        reassign_agent_resources()
        CONFIGS.write_all()
Esempio n. 3
0
def cluster_departed():
    if config('plugin') in ['nvp', 'nsx']:
        log(
            'Unable to re-assign agent resources for'
            ' failed nodes with nvp|nsx',
            level=WARNING)
        return
    if config('plugin') == 'n1kv':
        log('Unable to re-assign agent resources for failed nodes with n1kv',
            level=WARNING)
        return
    if not config('ha-legacy-mode') and eligible_leader(None):
        reassign_agent_resources()
        CONFIGS.write_all()
 def test_agents_down_relocation_impossible(self, _client):
     self.NetworkServiceContext.return_value = \
         DummyNetworkServiceContext(return_value=network_context)
     dummy_client = MagicMock()
     dummy_client.list_agents.side_effect = \
         agents_some_dead_cl1.itervalues()
     dummy_client.list_networks_on_dhcp_agent.return_value = \
         dhcp_agent_networks
     dummy_client.list_routers_on_l3_agent.return_value = \
         l3_agent_routers
     _client.return_value = dummy_client
     self.unit_private_ip.return_value = 'cluster1-machine1.internal'
     self.relations_of_type.return_value = []
     neutron_utils.reassign_agent_resources()
     self.assertTrue(self.log.called)
     assert not dummy_client.remove_router_from_l3_agent.called
     assert not dummy_client.remove_network_from_dhcp_agent.called
    def test_agents_down_relocation_required(self, _client):
        self.NetworkServiceContext.return_value = \
            DummyNetworkServiceContext(return_value=network_context)
        dummy_client = MagicMock()
        dummy_client.list_agents.side_effect = \
            agents_some_dead_cl2.itervalues()
        dummy_client.list_networks_on_dhcp_agent.return_value = \
            dhcp_agent_networks
        dummy_client.list_routers_on_l3_agent.return_value = \
            l3_agent_routers
        _client.return_value = dummy_client
        self.unit_private_ip.return_value = 'cluster2-machine1.internal'
        self.relations_of_type.return_value = \
            [{'private-address': 'cluster2-machine3.internal'}]
        neutron_utils.reassign_agent_resources()

        # Ensure routers removed from dead l3 agent
        dummy_client.remove_router_from_l3_agent.assert_has_calls(
            [call(l3_agent='84a04126-38ce-11e3-9449-3c970e8b1cf7',
                  router_id='bong'),
             call(l3_agent='84a04126-38ce-11e3-9449-3c970e8b1cf7',
                  router_id='baz')], any_order=True)
        # and re-assigned across the remaining two live agents
        dummy_client.add_router_to_l3_agent.assert_has_calls(
            [call(l3_agent='00f4268a-51c9-11e3-9177-1c6f65b044df',
                  body={'router_id': 'baz'}),
             call(l3_agent='72453824-38ce-11e3-938e-3c970e8b1cf7',
                  body={'router_id': 'bong'})], any_order=True)
        # Ensure networks removed from dead dhcp agent
        dummy_client.remove_network_from_dhcp_agent.assert_has_calls(
            [call(dhcp_agent='92b8b6bc-38ce-11e3-8537-3c970e8b1cf7',
                  network_id='foo'),
             call(dhcp_agent='92b8b6bc-38ce-11e3-8537-3c970e8b1cf7',
                  network_id='bar')], any_order=True)
        # and re-assigned across the remaining two live agents
        dummy_client.add_network_to_dhcp_agent.assert_has_calls(
            [call(dhcp_agent='53d6eefc-38cc-11e3-b3c8-3c970e8b1cf7',
                  body={'network_id': 'foo'}),
             call(dhcp_agent='ebdcc950-51c8-11e3-a804-1c6f65b044df',
                  body={'network_id': 'bar'})], any_order=True)
 def test_no_network_context(self):
     self.NetworkServiceContext.return_value = \
         DummyNetworkServiceContext(return_value=None)
     neutron_utils.reassign_agent_resources()
     self.assertTrue(self.log.called)