'Ensure external gateway set doesn\'t add excess IPs on router gw
Setting the gateway of a router to an external network with more than
one IPv4 and one IPv6 subnet should only add an address from the first
IPv4 subnet, an address from the first IPv6-stateful subnet, and an
address from each IPv6-stateless (SLAAC and DHCPv6-stateless) subnet'

def test_router_add_gateway_multiple_subnets_ipv6(self):

    with self.router() as r:
        with self.network() as n:
            with self.subnet(cidr='10.0.0.0/24', network=n) as s1:
                with self.subnet(cidr='10.0.1.0/24', network=n) as s2:
                    with self.subnet(cidr='2001:db8::/64', network=n, ip_version=6, ipv6_ra_mode=lib_constants.IPV6_SLAAC, ipv6_address_mode=lib_constants.IPV6_SLAAC) as s3:
                        with self.subnet(cidr='2001:db8:1::/64', network=n, ip_version=6, ipv6_ra_mode=lib_constants.DHCPV6_STATEFUL, ipv6_address_mode=lib_constants.DHCPV6_STATEFUL) as s4:
                            with self.subnet(cidr='2001:db8:2::/64', network=n, ip_version=6, ipv6_ra_mode=lib_constants.DHCPV6_STATELESS, ipv6_address_mode=lib_constants.DHCPV6_STATELESS) as s5:
                                self._set_net_external(n['network']['id'])
                                self._add_external_gateway_to_router(r['router']['id'], n['network']['id'])
                                res = self._show('routers', r['router']['id'])
                                fips = res['router']['external_gateway_info']['external_fixed_ips']
                                fip_subnet_ids = {fip['subnet_id'] for fip in fips}
                                if (s1['subnet']['id'] in fip_subnet_ids):
                                    self.assertEqual({s1['subnet']['id'], s3['subnet']['id'], s4['subnet']['id'], s5['subnet']['id']}, fip_subnet_ids)
                                else:
                                    self.assertEqual({s2['subnet']['id'], s3['subnet']['id'], s4['subnet']['id'], s5['subnet']['id']}, fip_subnet_ids)
                                self._remove_external_gateway_from_router(r['router']['id'], n['network']['id'])
