Esempio n. 1
0
def send_vip_advertisements(lb_id):
    """Sends address advertisements for each load balancer VIP.

    This method will send either GARP (IPv4) or neighbor advertisements (IPv6)
    for the VIP addresses on a load balancer.

    :param lb_id: The load balancer ID to send advertisements for.
    :returns: None
    """
    try:
        vips = get_haproxy_vip_addresses(lb_id)

        for vip in vips:
            interface = network_utils.get_interface_name(
                vip, net_ns=consts.AMPHORA_NAMESPACE)
            ip_advertisement.send_ip_advertisement(
                interface, vip, net_ns=consts.AMPHORA_NAMESPACE)
    except Exception as e:
        LOG.debug(
            'Send VIP advertisement failed due to :%s. '
            'This amphora may not be the MASTER. Ignoring.', str(e))
Esempio n. 2
0
    def test_send_ip_advertisement(self, mock_na, mock_garp, mock_is_ipv6):
        FAKE_INTERFACE = 'fake0'
        FAKE_NETNS = 'fake_netns'
        IPV4_ADDRESS = '203.0.113.9'
        IPV6_ADDRESS = '2001:db8::33'

        mock_is_ipv6.side_effect = [mock.DEFAULT, mock.DEFAULT, False]

        # Test IPv4 advertisement
        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE, IPV4_ADDRESS)

        mock_garp.assert_called_once_with(FAKE_INTERFACE, IPV4_ADDRESS, None)
        mock_na.assert_not_called()

        # Test IPv4 advertisement with a network namespace
        mock_garp.reset_mock()
        mock_na.reset_mock()

        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE,
                                               IPV4_ADDRESS,
                                               net_ns=FAKE_NETNS)

        mock_garp.assert_called_once_with(FAKE_INTERFACE, IPV4_ADDRESS,
                                          FAKE_NETNS)
        mock_na.assert_not_called()

        # Test IPv6 advertisement
        mock_garp.reset_mock()
        mock_na.reset_mock()

        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE, IPV6_ADDRESS)

        mock_garp.assert_not_called()
        mock_na.assert_called_once_with(FAKE_INTERFACE, IPV6_ADDRESS, None)

        # Test IPv6 advertisement with a network namespace
        mock_garp.reset_mock()
        mock_na.reset_mock()

        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE,
                                               IPV6_ADDRESS,
                                               net_ns=FAKE_NETNS)

        mock_garp.assert_not_called()
        mock_na.assert_called_once_with(FAKE_INTERFACE, IPV6_ADDRESS,
                                        FAKE_NETNS)

        # Test bogus IP
        mock_garp.reset_mock()
        mock_na.reset_mock()

        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE, 'not an IP')

        mock_garp.assert_not_called()
        mock_na.assert_not_called()

        # Test unknown IP version
        mock_garp.reset_mock()
        mock_na.reset_mock()

        ip_advertisement.send_ip_advertisement(FAKE_INTERFACE, IPV6_ADDRESS)

        mock_garp.assert_not_called()
        mock_na.assert_not_called()