Skip to content

Commit 871450a

Browse files
author
Dean Troyer
committed
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
1 parent 0a0bcbb commit 871450a

3 files changed

Lines changed: 119 additions & 53 deletions

File tree

openstackclient/common/quota.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ def take_action(self, parsed_args):
299299
identity_client = self.app.client_manager.identity
300300
compute_client = self.app.client_manager.compute
301301
volume_client = self.app.client_manager.volume
302-
network_client = self.app.client_manager.network
303302
compute_kwargs = {}
304303
for k, v in COMPUTE_QUOTAS.items():
305304
value = getattr(parsed_args, k, None)
@@ -352,7 +351,11 @@ def take_action(self, parsed_args):
352351
volume_client.quotas.update(
353352
project,
354353
**volume_kwargs)
355-
if network_kwargs:
354+
if (
355+
network_kwargs and
356+
self.app.client_manager.is_network_endpoint_enabled()
357+
):
358+
network_client = self.app.client_manager.network
356359
network_client.update_quota(
357360
project,
358361
**network_kwargs)

openstackclient/tests/functional/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ def execute(cmd, fail_ok=False, merge_stderr=False):
4242
return result
4343

4444

45+
def is_service_enabled(service):
46+
"""Ask client cloud if service is available"""
47+
try:
48+
ret = execute('openstack service show -f value -c enabled ' + service)
49+
except exceptions.CommandFailed:
50+
# We get here for multiple reasons, all of them mean that a working
51+
# service is not avilable
52+
return False
53+
54+
return "True" in ret
55+
56+
4557
class TestCase(testtools.TestCase):
4658

4759
delimiter_line = re.compile('^\+\-[\+\-]+\-\+$')

openstackclient/tests/functional/common/test_quota.py

Lines changed: 102 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,125 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import json
14+
1315
from openstackclient.tests.functional import base
1416

1517

1618
class QuotaTests(base.TestCase):
17-
"""Functional tests for quota. """
18-
# Test quota information for compute, network and volume.
19-
EXPECTED_FIELDS = ['instances', 'networks', 'volumes']
20-
EXPECTED_CLASS_FIELDS = ['instances', 'volumes']
19+
"""Functional tests for quota
20+
21+
Note that for 'set' tests use different quotas for each API in different
22+
test runs as these may run in parallel and otherwise step on each other.
23+
"""
24+
2125
PROJECT_NAME = None
2226

2327
@classmethod
2428
def setUpClass(cls):
29+
cls.haz_network = base.is_service_enabled('network')
2530
cls.PROJECT_NAME =\
2631
cls.get_openstack_configuration_value('auth.project_name')
2732

2833
def test_quota_list_network_option(self):
29-
self.openstack('quota set --networks 40 ' +
30-
self.PROJECT_NAME)
31-
raw_output = self.openstack('quota list --network')
32-
self.assertIsNotNone(raw_output)
33-
self.assertIn("40", raw_output)
34+
if not self.haz_network:
35+
self.skipTest("No Network service present")
36+
self.openstack('quota set --networks 40 ' + self.PROJECT_NAME)
37+
cmd_output = json.loads(self.openstack(
38+
'quota list -f json --network'
39+
))
40+
self.assertIsNotNone(cmd_output)
41+
self.assertEqual(
42+
40,
43+
cmd_output[0]["Networks"],
44+
)
3445

3546
def test_quota_list_compute_option(self):
36-
self.openstack('quota set --instances 40 ' +
37-
self.PROJECT_NAME)
38-
raw_output = self.openstack('quota list --compute')
39-
self.assertIsNotNone(raw_output)
40-
self.assertIn("40", raw_output)
47+
self.openstack('quota set --instances 30 ' + self.PROJECT_NAME)
48+
cmd_output = json.loads(self.openstack(
49+
'quota list -f json --compute'
50+
))
51+
self.assertIsNotNone(cmd_output)
52+
self.assertEqual(
53+
30,
54+
cmd_output[0]["Instances"],
55+
)
4156

4257
def test_quota_list_volume_option(self):
43-
self.openstack('quota set --backups 40 ' +
44-
self.PROJECT_NAME)
45-
raw_output = self.openstack('quota list --volume')
46-
self.assertIsNotNone(raw_output)
47-
self.assertIn("40", raw_output)
48-
49-
def test_quota_set(self):
50-
self.openstack('quota set --instances 11 --volumes 11 --networks 11 ' +
51-
self.PROJECT_NAME)
52-
opts = self.get_opts(self.EXPECTED_FIELDS)
53-
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts)
54-
self.assertEqual("11\n11\n11\n", raw_output)
55-
56-
def test_quota_show(self):
57-
raw_output = self.openstack('quota show ' + self.PROJECT_NAME)
58-
for expected_field in self.EXPECTED_FIELDS:
59-
self.assertIn(expected_field, raw_output)
58+
self.openstack('quota set --volumes 20 ' + self.PROJECT_NAME)
59+
cmd_output = json.loads(self.openstack(
60+
'quota list -f json --volume'
61+
))
62+
self.assertIsNotNone(cmd_output)
63+
self.assertEqual(
64+
20,
65+
cmd_output[0]["Volumes"],
66+
)
6067

61-
def test_quota_show_default_project(self):
62-
raw_output = self.openstack('quota show')
63-
for expected_field in self.EXPECTED_FIELDS:
64-
self.assertIn(expected_field, raw_output)
68+
def test_quota_set_project(self):
69+
"""Test quota set, show"""
70+
network_option = ""
71+
if self.haz_network:
72+
network_option = "--routers 21 "
73+
self.openstack(
74+
'quota set --cores 31 --backups 41 ' +
75+
network_option +
76+
self.PROJECT_NAME
77+
)
78+
cmd_output = json.loads(self.openstack(
79+
'quota show -f json ' + self.PROJECT_NAME
80+
))
81+
self.assertIsNotNone(cmd_output)
82+
self.assertEqual(
83+
31,
84+
cmd_output["cores"],
85+
)
86+
self.assertEqual(
87+
41,
88+
cmd_output["backups"],
89+
)
90+
if self.haz_network:
91+
self.assertEqual(
92+
21,
93+
cmd_output["routers"],
94+
)
6595

66-
def test_quota_show_with_default_option(self):
67-
raw_output = self.openstack('quota show --default')
68-
for expected_field in self.EXPECTED_FIELDS:
69-
self.assertIn(expected_field, raw_output)
96+
# Check default quotas
97+
cmd_output = json.loads(self.openstack(
98+
'quota show -f json --default'
99+
))
100+
self.assertIsNotNone(cmd_output)
101+
# We don't necessarily know the default quotas, we're checking the
102+
# returned attributes
103+
self.assertTrue(cmd_output["cores"] >= 0)
104+
self.assertTrue(cmd_output["backups"] >= 0)
105+
if self.haz_network:
106+
self.assertTrue(cmd_output["routers"] >= 0)
70107

71-
def test_quota_show_with_class_option(self):
72-
raw_output = self.openstack('quota show --class')
73-
for expected_field in self.EXPECTED_CLASS_FIELDS:
74-
self.assertIn(expected_field, raw_output)
108+
def test_quota_set_class(self):
109+
self.openstack(
110+
'quota set --key-pairs 33 --snapshots 43 ' +
111+
'--class default'
112+
)
113+
cmd_output = json.loads(self.openstack(
114+
'quota show -f json --class default'
115+
))
116+
self.assertIsNotNone(cmd_output)
117+
self.assertEqual(
118+
33,
119+
cmd_output["key-pairs"],
120+
)
121+
self.assertEqual(
122+
43,
123+
cmd_output["snapshots"],
124+
)
75125

76-
def test_quota_class_set(self):
77-
class_name = 'default'
78-
class_expected_fields = ['instances', 'volumes']
79-
self.openstack('quota set --instances 11 --volumes 11 --class ' +
80-
class_name)
81-
opts = self.get_opts(class_expected_fields)
82-
raw_output = self.openstack('quota show --class ' + class_name + opts)
83-
self.assertEqual("11\n11\n", raw_output)
126+
# Check default quota class
127+
cmd_output = json.loads(self.openstack(
128+
'quota show -f json --class'
129+
))
130+
self.assertIsNotNone(cmd_output)
131+
# We don't necessarily know the default quotas, we're checking the
132+
# returned attributes
133+
self.assertTrue(cmd_output["key-pairs"] >= 0)
134+
self.assertTrue(cmd_output["snapshots"] >= 0)

0 commit comments

Comments
 (0)