Merge "Tempest: Add default-subnetpools tests"
diff --git a/neutron/tests/tempest/api/test_subnetpools.py b/neutron/tests/tempest/api/test_subnetpools.py
index ec47606..1132d54 100644
--- a/neutron/tests/tempest/api/test_subnetpools.py
+++ b/neutron/tests/tempest/api/test_subnetpools.py
@@ -324,6 +324,74 @@
body = self.client.show_subnetpool(pool_id)
self.assertIsNone(body['subnetpool']['address_scope_id'])
+ @decorators.idempotent_id('4c6963c2-f54c-4347-b288-75d18421c4c4')
+ @test.requires_ext(extension='default-subnetpools', service='network')
+ def test_tenant_create_non_default_subnetpool(self):
+ """
+ Test creates a subnetpool, the "is_default" attribute is False.
+ """
+ created_subnetpool = self._create_subnetpool()
+ self.assertFalse(created_subnetpool['is_default'])
+
+
+class DefaultSubnetPoolsTest(SubnetPoolsTestBase):
+
+ @classmethod
+ def resource_setup(cls):
+ super(DefaultSubnetPoolsTest, cls).resource_setup()
+ body = cls.admin_client.list_subnetpools()
+ subnetpools = body['subnetpools']
+ for subnetpool in subnetpools:
+ if subnetpool.get('is_default'):
+ msg = 'Default subnetpool already exists. Only one is allowed.'
+ raise cls.skipException(msg)
+
+ @decorators.idempotent_id('cb839106-6184-4332-b292-5d07c074de4f')
+ @test.requires_ext(extension='default-subnetpools', service='network')
+ def test_admin_create_default_subnetpool(self):
+ """
+ Test uses administrative credentials to create a default subnetpool,
+ using the is_default=True.
+ """
+ created_subnetpool = self._create_subnetpool(is_admin=True,
+ is_default=True)
+ self.assertTrue(created_subnetpool['is_default'])
+
+ @decorators.idempotent_id('9e79730c-29b6-44a4-9504-bf3c7cedc56c')
+ @test.requires_ext(extension='default-subnetpools', service='network')
+ def test_convert_subnetpool_to_default_subnetpool(self):
+ """
+ Test creates a subnetpool, which is non default subnetpool.
+ Then it will update to a default subnetpool, by setting "is_default"
+ attribute to True.
+ """
+ created_subnetpool = self._create_subnetpool()
+ subnetpool_id = created_subnetpool['id']
+ self.assertFalse(created_subnetpool['is_default'])
+ subnetpool_data = {'is_default': True}
+ self.admin_client.update_subnetpool(subnetpool_id,
+ **subnetpool_data)
+ show_body = self.client.show_subnetpool(subnetpool_id)
+ self.assertTrue(show_body['subnetpool']['is_default'])
+
+ @decorators.idempotent_id('39687561-7a37-47b8-91ce-f9143ae26969')
+ @test.requires_ext(extension='default-subnetpools', service='network')
+ def test_convert_default_subnetpool_to_non_default(self):
+ """
+ Test uses administrative credentials to create a default subnetpool,
+ using the is_default=True.
+ Then it will update "is_default" attribute to False.
+ """
+ created_subnetpool = self._create_subnetpool(is_admin=True,
+ is_default=True)
+ subnetpool_id = created_subnetpool['id']
+ self.assertTrue(created_subnetpool['is_default'])
+ subnetpool_data = {'is_default': False}
+ self.admin_client.update_subnetpool(subnetpool_id,
+ **subnetpool_data)
+ show_body = self.client.show_subnetpool(subnetpool_id)
+ self.assertFalse(show_body['subnetpool']['is_default'])
+
class SubnetPoolsTestV6(SubnetPoolsTest):
diff --git a/neutron/tests/tempest/api/test_subnetpools_negative.py b/neutron/tests/tempest/api/test_subnetpools_negative.py
index c973d76..017eca4 100644
--- a/neutron/tests/tempest/api/test_subnetpools_negative.py
+++ b/neutron/tests/tempest/api/test_subnetpools_negative.py
@@ -60,6 +60,14 @@
is_admin=False, shared=True)
@test.attr(type='negative')
+ @decorators.idempotent_id('6ae09d8f-95be-40ed-b1cf-8b850d45bab5')
+ @test.requires_ext(extension='default-subnetpools', service='network')
+ def test_tenant_create_default_subnetpool(self):
+ # 'default' subnetpool can only be created by admin.
+ self.assertRaises(lib_exc.Forbidden, self._create_subnetpool,
+ is_admin=False, is_default=True)
+
+ @test.attr(type='negative')
@decorators.idempotent_id('4be84d30-60ca-4bd3-8512-db5b36ce1378')
def test_update_non_existent_subnetpool(self):
non_exist_id = data_utils.rand_name('subnetpool')