'Test that conntrack immediately drops stateful connection
that uses floating IP once it\'s disassociated.'

def _test_conntrack_disassociate_fip(self, ha):

    router_info = self.generate_router_info(enable_ha=ha)
    router = self.manage_router(self.agent, router_info)
    port = net_helpers.get_free_namespace_port(constants.PROTO_NAME_TCP, router.ns_name)
    client_address = '19.4.4.3'
    server_address = '35.4.0.4'
    def clean_fips(router):
        router.router[constants.FLOATINGIP_KEY] = []
    clean_fips(router)
    self._add_fip(router, client_address, fixed_address=server_address)
    router.process()
    router_ns = ip_lib.IPWrapper(namespace=router.ns_name)
    netcat = net_helpers.NetcatTester(router.ns_name, router.ns_name, client_address, port, protocol=net_helpers.NetcatTester.TCP)
    self.addCleanup(netcat.stop_processes)
    def assert_num_of_conntrack_rules(n):
        out = router_ns.netns.execute(['conntrack', '-L', '--orig-src', client_address])
        self.assertEqual(n, len([line for line in out.strip().split('\n') if line]))
    if ha:
        common_utils.wait_until_true((lambda : (router.ha_state == 'master')))
    with self.assert_max_execution_time(100):
        assert_num_of_conntrack_rules(0)
        self.assertTrue(netcat.test_connectivity())
        assert_num_of_conntrack_rules(1)
        clean_fips(router)
        router.process()
        assert_num_of_conntrack_rules(0)
        with testtools.ExpectedException(RuntimeError):
            netcat.test_connectivity()
