|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | +import json |
| 14 | + |
13 | 15 | from openstackclient.tests.functional import base |
14 | 16 |
|
15 | 17 |
|
16 | 18 | 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 | + |
21 | 25 | PROJECT_NAME = None |
22 | 26 |
|
23 | 27 | @classmethod |
24 | 28 | def setUpClass(cls): |
| 29 | + cls.haz_network = base.is_service_enabled('network') |
25 | 30 | cls.PROJECT_NAME =\ |
26 | 31 | cls.get_openstack_configuration_value('auth.project_name') |
27 | 32 |
|
28 | 33 | 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 | + ) |
34 | 45 |
|
35 | 46 | 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 | + ) |
41 | 56 |
|
42 | 57 | 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 | + ) |
60 | 67 |
|
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 | + ) |
65 | 95 |
|
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) |
70 | 107 |
|
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 | + ) |
75 | 125 |
|
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