Fix quota functional tests for nova-net

We need to skip some functional tests when testing against a nova-net cloud
so add the bits to detect that.

Also JSON-ify the quota functional tests and add the skips for nova-net.

Change-Id: Ibfeeb3f967f34c98e80271a8214cf95dc50407f1
This commit is contained in:
Dean Troyer 2017-04-26 17:02:12 -05:00
parent 0a0bcbbda2
commit 871450abcd
3 changed files with 119 additions and 53 deletions

View File

@ -299,7 +299,6 @@ class SetQuota(command.Command):
identity_client = self.app.client_manager.identity identity_client = self.app.client_manager.identity
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.compute
volume_client = self.app.client_manager.volume volume_client = self.app.client_manager.volume
network_client = self.app.client_manager.network
compute_kwargs = {} compute_kwargs = {}
for k, v in COMPUTE_QUOTAS.items(): for k, v in COMPUTE_QUOTAS.items():
value = getattr(parsed_args, k, None) value = getattr(parsed_args, k, None)
@ -352,7 +351,11 @@ class SetQuota(command.Command):
volume_client.quotas.update( volume_client.quotas.update(
project, project,
**volume_kwargs) **volume_kwargs)
if network_kwargs: if (
network_kwargs and
self.app.client_manager.is_network_endpoint_enabled()
):
network_client = self.app.client_manager.network
network_client.update_quota( network_client.update_quota(
project, project,
**network_kwargs) **network_kwargs)

View File

@ -42,6 +42,18 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
return result return result
def is_service_enabled(service):
"""Ask client cloud if service is available"""
try:
ret = execute('openstack service show -f value -c enabled ' + service)
except exceptions.CommandFailed:
# We get here for multiple reasons, all of them mean that a working
# service is not avilable
return False
return "True" in ret
class TestCase(testtools.TestCase): class TestCase(testtools.TestCase):
delimiter_line = re.compile('^\+\-[\+\-]+\-\+$') delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')

View File

@ -10,74 +10,125 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import json
from openstackclient.tests.functional import base from openstackclient.tests.functional import base
class QuotaTests(base.TestCase): class QuotaTests(base.TestCase):
"""Functional tests for quota. """ """Functional tests for quota
# Test quota information for compute, network and volume.
EXPECTED_FIELDS = ['instances', 'networks', 'volumes'] Note that for 'set' tests use different quotas for each API in different
EXPECTED_CLASS_FIELDS = ['instances', 'volumes'] test runs as these may run in parallel and otherwise step on each other.
"""
PROJECT_NAME = None PROJECT_NAME = None
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.haz_network = base.is_service_enabled('network')
cls.PROJECT_NAME =\ cls.PROJECT_NAME =\
cls.get_openstack_configuration_value('auth.project_name') cls.get_openstack_configuration_value('auth.project_name')
def test_quota_list_network_option(self): def test_quota_list_network_option(self):
self.openstack('quota set --networks 40 ' + if not self.haz_network:
self.PROJECT_NAME) self.skipTest("No Network service present")
raw_output = self.openstack('quota list --network') self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
self.assertIsNotNone(raw_output) cmd_output = json.loads(self.openstack(
self.assertIn("40", raw_output) 'quota list -f json --network'
))
self.assertIsNotNone(cmd_output)
self.assertEqual(
40,
cmd_output[0]["Networks"],
)
def test_quota_list_compute_option(self): def test_quota_list_compute_option(self):
self.openstack('quota set --instances 40 ' + self.openstack('quota set --instances 30 ' + self.PROJECT_NAME)
self.PROJECT_NAME) cmd_output = json.loads(self.openstack(
raw_output = self.openstack('quota list --compute') 'quota list -f json --compute'
self.assertIsNotNone(raw_output) ))
self.assertIn("40", raw_output) self.assertIsNotNone(cmd_output)
self.assertEqual(
30,
cmd_output[0]["Instances"],
)
def test_quota_list_volume_option(self): def test_quota_list_volume_option(self):
self.openstack('quota set --backups 40 ' + self.openstack('quota set --volumes 20 ' + self.PROJECT_NAME)
self.PROJECT_NAME) cmd_output = json.loads(self.openstack(
raw_output = self.openstack('quota list --volume') 'quota list -f json --volume'
self.assertIsNotNone(raw_output) ))
self.assertIn("40", raw_output) self.assertIsNotNone(cmd_output)
self.assertEqual(
20,
cmd_output[0]["Volumes"],
)
def test_quota_set(self): def test_quota_set_project(self):
self.openstack('quota set --instances 11 --volumes 11 --networks 11 ' + """Test quota set, show"""
self.PROJECT_NAME) network_option = ""
opts = self.get_opts(self.EXPECTED_FIELDS) if self.haz_network:
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts) network_option = "--routers 21 "
self.assertEqual("11\n11\n11\n", raw_output) self.openstack(
'quota set --cores 31 --backups 41 ' +
network_option +
self.PROJECT_NAME
)
cmd_output = json.loads(self.openstack(
'quota show -f json ' + self.PROJECT_NAME
))
self.assertIsNotNone(cmd_output)
self.assertEqual(
31,
cmd_output["cores"],
)
self.assertEqual(
41,
cmd_output["backups"],
)
if self.haz_network:
self.assertEqual(
21,
cmd_output["routers"],
)
def test_quota_show(self): # Check default quotas
raw_output = self.openstack('quota show ' + self.PROJECT_NAME) cmd_output = json.loads(self.openstack(
for expected_field in self.EXPECTED_FIELDS: 'quota show -f json --default'
self.assertIn(expected_field, raw_output) ))
self.assertIsNotNone(cmd_output)
# We don't necessarily know the default quotas, we're checking the
# returned attributes
self.assertTrue(cmd_output["cores"] >= 0)
self.assertTrue(cmd_output["backups"] >= 0)
if self.haz_network:
self.assertTrue(cmd_output["routers"] >= 0)
def test_quota_show_default_project(self): def test_quota_set_class(self):
raw_output = self.openstack('quota show') self.openstack(
for expected_field in self.EXPECTED_FIELDS: 'quota set --key-pairs 33 --snapshots 43 ' +
self.assertIn(expected_field, raw_output) '--class default'
)
cmd_output = json.loads(self.openstack(
'quota show -f json --class default'
))
self.assertIsNotNone(cmd_output)
self.assertEqual(
33,
cmd_output["key-pairs"],
)
self.assertEqual(
43,
cmd_output["snapshots"],
)
def test_quota_show_with_default_option(self): # Check default quota class
raw_output = self.openstack('quota show --default') cmd_output = json.loads(self.openstack(
for expected_field in self.EXPECTED_FIELDS: 'quota show -f json --class'
self.assertIn(expected_field, raw_output) ))
self.assertIsNotNone(cmd_output)
def test_quota_show_with_class_option(self): # We don't necessarily know the default quotas, we're checking the
raw_output = self.openstack('quota show --class') # returned attributes
for expected_field in self.EXPECTED_CLASS_FIELDS: self.assertTrue(cmd_output["key-pairs"] >= 0)
self.assertIn(expected_field, raw_output) self.assertTrue(cmd_output["snapshots"] >= 0)
def test_quota_class_set(self):
class_name = 'default'
class_expected_fields = ['instances', 'volumes']
self.openstack('quota set --instances 11 --volumes 11 --class ' +
class_name)
opts = self.get_opts(class_expected_fields)
raw_output = self.openstack('quota show --class ' + class_name + opts)
self.assertEqual("11\n11\n", raw_output)