Permalink
Browse files

Merge "Make BDM dict __init__ behave more like a dict"

  • Loading branch information...
2 parents 5eae48a + 74c46be commit 27fbfac5d5e502cf479e0de2521fc53ab3bb0f5d Jenkins committed with openstack-gerrit Jul 17, 2014
Showing with 12 additions and 1 deletion.
  1. +2 −1 nova/block_device.py
  2. +10 −0 nova/tests/test_block_device.py
View
@@ -75,10 +75,11 @@ class BlockDeviceDict(dict):
_required_fields = set(['source_type'])
- def __init__(self, bdm_dict=None, do_not_default=None):
+ def __init__(self, bdm_dict=None, do_not_default=None, **kwargs):
super(BlockDeviceDict, self).__init__()
bdm_dict = bdm_dict or {}
+ bdm_dict.update(kwargs)
do_not_default = do_not_default or set()
self._validate(bdm_dict)
@@ -386,6 +386,16 @@ def fake_validate(obj, dct):
self.assertNotIn('db_field1', dev_dict)
self.assertFalse('db_field2'in dev_dict)
+ # Passing kwargs to constructor works
+ dev_dict = block_device.BlockDeviceDict(field1='foo')
+ self.assertIn('field1', dev_dict)
+ self.assertIn('field2', dev_dict)
+ self.assertIsNone(dev_dict['field2'])
+ dev_dict = block_device.BlockDeviceDict(
+ {'field1': 'foo'}, field2='bar')
+ self.assertEqual('foo', dev_dict['field1'])
+ self.assertEqual('bar', dev_dict['field2'])
+
def test_validate(self):
self.assertRaises(exception.InvalidBDMFormat,
block_device.BlockDeviceDict,

0 comments on commit 27fbfac

Please sign in to comment.