Merge "Fixed ceilometer arithmetic transformer bug"

This commit is contained in:
Jenkins 2017-07-27 06:13:19 +00:00 committed by Gerrit Code Review
commit 12091d1f8e
1 changed files with 8 additions and 5 deletions

View File

@ -14,6 +14,7 @@
# under the License. # under the License.
import collections import collections
import copy
import keyword import keyword
import math import math
import re import re
@ -101,14 +102,16 @@ class ArithmeticTransformer(transformer.TransformerBase):
def flush(self): def flush(self):
new_samples = [] new_samples = []
cache_clean_list = []
if not self.misconfigured: if not self.misconfigured:
for resource_id in self.cache: # When loop self.cache, the dict could not be change by others.
# If changed, will raise "RuntimeError: dictionary changed size
# during iteration". so we make a tmp copy and just loop it.
tmp_cache = copy.copy(self.cache)
for resource_id in tmp_cache:
if self._check_requirements(resource_id): if self._check_requirements(resource_id):
new_samples.append(self._calculate(resource_id)) new_samples.append(self._calculate(resource_id))
cache_clean_list.append(resource_id) if resource_id in self.cache:
for res_id in cache_clean_list: self.cache.pop(resource_id)
self.cache.pop(res_id)
return new_samples return new_samples
@classmethod @classmethod