From: armando-migliaccio Date: Tue, 24 Mar 2015 18:30:08 +0000 (-0700) Subject: Add API tests for Neutron DVR extension X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1e3cb4ee504b6e1e135cc7a97e2146f13361fe9e;p=openstack-build%2Fneutron-build.git Add API tests for Neutron DVR extension This patch adds a number of positive and negative tests for the DVR functionality implemented by Neutron. Generated using: ./tools/copy_api_tests_from_tempest.sh [path to tempest working directory] Change-Id: Ia300b736250249ba54bd8fefa1307e6898f71652 --- diff --git a/neutron/tests/api/base.py b/neutron/tests/api/base.py index 8f38be085..e0c738661 100644 --- a/neutron/tests/api/base.py +++ b/neutron/tests/api/base.py @@ -268,7 +268,8 @@ class BaseNetworkTest(neutron.tests.tempest.test.BaseTestCase): @classmethod def create_router(cls, router_name=None, admin_state_up=False, - external_network_id=None, enable_snat=None): + external_network_id=None, enable_snat=None, + **kwargs): ext_gw_info = {} if external_network_id: ext_gw_info['network_id'] = external_network_id @@ -276,7 +277,7 @@ class BaseNetworkTest(neutron.tests.tempest.test.BaseTestCase): ext_gw_info['enable_snat'] = enable_snat body = cls.client.create_router( router_name, external_gateway_info=ext_gw_info, - admin_state_up=admin_state_up) + admin_state_up=admin_state_up, **kwargs) router = body['router'] cls.routers.append(router) return router diff --git a/neutron/tests/api/base_routers.py b/neutron/tests/api/base_routers.py index c800a2e72..bbd069d33 100644 --- a/neutron/tests/api/base_routers.py +++ b/neutron/tests/api/base_routers.py @@ -25,8 +25,21 @@ class BaseRouterTest(base.BaseAdminNetworkTest): def resource_setup(cls): super(BaseRouterTest, cls).resource_setup() - def _delete_router(self, router_id): - self.client.delete_router(router_id) + def _cleanup_router(self, router): + self.delete_router(router) + self.routers.remove(router) + + def _create_router(self, name, admin_state_up=False, + external_network_id=None, enable_snat=None): + # associate a cleanup with created routers to avoid quota limits + router = self.create_router(name, admin_state_up, + external_network_id, enable_snat) + self.addCleanup(self._cleanup_router, router) + return router + + def _delete_router(self, router_id, network_client=None): + client = network_client or self.client + client.delete_router(router_id) # Asserting that the router is not found in the list # after deletion list_body = self.client.list_routers() diff --git a/neutron/tests/api/test_routers.py b/neutron/tests/api/test_routers.py index fc5efceda..7acde777d 100644 --- a/neutron/tests/api/test_routers.py +++ b/neutron/tests/api/test_routers.py @@ -38,18 +38,6 @@ class RoutersTest(base.BaseRouterTest): if cls._ip_version == 4 else CONF.network.tenant_network_v6_cidr) - def _cleanup_router(self, router): - self.delete_router(router) - self.routers.remove(router) - - def _create_router(self, name, admin_state_up=False, - external_network_id=None, enable_snat=None): - # associate a cleanup with created routers to avoid quota limits - router = self.create_router(name, admin_state_up, - external_network_id, enable_snat) - self.addCleanup(self._cleanup_router, router) - return router - @test.attr(type='smoke') @test.idempotent_id('f64403e2-8483-4b34-8ccd-b09a87bcc68c') def test_create_show_list_update_delete_router(self): @@ -357,3 +345,37 @@ class RoutersTest(base.BaseRouterTest): class RoutersIpV6Test(RoutersTest): _ip_version = 6 + + +class DvrRoutersTest(base.BaseRouterTest): + + @classmethod + def skip_checks(cls): + super(DvrRoutersTest, cls).skip_checks() + if not test.is_extension_enabled('dvr', 'network'): + msg = "DVR extension not enabled." + raise cls.skipException(msg) + + @test.attr(type='smoke') + @test.idempotent_id('141297aa-3424-455d-aa8d-f2d95731e00a') + def test_create_distributed_router(self): + name = data_utils.rand_name('router') + create_body = self.admin_client.create_router( + name, distributed=True) + self.addCleanup(self._delete_router, + create_body['router']['id'], + self.admin_client) + self.assertTrue(create_body['router']['distributed']) + + @test.attr(type='smoke') + @test.idempotent_id('644d7a4a-01a1-4b68-bb8d-0c0042cb1729') + def test_convert_centralized_router(self): + router = self._create_router(data_utils.rand_name('router')) + self.assertNotIn('distributed', router) + update_body = self.admin_client.update_router(router['id'], + distributed=True) + self.assertTrue(update_body['router']['distributed']) + show_body = self.admin_client.show_router(router['id']) + self.assertTrue(show_body['router']['distributed']) + show_body = self.client.show_router(router['id']) + self.assertNotIn('distributed', show_body['router']) diff --git a/neutron/tests/api/test_routers_negative.py b/neutron/tests/api/test_routers_negative.py index 0688e15ff..f87f4ae1a 100644 --- a/neutron/tests/api/test_routers_negative.py +++ b/neutron/tests/api/test_routers_negative.py @@ -14,6 +14,8 @@ # under the License. import netaddr +import testtools + from tempest_lib.common.utils import data_utils from tempest_lib import exceptions as lib_exc @@ -110,3 +112,27 @@ class RoutersNegativeTest(base.BaseRouterTest): class RoutersNegativeIpV6Test(RoutersNegativeTest): _ip_version = 6 + + +class DvrRoutersNegativeTest(base.BaseRouterTest): + + @classmethod + def skip_checks(cls): + super(DvrRoutersNegativeTest, cls).skip_checks() + if not test.is_extension_enabled('dvr', 'network'): + msg = "DVR extension not enabled." + raise cls.skipException(msg) + + @classmethod + def resource_setup(cls): + super(DvrRoutersNegativeTest, cls).resource_setup() + cls.router = cls.create_router(data_utils.rand_name('router')) + cls.network = cls.create_network() + cls.subnet = cls.create_subnet(cls.network) + + @test.attr(type=['negative', 'smoke']) + @test.idempotent_id('4990b055-8fc7-48ab-bba7-aa28beaad0b9') + def test_router_create_tenant_distributed_returns_forbidden(self): + with testtools.ExpectedException(lib_exc.Forbidden): + self.create_router( + data_utils.rand_name('router'), distributed=True)