Skip to content

Commit

Permalink
[Quota]: Fix quota delete
Browse files Browse the repository at this point in the history
Deleting quota through "neutron quota-delete" cmd
sends -> set quota = None.
We are now checking for both quota == -1 or quota is None to delete
Zookeeper quota counter.

Change-Id: I092991c76e3564d2bc40ec2fd6ee21b112a78da9
Closes-Bug: #1752965
Closes-Bug: #1753013
Closes-Bug: #1752407
  • Loading branch information
sahilsabharwal committed Apr 12, 2018
1 parent 6552585 commit 7c77dcc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/config/api-server/vnc_cfg_api_server/vnc_cfg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4897,7 +4897,8 @@ def dbe_update_notification(cls, obj_ids, extra_dict=None):
for obj_type, quota_limit in proj_dict.get('quota', {}).items():
path_prefix = _DEFAULT_ZK_COUNTER_PATH_PREFIX + obj_ids
path = path_prefix + "/" + obj_type
if (quota_counter.get(path) and quota_limit == -1):
if (quota_counter.get(path) and (quota_limit == -1 or
quota_limit is None)):
# free the counter from cache for resources updated
# with unlimted quota
del quota_counter[path]
Expand Down
8 changes: 5 additions & 3 deletions src/config/api-server/vnc_cfg_api_server/vnc_quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def update_zk_counter_helper(cls, path_prefix, quota_dict, proj_id,
for (obj_type, quota) in quota_dict.iteritems():
path = path_prefix + "/" + obj_type
if path in quota_counter:
if quota == -1 and db_conn._zk_db.quota_counter_exists(path):
if ((quota == -1 or quota is None) and
db_conn._zk_db.quota_counter_exists(path)):
db_conn._zk_db.delete_quota_counter(path)
try:
del quota_counter[path]
Expand All @@ -170,9 +171,10 @@ def update_zk_counter_helper(cls, path_prefix, quota_dict, proj_id,
else:
quota_counter[path].max_count = quota
else:
# deb_update_notification might have freed the counter,
# dbe_update_notification might have freed the counter,
# delete node if exists.
if quota == -1 and db_conn._zk_db.quota_counter_exists(path):
if ((quota == -1 or quota is None) and
db_conn._zk_db.quota_counter_exists(path)):
db_conn._zk_db.delete_quota_counter(path)
else:
new_quota_dict[obj_type] = quota
Expand Down
2 changes: 2 additions & 0 deletions src/config/common/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ class TestCase(testtools.TestCase, fixtures.TestWithFixtures):
(kazoo.recipe.counter.Counter, '__init__',fake_zk_counter_init),
(kazoo.recipe.counter.Counter, '_change',fake_zk_counter_change),
(kazoo.recipe.counter.Counter, 'value',fake_zk_counter_value),
(kazoo.recipe.counter.Counter, '_ensure_node',
fake_zk_counter_ensure_node),
(kazoo.handlers.gevent.SequentialGeventHandler, '__init__',stub),

(kombu.Connection, '__new__',FakeKombu.Connection),
Expand Down
3 changes: 3 additions & 0 deletions src/config/common/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,9 @@ def fake_zk_counter_change(self, value):
self._value = data
return self

def fake_zk_counter_ensure_node(self):
self._ensured_path = True

class ZookeeperClientMock(object):

def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions src/config/common/zkclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def __init__(self, client, path, max_count=sys.maxint, default=0):
super(ZookeeperCounter, self).__init__(client, path, default)

self.max_count = max_count
self._ensure_node()

def _inner_change(self, value):
data, version = self._value()
Expand Down

0 comments on commit 7c77dcc

Please sign in to comment.