From 14d9215c9ab22e84788ce83cbc563535f2fdf1c7 Mon Sep 17 00:00:00 2001 From: yangjianfeng Date: Tue, 6 Sep 2022 10:42:29 +0800 Subject: [PATCH] Create extra external network with address scope for `ndp proxy` tests For details, please refer to https://review.opendev.org/855850 Closes-Bug: #1987410 Change-Id: I9f3176a9688db8c4f4417139b712d1570c5ab7bb --- neutron_tempest_plugin/api/test_ndp_proxy.py | 24 ++++++++--- .../api/test_ndp_proxy_negative.py | 41 ++++++++++++++++--- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/neutron_tempest_plugin/api/test_ndp_proxy.py b/neutron_tempest_plugin/api/test_ndp_proxy.py index 1b2165ba..92d65c21 100644 --- a/neutron_tempest_plugin/api/test_ndp_proxy.py +++ b/neutron_tempest_plugin/api/test_ndp_proxy.py @@ -24,23 +24,35 @@ from neutron_tempest_plugin import config CONF = config.CONF -class NDPProxyTestJSON(base.BaseNetworkTest): +class NDPProxyTestJSON(base.BaseAdminNetworkTest): credentials = ['primary', 'admin'] - required_extensions = ['router', 'l3-ndp-proxy'] + required_extensions = ['router', 'l3-ndp-proxy', 'address-scope'] @classmethod def resource_setup(cls): super(NDPProxyTestJSON, cls).resource_setup() - cls.ext_net_id = CONF.network.public_network_id - + address_scope = cls.create_address_scope( + "test-as", **{'ip_version': constants.IP_VERSION_6}) + subnetpool = cls.create_subnetpool( + "test-subnetpool", + **{'address_scope_id': address_scope['id'], + 'default_prefixlen': 112, + 'prefixes': ['2001:abc::0/96']}) + # Create an external network and it's subnet + ext_net = cls.create_network('test-ext-net', client=cls.admin_client, + external=True) + cls.create_subnet( + ext_net, client=cls.admin_client, + ip_version=constants.IP_VERSION_6, + **{'subnetpool_id': subnetpool['id'], "cidr": "2001:abc::1:0/112"}) # Create network, subnet, router and add interface cls.network = cls.create_network() cls.subnet = cls.create_subnet( cls.network, ip_version=constants.IP_VERSION_6, - cidr='2002::abcd:0/112') + **{'subnetpool_id': subnetpool['id'], "cidr": "2001:abc::2:0/112"}) cls.router = cls.create_router(data_utils.rand_name('router'), - external_network_id=cls.ext_net_id, + external_network_id=ext_net['id'], enable_ndp_proxy=True) cls.create_router_interface(cls.router['id'], cls.subnet['id']) diff --git a/neutron_tempest_plugin/api/test_ndp_proxy_negative.py b/neutron_tempest_plugin/api/test_ndp_proxy_negative.py index acbbdcb9..56188f30 100644 --- a/neutron_tempest_plugin/api/test_ndp_proxy_negative.py +++ b/neutron_tempest_plugin/api/test_ndp_proxy_negative.py @@ -24,16 +24,28 @@ from neutron_tempest_plugin import config CONF = config.CONF -class NDPProxyNegativeTestJSON(base.BaseNetworkTest): +class NDPProxyNegativeTestJSON(base.BaseAdminNetworkTest): credentials = ['primary', 'admin'] - required_extensions = ['router', 'l3-ndp-proxy'] + required_extensions = ['router', 'l3-ndp-proxy', 'address-scope'] @classmethod def resource_setup(cls): super(NDPProxyNegativeTestJSON, cls).resource_setup() - cls.ext_net_id = CONF.network.public_network_id - + address_scope = cls.create_address_scope( + "test-as", **{'ip_version': constants.IP_VERSION_6}) + subnetpool = cls.create_subnetpool( + "test-subnetpool", + **{'address_scope_id': address_scope['id'], + 'default_prefixlen': 112, + 'prefixes': ['2001:abc::0/96']}) + # Create an external network and it's subnet + ext_net = cls.create_network('test-ext-net', client=cls.admin_client, + external=True) + cls.create_subnet( + ext_net, client=cls.admin_client, + ip_version=constants.IP_VERSION_6, + **{'subnetpool_id': subnetpool['id'], "cidr": "2001:abc::1:0/112"}) # Create network, subnet, router and add interface cls.network = cls.create_network() cls.subnet = cls.create_subnet( @@ -41,7 +53,7 @@ class NDPProxyNegativeTestJSON(base.BaseNetworkTest): cidr='2002::abcd:0/112') cls.router = cls.create_router( data_utils.rand_name('router'), - external_network_id=cls.ext_net_id) + external_network_id=ext_net['id']) @decorators.attr(type='negative') @decorators.idempotent_id('a0897204-bb85-41cc-a5fd-5d0ab8116a07') @@ -102,3 +114,22 @@ class NDPProxyNegativeTestJSON(base.BaseNetworkTest): self.router['id'], enable_ndp_proxy=True, external_gateway_info={}) + + @decorators.attr(type='negative') + @decorators.idempotent_id('194b5ee7-4c59-4643-aabf-80a125c3f688') + def test_enable_ndp_proxy_without_address_scope(self): + extnet = self.create_network("extnet", client=self.admin_client, + external=True) + self.create_subnet(extnet, client=self.admin_client, + ip_version=constants.IP_VERSION_6, + cidr='2001:abc1::0/112') + self.assertRaises(exceptions.Conflict, + self.client.create_router, + name=data_utils.rand_name('router'), + enable_ndp_proxy=True, + external_gateway_info={'network_id': extnet['id']}) + router = self.create_router(data_utils.rand_name('router')) + self.assertRaises(exceptions.Conflict, + self.client.update_router, + router['id'], enable_ndp_proxy=True, + external_gateway_info={'network_id': extnet['id']})