glance.images.get inappropriate return

Bug #1791067 reported by Volodymyr Litovka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Invalid
Undecided
Unassigned

Bug Description

Hello colleagues,

while working with glanceclient library, I faced an issue: when trying to find snapshot_id of the image, I'm calling glance.images.get and this call returns type of Image where block_devices_mapping property is type of 'Str', but with textual representation of List inside:

{
'container_format': 'bare',
'size': 0,
'block_device_mapping': '[{"guest_format": null, "boot_index": 0, "delete_on_termination": false, "no_device": null, "snapshot_id": "7fc78b3e-fa23-4710-914b-575ee0444c88", "device_name": "/dev/sda", "disk_bus": "scsi", "image_id": null, "source_type": "snapshot", "tag": null, "device_type": "disk", "volume_id": null, "destination_type": "volume", "volume_size": 10}]',
'locations': [{'url': 'swift+config://ref1/glance/35d2a539-0558-494a-92aa-85bdaf27caed', 'metadata': {}}], [ ... ] }

it looks strange since other properties are of different type (Integer (like 'size') or even List (like 'location')) and adds complexity to working with the result. It's better to have 'block_device_mappings' also type of List in order to work with natural Python data types like

image = glance.images.get(image_uuid)
for bd in image.block_device_mappings:
  if bd['boot_index'] == 0:
    snapshot_id = bd['snapshot_id']

So, the question is: is 'String' type of block_device_mapping bug or feature?

Thank you.

Revision history for this message
Volodymyr Litovka (doka.ua) wrote :

At the moment, such workaround is possible:

import ast

s = '[{"guest_format": null, "boot_index": 0, "delete_on_termination": false, "no_device": null, "snapshot_id": "7fc78b3e-fa23-4710-914b-575ee0444c88", "device_name": "/dev/sda", "disk_bus": "scsi", "image_id": null, "source_type": "snapshot", "tag": null, "device_type": "disk", "volume_id": null, "destination_type": "volume", "volume_size": 10}]'
s1 = s.replace('null', 'None').replace('true', 'True').replace('false', 'False')
bdm = ast.literal_eval(s1)
for bd in bdm:
    if bd['boot_index'] == 0:
        print(bd['snapshot_id'])

but such evaluation of result is very risky business.

Revision history for this message
Abhishek Kekane (abhishek-kekane) wrote :

Need more information on how to reproduce, detail steps would be good to have.

Changed in python-glanceclient:
status: New → Incomplete
Changed in python-glanceclient:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.