db: Trivial style changes

Rewrap some code just to make it a little less fugly to read.

Change-Id: If78bbd578bbba73fc85446ad55d34d3addd6c4af
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2021-06-16 14:05:37 +01:00
parent 38a022166f
commit c3e113eb31
2 changed files with 39 additions and 26 deletions

View File

@ -181,23 +181,30 @@ class DbCommands(object):
# NOTE(mdoff): Multiple cells not yet implemented. Currently
# fanout only looks for cell0.
try:
cell_mapping = objects.CellMapping.get_by_uuid(ctxt,
objects.CellMapping.CELL0_UUID)
cell_mapping = objects.CellMapping.get_by_uuid(
ctxt, objects.CellMapping.CELL0_UUID,
)
with context.target_cell(ctxt, cell_mapping) as cctxt:
migration.db_sync(version, context=cctxt)
except exception.CellMappingNotFound:
print(_('WARNING: cell0 mapping not found - not'
' syncing cell0.'))
msg = _(
'WARNING: cell0 mapping not found - not syncing cell0.'
)
print(msg)
except Exception as e:
print(_("""ERROR: Could not access cell0.
Has the nova_api database been created?
Has the nova_cell0 database been created?
Has "nova-manage api_db sync" been run?
Has "nova-manage cell_v2 map_cell0" been run?
Is [api_database]/connection set in nova.conf?
Is the cell0 database connection URL correct?
Error: %s""") % str(e))
msg = _(
'ERROR: Could not access cell0.\n'
'Has the nova_api database been created?\n'
'Has the nova_cell0 database been created?\n'
'Has "nova-manage api_db sync" been run?\n'
'Has "nova-manage cell_v2 map_cell0" been run?\n'
'Is [api_database]/connection set in nova.conf?\n'
'Is the cell0 database connection URL correct?\n'
'Error: %s'
)
print(msg % str(e))
return 1
return migration.db_sync(version)
def version(self):

View File

@ -10,8 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
"""
Tests for database migrations.
"""Tests for database migrations.
There are "opportunistic" tests which allows testing against all 3 databases
(sqlite in memory, mysql, pg) in a properly configured unit test environment.
@ -48,7 +48,7 @@ class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
"""Test that the models match the database after migrations are run."""
def setUp(self):
super(NovaAPIModelsSync, self).setUp()
super().setUp()
self.engine = enginefacade.writer.get_engine()
def db_sync(self, engine):
@ -76,7 +76,6 @@ class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
def filter_metadata_diff(self, diff):
# Filter out diffs that shouldn't cause a sync failure.
new_diff = []
# Define a whitelist of ForeignKeys that exist on the model but not in
@ -87,12 +86,14 @@ class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
# DB at a later release and aren't on a model anymore.
column_whitelist = {
'build_requests': ['vm_state', 'instance_metadata',
'display_name', 'access_ip_v6', 'access_ip_v4', 'key_name',
'locked_by', 'image_ref', 'progress', 'request_spec_id',
'info_cache', 'user_id', 'task_state', 'security_groups',
'config_drive'],
'resource_providers': ['can_host'],
'build_requests': [
'vm_state', 'instance_metadata',
'display_name', 'access_ip_v6', 'access_ip_v4', 'key_name',
'locked_by', 'image_ref', 'progress', 'request_spec_id',
'info_cache', 'user_id', 'task_state', 'security_groups',
'config_drive',
],
'resource_providers': ['can_host'],
}
for element in diff:
@ -106,17 +107,22 @@ class NovaAPIModelsSync(test_migrations.ModelsMigrationsSync):
fkey = element[1]
tablename = fkey.table.name
column_keys = fkey.column_keys
if (tablename in fkey_whitelist and
column_keys == fkey_whitelist[tablename]):
if (
tablename in fkey_whitelist and
column_keys == fkey_whitelist[tablename]
):
continue
elif element[0] == 'remove_column':
tablename = element[2]
column = element[3]
if (tablename in column_whitelist and
column.name in column_whitelist[tablename]):
if (
tablename in column_whitelist and
column.name in column_whitelist[tablename]
):
continue
new_diff.append(element)
return new_diff