Commit a4c88669 authored by Zuul's avatar Zuul Committed by Gerrit Code Review

Merge "utils: move hash_of_set where it's solely used"

parents 416196b7 5d39206c
......@@ -65,6 +65,10 @@ POLLING_OPTS = [
]
def hash_of_set(s):
return str(hash(frozenset(s)))
class EmptyPollstersList(Exception):
def __init__(self):
msg = ('No valid pollsters can be loaded with the startup parameter'
......@@ -95,7 +99,7 @@ class Resources(object):
if self._resources:
static_resources_group = self.agent_manager.construct_group_id(
utils.hash_of_set(self._resources))
hash_of_set(self._resources))
return [v for v in self._resources if
not self.agent_manager.partition_coordinator or
self.agent_manager.hashrings[
......@@ -334,7 +338,7 @@ class AgentManager(cotyledon.Service):
for d in self.discoveries])
# let each set of statically-defined resources have its own group
static_resource_groups = set([
self.construct_group_id(utils.hash_of_set(p.resources))
self.construct_group_id(hash_of_set(p.resources))
for p in self.polling_manager.sources
if p.resources
])
......
......@@ -78,6 +78,14 @@ class TestManager(base.BaseTestCase):
super(TestManager, self).setUp()
self.conf = service.prepare_service([], [])
def test_hash_of_set(self):
x = ['a', 'b']
y = ['a', 'b', 'a']
z = ['a', 'c']
self.assertEqual(manager.hash_of_set(x), manager.hash_of_set(y))
self.assertNotEqual(manager.hash_of_set(x), manager.hash_of_set(z))
self.assertNotEqual(manager.hash_of_set(y), manager.hash_of_set(z))
def test_load_plugins(self):
mgr = manager.AgentManager(0, self.conf)
self.assertIsNotNone(list(mgr.extensions))
......
#
# Copyright 2012 New Dream Network, LLC (DreamHost)
# Copyright (c) 2013 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for ceilometer/utils.py
"""
from oslotest import base
from ceilometer import utils
class TestUtils(base.BaseTestCase):
def test_hash_of_set(self):
x = ['a', 'b']
y = ['a', 'b', 'a']
z = ['a', 'c']
self.assertEqual(utils.hash_of_set(x), utils.hash_of_set(y))
self.assertNotEqual(utils.hash_of_set(x), utils.hash_of_set(z))
self.assertNotEqual(utils.hash_of_set(y), utils.hash_of_set(z))
......@@ -50,10 +50,6 @@ def execute(*cmd, **kwargs):
return processutils.execute(*cmd, **kwargs)
def hash_of_set(s):
return str(hash(frozenset(s)))
def spawn_thread(target, *args, **kwargs):
t = threading.Thread(target=target, args=args, kwargs=kwargs)
t.daemon = True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment