Skip to content

Commit 9fa03d4

Browse files
committed
bdm: store empty object as connection_info by default
There are several code paths which expect connection_info to be a valid JSON object. However, if we don't find a value, we are setting it to an initial value of 'None' which evenutally gets converted to 'null' as JSON and stored in the database. This patch sets the default value to {} so that any new block device mappings have an empty object, rather than NULL. Closes-Bug: #1821244 Change-Id: I15a7c13edf78884ec223fd531a78a341106b41b8
1 parent c338612 commit 9fa03d4

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

nova/tests/unit/virt/test_block_device.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,31 @@ class TestDriverBlockDevice(test.NoDBTestCase):
120120
'connection_info': {"fake": "connection_info"},
121121
'delete_on_termination': False}
122122

123+
volume_bdm_dict_without_conn_info = block_device.BlockDeviceDict(
124+
{'id': 3, 'instance_uuid': uuids.instance,
125+
'device_name': '/dev/sda1',
126+
'source_type': 'volume',
127+
'disk_bus': 'scsi',
128+
'device_type': 'disk',
129+
'volume_size': 8,
130+
'destination_type': 'volume',
131+
'volume_id': 'fake-volume-id-1',
132+
'guest_format': 'ext4',
133+
'connection_info': None,
134+
'delete_on_termination': False,
135+
'boot_index': 0})
136+
137+
volume_driver_bdm_without_conn_info = {
138+
'attachment_id': None,
139+
'mount_device': '/dev/sda1',
140+
'connection_info': {},
141+
'delete_on_termination': False,
142+
'disk_bus': 'scsi',
143+
'device_type': 'disk',
144+
'guest_format': 'ext4',
145+
'boot_index': 0,
146+
'volume_type': None}
147+
123148
volsnapshot_bdm_dict = block_device.BlockDeviceDict(
124149
{'id': 4, 'instance_uuid': uuids.instance,
125150
'device_name': '/dev/sda2',
@@ -223,6 +248,8 @@ def setUp(self):
223248
self.context, self.ephemeral_bdm_dict)
224249
self.volume_bdm = fake_block_device.fake_bdm_object(
225250
self.context, self.volume_bdm_dict)
251+
self.volume_bdm_without_conn_info = fake_block_device.fake_bdm_object(
252+
self.context, self.volume_bdm_dict_without_conn_info)
226253
self.volsnapshot_bdm = fake_block_device.fake_bdm_object(
227254
self.context, self.volsnapshot_bdm_dict)
228255
self.volimage_bdm = fake_block_device.fake_bdm_object(
@@ -1199,6 +1226,11 @@ def test_convert_volume(self):
11991226
driver_block_device.convert_volume(
12001227
self.volsnapshot_bdm))
12011228

1229+
def test_convert_volume_without_connection_info(self):
1230+
self.assertEqual(self.volume_driver_bdm_without_conn_info,
1231+
driver_block_device.convert_volume(
1232+
self.volume_bdm_without_conn_info))
1233+
12021234
def test_legacy_block_devices(self):
12031235
test_snapshot = self.driver_classes['volsnapshot'](
12041236
self.volsnapshot_bdm)

nova/virt/block_device.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,13 @@ def _transform(self):
281281
if k in self._new_fields | set(['delete_on_termination'])}
282282
)
283283
self['mount_device'] = self._bdm_obj.device_name
284+
# connection_info might not be set so default to an empty dict so that
285+
# it can be serialized to an empty JSON object.
284286
try:
285287
self['connection_info'] = jsonutils.loads(
286288
self._bdm_obj.connection_info)
287289
except TypeError:
288-
self['connection_info'] = None
290+
self['connection_info'] = {}
289291
# volume_type might not be set on the internal bdm object so default
290292
# to None if not set
291293
self['volume_type'] = (

0 commit comments

Comments
 (0)