OpenStack Nova: Snapshot creation failed when image property have version, context and method values

Solution Verified - Updated -

Environment

  • Red Hat OpenStack Platform 10+
    openstack-glance 13.0.0+

Issue

When creating a snapshot of a server using the nova API, failure occurs if the image contains the metadata property "version" or "context" or "method" values.

# nova image-create 7090ab03-a204-49ed-99a6-93bfc9713819 snapshot
ERROR (ClientException): Unexpected API Error. Please report this at http://bugs.launchpad.net/nova/ and attach the Nova API log if possible.
<type 'exceptions.TypeError'> (HTTP 500) (Request-ID: req-ab00498b-008b-4990-836e-c4c1631694e5)

Resolution

An errata was released to solve this issue.
Also, the fix was released for RHOSP 10 on package openstack-nova-14.1.0-56.el7ost

Root Cause

The Image metadata is passed as an argument to _create_v2() (nova/image/glance.py) which is then passed to call() (nova/image/glance.py) as kwargs. The function already takes in context, method, and version arguments, so any of these metadata properties would cause the snapshot to fail.

Diagnostic Steps

Note: The line numbers can change depending on the version, it may be different in your machine.

2018-03-02 09:42:52.906 27746 ERROR nova.api.openstack.extensions   File "/usr/lib/python2.7/site-packages/nova/image/glance.py", line 704, in _create_v2  <<<<--- [1]error from line 704.

2018-03-02 09:42:52.906 27746 ERROR nova.api.openstack.extensions     context, 2, 'create', **sent_service_image_meta) <<<<--- [2] the dictionary sent_service_image_meta which contains the custom property keys and values.

2018-03-02 09:42:52.906 27746 ERROR nova.api.openstack.extensions TypeError: call() got multiple values for keyword argument 'version' <<<<--- [3]regarding multiple values for 'version'  <<<<--- as from the call() method.

[1] As we can see as per the logs the error is coming from line 704 in the /usr/lib/python2.7/site-packages/nova/image/glance.py of Nova code, we would further need to investigate it.

[2] Here we see the code line which is raising the error, as described above in the [2] it is from the sent_service_image_meta dictionary.

# sed -n 704,705p /usr/lib/python2.7/site-packages/nova/image/glance.py
        image = self._client.call(
            context, 2, 'create', **sent_service_image_meta)

To debug it further, checking self._client attribute value:

# grep "self._client " /usr/lib/python2.7/site-packages/nova/image/glance.py
        self._client = client or GlanceClientWrapper()
        self._client = client or GlanceClientWrapper()

[3] sent_service_image_meta dictionary values are conflicting in the call() method with parameter 'version'.

Here where call() is defined under the GlanceClientWrapper() class, for further tracing let's print the call() from this class.

Output from the file: /usr/lib/python2.7/site-packages/nova/image/glance.py

class GlanceClientWrapper(object):
    """Glance client wrapper class that implements retries."""

####*** omitting rest of the output except the defined call function ***####

    def call(self, context, version, method, *args, **kwargs): 

As we can see above the call() method already defines self, context, version & method parameters along with the **kwargs dictionary.

**kwargs is the dictionary which will take input of your property in image from the sent_service_image_meta. The property key name cannot be conflicting with the other parameters such as self, context, version, method.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.