Skip to content

Commit

Permalink
Merge "[Quota]: Fix quota delete"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul v3 CI authored and opencontrail-ci-admin committed Apr 16, 2018
2 parents 5074256 + 7c77dcc commit 83b7060
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
Expand Up @@ -4902,7 +4902,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
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
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
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
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 83b7060

Please sign in to comment.