def test_migrate_nova_databases(self, check_output): "Migrate database with nova-manage" self.relation_ids.return_value = [] self.os_release.return_value = 'diablo' utils.migrate_nova_databases() check_output.assert_called_with(['nova-manage', 'db', 'sync']) self.assertTrue(self.enable_services.called) self.cmd_all_services.assert_called_with('start')
def test_migrate_nova_databases_cluster(self, check_output): "Migrate database with nova-manage in a clustered env" self.relation_ids.return_value = ['cluster:1'] self.os_release.return_value = 'diablo' utils.migrate_nova_databases() check_output.assert_called_with(['nova-manage', 'db', 'sync']) self.assertNotIn(call(['nova-manage', 'db', 'online_data_migrations']), check_output.mock_calls) self.peer_store.assert_called_with('dbsync_state', 'complete') self.assertTrue(self.enable_services.called) self.cmd_all_services.assert_called_with('start')
def leader_init_db_if_ready(skip_acl_check=False, skip_cells_restarts=False, db_rid=None, unit=None): """Initialise db if leader and db not yet intialised. NOTE: must be called from database context. """ if not is_leader(): log("Not leader - skipping db init", level=DEBUG) return if is_db_initialised(): log("Database already initialised - skipping db init", level=DEBUG) return # Bugs 1353135 & 1187508. Dbs can appear to be ready before the units # acl entry has been added. So, if the db supports passing a list of # permitted units then check if we're in the list. allowed_units = relation_get('nova_allowed_units', rid=db_rid, unit=unit) if skip_acl_check or (allowed_units and local_unit() in allowed_units.split()): status_set('maintenance', 'Running nova db migration') migrate_nova_databases() log('Triggering remote cloud-compute restarts.') [ compute_joined(rid=rid, remote_restart=True) for rid in relation_ids('cloud-compute') ] log('Triggering remote neutron-network-service restarts.') [ quantum_joined(rid=rid, remote_restart=True) for rid in relation_ids('quantum-network-service') ] if not skip_cells_restarts: log('Triggering remote cell restarts.') [ nova_cell_relation_joined(rid=rid, remote_restart=True) for rid in relation_ids('cell') ] else: log('allowed_units either not presented, or local unit ' 'not in acl list: %s' % repr(allowed_units))
def test_migrate_nova_databases_ocata(self, cellv2_ready, get_cell_uuid, check_output): "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 = 'ocata' 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']), ]) self.peer_store.assert_called_with('dbsync_state', 'complete') self.assertTrue(self.enable_services.called) self.cmd_all_services.assert_called_with('start')