nova-manage db online_data_migrations can fail when upgrading to newton under certain conditions

Bug #1696417 reported by Trygve Vea
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Confirmed
Undecided
Unassigned

Bug Description

Reproduceable under conditions:

* Mitaka upgraded to Newton
* online_data_migrations have not yet migrated flavors and/or aggregates from the nova database, to the nova-api database
* One or more of the datetime-fields (created_at, updated_at, deleted_at) are set.
** Because a custom flavor has been created
** Because a flavor has been updated
** Because a flavor has been deleted (deleted flavors are probably not relevant, as the new table have no deleted flag, it just removes them altogether)

Steps to reproduce:

* Run 'nova-manage db online_data_migrations'

It throws an error message like:
Error attempting to run <function migrate_flavors at 0x488f398>

Workaround:

* Set created_at,updated_at and deleted_at to NULL
* Run migration

I have done quite a bit of troubleshooting, but haven't managed to write a patch so far. As far as I can tell, inserting a flavor or aggregate to the new tables fail due to the datetime fields including a timezone. There exists code for stripping away the timezone in nova/db/sqlalchemy/api.py (convert_objects_related_datetimes) - but the timezone reappears in nova/objects/flavor.py

Revision history for this message
Sylvain Bauza (sylvain-bauza) wrote :

Could you please provide more details about at least the stacktrace ?

Changed in nova:
status: New → Incomplete
Revision history for this message
Trygve Vea (trygve-vea-gmail) wrote :

There is no stacktrace to provide, the output of command is:

# nova-manage db online_data_migrations
Option "rpc_backend" from group "DEFAULT" is deprecated for removal. Its value may be silently ignored in the future.
Option "notification_topics" from group "DEFAULT" is deprecated. Use option "topics" from group "oslo_messaging_notifications".
Running batches of 50 until complete
Error attempting to run <function migrate_flavors at 0x63f3848>
Error attempting to run <function migrate_aggregates at 0x634f7d0>

Adding --verbose or --debug does not change the output either.

Revision history for this message
Jessica Repka (jrepka) wrote :

There's a workaround for this,
Run these in this order

nova-manage db sync;
nova-manage api_db sync;
nova-manage db online_data_migrations;

Recently ran into this out of nowhere, this seems to resolve the issue.

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

Automatically discovered version mitaka in description. If this is incorrect, please update the description to include 'nova version: ...'

tags: added: openstack-version.mitaka
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for OpenStack Compute (nova) because there has been no activity for 60 days.]

Changed in nova:
status: Incomplete → Expired
Revision history for this message
Guang Yee (guang-yee) wrote :

I also ran into this exact same issue. We have mysql as the backend. And the datetime type is not timezone aware. Neither "--verbose" and "--debug" are effective for the online_data_migrations command as they are not being taken into consideration. I ended up manually printing out the traceback by adding these two lines

import sys, traceback
traceback.print_exc(file=sys.stdout)

here https://github.com/openstack/nova/blob/stable/newton/nova/cmd/manage.py#L897

And able to see more information on the failure. Here's a sample traceback.

Running batches of 50 until complete
-------------- 2017-05-19 23:34:43+00:00 -----------------
Error attempting to run <function migrate_flavors at 0x7f5a0d758e60>
Traceback (most recent call last):
  File "/opt/stack/venv/nova-20170728T171245Z/lib/python2.7/site-packages/nova/cmd/manage.py", line 892, in _run_migration
    found, done = migration_meth(ctxt, count)
  File "/opt/stack/venv/nova-20170728T171245Z/lib/python2.7/site-packages/nova/objects/flavor.py", line 717, in migrate_flavors
    flavor._flavor_create(ctxt, flavor_values)
  File "/opt/stack/venv/nova-20170728T171245Z/lib/python2.7/site-packages/nova/objects/flavor.py", line 463, in _flavor_create
    return _flavor_create(context, updates)
  File "/opt/stack/venv/nova-20170728T171245Z/lib/python2.7/site-packages/oslo_db/sqlalchemy/enginefacade.py", line 824, in wrapper
    return fn(*args, **kwargs)
  File "/opt/stack/venv/nova-20170728T171245Z/lib/python2.7/site-packages/nova/objects/flavor.py", line 166, in _flavor_create
    raise db_exc.DBError(e)
DBError: (_mysql_exceptions.OperationalError) (1292, "Incorrect datetime value: '2017-05-19 23:34:43+00:00' for column 'created_at' at row 1") [SQL: u'INSERT INTO flavors (created_at, updated_at, id, name, memory_mb, vcpus, root_gb, ephemeral_gb, flavorid, swap, rxtx_factor, vcpu_weight, disabled, is_public) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'] [parameters: (datetime.datetime(2017, 5, 19, 23, 34, 43, tzinfo=<iso8601.Utc>), None, 16, 'foo', 1024, 1, 2, 0, '50aae60f-ba2a-40d8-a0c3-2117ba0dd2a6', 0, 1.0, 0, 0, 0)]

Looks like migrations code is attempting to insert a timezone aware datetime field into mysql.

Changed in nova:
status: Expired → Confirmed
Revision history for this message
Guang Yee (guang-yee) wrote :

But the fix is a bit complicated. I can think of a few option.

1. expose a global configurable option in oslo.versionedobjects to set the tzinfo_aware option.

https://github.com/openstack/oslo.versionedobjects/blob/master/oslo_versionedobjects/fields.py#L453

It shouldn't be per class as a given DB is either timezone-aware or not.

2. expose the option at the service level (i.e. in Nova config) and pass in the tzinfo_aware parameter when we instantiate the DateTimeField.

3. expose a global option in oslo.db and do the conversion there.

Revision history for this message
Guang Yee (guang-yee) wrote :

Pushed a patch for option #1 here

https://review.openstack.org/#/c/502189/

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.