Only run map_instances for Ocata

map_instances only needs to be run during the transition from
Newton to Ocata to map existing instances into a cell. All
new Ocata instances will be automatically mapped to a call.
This change limits the slow running map_instances command to
just run for upgrades to Ocata

Change-Id: Ic2e2df530504284d28cfcab26a71d211342203fa
Closes-Bug: #1743357
This commit is contained in:
Liam Young 2018-01-15 12:04:00 +00:00
parent 33881c371b
commit a0778a5304
2 changed files with 35 additions and 2 deletions

View File

@ -839,7 +839,8 @@ def finalize_migrate_nova_databases():
@retry_on_exception(5, base_delay=3, exc_type=subprocess.CalledProcessError)
def migrate_nova_databases():
'''Runs nova-manage to initialize new databases or migrate existing'''
if CompareOpenStackReleases(os_release('nova-common')) < 'ocata':
release = CompareOpenStackReleases(os_release('nova-common'))
if release < 'ocata':
migrate_nova_api_database()
migrate_nova_database()
online_data_migrations_if_needed()
@ -851,7 +852,10 @@ def migrate_nova_databases():
migrate_nova_database()
online_data_migrations_if_needed()
add_hosts_to_cell()
map_instances()
# Populate the cells mapping table if upgrading to a cells
# environment for the first time eg Newton -> Ocata
if release == 'ocata':
map_instances()
finalize_migrate_nova_databases()

View File

@ -736,6 +736,35 @@ class NovaCCUtilsTests(CharmTestCase):
self.assertTrue(self.enable_services.called)
self.cmd_all_services.assert_called_with('start')
@patch('subprocess.Popen')
@patch('subprocess.check_output')
@patch.object(utils, 'get_cell_uuid')
@patch.object(utils, 'is_cellv2_init_ready')
def test_migrate_nova_databases_pike(self, cellv2_ready, get_cell_uuid,
check_output, Popen):
"Migrate database with nova-manage in a clustered env"
get_cell_uuid.return_value = 'c83121db-f1c7-464a-b657-38c28fac84c6'
self.relation_ids.return_value = ['cluster:1']
self.os_release.return_value = 'pike'
utils.migrate_nova_databases()
check_output.assert_has_calls([
call(['nova-manage', 'api_db', 'sync']),
call(['nova-manage', 'cell_v2', 'map_cell0']),
call(['nova-manage', 'cell_v2', 'create_cell', '--name', 'cell1',
'--verbose']),
call(['nova-manage', 'db', 'sync']),
call(['nova-manage', 'db', 'online_data_migrations']),
call(['nova-manage', 'cell_v2', 'discover_hosts', '--cell_uuid',
'c83121db-f1c7-464a-b657-38c28fac84c6', '--verbose']),
])
map_call = call([
'nova-manage', 'cell_v2', 'map_instances', '--cell_uuid',
'c83121db-f1c7-464a-b657-38c28fac84c6'])
self.assertFalse(map_call in Popen.call_args_list)
self.peer_store.assert_called_with('dbsync_state', 'complete')
self.assertTrue(self.enable_services.called)
self.cmd_all_services.assert_called_with('start')
@patch('subprocess.check_output')
def test_migrate_nova_flavors(self, check_output):
utils.migrate_nova_flavors()