def test_serialize(self): metadata = {'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1', 'mappings': [ {'virtual': 'aaa', 'device': 'bbb'}, {'virtual': 'xxx', 'device': 'yyy'}], 'block_device_mapping': [ {'virtual_device': 'fake', 'device_name': '/dev/fake'}, {'virtual_device': 'ephemeral0', 'device_name': '/dev/fake0'}]}} converted_expected = { 'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1', 'mappings': '[{"device": "bbb", "virtual": "aaa"}, ' '{"device": "yyy", "virtual": "xxx"}]', 'block_device_mapping': '[{"virtual_device": "fake", "device_name": "/dev/fake"}, ' '{"virtual_device": "ephemeral0", ' '"device_name": "/dev/fake0"}]'}} converted = service_utils._convert(metadata, 'to') self.assertEqual(converted, converted_expected) self.assertEqual(service_utils._convert(converted, 'from'), metadata)
def test_serialize(self): metadata = { "name": "image1", "is_public": True, "foo": "bar", "properties": { "prop1": "propvalue1", "mappings": [{"virtual": "aaa", "device": "bbb"}, {"virtual": "xxx", "device": "yyy"}], "block_device_mapping": [ {"virtual_device": "fake", "device_name": "/dev/fake"}, {"virtual_device": "ephemeral0", "device_name": "/dev/fake0"}, ], }, } converted_expected = {"name": "image1", "is_public": True, "foo": "bar", "properties": {"prop1": "propvalue1"}} converted = service_utils._convert(metadata, "to") self.assertEqual(metadata, service_utils._convert(converted, "from")) # Fields that rely on dict ordering can't be compared as text mappings = jsonutils.loads(converted["properties"].pop("mappings")) self.assertEqual([{"device": "bbb", "virtual": "aaa"}, {"device": "yyy", "virtual": "xxx"}], mappings) bd_mapping = jsonutils.loads(converted["properties"].pop("block_device_mapping")) self.assertEqual( [ {"virtual_device": "fake", "device_name": "/dev/fake"}, {"virtual_device": "ephemeral0", "device_name": "/dev/fake0"}, ], bd_mapping, ) # Compare the remaining self.assertEqual(converted_expected, converted)
def test_serialize(self): metadata = { 'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1', 'mappings': [{ 'virtual': 'aaa', 'device': 'bbb' }, { 'virtual': 'xxx', 'device': 'yyy' }], 'block_device_mapping': [{ 'virtual_device': 'fake', 'device_name': '/dev/fake' }, { 'virtual_device': 'ephemeral0', 'device_name': '/dev/fake0' }] } } converted_expected = { 'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1' } } converted = service_utils._convert(metadata, 'to') self.assertEqual(metadata, service_utils._convert(converted, 'from')) # Fields that rely on dict ordering can't be compared as text mappings = jsonutils.loads(converted['properties'].pop('mappings')) self.assertEqual([{ "device": "bbb", "virtual": "aaa" }, { "device": "yyy", "virtual": "xxx" }], mappings) bd_mapping = jsonutils.loads( converted['properties'].pop('block_device_mapping')) self.assertEqual([{ "virtual_device": "fake", "device_name": "/dev/fake" }, { "virtual_device": "ephemeral0", "device_name": "/dev/fake0" }], bd_mapping) # Compare the remaining self.assertEqual(converted_expected, converted)
def test_serialize(self): metadata = {'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1', 'mappings': '[' '{"virtual":"aaa","device":"bbb"},' '{"virtual":"xxx","device":"yyy"}]', 'block_device_mapping': '[' '{"virtual_device":"fake","device_name":"/dev/fake"},' '{"virtual_device":"ephemeral0",' '"device_name":"/dev/fake0"}]'}} expected = { 'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': {'prop1': 'propvalue1', 'mappings': [ {'virtual': 'aaa', 'device': 'bbb'}, {'virtual': 'xxx', 'device': 'yyy'}, ], 'block_device_mapping': [ {'virtual_device': 'fake', 'device_name': '/dev/fake'}, {'virtual_device': 'ephemeral0', 'device_name': '/dev/fake0'} ] } } converted = service_utils._convert(metadata) self.assertEqual(expected, converted)
def test_serialize(self): metadata = {'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': { 'prop1': 'propvalue1', 'mappings': [ {'virtual': 'aaa', 'device': 'bbb'}, {'virtual': 'xxx', 'device': 'yyy'}], 'block_device_mapping': [ {'virtual_device': 'fake', 'device_name': '/dev/fake'}, {'virtual_device': 'ephemeral0', 'device_name': '/dev/fake0'}]}} converted_expected = { 'name': 'image1', 'is_public': True, 'foo': 'bar', 'properties': {'prop1': 'propvalue1'} } converted = service_utils._convert(metadata, 'to') self.assertEqual(metadata, service_utils._convert(converted, 'from')) # Fields that rely on dict ordering can't be compared as text mappings = jsonutils.loads(converted['properties'] .pop('mappings')) self.assertEqual([{"device": "bbb", "virtual": "aaa"}, {"device": "yyy", "virtual": "xxx"}], mappings) bd_mapping = jsonutils.loads(converted['properties'] .pop('block_device_mapping')) self.assertEqual([{"virtual_device": "fake", "device_name": "/dev/fake"}, {"virtual_device": "ephemeral0", "device_name": "/dev/fake0"}], bd_mapping) # Compare the remaining self.assertEqual(converted_expected, converted)