def test_floating_forward_rules(self):
    router = mock.MagicMock()
    router.get.return_value = [{'host': HOSTNAME}, {'host': mock.sentinel.otherhost}]
    ri = self._create_router(router)
    floating_ip = '0.0.0.0'
    rtr_2_fip_name = 'fake_router'
    fixed_ip = '192.168.0.1'
    fip = {'id': _uuid(), 'fixed_ip_address': '192.168.0.1', 'floating_ip_address': '0.0.0.0'}
    instance = mock.Mock()
    instance.get_rtr_ext_device_name = mock.Mock(return_value=rtr_2_fip_name)
    ri.fip_ns = instance
    dnat_from_floatingip_to_fixedip = ('PREROUTING', ('-d %s/32 -i %s -j DNAT --to-destination %s' % (floating_ip, rtr_2_fip_name, fixed_ip)))
    to_source = ('-s %s/32 -j SNAT --to-source %s' % (fixed_ip, floating_ip))
    if ri.iptables_manager.random_fully:
        to_source += ' --random-fully'
    snat_from_fixedip_to_floatingip = ('float-snat', to_source)
    actual = ri.floating_forward_rules(fip)
    expected = [dnat_from_floatingip_to_fixedip, snat_from_fixedip_to_floatingip]
    self.assertEqual(expected, actual)
def test_floating_forward_rules(self):
    router = mock.MagicMock()
    router.get.return_value = [{'host': HOSTNAME}, {'host': mock.sentinel.otherhost}]
    ri = self._create_router(router)
    floating_ip = '0.0.0.0'
    rtr_2_fip_name = 'fake_router'
    fixed_ip = '192.168.0.1'
    fip = {'id': _uuid(), 'fixed_ip_address': '192.168.0.1', 'floating_ip_address': '0.0.0.0'}
    instance = mock.Mock()
    instance.get_rtr_ext_device_name = mock.Mock(return_value=rtr_2_fip_name)
    ri.fip_ns = instance
    dnat_from_floatingip_to_fixedip = ('PREROUTING', ('-d %s/32 -i %s -j DNAT --to-destination %s' % (floating_ip, rtr_2_fip_name, fixed_ip)))
    to_source = ('-s %s/32 -j SNAT --to-source %s' % (fixed_ip, floating_ip))
    if ri.iptables_manager.random_fully:
        to_source += ' --random-fully'
    snat_from_fixedip_to_floatingip = ('float-snat', to_source)
    actual = ri.floating_forward_rules(fip)
    expected = [dnat_from_floatingip_to_fixedip, snat_from_fixedip_to_floatingip]
    self.assertEqual(expected, actual)