Skip to content

Commit

Permalink
Merge "Make BDM dict __init__ behave more like a dict"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 17, 2014
2 parents 5eae48a + 74c46be commit 27fbfac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nova/block_device.py
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions nova/tests/test_block_device.py
Expand Up @@ -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,
Expand Down

0 comments on commit 27fbfac

Please sign in to comment.