Skip to content

Commit 0a7483e

Browse files
committed
Fix Setting Quotas in Neutron
Currently Quota Set command doenst work in SDK version 0.9.12 as the request formed for the Neutron API is not correct. This patch attempts to fix the same. Change-Id: Id58b05bcdbfee73cb9b93dd5533b4c7d93dd03aa Partial-Bug:#1652317 Closes-Bug:#1655445
1 parent 8b7e049 commit 0a7483e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

openstack/network/v2/quota.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ class Quota(resource.Resource):
5858
#: The maximum amount of security groups you can create. *Type: int*
5959
security_groups = resource.Body('security_group', type=int)
6060

61+
def _prepare_request(self, requires_id=True, prepend_key=False):
62+
_request = super(Quota, self)._prepare_request(requires_id,
63+
prepend_key)
64+
if self.resource_key in _request.body:
65+
_body = _request.body[self.resource_key]
66+
else:
67+
_body = _request.body
68+
if 'id' in _body:
69+
del _body['id']
70+
return _request
71+
6172

6273
class QuotaDefault(Quota):
6374
base_path = '/quotas/%(project)s/default'

openstack/tests/functional/network/v2/test_quota.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ def test_list(self):
2727
self.assertIn('security_group', qot)
2828
self.assertIn('subnetpool', qot)
2929
self.assertIn('rbac_policy', qot)
30+
31+
def test_set(self):
32+
attrs = {'network': 123456789}
33+
self.conn.network.update_quota(**attrs)
34+
quota_list = self.conn.network.get_quota()
35+
for quota in quota_list:
36+
self.assertIn('123456789', quota)

openstack/tests/unit/network/v2/test_quota.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ def test_make_it(self):
6767
self.assertEqual(EXAMPLE['l7policy'], sot.l7_policies)
6868
self.assertEqual(EXAMPLE['pool'], sot.pools)
6969

70+
def test_prepare_request(self):
71+
body = {'id': 'ABCDEFGH', 'network': '12345'}
72+
quota_obj = quota.Quota(**body)
73+
response = quota_obj._prepare_request()
74+
self.assertNotIn('id', response)
75+
7076

7177
class TestQuotaDefault(testtools.TestCase):
7278

0 commit comments

Comments
 (0)