def upgrade_db(orig_id, seed_id, db_role_name): orig_env = environment_obj.Environment(orig_id) seed_env = environment_obj.Environment(seed_id) env_util.delete_fuel_resources(seed_env) # Wait for Neutron to reconfigure networks time.sleep(7) # FIXME: Use more deterministic way maintenance.disable_apis(orig_env) maintenance.stop_corosync_services(seed_env) maintenance.stop_upstart_services(seed_env) expected_dbs = set(magic_consts.OS_SERVICES) existing_dbs = set(db.get_databases(orig_env)) dbs = existing_dbs & expected_dbs if len(dbs) < len(magic_consts.OS_SERVICES): LOG.info('Skipping nonexistent tables: %s', ', '.join(expected_dbs - existing_dbs)) LOG.info('Will dump tables: %s', ', '.join(dbs)) fname = os.path.join(magic_consts.FUEL_CACHE, 'dbs.original.sql.gz') db.mysqldump_from_env(orig_env, db_role_name, dbs, fname) fname2 = os.path.join( magic_consts.FUEL_CACHE, 'dbs.original.cluster_%s.sql.gz' % (orig_env.data['id'],), ) shutil.copy(fname, fname2) db.mysqldump_restore_to_env(seed_env, db_role_name, fname) db.db_sync(seed_env)
def upgrade_db(orig_id, seed_id, db_role_name): orig_env = environment_obj.Environment(orig_id) seed_env = environment_obj.Environment(seed_id) env_util.delete_fuel_resources(seed_env) # Wait for Neutron to reconfigure networks time.sleep(7) # FIXME: Use more deterministic way maintenance.disable_apis(orig_env) maintenance.stop_corosync_services(seed_env) maintenance.stop_upstart_services(seed_env) expected_dbs = set(magic_consts.OS_SERVICES) existing_dbs = set(db.get_databases(orig_env)) dbs = existing_dbs & expected_dbs if len(dbs) < len(magic_consts.OS_SERVICES): LOG.info('Skipping nonexistent tables: %s', ', '.join(expected_dbs - existing_dbs)) LOG.info('Will dump tables: %s', ', '.join(dbs)) fname = os.path.join(magic_consts.FUEL_CACHE, 'dbs.original.sql.gz') db.mysqldump_from_env(orig_env, db_role_name, dbs, fname) fname2 = os.path.join( magic_consts.FUEL_CACHE, 'dbs.original.cluster_%s.sql.gz' % (orig_env.data['id'], ), ) shutil.copy(fname, fname2) db.mysqldump_restore_to_env(seed_env, db_role_name, fname) db.db_sync(seed_env)
def test_db_sync(mocker, node, mock_subprocess, mock_ssh_call): get_one_controller = mocker.patch('octane.util.env.get_one_controller') get_one_controller.return_value = node db.db_sync('env') assert not mock_subprocess.called assert all(call[1]['parse_levels'] for call in mock_ssh_call.call_args_list) assert all(call[1]['node'] == node for call in mock_ssh_call.call_args_list)