Comment 9 for bug 1269935

Revision history for this message
Ankit Agrawal (ankitagrawal) wrote :

Hi, I tested this issue with latest code and found following points

1. Call glance api update image using curl command (with metadata 'tesinsg\nisssue')
$ curl -i 'http://10.69.4.178:9292/v1/images/ce33c155-91bc-4b85-b9d0-a8735b35536f' -X PUT -H 'Accept-Encoding: gzip, deflate' -H 'Accept: */*' -H 'User-Agent: python-glanceclient' -H 'x-glance-registry-purge-props: false' -H 'Content-Type: application/octet-stream' -H 'X-Auth-Token: 5552cacaade544ceade9489317b4d446' -H 'x-image-meta-property-test: tesinsg\nisssue'

Result: Status 200. There is no issue and metadata value is saved as it is (with containing '\n').

2. Update image using python-glanceclient
$ glance image-update ce33c155-91bc-4b85-b9d0-a8735b35536f --property testkey=akt\nagrawal

Result: Status 200. '\' is removed from the metadata value and stored value will be testkey=aktnagrawal ('\' is removed).
Analysis: '\' is a special character in python which is escaped by "sys.argv".

The correct ways to add new line using python-glanceclient
a) $ glance image-update ce33c155-91bc-4b85-b9d0-a8735b35536f --property testkey=akt\\nagrawal -- (with '\\n')
b) $ glance image-update ce33c155-91bc-4b85-b9d0-a8735b35536f --property testkey='akt\nagrawal'
c) $ glance image-update ce33c155-91bc-4b85-b9d0-a8735b35536f --property testkey="akt\nagrawal"

3. Call nova api update image using curl command
$ curl -i 'http://10.69.4.178:8774/v2/8327f833d88c42d693d9b38d3400565c/images/ce33c155-91bc-4b85-b9d0-a8735b35536f/metadata' -X POST -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: python-novaclient" -H "X-Auth-Project-Id: admin" -H "X-Auth-Token: 5552cacaade544ceade9489317b4d446" -d '{"metadata": {"key1": "firstline\nsecondline", "application_version": "1"}}'

Result: Status 200. All the characters after (including) '\n' is removed from the metadata value.

Data is being lost when calling "self.session.request()" method from "_request" method of python-glanceclient/glanceclient/common/http.py module.
self.session is an object of requests.Session() which is a third party library, so IMO this issue can not be handled from glance or glance-client.

The correct way to add new line in metadata is to send with "\\n".