Manage hosts in the current zone.
"""
-import UserDict
+import collections
from oslo_config import cfg
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
-class ReadOnlyDict(UserDict.IterableUserDict):
+class ReadOnlyDict(collections.Mapping):
"""A read-only dict."""
def __init__(self, source=None):
- self.data = {}
- self.update(source)
-
- def __setitem__(self, key, item):
- raise TypeError
-
- def __delitem__(self, key):
- raise TypeError
+ if source is not None:
+ self.data = dict(source)
+ else:
+ self.data = {}
- def clear(self):
- raise TypeError
+ def __getitem__(self, key):
+ return self.data[key]
- def pop(self, key, *args):
- raise TypeError
+ def __iter__(self):
+ return iter(self.data)
- def popitem(self):
- raise TypeError
+ def __len__(self):
+ return len(self.data)
- def update(self, source=None):
- if source is None:
- return
- elif isinstance(source, UserDict.UserDict):
- self.data = source.data
- elif isinstance(source, type({})):
- self.data = source
- else:
- raise TypeError
+ def __repr__(self):
+ return '%s(%r)' % (self.__class__.__name__, self.data)
class HostState(object):
'provisioned_capacity_gb': 9300},
}
]
+
+ def sort_func(data):
+ return data['name']
+
self.assertEqual(len(expected), len(res))
- self.assertEqual(sorted(expected), sorted(res))
+ self.assertEqual(sorted(expected, key=sort_func),
+ sorted(res, key=sort_func))
class HostStateTestCase(test.TestCase):
python -m testtools.run \
cinder.tests.unit.image.test_glance \
cinder.tests.unit.keymgr.test_mock_key_mgr \
+ cinder.tests.unit.scheduler.test_allocated_capacity_weigher \
+ cinder.tests.unit.scheduler.test_capacity_weigher \
+ cinder.tests.unit.scheduler.test_chance_weigher \
+ cinder.tests.unit.scheduler.test_filter_scheduler \
+ cinder.tests.unit.scheduler.test_goodness_weigher \
+ cinder.tests.unit.scheduler.test_host_filters \
+ cinder.tests.unit.scheduler.test_host_manager \
+ cinder.tests.unit.scheduler.test_rpcapi \
+ cinder.tests.unit.scheduler.test_scheduler \
+ cinder.tests.unit.scheduler.test_scheduler_options \
+ cinder.tests.unit.scheduler.test_volume_number_weigher \
cinder.tests.unit.targets.test_base_iscsi_driver \
cinder.tests.unit.targets.test_cxt_driver \
cinder.tests.unit.targets.test_iser_driver \