Merge "Remove test duplication between tempest and n-t-p QuotasTest"
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
# Copyright 2015 Cloudwatt
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tempest.api.network import base
|
||||
from tempest.common import identity
|
||||
from tempest.common import utils
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from tempest.lib.common.utils import test_utils
|
||||
from tempest.lib import decorators
|
||||
from tempest.lib import exceptions as lib_exc
|
||||
|
||||
|
||||
class QuotasNegativeTest(base.BaseAdminNetworkTest):
|
||||
"""Tests the following operations in the Neutron API:
|
||||
|
||||
set network quota and exceed this quota
|
||||
|
||||
v2.0 of the API is assumed.
|
||||
It is also assumed that the per-project quota extension API is configured
|
||||
in /etc/neutron/neutron.conf as follows:
|
||||
|
||||
quota_driver = neutron.db.quota.driver.DbQuotaDriver
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(QuotasNegativeTest, cls).skip_checks()
|
||||
if not utils.is_extension_enabled('quotas', 'network'):
|
||||
msg = "quotas extension not enabled."
|
||||
raise cls.skipException(msg)
|
||||
|
||||
def setUp(self):
|
||||
super(QuotasNegativeTest, self).setUp()
|
||||
name = data_utils.rand_name('test_project_')
|
||||
description = data_utils.rand_name('desc_')
|
||||
self.creds_client = identity.identity_utils(self.os_admin)
|
||||
self.project = self.creds_client.create_project(
|
||||
name=name, description=description)
|
||||
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||
self.project['id'])
|
||||
|
||||
def tearDown(self):
|
||||
super(QuotasNegativeTest, self).tearDown()
|
||||
self.credentials_provider.cleanup_default_secgroup(
|
||||
self.os_admin.security_groups_client, self.project['id'])
|
||||
|
||||
@decorators.attr(type=['negative'])
|
||||
@decorators.idempotent_id('644f4e1b-1bf9-4af0-9fd8-eb56ac0f51cf')
|
||||
def test_network_quota_exceeding(self):
|
||||
"""Test creating network when exceeding network quota will fail"""
|
||||
# Set the network quota to two
|
||||
self.admin_quotas_client.update_quotas(self.project['id'], network=2)
|
||||
|
||||
# Create two networks
|
||||
n1 = self.admin_networks_client.create_network(
|
||||
project_id=self.project['id'])
|
||||
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
|
||||
self.admin_networks_client.delete_network,
|
||||
n1['network']['id'])
|
||||
n2 = self.admin_networks_client.create_network(
|
||||
project_id=self.project['id'])
|
||||
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
|
||||
self.admin_networks_client.delete_network,
|
||||
n2['network']['id'])
|
||||
|
||||
# Try to create a third network while the quota is two
|
||||
with self.assertRaisesRegex(
|
||||
lib_exc.Conflict,
|
||||
r"Quota exceeded for resources: \['network'\].*"):
|
||||
n3 = self.admin_networks_client.create_network(
|
||||
project_id=self.project['id'])
|
||||
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
|
||||
self.admin_networks_client.delete_network,
|
||||
n3['network']['id'])
|
||||
@@ -1,107 +0,0 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import testtools
|
||||
|
||||
from tempest.api.network import base
|
||||
from tempest.common import identity
|
||||
from tempest.common import utils
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from tempest.lib.common.utils import test_utils
|
||||
from tempest.lib import decorators
|
||||
|
||||
|
||||
class QuotasTest(base.BaseAdminNetworkTest):
|
||||
"""Tests the following operations in the Neutron API:
|
||||
|
||||
list quotas for projects who have non-default quota values
|
||||
show quotas for a specified project
|
||||
update quotas for a specified project
|
||||
reset quotas to default values for a specified project
|
||||
|
||||
v2.0 of the API is assumed.
|
||||
It is also assumed that the per-project quota extension API is configured
|
||||
in /etc/neutron/neutron.conf as follows:
|
||||
|
||||
quota_driver = neutron.db.quota.driver.DbQuotaDriver
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def skip_checks(cls):
|
||||
super(QuotasTest, cls).skip_checks()
|
||||
if not utils.is_extension_enabled('quotas', 'network'):
|
||||
msg = "quotas extension not enabled."
|
||||
raise cls.skipException(msg)
|
||||
|
||||
def _check_quotas(self, new_quotas):
|
||||
# Add a project to conduct the test
|
||||
project = data_utils.rand_name('test_project_')
|
||||
description = data_utils.rand_name('desc_')
|
||||
project = identity.identity_utils(self.os_admin).create_project(
|
||||
name=project, description=description)
|
||||
project_id = project['id']
|
||||
self.addCleanup(identity.identity_utils(self.os_admin).delete_project,
|
||||
project_id)
|
||||
|
||||
# Change quotas for project
|
||||
quota_set = self.admin_quotas_client.update_quotas(
|
||||
project_id, **new_quotas)['quota']
|
||||
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
|
||||
self.admin_quotas_client.reset_quotas, project_id)
|
||||
for key, value in new_quotas.items():
|
||||
self.assertEqual(value, quota_set[key])
|
||||
|
||||
# Confirm our project is listed among projects with non default quotas
|
||||
non_default_quotas = self.admin_quotas_client.list_quotas()
|
||||
found = False
|
||||
for qs in non_default_quotas['quotas']:
|
||||
if qs['project_id'] == project_id:
|
||||
found = True
|
||||
self.assertTrue(found)
|
||||
|
||||
# Confirm from API quotas were changed as requested for project
|
||||
quota_set = self.admin_quotas_client.show_quotas(project_id)
|
||||
quota_set = quota_set['quota']
|
||||
for key, value in new_quotas.items():
|
||||
self.assertEqual(value, quota_set[key])
|
||||
|
||||
# Reset quotas to default and confirm
|
||||
self.admin_quotas_client.reset_quotas(project_id)
|
||||
non_default_quotas = self.admin_quotas_client.list_quotas()
|
||||
for q in non_default_quotas['quotas']:
|
||||
self.assertNotEqual(project_id, q['project_id'])
|
||||
quota_set = self.admin_quotas_client.show_quotas(project_id)['quota']
|
||||
default_quotas = self.admin_quotas_client.show_default_quotas(
|
||||
project_id)['quota']
|
||||
self.assertEqual(default_quotas, quota_set)
|
||||
|
||||
@decorators.idempotent_id('2390f766-836d-40ef-9aeb-e810d78207fb')
|
||||
def test_quotas(self):
|
||||
"""Test update/list/show/reset of network quotas"""
|
||||
new_quotas = {'network': 0, 'port': 0}
|
||||
self._check_quotas(new_quotas)
|
||||
|
||||
@testtools.skipUnless(utils.is_extension_enabled(
|
||||
'quota_details', 'network'), 'Quota details extension not enabled.')
|
||||
@decorators.idempotent_id('7b05ec5f-bf44-43cb-b28f-ddd72a824288')
|
||||
def test_show_quota_details(self):
|
||||
"""Test showing network quota details"""
|
||||
# Show quota details for an existing project
|
||||
quota_details = self.admin_quotas_client.show_quota_details(
|
||||
self.admin_quotas_client.tenant_id)['quota']
|
||||
expected_keys = ['used', 'limit', 'reserved']
|
||||
for resource_type in quota_details:
|
||||
for key in expected_keys:
|
||||
self.assertIn(key, quota_details[resource_type])
|
||||
Reference in New Issue
Block a user