Configure placement DB context manager for nova-manage/status

The create_incomplete_consumers online data migration was added in
Rocky via change Id609789ef6b4a4c745550cde80dd49cabe03869a. That
relies on hitting some tables in the API (or placement) database.
The DB API code for that migration relies on a placement context
manager which looks like it was regressed with change
I2fff528060ec52a4a2e26a6484bdf18359b95f77 (also in Rocky). This
results in a DB error trying to query the projects table but
because of a generic try/except in _run_migration, the failure
was missed in CI testing.

Similarly, the nova-status upgrade check "_check_resource_providers"
routine also uses the placement DB API context manager to count the
number of compute resource providers in the API (or placement) DB,
which is returning 0 because it's not using the proper DB connection.
This was not caught in the nova-status CLI tests because they use
the DatabaseFixture which *does* configure the global placement DB
API context manager.

This adds the configuration of the global placement DB API context
manager so we can properly query the placement-related tables.
The blanket problematic try/except from _run_migration is left
as-is in this change but will be addressed in a separate patch.

Integration testing of this fix is being performed with devstack:

  https://review.openstack.org/599847/

Change-Id: I9d97b7a904e2b7d15c763e2a067cc5909cc6c9c5
Closes-Bug: #1790701
Closes-Bug: #1790721
(cherry picked from commit 63c10d2d53)
This commit is contained in:
Matt Riedemann 2018-09-04 14:53:25 -04:00
parent 30a509018a
commit 7f25c3e607
3 changed files with 16 additions and 4 deletions

View File

@ -44,7 +44,6 @@ import six
import six.moves.urllib.parse as urlparse
from sqlalchemy.engine import url as sqla_url
from nova.api.openstack.placement import db_api as placement_db
from nova.api.openstack.placement.objects import consumer as consumer_obj
from nova.cmd import common as cmd_common
from nova.compute import api as compute_api
@ -853,8 +852,6 @@ class ApiDbCommands(object):
# the placement sync to and with the api sync.
result = True
if CONF.placement_database.connection is not None:
# Establish the independent context manager for the placement db.
placement_db.configure(CONF)
result = migration.db_sync(version2, database='placement')
return migration.db_sync(version2, database='api') and result

View File

@ -18,6 +18,7 @@
from oslo_log import log
from oslo_utils import importutils
from nova.api.openstack.placement import db_api as placement_db
from nova.common import config
import nova.conf
from nova.db.sqlalchemy import api as sqlalchemy_api
@ -61,3 +62,4 @@ def parse_args(argv, default_config_files=None, configure_db=True,
if configure_db:
sqlalchemy_api.configure(CONF)
placement_db.configure(CONF)

View File

@ -86,14 +86,27 @@ class ConfTest(test.NoDBTestCase):
class TestParseArgs(test.NoDBTestCase):
def setUp(self):
super(TestParseArgs, self).setUp()
m = mock.patch('nova.db.sqlalchemy.api.configure')
self.nova_db_config_mock = m.start()
self.addCleanup(self.nova_db_config_mock.stop)
m = mock.patch('nova.api.openstack.placement.db_api.configure')
self.placement_db_config_mock = m.start()
self.addCleanup(self.placement_db_config_mock.stop)
@mock.patch.object(config.log, 'register_options')
def test_parse_args_glance_debug_false(self, register_options):
self.flags(debug=False, group='glance')
config.parse_args([], configure_db=False, init_rpc=False)
self.assertIn('glanceclient=WARN', config.CONF.default_log_levels)
self.nova_db_config_mock.assert_not_called()
self.placement_db_config_mock.assert_not_called()
@mock.patch.object(config.log, 'register_options')
def test_parse_args_glance_debug_true(self, register_options):
self.flags(debug=True, group='glance')
config.parse_args([], configure_db=False, init_rpc=False)
config.parse_args([], configure_db=True, init_rpc=False)
self.assertIn('glanceclient=DEBUG', config.CONF.default_log_levels)
self.nova_db_config_mock.assert_called_once_with(config.CONF)
self.placement_db_config_mock.assert_called_once_with(config.CONF)