@mock.patch.object(ip_lib, 'send_ip_addr_adv_notif')
@mock.patch.object(ip_lib, 'IPDevice')
@mock.patch.object(ip_lib, 'add_ip_rule')
def test_floating_ip_added_dist(self, mock_add_ip_rule, mIPDevice, mock_adv_notif):
    router = mock.MagicMock()
    ri = self._create_router(router)
    ri.ex_gw_port = ri.router['gw_port']
    ext_net_id = _uuid()
    subnet_id = _uuid()
    agent_gw_port = {'fixed_ips': [{'ip_address': '0.0.0.0', 'prefixlen': 24, 'subnet_id': subnet_id}], 'subnets': [{'id': subnet_id, 'cidr': '20.0.0.0/24', 'gateway_ip': '0.0.0.0'}], 'id': _uuid(), 'network_id': ext_net_id, 'mac_address': 'ca:fe:de:ad:be:ef'}
    fip = {'id': _uuid(), 'host': HOSTNAME, 'floating_ip_address': '0.0.0.0', 'fixed_ip_address': '192.168.0.1', 'floating_network_id': ext_net_id, 'port_id': _uuid()}
    ri.fip_ns = mock.Mock()
    ri.fip_ns.agent_gateway_port = agent_gw_port
    ri.create_dvr_external_gateway_on_agent(ri.ex_gw_port)
    ri._check_rtr_2_fip_connect = mock.Mock()
    ri.connect_rtr_2_fip()
    self.assertTrue(ri.rtr_fip_connect)
    ri.fip_ns.allocate_rule_priority.return_value = FIP_PRI
    subnet = lla.LinkLocalAddressPair('169.254.30.42/31')
    ri.rtr_fip_subnet = subnet
    ri.fip_ns.local_subnets = mock.Mock()
    ri.fip_ns.local_subnets.allocate.return_value = subnet
    ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address'])
    ri.floating_ip_added_dist(fip, ip_cidr)
    mock_add_ip_rule.assert_called_with(namespace=ri.router_namespace.name, ip='192.168.0.1', table=16, priority=FIP_PRI)
    ri.fip_ns.local_subnets.allocate.assert_not_called()
    ri.rtr_fip_subnet = None
    ri.floating_ip_added_dist(fip, ip_cidr)
    mock_add_ip_rule.assert_called_with(namespace=ri.router_namespace.name, ip='192.168.0.1', table=16, priority=FIP_PRI)
    ri.fip_ns.local_subnets.allocate.assert_called_once_with(ri.router_id)
@mock.patch.object(ip_lib, 'send_ip_addr_adv_notif')
@mock.patch.object(ip_lib, 'IPDevice')
@mock.patch.object(ip_lib, 'add_ip_rule')
def test_floating_ip_added_dist(self, mock_add_ip_rule, mIPDevice, mock_adv_notif):
    router = mock.MagicMock()
    ri = self._create_router(router)
    ri.ex_gw_port = ri.router['gw_port']
    ext_net_id = _uuid()
    subnet_id = _uuid()
    agent_gw_port = {'fixed_ips': [{'ip_address': '0.0.0.0', 'prefixlen': 24, 'subnet_id': subnet_id}], 'subnets': [{'id': subnet_id, 'cidr': '20.0.0.0/24', 'gateway_ip': '0.0.0.0'}], 'id': _uuid(), 'network_id': ext_net_id, 'mac_address': 'ca:fe:de:ad:be:ef'}
    fip = {'id': _uuid(), 'host': HOSTNAME, 'floating_ip_address': '0.0.0.0', 'fixed_ip_address': '192.168.0.1', 'floating_network_id': ext_net_id, 'port_id': _uuid()}
    ri.fip_ns = mock.Mock()
    ri.fip_ns.agent_gateway_port = agent_gw_port
    ri.create_dvr_external_gateway_on_agent(ri.ex_gw_port)
    ri._check_rtr_2_fip_connect = mock.Mock()
    ri.connect_rtr_2_fip()
    self.assertTrue(ri.rtr_fip_connect)
    ri.fip_ns.allocate_rule_priority.return_value = FIP_PRI
    subnet = lla.LinkLocalAddressPair('169.254.30.42/31')
    ri.rtr_fip_subnet = subnet
    ri.fip_ns.local_subnets = mock.Mock()
    ri.fip_ns.local_subnets.allocate.return_value = subnet
    ip_cidr = common_utils.ip_to_cidr(fip['floating_ip_address'])
    ri.floating_ip_added_dist(fip, ip_cidr)
    mock_add_ip_rule.assert_called_with(namespace=ri.router_namespace.name, ip='192.168.0.1', table=16, priority=FIP_PRI)
    ri.fip_ns.local_subnets.allocate.assert_not_called()
    ri.rtr_fip_subnet = None
    ri.floating_ip_added_dist(fip, ip_cidr)
    mock_add_ip_rule.assert_called_with(namespace=ri.router_namespace.name, ip='192.168.0.1', table=16, priority=FIP_PRI)
    ri.fip_ns.local_subnets.allocate.assert_called_once_with(ri.router_id)