Commit Graph

19 Commits

Author SHA1 Message Date
Stephen Finucane 833b7b60dd db: Compact Icehouse database migrations
Compacts Icehouse database migrations into a single migration,
'234_icehouse.py'.

Users will now need to update to Icehouse before updating to Juno or
later.

Specific changes include:

- Drop all references to dump tables entirely, since they were added in
  216 and dropped in 232.
- Drop the 'compute_node_stats' table in favour of a 'stats' column on
  the 'compute_nodes' table
- Add 'metrics' and 'extra_resources' to 'compute_nodes'
- Add 'ephemeral_key_uuid' to 'instances'
- Add 'host' and 'details' to 'instance_actions_events'
- Add an index to the 'reservations' table covering the 'deleted' and
  'expire' columns

Change-Id: I17db7cdaad2c6368092b4fb00d5959711ad249f9
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-01-07 11:47:43 +00:00
Stephen Finucane 4701d28da3 db: Drop "remove" of index
We were simply referencing this function - not calling it. This has been
this way since commit 817baeb937 was first merged way back in 2013 so
it clearly has not been missed.

Change-Id: I2623bd4fe91906e928e891fb3250c02873d7fb09
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-01-07 11:47:43 +00:00
Stephen Finucane b7ba576cdd db: Merge in unique constraints
These can go inline, so do just that.

Change-Id: I7f708e93d5074395f962dc8f6b1ee355ddab66e8
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-01-07 11:47:43 +00:00
Stephen Finucane d693d755db db: Clean up base migration
We're going to be flattening these migrations is short order. Start by
cleaning up the existing base migration to remove some of the oddities
and generally make merging of migrations as painless as possible.

A comparison of schemas before and after this [1] shows no significant
differences.

[1] https://that.guru/blog/comparing-nova-db-migrations/

Change-Id: I883562754f9330f9c797813714d8fe5b74227027
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-01-07 11:47:43 +00:00
Mohammed Naser b39d8b8c96 db: fix database migrations when name includes dash
If the name of the database used includes a dash, it will fail the
migrations with an error like this:

  You have an error in your SQL syntax; check the manual that corresponds to
  your MySQL server version for the right syntax to use near '-cell0 DEFAULT
  CHARACTER SET utf8' at line 1

Even more difficult, any future migration fails with the instances table
already existing making it very hard to troubleshoot.  This patch fixes
it by wrapping the schema name in the query.

Closes-Bug: #1892370
Change-Id: Ic96dc415396985737b5bdeffed61077af5f245e6
2020-08-20 09:45:02 -04:00
Eric Fried 8899f8b5b5 Hacking N363: `in (not_a_tuple)`
A few places in the code had conditionals including:

 if something in (element):

which was clearly intended to be

 if something in (element,):

(I.e. `in $tuple`, not `in element` with redundant parens) or just

 if something == element:

Fix those [1] and introduce hacking rule N363 to disallow this kind of
thing in the future.

[1] NOTE: These weren't actually latent bugs because

 'foo' in ('foo')

which is the same as

 'foo' in 'foo'

returns True. In order to be a bug, the left operand would have to be
able to be a substring of the right:

 'foo' in ('foobar')  # True
 'foo' in ('foobar',) # False

...which I don't think is possible in any of the scenarios found.

Change-Id: I950d07eb533e0d43466c58e36b314aaaf8560251
2019-06-07 16:08:12 -05:00
Ngo Quoc Cuong efae7d796a Remove translation of log messages
The i18n team has decided not to translate the logs because it
seems like it not very useful; operators prefer to have them in
English so that they can search for those strings on the internet.

Partially fix on nova/conductor, nova/console, nova/consoleauth,
nova/db and nova/image other paths will be fixed on next commits

Change-Id: I132f60cb4743f85c96ec5231d6f860cfb0815758
2017-07-18 09:03:39 +00:00
zhangyanxian 95c63d9317 Fix typo in 216_havana.py
TrivialFix

Change-Id: Ia25cf822ddf77de32efcfb75dd1ab17efc081929
2017-01-20 06:35:09 +00:00
Sean Dague cdf74c57a6 remove db2 support from tree
This removes db2 support from tree completely. This is an oddball non
open database that made doing live data migrations difficult. It is
used by 0% of users in the OpenStack User Survey.

Supporting commercial software that doesn't have users at the cost of
delivering features and fixes to our community is the wrong
tradeoff. This corrects that.

It rewrites migrations, which we typically don't ever do, but it is
better if newton fresh environments fail early in db creation instead
of very deep in the data migration process.

Change-Id: Ifeb9929e4515e3483eb65d371126afd7672b92a4
2016-05-23 07:33:20 -04:00
Dan Smith 1a1a41bdbe Remove flavor seeding from the base migration
In a time long ago and a land far far away, someone thought it was a
good idea to populate the database with default flavors. That was
probably reasonable at the time, but it no longer makes sense and
in fact causes us some pain now.

This patch removes those default flavors from the database. That means
that new deploys will not have them, but doesn't actually rewrite
history in any way.

This will require changes to our docs, which largely assume the presence
of these default flavors from time zero.

DocImpact

Depends-On: Ic275887e97221d9ce5ce6f12cdcfb5ac94e300b0
Change-Id: I80b63ce1ebca01be61ac0f43d26a2992ecf16678
2016-04-05 08:01:33 -07:00
Matt Riedemann 9a84211729 Add DB2 support
Notes on migration changes/tests:

1. The initial havana migration does not create any foreign keys which
   require the instances.uuid column since it's nullable and DB2 won't
   allow creating a unique constraint over a nullable column. To create
   the foreign keys on instances.uuid, this change depends on commit
   e07a2b2d4b to make instances.uuid
   non-nullable and create a unique constraint on that column. Then
   the new migration here creates the missing instances.uuid
   related foreign keys for DB2.

2. Commit b930fb3a6b changed
   test_migrations.py to use oslo.db's opportunistic test fixture
   which currently only supports sqlite/mysql/postgresql. Unit test
   support for DB2 therefore needs to be added to oslo.db and then
   hooked into nova, but that's targeted for the 2016.1 'M' release
   so is not part of this change.

3. The 247_nullable_mismatch migration is updated for DB2 because
   making the pci_devices.deleted column nullable=True fails since
   the column is in a UniqueConstraint already (DB2 would require
   it to be in a unique index instead for the column to be nullable).
   There is a foreign key involved (created in 246) so for DB2 to
   have the same FKey it requires a UC and that requires the deleted
   column to be non-null, which doesn't work with the SoftDeleteMixin.
   So in this case the schema will diverge for DB2 until we make
   the deleted column non-nullable for all tables.

4. The 252_add_instance_extra_table migration is updated for DB2
   because a foreign key is created between the instance_extra
   table and the instances.uuid column (which is nullable at the
   time) so we have to handle that foreign key constraint creation
   in the 296 migration with the other foreign keys to
   instances.uuid.

5. The 271 migration is updated to add ibm_db_sa the same as
   sqlite and postgresql since it works the same in this case for
   DB2.

6. The API migrations need checks for DB2 to avoid a duplicate index
   SQL0605W error since DB2 implicitly creates an Index when a
   UniqueConstraint is created and will fail if trying to add a
   duplicate index on the same column(s) that are in the UC.

Implements blueprint db2-database

Change-Id: Ic4224e2545bcdfeb236b071642f9f16d9ee3b99f
2015-07-08 16:45:37 -07:00
Victor Stinner 2daf8c38ad Fix Python 3 issues in nova.db.sqlalchemy
* Replace dict(obj.iteritems()) with dict(obj) where obj is a dictionary
  or an oslo.db object
* Replace obj.iteritems() with obj.items() where obj is a dictionary:
  obj.items() works on Python 2 and Python 3.
* Replace filter() and map() with list-comprehension using if when a list is
  expected. On Python 3, filter() and map() return an iterator.
* Replace obj.keys() with list(obj.keys()) when a list is expected.
  Replace obj.keys()[0] with list(obj.keys())[0]. On Python 3,
  dict.keys() now returns an iterator.
* Replace (int, long) with six.integer_types
* Get the name of a function using the __name__ attribute, instead of
  the func_name attribute. The func_name attribute was removed
  in Python 3.
* InstanceTypeTestCase: use dict.update() to combine dictionaries
  instead of using dict.items()+reduce()+dict()
* matchers.py: replace StringIO.StringIO with six.StringIO.
* tox.ini: add nova.tests.unit.db.test_db_api to Python 3.4

Blueprint nova-python3
Change-Id: Iae4f6d971818d5b38e838a83753a0707e954bb04
2015-06-30 07:06:54 -07:00
Sean Dague e2e846f74b remove downgrade support from our database migrations
The TC approved a cross project spec to stop putting db downgrade into
project migration repos:
https://github.com/openstack/openstack-specs/blob/master/specs/no-downward-sql-migration.rst
This was done after quite a bit of feedback from the operator
community, and everyone was good with it.

This implements that spec for Nova, adjust the tests to pass
accordingly, and changes the test which requires downgrade functions
to one that prohibits them.

Implements bp nova-no-downward-sql-migration

Change-Id: I9b164b748998530d62bbc6baf356a9c3f61584cc
2015-04-21 10:29:35 -04:00
Davanum Srinivas 97d63d8745 Use oslo.log
Convert the use of the incubated version of the log module
to the new oslo.log library.

Sync oslo-incubator modules to update their imports as well.

Co-Authored-By: Doug Hellmann <doug@doughellmann.com>
Change-Id: Ic4932e3f58191869c30bd07a010a6e9fdcb2a12c
2015-02-22 07:56:40 -05:00
Mike Durnosvistov b7535793af Replacement `_` on `_LE` in all LOG.exception
oslo.i18n uses different marker functions to separate the
translatable messages into different catalogs, which the translation
teams can prioritize translating.  For details, please refer to:
http://docs.openstack.org/developer/oslo.i18n/guidelines.html#guidelines-for-use-in-openstack

There were not marker fuctions some places in directory network.
This commit makes changes:
* Add missing marker functions
* Use ',' instead of '%' while adding variables to log messages

Added a hacking rule for the log exception about checking
translation for it.

Change-Id: If80ea6f177bb65afcdffce71550bb38fedcc54eb
2014-11-20 11:19:09 +02:00
Angus Lees f3cc688405 Issue multiple SQL statements in separate engine.execute() calls
Some sqlalchemy drivers (eg: mysqlconnector) don't support
engine.execute("sql stmt 1; sql stmt 2;") and require a separate
execute() call for each SQL statement.  After discussions with
sqlalchemy author, he confirmed it would be better to fix callers rather
than attempt to patch in support for multiple statements.

With this patch, nova-manage db sync succeeds using mysqlconnector.

Change-Id: I57e6ecdafe90110eaffe757f0ef0bf7b41b0f3e3
2014-07-31 14:03:45 +10:00
Davanum Srinivas 826aed0ec7 Use oslo.i18n
oslo.i18n provides the i18n functions that were provided by
oslo-incubator's gettextutils module. Some tests that were
using internal details of the library were removed.

Change-Id: I44cfd5552e0dd86af21073419d31622f5fdb28e0
2014-07-18 14:28:09 -04:00
liu-sheng 74f953a1d7 Remove vi modelines
We don't need to have the vi modelines in each source file,
it can be set in a user's vimrc if required.

Also a check is added to hacking to detect if they are re-added.

Change-Id: I347307a5145b2760c69085b6ca850d6a9137ffc6
Closes-Bug: #1229324
2014-02-03 14:19:44 +00:00
Dan Prince 029ebabc54 Finish compacting pre-Icehouse database migrations
Compacts the pre-Icehouse database migrations into a
single migration (216_havana.py).

Pre-Icehouse users will now need to upgrade to Havana before
running any Icehouse migrations.

Tested on MySQL and PostgreSQL schemas on Fedora 19 to ensure the
new compacted migration generates an identical schema to the
previous migrate scripts in Havana.

Specific changes include:

  1) Add aggregate metadata unique constraint.

  2) Fix migrations index (add deleted column).

  3) Add pci_devices table.

  4) fix migrations_instance_uuid_and_status_idx index.

Implements: blueprint compact-havana-db-migrations

Change-Id: Id96e13b0ed65837761bd173c9e32ebcc1ff5f376
2014-01-27 13:35:04 -05:00