Create server with an image containing a long unicode property value fails

Bug #1425657 reported by Samuel Matzek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Samuel Matzek

Bug Description

Creating a sever using a Glance image which has a long (~256 char) unicode property value fails with database truncation.

The root cause is the same as bug:
https://bugs.launchpad.net/nova/+bug/1389102
and fix:
https://review.openstack.org/#/c/134597/

What's happening is the nova.utils.get_system_metadata_from_image method is truncating the Glance property value to 255 characters and this is then later used downstream in the create to be written to system metadata. Databases like PostgreSQL will throw an error because when the non-English locale string is encoded to be written to the DB it is greater than the 256 limit of the system metadata database table.

A partial stack is:
...
File "/usr/lib/python2.7/site-packages/nova/api/openstack/compute/servers.py", line 610, in create
  check_server_group_quota=check_server_group_quota)
File "/usr/lib/python2.7/site-packages/nova/hooks.py", line 149, in inner
  rv = f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/nova/compute/api.py", line 1485, in create
  check_server_group_quota=check_server_group_quota)
File "/usr/lib/python2.7/site-packages/nova/compute/api.py", line 1127, in _create_instance
  instance_group, check_server_group_quota)
File "/usr/lib/python2.7/site-packages/nova/compute/api.py", line 965, in _provision_instances
  quotas.rollback()
File "/usr/lib/python2.7/site-packages/oslo_utils/excutils.py", line 82, in __exit__
  six.reraise(self.type_, self.value, self.tb)
File "/usr/lib/python2.7/site-packages/nova/compute/api.py", line 928, in _provision_instances
  num_instances, i, shutdown_terminate)
File "/usr/lib/python2.7/site-packages/nova/compute/api.py", line 1385, in create_db_entry_for_new_instance
  instance.create()
File "/usr/lib/python2.7/site-packages/nova/objects/base.py", line 206, in wrapper
  return fn(self, ctxt, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/nova/objects/instance.py", line 613, in create
  db_inst = db.instance_create(context, updates)
File "/usr/lib/python2.7/site-packages/nova/db/api.py", line 636, in instance_create
  return IMPL.instance_create(context, values)
File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/api.py", line 145, in wrapper
  return f(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/nova/db/sqlalchemy/api.py", line 1595, in instance_create
....

The fix for this defect will likely be taking the fix from https://review.openstack.org/#/c/134597/ and making a utility method in nova.utils to do safe truncation. This utility method could then be called from nova.utils.get_system_metadata_from_image method and its existing location in nova/compute/utils.py

Found in Nova Kilo.

Tags: quotas
Revision history for this message
Davanum Srinivas (DIMS) (dims-v) wrote :

Samuel, will you be filing a review?

Changed in nova:
status: New → Confirmed
importance: Undecided → Low
Revision history for this message
Samuel Matzek (smatzek) wrote :

I plan to file a bug fix / code review for this along the lines of what I describe in the bug description. I will probably get to this next week.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/161549

Changed in nova:
assignee: nobody → Samuel Matzek (smatzek)
status: Confirmed → In Progress
Joe Gordon (jogo)
tags: added: quotas
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/161549
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=8ec6a73fef7d26301481935dcd5999c7cd419cba
Submitter: Jenkins
Branch: master

commit 8ec6a73fef7d26301481935dcd5999c7cd419cba
Author: Samuel Matzek <email address hidden>
Date: Wed Mar 4 20:17:08 2015 -0600

    Truncate encoded instance sys meta to 255 or less

    In nova/utils.py function get_system_metadata_from_image converts
    image metadata into instance system metadata. Since Nova's DB
    column is limited to 255 characters for system metadata, the image
    properties are truncated to 255 characters. However, the Glance
    image may have non-English unicode property values that are longer
    than 255 after being encoded to bytes. We need to truncate the
    encoded byte property value to 255 or fewer bytes in order to ensure
    the DB insert operation succeeds. The same encoding and truncation
    issue was fixed for the instance fault table under change id
    I62fa2830b22e367eb9486d09d3c8818a18ebd20d. This fix refactors
    that code fix into a utility method and uses it to fix both problems.

    Change-Id: Ie1051777dd09a2fb91afbadad3728956f83452cf
    Closes-Bug: #1425657
    Related-Bug: #1389102

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → kilo-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: kilo-3 → 2015.1.0
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.