notification.info_from_instance should use get()

Bug #1224921 reported by Phil Day
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Opinion
Wishlist
Unassigned

Bug Description

notification.info_from_instance() reads many values from the instance structure, including capacity vales that are populated from the instance_system_metadata table. However there are cases where these values are not present - for example if a deleted instance is passed in then the DB queries do not always do the joins. This results in a KeyError exception.

Whilst such cases are triggered by bugs the notification code should be more robust and use .get() methods instead.

Tags: compute
Matt Riedemann (mriedem)
tags: added: compute
Revision history for this message
Jake Liu (jake-liu) wrote :

Hi Phil, can you please give more detail on the problem.

Do you mean that we need change the following to instance_ref.get()?

instance_info = dict(
        # Owner properties
        tenant_id=instance_ref['project_id'],
        user_id=instance_ref['user_id'],

        # Identity properties
        instance_id=instance_ref['uuid'],
        display_name=instance_ref['display_name'],
        reservation_id=instance_ref['reservation_id'],
        hostname=instance_ref['hostname'],

        # Type properties
        instance_type=instance_type_name,
        instance_type_id=instance_ref['instance_type_id'],
        architecture=instance_ref['architecture'],

        # Capacity properties
        memory_mb=instance_ref['memory_mb'],
        disk_gb=instance_ref['root_gb'] + instance_ref['ephemeral_gb'],
        vcpus=instance_ref['vcpus'],
        # Note(dhellmann): This makes th
        ...............

I'm not clear about the following:
notification.info_from_instance() reads many values from the instance structure, including capacity vales that are populated from the instance_system_metadata table.
>>>>>>>>> How does capacity vales get from system metadata in this function?

Thanks.

Changed in nova:
assignee: nobody → Jake Liu (jake-liu)
Revision history for this message
Jeffrey Zhang (jeffrey4l) wrote :

1. the info_from_instance() method return a dict object already.
2. the instance_ref should came from DB. And the deletion doesn't remove the data, the just mark it as delete. So your issue should not exist.

Revision history for this message
Mathew Odden (locke105) wrote :

Phil, can you confirm this is still an issue?

Changed in nova:
assignee: Jake Liu (jake-liu) → nobody
status: New → Incomplete
Revision history for this message
Phil Day (philip-day) wrote :

To answer your original question Jake yes that was the code that I thought should be changed to use get.

I don't have any current examples of where this is causing a problem, as the bug that led me to this has a fix that avoids thsi code altogether. However it still feels like an exception waiting to happen

Revision history for this message
Sean Dague (sdague) wrote :

Long incomplete bug, marking as Opinion. It might be valid, but it's not anything actionable.

Changed in nova:
status: Incomplete → Invalid
status: Invalid → Opinion
importance: Undecided → Wishlist
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.