def _verify_correct_proxy_chain(self, original_ptg_id,
                                    expected_chain_length=None):
        original_ptg = self.show_policy_target_group(
            original_ptg_id)['policy_target_group']
        l3p = self._get_l3p_from_ptg(original_ptg)
        router = self._get_object(
            'routers', l3p['routers'][0], self.ext_api)['router']
        router_ports = self._list(
            'ports', query_params=router['id'] % 'device_id=%s')['ports']
        cumulative_cidrs = set()
        curr = original_ptg
        chain_length = 1
        while curr['proxy_group_id']:
            chain_length += 1
            proxy = self.show_policy_target_group(
                curr['proxy_group_id'])['policy_target_group']
            # Current PTG is not proxied, therefore it mustn't be attached to
            # the L3P router
            self.assertFalse(
                self._is_router_attached_to_any_subnet(
                    router_ports, curr),
                "Some ports are still attached to the PTG "
                "subnets:\nports:\n%s\nsubnets:\n%s" %
                (router_ports, curr['subnets']))
            # If L3 proxy, all subnets must be on different CIDRs
            if proxy['proxy_type'] == 'l2':
                self.assertTrue(
                    self._are_subnets_same(proxy, curr),
                    "PTG cidrs don't overlap on L2 proxy"
                    ":\nproxy_cidrs:\n%s\nproxied_cidrs:\n%s\n" %
                    (self._ptg_to_cidrs(proxy), (self._ptg_to_cidrs(curr))))
            else:
                self.assertTrue(
                    self._are_subnets_disjoint(proxy, curr),
                    "PTG cidrs overlap on L3 proxy"
                    ":\nproxy_cidrs:\n%s\nproxied_cidrs:\n%s\n" %
                    (self._ptg_to_cidrs(proxy), (self._ptg_to_cidrs(curr))))
            # Check that routes are correctly set
            curr_gateway_pt = self._ptg_gateway_pt(curr)
            if curr_gateway_pt:
                # Cumulated subnets are routed in current PTG subnets
                self.assertTrue(
                    self._are_cidr_routed_in_ptg_via_pt(curr, curr_gateway_pt,
                                                        cumulative_cidrs),
                    "PTG is not routing all the chained subnets:"
                    "\nPTG subnets:\n%s\nExpected routed CIDRs:%s\nExpected "
                    "nexthop:%s" % (self._get_ptg_subnets(curr),
                                    cumulative_cidrs,
                                    self._get_pt_ip(curr_gateway_pt)))
            cumulative_cidrs.update(self._ptg_to_cidrs(curr))
            curr = proxy
        # The last PTG of the proxy chain is fully connected to the router
        self.assertTrue(
            self._is_router_attached_to_all_subnets(
                router_ports, curr['subnets']),
            "Some ports are not attached to the PTG "
            "subnets:\nports:\n%s\nsubnets:\n%s" % (router_ports,
                                                    curr['subnets']))
        # Verify last PTG routes
        curr_gateway_pt = self._ptg_gateway_pt(curr)
        if curr_gateway_pt:
            # Cumulated subnets are routed in current PTG subnets
            self.assertTrue(
                self._are_cidr_routed_in_ptg_via_pt(curr, curr_gateway_pt,
                                                    cumulative_cidrs),
                "PTG is not routing all the chained subnets:"
                "\nPTG subnets:\n%s\nExpected routed CIDRs:%s\nExpected "
                "nexthop:%s" % (self._get_ptg_subnets(curr),
                                cumulative_cidrs,
                                self._get_pt_ip(curr_gateway_pt)))
            # Cumulated subnets are routed in L3P
            self.assertTrue(
                self._are_cidr_routed_in_router_via_pt(
                    router, curr_gateway_pt, cumulative_cidrs),
                "Router is not routing all the chained subnets:"
                "\nRouter:\n%s\nExpected routed CIDRs:%s\nExpected "
                "nexthop:%s" % (router, cumulative_cidrs,
                                self._get_pt_ip(curr_gateway_pt)))

        if expected_chain_length:
            self.assertEqual(expected_chain_length, chain_length)
dataset/ETHPy150Open openstack/group-based-policy/gbpservice/neutron/tests/unit/services/grouppolicy/test_resource_mapping_proxy_group.py/ResourceMappingProxyGroupGBPTestCase._verify_correct_proxy_chain/swapped operands of `%`