From 34573ab524bf664b1a81f4b32848498c53e4b545 Mon Sep 17 00:00:00 2001 From: Daniel Vincze Date: Tue, 29 Oct 2024 15:26:01 +0200 Subject: [PATCH] Refactor DB layer Refactors include mostly renames of Replica into Transfer, and Migration into Deployment. They also include some DB column refactoring (removing unnecessary ones). --- coriolis/conductor/rpc/server.py | 67 ++- coriolis/db/api.py | 232 ++++---- .../versions/020_rename_tables.py | 30 ++ coriolis/db/sqlalchemy/models.py | 52 +- .../tests/api/v1/test_replica_schedules.py | 16 +- .../test_replica_tasks_execution_actions.py | 2 +- .../api/v1/test_replica_tasks_executions.py | 16 +- coriolis/tests/conductor/rpc/test_server.py | 496 +++++++++--------- .../tests/replica_cron/rpc/test_server.py | 4 +- coriolis/tests/replica_cron/test_api.py | 2 +- .../replica_tasks_executions/test_api.py | 2 +- coriolis/tests/replicas/test_api.py | 2 +- 12 files changed, 471 insertions(+), 450 deletions(-) create mode 100644 coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py diff --git a/coriolis/conductor/rpc/server.py b/coriolis/conductor/rpc/server.py index d8decbe7b..1d9bad4e3 100644 --- a/coriolis/conductor/rpc/server.py +++ b/coriolis/conductor/rpc/server.py @@ -487,7 +487,7 @@ def get_endpoint(self, ctxt, endpoint_id): @endpoint_synchronized def delete_endpoint(self, ctxt, endpoint_id): - q_replicas_count = db_api.get_endpoint_replicas_count( + q_replicas_count = db_api.get_endpoint_transfers_count( ctxt, endpoint_id) if q_replicas_count != 0: raise exception.NotAuthorized("%s replicas would be orphaned!" % @@ -1102,7 +1102,7 @@ def execute_replica_tasks(self, ctxt, replica_id, shutdown_instances): ctxt, replica.id, instance, replica.info[instance]) # add new execution to DB: - db_api.add_replica_tasks_execution(ctxt, execution) + db_api.add_transfer_tasks_execution(ctxt, execution) LOG.info("Replica tasks execution added to DB: %s", execution.id) uses_minion_pools = any([ @@ -1124,7 +1124,7 @@ def execute_replica_tasks(self, ctxt, replica_id, shutdown_instances): def get_replica_tasks_executions(self, ctxt, replica_id, include_tasks=False, include_task_info=False): - return db_api.get_replica_tasks_executions( + return db_api.get_transfer_tasks_executions( ctxt, replica_id, include_tasks, include_task_info=include_task_info, to_dict=True) @@ -1144,7 +1144,7 @@ def delete_replica_tasks_execution(self, ctxt, replica_id, execution_id): "Cannot delete execution '%s' for Replica '%s' as it is " "currently in '%s' state." % ( execution_id, replica_id, execution.status)) - db_api.delete_replica_tasks_execution(ctxt, execution_id) + db_api.delete_transfer_tasks_execution(ctxt, execution_id) @tasks_execution_synchronized def cancel_replica_tasks_execution(self, ctxt, replica_id, execution_id, @@ -1165,7 +1165,7 @@ def cancel_replica_tasks_execution(self, ctxt, replica_id, execution_id, def _get_replica_tasks_execution(self, ctxt, replica_id, execution_id, include_task_info=False, to_dict=False): - execution = db_api.get_replica_tasks_execution( + execution = db_api.get_transfer_tasks_execution( ctxt, replica_id, execution_id, include_task_info=include_task_info, to_dict=to_dict) if not execution: @@ -1176,7 +1176,7 @@ def _get_replica_tasks_execution(self, ctxt, replica_id, execution_id, def get_replicas(self, ctxt, include_tasks_executions=False, include_task_info=False): - return db_api.get_replicas( + return db_api.get_transfers( ctxt, include_tasks_executions, include_task_info=include_task_info, to_dict=True) @@ -1191,7 +1191,7 @@ def delete_replica(self, ctxt, replica_id): replica = self._get_replica(ctxt, replica_id) self._check_replica_running_executions(ctxt, replica) self._check_delete_reservation_for_transfer(replica) - db_api.delete_replica(ctxt, replica_id) + db_api.delete_transfer(ctxt, replica_id) @replica_synchronized def delete_replica_disks(self, ctxt, replica_id): @@ -1238,7 +1238,7 @@ def delete_replica_disks(self, ctxt, replica_id): for instance in replica.instances: db_api.update_transfer_action_info_for_instance( ctxt, replica.id, instance, replica.info[instance]) - db_api.add_replica_tasks_execution(ctxt, execution) + db_api.add_transfer_tasks_execution(ctxt, execution) LOG.info("Replica tasks execution created: %s", execution.id) self._begin_tasks(ctxt, replica, execution) @@ -1281,7 +1281,7 @@ def create_instances_replica(self, ctxt, replica_scenario, ctxt, destination_endpoint_id) self._check_endpoints(ctxt, origin_endpoint, destination_endpoint) - replica = models.Replica() + replica = models.Transfer() replica.id = str(uuid.uuid4()) replica.base_id = replica.id replica.scenario = replica_scenario @@ -1307,13 +1307,13 @@ def create_instances_replica(self, ctxt, replica_scenario, self._create_reservation_for_replica(replica) - db_api.add_replica(ctxt, replica) + db_api.add_transfer(ctxt, replica) LOG.info("Replica created: %s", replica.id) return self.get_replica(ctxt, replica.id) def _get_replica(self, ctxt, replica_id, include_task_info=False, to_dict=False): - replica = db_api.get_replica( + replica = db_api.get_transfer( ctxt, replica_id, include_task_info=include_task_info, to_dict=to_dict) if not replica: @@ -1329,10 +1329,9 @@ def get_migration(self, ctxt, migration_id, include_task_info=False): def get_deployments(self, ctxt, include_tasks, include_task_info=False): - return db_api.get_migrations( + return db_api.get_deployments( ctxt, include_tasks, include_task_info=include_task_info, - replica_migrations_only=True, to_dict=True) @deployment_synchronized @@ -1343,7 +1342,7 @@ def get_deployment(self, ctxt, deployment_id, include_task_info=False): @staticmethod def _check_running_replica_migrations(ctxt, replica_id): - migrations = db_api.get_replica_migrations(ctxt, replica_id) + migrations = db_api.get_transfer_deployments(ctxt, replica_id) if [m.id for m in migrations if m.executions[0].status in ( constants.ACTIVE_EXECUTION_STATUSES)]: raise exception.InvalidReplicaState( @@ -1411,7 +1410,7 @@ def deploy_replica_instances( instances = replica.instances - migration = models.Migration() + migration = models.Deployment() migration.id = str(uuid.uuid4()) migration.base_id = migration.id migration.origin_endpoint_id = replica.origin_endpoint_id @@ -1612,7 +1611,7 @@ def deploy_replica_instances( on_error=True) self._check_execution_tasks_sanity(execution, migration.info) - db_api.add_migration(ctxt, migration) + db_api.add_deployment(ctxt, migration) LOG.info("Migration created: %s", migration.id) if not skip_os_morphing and ( @@ -1755,7 +1754,7 @@ def confirm_replica_minions_allocation( self._update_task_info_for_minion_allocations( ctxt, replica, minion_machine_allocations) - last_replica_execution = db_api.get_replica_tasks_execution( + last_replica_execution = db_api.get_transfer_tasks_execution( ctxt, replica.id, last_replica_execution.id) self._begin_tasks( ctxt, replica, last_replica_execution) @@ -1832,7 +1831,7 @@ def report_migration_minions_allocation_error( def _get_migration(self, ctxt, migration_id, include_task_info=False, to_dict=False): - migration = db_api.get_migration( + migration = db_api.get_deployment( ctxt, migration_id, include_task_info=include_task_info, to_dict=to_dict) if not migration: @@ -1847,7 +1846,7 @@ def _delete_migration(self, ctxt, migration_id): raise exception.InvalidMigrationState( "Cannot delete Migration '%s' as it is currently in " "'%s' state." % (migration_id, execution.status)) - db_api.delete_migration(ctxt, migration_id) + db_api.delete_deployment(ctxt, migration_id) @deployment_synchronized def delete_deployment(self, ctxt, deployment_id): @@ -2078,7 +2077,7 @@ def _update_reservation_fulfillment_for_execution(self, ctxt, execution): transfer_id = transfer_action.base_id if transfer_action.type == constants.TRANSFER_ACTION_TYPE_MIGRATION: deployment = self._get_migration(ctxt, transfer_id) - transfer_id = deployment.replica_id + transfer_id = deployment.transfer_id transfer_action = self._get_replica( ctxt, transfer_id, include_task_info=False) else: @@ -2633,8 +2632,8 @@ def _update_replica_volumes_info(self, ctxt, replica_id, instance, def _update_volumes_info_for_migration_parent_replica( self, ctxt, migration_id, instance, updated_task_info): - migration = db_api.get_migration(ctxt, migration_id) - replica_id = migration.replica_id + migration = db_api.get_deployment(ctxt, migration_id) + replica_id = migration.transfer_id with lockutils.lock( constants.REPLICA_LOCK_NAME_FORMAT % replica_id, @@ -2751,7 +2750,7 @@ def _check_other_tasks_running(execution, current_task): # NOTE: considering all the instances of the Replica get # the same params, it doesn't matter which instance's # update task finishes last: - db_api.update_replica( + db_api.update_transfer( ctxt, execution.action_id, task_info) elif task_type in ( @@ -3242,7 +3241,7 @@ def update_task_progress_update( def _get_replica_schedule(self, ctxt, replica_id, schedule_id, expired=True): - schedule = db_api.get_replica_schedule( + schedule = db_api.get_transfer_schedule( ctxt, replica_id, schedule_id, expired=expired) if not schedule: raise exception.NotFound( @@ -3255,17 +3254,17 @@ def create_replica_schedule(self, ctxt, replica_id, shutdown_instance): keystone.create_trust(ctxt) replica = self._get_replica(ctxt, replica_id) - replica_schedule = models.ReplicaSchedule() + replica_schedule = models.TransferSchedule() replica_schedule.id = str(uuid.uuid4()) - replica_schedule.replica = replica - replica_schedule.replica_id = replica_id + replica_schedule.transfer = replica + replica_schedule.transfer_id = replica_id replica_schedule.schedule = schedule replica_schedule.expiration_date = exp_date replica_schedule.enabled = enabled replica_schedule.shutdown_instance = shutdown_instance replica_schedule.trust_id = ctxt.trust_id - db_api.add_replica_schedule( + db_api.add_transfer_schedule( ctxt, replica_schedule, lambda ctxt, sched: self._replica_cron_client.register( ctxt, sched)) @@ -3275,7 +3274,7 @@ def create_replica_schedule(self, ctxt, replica_id, @schedule_synchronized def update_replica_schedule(self, ctxt, replica_id, schedule_id, updated_values): - db_api.update_replica_schedule( + db_api.update_transfer_schedule( ctxt, replica_id, schedule_id, updated_values, None, lambda ctxt, sched: self._replica_cron_client.register( ctxt, sched)) @@ -3300,15 +3299,15 @@ def delete_replica_schedule(self, ctxt, replica_id, schedule_id): 'Replica Schedule cannot be deleted while the Replica is in ' '%s state. Please wait for the Replica execution to finish' % (replica_status)) - db_api.delete_replica_schedule( + db_api.delete_transfer_schedule( ctxt, replica_id, schedule_id, None, lambda ctxt, sched: self._cleanup_schedule_resources( ctxt, sched)) @replica_synchronized def get_replica_schedules(self, ctxt, replica_id=None, expired=True): - return db_api.get_replica_schedules( - ctxt, replica_id=replica_id, expired=expired) + return db_api.get_transfer_schedules( + ctxt, transfer_id=replica_id, expired=expired) @schedule_synchronized def get_replica_schedule(self, ctxt, replica_id, @@ -3326,7 +3325,7 @@ def update_replica( "instance_osmorphing_minion_pool_mappings"] if any([mpf in updated_properties for mpf in minion_pool_fields]): # NOTE: this is just a dummy Replica model to use for validation: - dummy = models.Replica() + dummy = models.Transfer() dummy.id = replica.id dummy.instances = replica.instances dummy.origin_endpoint_id = replica.origin_endpoint_id @@ -3409,7 +3408,7 @@ def update_replica( db_api.update_transfer_action_info_for_instance( ctxt, replica.id, instance, replica.info[instance]) - db_api.add_replica_tasks_execution(ctxt, execution) + db_api.add_transfer_tasks_execution(ctxt, execution) LOG.debug("Execution for Replica update tasks created: %s", execution.id) diff --git a/coriolis/db/api.py b/coriolis/db/api.py index 65be5d456..06361c6a4 100644 --- a/coriolis/db/api.py +++ b/coriolis/db/api.py @@ -98,26 +98,26 @@ def _update_sqlalchemy_object_fields( "of type '%s': %s" % (type(obj), values_to_update.keys())) -def _get_replica_schedules_filter(context, replica_id=None, - schedule_id=None, expired=True): +def _get_transfer_schedules_filter(context, transfer_id=None, + schedule_id=None, expired=True): now = timeutils.utcnow() - q = _soft_delete_aware_query(context, models.ReplicaSchedule) - q = q.join(models.Replica) + q = _soft_delete_aware_query(context, models.TransferSchedule) + q = q.join(models.Transfer) sched_filter = q.filter() if is_user_context(context): sched_filter = sched_filter.filter( - models.Replica.project_id == context.project_id) + models.Transfer.project_id == context.project_id) - if replica_id: + if transfer_id: sched_filter = sched_filter.filter( - models.Replica.id == replica_id) + models.Transfer.id == transfer_id) if schedule_id: sched_filter = sched_filter.filter( - models.ReplicaSchedule.id == schedule_id) + models.TransferSchedule.id == schedule_id) if not expired: sched_filter = sched_filter.filter( - or_(models.ReplicaSchedule.expiration_date == null(), - models.ReplicaSchedule.expiration_date > now)) + or_(models.TransferSchedule.expiration_date == null(), + models.TransferSchedule.expiration_date > now)) return sched_filter @@ -274,37 +274,37 @@ def delete_endpoint(context, endpoint_id): @enginefacade.reader -def get_replica_tasks_executions(context, replica_id, include_tasks=False, - include_task_info=False, to_dict=False): +def get_transfer_tasks_executions(context, transfer_id, include_tasks=False, + include_task_info=False, to_dict=False): q = _soft_delete_aware_query(context, models.TasksExecution) - q = q.join(models.Replica) + q = q.join(models.Transfer) if include_task_info: q = q.options(orm.joinedload('action').undefer('info')) if include_tasks: q = _get_tasks_with_details_options(q) if is_user_context(context): - q = q.filter(models.Replica.project_id == context.project_id) + q = q.filter(models.Transfer.project_id == context.project_id) db_result = q.filter( - models.Replica.id == replica_id).all() + models.Transfer.id == transfer_id).all() if to_dict: return [e.to_dict() for e in db_result] return db_result @enginefacade.reader -def get_replica_tasks_execution(context, replica_id, execution_id, - include_task_info=False, to_dict=False): +def get_transfer_tasks_execution(context, transfer_id, execution_id, + include_task_info=False, to_dict=False): q = _soft_delete_aware_query(context, models.TasksExecution).join( - models.Replica) + models.Transfer) if include_task_info: q = q.options(orm.joinedload('action').undefer('info')) q = _get_tasks_with_details_options(q) if is_user_context(context): - q = q.filter(models.Replica.project_id == context.project_id) + q = q.filter(models.Transfer.project_id == context.project_id) db_result = q.filter( - models.Replica.id == replica_id, + models.Transfer.id == transfer_id, models.TasksExecution.id == execution_id).first() if to_dict and db_result is not None: return db_result.to_dict() @@ -312,7 +312,7 @@ def get_replica_tasks_execution(context, replica_id, execution_id, @enginefacade.writer -def add_replica_tasks_execution(context, execution): +def add_transfer_tasks_execution(context, execution): if is_user_context(context): if execution.action.project_id != context.project_id: raise exception.NotAuthorized() @@ -330,12 +330,12 @@ def add_replica_tasks_execution(context, execution): @enginefacade.writer -def delete_replica_tasks_execution(context, execution_id): +def delete_transfer_tasks_execution(context, execution_id): q = _soft_delete_aware_query(context, models.TasksExecution).filter( models.TasksExecution.id == execution_id) if is_user_context(context): - if not q.join(models.Replica).filter( - models.Replica.project_id == context.project_id).first(): + if not q.join(models.Transfer).filter( + models.Transfer.project_id == context.project_id).first(): raise exception.NotAuthorized() count = q.soft_delete() if count == 0: @@ -343,28 +343,28 @@ def delete_replica_tasks_execution(context, execution_id): @enginefacade.reader -def get_replica_schedules(context, replica_id=None, expired=True): - sched_filter = _get_replica_schedules_filter( - context, replica_id=replica_id, expired=expired) +def get_transfer_schedules(context, transfer_id=None, expired=True): + sched_filter = _get_transfer_schedules_filter( + context, transfer_id=transfer_id, expired=expired) return sched_filter.all() @enginefacade.reader -def get_replica_schedule(context, replica_id, schedule_id, expired=True): - sched_filter = _get_replica_schedules_filter( - context, replica_id=replica_id, schedule_id=schedule_id, +def get_transfer_schedule(context, transfer_id, schedule_id, expired=True): + sched_filter = _get_transfer_schedules_filter( + context, transfer_id=transfer_id, schedule_id=schedule_id, expired=expired) return sched_filter.first() @enginefacade.writer -def update_replica_schedule(context, replica_id, schedule_id, - updated_values, pre_update_callable=None, - post_update_callable=None): +def update_transfer_schedule(context, transfer_id, schedule_id, + updated_values, pre_update_callable=None, + post_update_callable=None): # NOTE(gsamfira): we need to refactor the DB layer a bit to allow # two-phase transactions or at least allow running these functions # inside a single transaction block. - schedule = get_replica_schedule(context, replica_id, schedule_id) + schedule = get_transfer_schedule(context, transfer_id, schedule_id) if pre_update_callable: pre_update_callable(schedule=schedule) for val in ["schedule", "expiration_date", "enabled", "shutdown_instance"]: @@ -378,23 +378,23 @@ def update_replica_schedule(context, replica_id, schedule_id, @enginefacade.writer -def delete_replica_schedule(context, replica_id, - schedule_id, pre_delete_callable=None, - post_delete_callable=None): +def delete_transfer_schedule(context, transfer_id, + schedule_id, pre_delete_callable=None, + post_delete_callable=None): # NOTE(gsamfira): we need to refactor the DB layer a bit to allow # two-phase transactions or at least allow running these functions # inside a single transaction block. - q = _soft_delete_aware_query(context, models.ReplicaSchedule).filter( - models.ReplicaSchedule.id == schedule_id, - models.ReplicaSchedule.replica_id == replica_id) + q = _soft_delete_aware_query(context, models.TransferSchedule).filter( + models.TransferSchedule.id == schedule_id, + models.TransferSchedule.transfer_id == transfer_id) schedule = q.first() if not schedule: raise exception.NotFound( "No such schedule") if is_user_context(context): - if not q.join(models.Replica).filter( - models.Replica.project_id == context.project_id).first(): + if not q.join(models.Transfer).filter( + models.Transfer.project_id == context.project_id).first(): raise exception.NotAuthorized() if pre_delete_callable: pre_delete_callable(context, schedule) @@ -406,39 +406,39 @@ def delete_replica_schedule(context, replica_id, @enginefacade.writer -def add_replica_schedule(context, schedule, post_create_callable=None): +def add_transfer_schedule(context, schedule, post_create_callable=None): # NOTE(gsamfira): we need to refactor the DB layer a bit to allow # two-phase transactions or at least allow running these functions # inside a single transaction block. - if schedule.replica.project_id != context.project_id: + if schedule.transfer.project_id != context.project_id: raise exception.NotAuthorized() _session(context).add(schedule) if post_create_callable: post_create_callable(context, schedule) -def _get_replica_with_tasks_executions_options(q): - return q.options(orm.joinedload(models.Replica.executions)) +def _get_transfer_with_tasks_executions_options(q): + return q.options(orm.joinedload(models.Transfer.executions)) @enginefacade.reader -def get_replicas(context, - replica_scenario=None, - include_tasks_executions=False, - include_task_info=False, - to_dict=False): - q = _soft_delete_aware_query(context, models.Replica) +def get_transfers(context, + transfer_scenario=None, + include_tasks_executions=False, + include_task_info=False, + to_dict=False): + q = _soft_delete_aware_query(context, models.Transfer) if include_tasks_executions: - q = _get_replica_with_tasks_executions_options(q) + q = _get_transfer_with_tasks_executions_options(q) if include_task_info: q = q.options(orm.undefer('info')) q = q.filter() - if replica_scenario: - q.filter(models.Replica.scenario == replica_scenario) + if transfer_scenario: + q.filter(models.Transfer.scenario == transfer_scenario) if is_user_context(context): q = q.filter( - models.Replica.project_id == context.project_id) + models.Transfer.project_id == context.project_id) db_result = q.all() if to_dict: return [ @@ -450,55 +450,55 @@ def get_replicas(context, @enginefacade.reader -def get_replica(context, replica_id, - replica_scenario=None, - include_task_info=False, - to_dict=False): - q = _soft_delete_aware_query(context, models.Replica) - q = _get_replica_with_tasks_executions_options(q) +def get_transfer(context, transfer_id, + transfer_scenario=None, + include_task_info=False, + to_dict=False): + q = _soft_delete_aware_query(context, models.Transfer) + q = _get_transfer_with_tasks_executions_options(q) if include_task_info: q = q.options(orm.undefer('info')) - if replica_scenario: + if transfer_scenario: q = q.filter( - models.Replica.scenario == replica_scenario) + models.Transfer.scenario == transfer_scenario) if is_user_context(context): q = q.filter( - models.Replica.project_id == context.project_id) + models.Transfer.project_id == context.project_id) - replica = q.filter( - models.Replica.id == replica_id).first() - if to_dict and replica is not None: - return replica.to_dict(include_task_info=include_task_info) + transfer = q.filter( + models.Transfer.id == transfer_id).first() + if to_dict and transfer is not None: + return transfer.to_dict(include_task_info=include_task_info) - return replica + return transfer @enginefacade.reader -def get_endpoint_replicas_count( - context, endpoint_id, replica_scenario=None): +def get_endpoint_transfers_count( + context, endpoint_id, transfer_scenario=None): scenario_filter_kwargs = {} - if replica_scenario: - scenario_filter_kwargs = {"scenario": replica_scenario} + if transfer_scenario: + scenario_filter_kwargs = {"scenario": transfer_scenario} origin_args = {'origin_endpoint_id': endpoint_id} origin_args.update(scenario_filter_kwargs) q_origin_count = _soft_delete_aware_query( - context, models.Replica).filter_by(**origin_args).count() + context, models.Transfer).filter_by(**origin_args).count() destination_args = {'destination_endpoint_id': endpoint_id} destination_args.update(scenario_filter_kwargs) q_destination_count = _soft_delete_aware_query( - context, models.Replica).filter_by(**destination_args).count() + context, models.Transfer).filter_by(**destination_args).count() return q_origin_count + q_destination_count @enginefacade.writer -def add_replica(context, replica): - replica.user_id = context.user - replica.project_id = context.project_id - _session(context).add(replica) +def add_transfer(context, transfer): + transfer.user_id = context.user + transfer.project_id = context.project_id + _session(context).add(transfer) @enginefacade.writer @@ -516,39 +516,35 @@ def _delete_transfer_action(context, cls, id): @enginefacade.writer -def delete_replica(context, replica_id): - _delete_transfer_action(context, models.Replica, replica_id) +def delete_transfer(context, transfer_id): + _delete_transfer_action(context, models.Transfer, transfer_id) @enginefacade.reader -def get_replica_migrations(context, replica_id): - q = _soft_delete_aware_query(context, models.Migration) - q = q.join("replica") +def get_transfer_deployments(context, transfer_id): + q = _soft_delete_aware_query(context, models.Deployment) + q = q.join("transfer") q = q.options(orm.joinedload("executions")) if is_user_context(context): q = q.filter( - models.Migration.project_id == context.project_id) + models.Deployment.project_id == context.project_id) return q.filter( - models.Replica.id == replica_id).all() + models.Transfer.id == transfer_id).all() @enginefacade.reader -def get_migrations(context, - include_tasks=False, - include_task_info=False, - to_dict=False, - replica_migrations_only=False): - q = _soft_delete_aware_query(context, models.Migration) +def get_deployments(context, + include_tasks=False, + include_task_info=False, + to_dict=False): + q = _soft_delete_aware_query(context, models.Deployment) if include_tasks: - q = _get_migration_task_query_options(q) + q = _get_deployment_task_query_options(q) else: q = q.options(orm.joinedload("executions")) if include_task_info: q = q.options(orm.undefer('info')) - if replica_migrations_only: - q.filter(models.Migration.replica_id is not None) - args = {} if is_user_context(context): args["project_id"] = context.project_id @@ -569,7 +565,7 @@ def _get_tasks_with_details_options(query): joinedload("events")) -def _get_migration_task_query_options(query): +def _get_deployment_task_query_options(query): return query.options( orm.joinedload("executions"). joinedload("tasks"). @@ -582,13 +578,13 @@ def _get_migration_task_query_options(query): @enginefacade.reader -def get_migration(context, migration_id, include_task_info=False, - to_dict=False): - q = _soft_delete_aware_query(context, models.Migration) - q = _get_migration_task_query_options(q) +def get_deployment(context, deployment_id, include_task_info=False, + to_dict=False): + q = _soft_delete_aware_query(context, models.Deployment) + q = _get_deployment_task_query_options(q) if include_task_info: q = q.options(orm.undefer('info')) - args = {"id": migration_id} + args = {"id": deployment_id} if is_user_context(context): args["project_id"] = context.project_id db_result = q.filter_by(**args).first() @@ -599,15 +595,15 @@ def get_migration(context, migration_id, include_task_info=False, @enginefacade.writer -def add_migration(context, migration): - migration.user_id = context.user - migration.project_id = context.project_id - _session(context).add(migration) +def add_deployment(context, deployment): + deployment.user_id = context.user + deployment.project_id = context.project_id + _session(context).add(deployment) @enginefacade.writer -def delete_migration(context, migration_id): - _delete_transfer_action(context, models.Migration, migration_id) +def delete_deployment(context, deployment_id): + _delete_transfer_action(context, models.Deployment, deployment_id) @enginefacade.writer @@ -941,10 +937,10 @@ def update_task_progress_update( @enginefacade.writer -def update_replica(context, replica_id, updated_values): - replica = get_replica(context, replica_id) - if not replica: - raise exception.NotFound("Replica not found") +def update_transfer(context, transfer_id, updated_values): + transfer = get_transfer(context, transfer_id) + if not transfer: + raise exception.NotFound("Transfer not found") mapped_info_fields = { 'destination_environment': 'target_environment'} @@ -957,11 +953,11 @@ def update_replica(context, replica_id, updated_values): for field in updateable_fields: if mapped_info_fields.get(field, field) in updated_values: LOG.debug( - "Updating the '%s' field of Replica '%s' to: '%s'", - field, replica_id, updated_values[ + "Updating the '%s' field of Transfer '%s' to: '%s'", + field, transfer_id, updated_values[ mapped_info_fields.get(field, field)]) setattr( - replica, field, + transfer, field, updated_values[mapped_info_fields.get(field, field)]) non_updateable_fields = set( @@ -970,12 +966,12 @@ def update_replica(context, replica_id, updated_values): for field in updateable_fields}) if non_updateable_fields: LOG.warn( - "The following Replica fields can NOT be updated: %s", + "The following Transfer fields can NOT be updated: %s", non_updateable_fields) # the oslo_db library uses this method for both the `created_at` and # `updated_at` fields - setattr(replica, 'updated_at', timeutils.utcnow()) + setattr(transfer, 'updated_at', timeutils.utcnow()) @enginefacade.writer diff --git a/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py b/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py new file mode 100644 index 000000000..cc5e259ef --- /dev/null +++ b/coriolis/db/sqlalchemy/migrate_repo/versions/020_rename_tables.py @@ -0,0 +1,30 @@ +import sqlalchemy + + +def upgrade(migrate_engine): + meta = sqlalchemy.MetaData() + meta.bind = migrate_engine + + replica = sqlalchemy.Table('replica', meta, autoload=True) + replica.rename('transfer') + + migration = sqlalchemy.Table('migration', meta, autoload=True) + migration.rename('deployment') + migration.c.replica_id.alter(name='transfer_id', nullable=False) + migration.c.replication_count.drop() + + replica_schedule = sqlalchemy.Table( + 'replica_schedules', meta, autoload=True) + replica_schedule.rename('transfer_schedules') + replica_schedule.c.replica_id.alter(name='transfer_id') + + # NOTE(dvincze): Update models polymorphic identity + # Due to the model code changes, this cannot be done using the ORM. + # Had to resort to using raw SQL statements. + with migrate_engine.connect() as conn: + conn.execute( + 'UPDATE base_transfer_action SET type = "transfer" ' + 'WHERE type = "replica";') + conn.execute( + 'UPDATE base_transfer_action SET type = "deployment" ' + 'WHERE type = "migration";') diff --git a/coriolis/db/sqlalchemy/models.py b/coriolis/db/sqlalchemy/models.py index beac9c3b3..2f101be77 100644 --- a/coriolis/db/sqlalchemy/models.py +++ b/coriolis/db/sqlalchemy/models.py @@ -323,23 +323,23 @@ def to_dict(self, include_task_info=True, include_executions=True): return result -class Replica(BaseTransferAction): - __tablename__ = 'replica' +class Transfer(BaseTransferAction): + __tablename__ = 'transfer' id = sqlalchemy.Column( sqlalchemy.String(36), sqlalchemy.ForeignKey( 'base_transfer_action.base_id'), primary_key=True) scenario = sqlalchemy.Column( - sqlalchemy.String(255), + sqlalchemy.String(255), nullable=False, default=constants.REPLICA_SCENARIO_REPLICA) __mapper_args__ = { - 'polymorphic_identity': 'replica', + 'polymorphic_identity': 'transfer', } def to_dict(self, include_task_info=True, include_executions=True): - base = super(Replica, self).to_dict( + base = super(Transfer, self).to_dict( include_task_info=include_task_info, include_executions=include_executions) base.update({ @@ -348,40 +348,36 @@ def to_dict(self, include_task_info=True, include_executions=True): return base -class Migration(BaseTransferAction): - __tablename__ = 'migration' +class Deployment(BaseTransferAction): + __tablename__ = 'deployment' id = sqlalchemy.Column( sqlalchemy.String(36), sqlalchemy.ForeignKey( 'base_transfer_action.base_id'), primary_key=True) - replica_id = sqlalchemy.Column( + transfer_id = sqlalchemy.Column( sqlalchemy.String(36), - sqlalchemy.ForeignKey('replica.id'), nullable=True) - replica = orm.relationship( - Replica, backref=orm.backref("migrations"), foreign_keys=[replica_id]) + sqlalchemy.ForeignKey('transfer.id'), nullable=False) + transfer = orm.relationship( + Transfer, backref=orm.backref("deployments"), + foreign_keys=[transfer_id]) shutdown_instances = sqlalchemy.Column( sqlalchemy.Boolean, nullable=False, default=False) - replication_count = sqlalchemy.Column( - sqlalchemy.Integer, nullable=False, default=2) __mapper_args__ = { - 'polymorphic_identity': 'migration', + 'polymorphic_identity': 'deployment', } def to_dict(self, include_task_info=True, include_tasks=True): - base = super(Migration, self).to_dict( + base = super(Deployment, self).to_dict( include_task_info=include_task_info, include_executions=include_tasks) - replica_scenario_type = None - if self.replica: - replica_scenario_type = self.replica.scenario + base.update({ "id": self.id, - "replica_id": self.replica_id, - "replica_scenario_type": replica_scenario_type, + "transfer_id": self.transfer_id, + "transfer_scenario_type": self.transfer.scenario, "shutdown_instances": self.shutdown_instances, - "replication_count": self.replication_count, }) return base @@ -667,18 +663,18 @@ class Endpoint(BASE, models.TimestampMixin, models.ModelBase, secondary="endpoint_region_mapping") -class ReplicaSchedule(BASE, models.TimestampMixin, models.ModelBase, - models.SoftDeleteMixin): - __tablename__ = "replica_schedules" +class TransferSchedule(BASE, models.TimestampMixin, models.ModelBase, + models.SoftDeleteMixin): + __tablename__ = "transfer_schedules" id = sqlalchemy.Column(sqlalchemy.String(36), default=lambda: str(uuid.uuid4()), primary_key=True) - replica_id = sqlalchemy.Column( + transfer_id = sqlalchemy.Column( sqlalchemy.String(36), - sqlalchemy.ForeignKey('replica.id'), nullable=False) - replica = orm.relationship( - Replica, backref=orm.backref("schedules"), foreign_keys=[replica_id]) + sqlalchemy.ForeignKey('transfer.id'), nullable=False) + transfer = orm.relationship( + Transfer, backref=orm.backref("schedules"), foreign_keys=[transfer_id]) schedule = sqlalchemy.Column(types.Json, nullable=False) expiration_date = sqlalchemy.Column( sqlalchemy.types.DateTime, nullable=True) diff --git a/coriolis/tests/api/v1/test_replica_schedules.py b/coriolis/tests/api/v1/test_replica_schedules.py index 27a8ac1da..c32cc792f 100644 --- a/coriolis/tests/api/v1/test_replica_schedules.py +++ b/coriolis/tests/api/v1/test_replica_schedules.py @@ -33,7 +33,7 @@ def test_show( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id result = self.replica_schedules.show(mock_req, replica_id, id) @@ -58,7 +58,7 @@ def test_show_not_found( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id mock_get_schedule.return_value = None self.assertRaises( @@ -84,7 +84,7 @@ def test_index( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id mock_req.GET = {"show_expired": "False"} result = self.replica_schedules.index(mock_req, replica_id) @@ -338,7 +338,7 @@ def test_create( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id body = mock.sentinel.body schedule = mock.sentinel.schedule exp_date = mock.sentinel.exp_date @@ -368,7 +368,7 @@ def test_create_except( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id body = mock.sentinel.body mock_validate_create_body.side_effect = Exception("err") @@ -397,7 +397,7 @@ def test_update( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id body = mock.sentinel.body @@ -425,7 +425,7 @@ def test_update_except( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id body = mock.sentinel.body mock_validate_update_body.side_effect = Exception("err") @@ -451,7 +451,7 @@ def test_delete( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id self.assertRaises( diff --git a/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py b/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py index 3e46b7254..2ed8e2fd9 100644 --- a/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py +++ b/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py @@ -37,7 +37,7 @@ def test_cancel( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id body = config["body"] if exception_raised: mock_cancel.side_effect = getattr(exception, exception_raised)( diff --git a/coriolis/tests/api/v1/test_replica_tasks_executions.py b/coriolis/tests/api/v1/test_replica_tasks_executions.py index fce66069f..b1b2b11bb 100644 --- a/coriolis/tests/api/v1/test_replica_tasks_executions.py +++ b/coriolis/tests/api/v1/test_replica_tasks_executions.py @@ -29,7 +29,7 @@ def test_show( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id result = self.replica_api.show(mock_req, replica_id, id) @@ -55,7 +55,7 @@ def test_show_not_found( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id mock_get_execution.return_value = None @@ -83,7 +83,7 @@ def test_index( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id result = self.replica_api.index(mock_req, replica_id) @@ -109,7 +109,7 @@ def test_detail( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id result = self.replica_api.detail(mock_req, replica_id) @@ -135,7 +135,7 @@ def test_create( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id execution = {"shutdown_instances": True} mock_body = {"execution": execution} @@ -162,7 +162,7 @@ def test_create_no_executions( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id mock_body = {} result = self.replica_api.create(mock_req, replica_id, mock_body) @@ -186,7 +186,7 @@ def test_delete( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id self.assertRaises( @@ -209,7 +209,7 @@ def test_delete_not_found( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.replica_id + replica_id = mock.sentinel.transfer_id id = mock.sentinel.id mock_delete.side_effect = exception.NotFound() diff --git a/coriolis/tests/conductor/rpc/test_server.py b/coriolis/tests/conductor/rpc/test_server.py index 857c6b64b..0582c990e 100644 --- a/coriolis/tests/conductor/rpc/test_server.py +++ b/coriolis/tests/conductor/rpc/test_server.py @@ -269,9 +269,9 @@ def call_get_endpoint(): self.assertRaises(exception.NotFound, call_get_endpoint) @mock.patch.object(db_api, "delete_endpoint") - @mock.patch.object(db_api, "get_endpoint_replicas_count") + @mock.patch.object(db_api, "get_endpoint_transfers_count") def test_delete_endpoint( - self, mock_get_endpoint_replicas_count, mock_delete_endpoint + self, mock_get_endpoint_transfers_count, mock_delete_endpoint ): def call_delete_endpoint(): return testutils.get_wrapped_function(self.server.delete_endpoint)( @@ -279,14 +279,14 @@ def call_delete_endpoint(): mock.sentinel.endpoint_id # type: ignore ) - mock_get_endpoint_replicas_count.return_value = 0 + mock_get_endpoint_transfers_count.return_value = 0 call_delete_endpoint() mock_delete_endpoint.assert_called_once_with( mock.sentinel.context, mock.sentinel.endpoint_id ) # endpoint has replicas - mock_get_endpoint_replicas_count.return_value = 1 + mock_get_endpoint_transfers_count.return_value = 1 self.assertRaises(exception.NotAuthorized, call_delete_endpoint) @mock.patch.object( @@ -1103,12 +1103,12 @@ def test_delete_replica_disks_invalid_state( delete_replica_disks, self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True, ) mock_check_replica_running.assert_called_once_with( @@ -1190,7 +1190,7 @@ def convert_to_task(task_config): server.ConductorServerEndpoint, "_minion_manager_client" ) - @mock.patch.object(db_api, "add_replica_tasks_execution") + @mock.patch.object(db_api, "add_transfer_tasks_execution") @mock.patch.object(db_api, "update_transfer_action_info_for_instance") @mock.patch.object( server.ConductorServerEndpoint, @@ -1231,7 +1231,7 @@ def test_execute_replica_tasks( mock_create_task, mock_check_execution_tasks_sanity, mock_update_transfer_action_info_for_instance, - mock_add_replica_tasks_execution, + mock_add_transfer_tasks_execution, mock_minion_manager_client, mock_set_tasks_execution_status, mock_begin_tasks, @@ -1249,7 +1249,7 @@ def call_execute_replica_tasks(): .get_wrapped_function(self.server.execute_replica_tasks)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, shutdown_instances, # type: ignore ) @@ -1288,7 +1288,7 @@ def create_task_side_effect( result = call_execute_replica_tasks() mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True, ) mock_check_reservation.assert_called_once_with(mock_replica) @@ -1356,7 +1356,7 @@ def create_task_side_effect( mock_tasks_execution.return_value, mock_replica.info) - mock_add_replica_tasks_execution.assert_called_once_with( + mock_add_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, mock_tasks_execution.return_value) @@ -1380,7 +1380,7 @@ def create_task_side_effect( mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock_tasks_execution.return_value.id) self.assertEqual( @@ -1392,53 +1392,53 @@ def create_task_side_effect( self.assertEqual( result, mock_get_replica_tasks_execution.return_value) - @mock.patch.object(db_api, "get_replica_tasks_executions") + @mock.patch.object(db_api, "get_transfer_tasks_executions") def test_get_replica_tasks_executions( self, - mock_get_replica_tasks_executions + mock_get_transfer_tasks_executions ): result = testutils.get_wrapped_function( self.server.get_replica_tasks_executions)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False ) self.assertEqual( - mock_get_replica_tasks_executions.return_value, + mock_get_transfer_tasks_executions.return_value, result ) - mock_get_replica_tasks_executions.assert_called_once_with( + mock_get_transfer_tasks_executions.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=True ) - @mock.patch.object(db_api, "get_replica_tasks_execution") + @mock.patch.object(db_api, "get_transfer_tasks_execution") def test_get_replica_tasks_execution( self, - mock_get_replica_tasks_execution + mock_get_transfer_tasks_execution ): result = testutils.get_wrapped_function( self.server.get_replica_tasks_execution)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False ) self.assertEqual( - mock_get_replica_tasks_execution.return_value, + mock_get_transfer_tasks_execution.return_value, result ) - mock_get_replica_tasks_execution.assert_called_once_with( + mock_get_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=True @@ -1448,10 +1448,10 @@ def test_get_replica_tasks_execution( server.ConductorServerEndpoint, '_get_replica_tasks_execution' ) - @mock.patch.object(db_api, 'delete_replica_tasks_execution') + @mock.patch.object(db_api, 'delete_transfer_tasks_execution') def test_delete_replica_tasks_execution( self, - mock_delete_replica_tasks_execution, + mock_delete_transfer_tasks_execution, mock_get_replica_tasks_execution ): def call_delete_replica_tasks_execution(): @@ -1459,21 +1459,21 @@ def call_delete_replica_tasks_execution(): self.server.delete_replica_tasks_execution)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, # type: ignore ) call_delete_replica_tasks_execution() mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id) - mock_delete_replica_tasks_execution.assert_called_once_with( + mock_delete_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, mock.sentinel.execution_id) # raises exception if status is active - mock_get_replica_tasks_execution.return_value.status = constants\ - .EXECUTION_STATUS_RUNNING + mock_get_replica_tasks_execution.return_value.status = ( + constants.EXECUTION_STATUS_RUNNING) self.assertRaises( exception.InvalidMigrationState, @@ -1494,13 +1494,13 @@ def test_cancel_replica_tasks_execution( self.server.cancel_replica_tasks_execution)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, False ) mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id) mock_cancel_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, @@ -1515,13 +1515,13 @@ def test_cancel_replica_tasks_execution( self.server.cancel_replica_tasks_execution)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, True ) mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id) mock_cancel_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, @@ -1543,13 +1543,13 @@ def test_cancel_replica_tasks_execution_status_not_active( self.server.cancel_replica_tasks_execution), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, False ) mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id) mock_cancel_replica_tasks_execution.assert_not_called() @@ -1570,64 +1570,64 @@ def test_cancel_replica_tasks_execution_status_cancelling_no_force( self.server.cancel_replica_tasks_execution), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, False ) mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id) mock_cancel_replica_tasks_execution.assert_not_called() - @mock.patch.object(db_api, 'get_replica_tasks_execution') + @mock.patch.object(db_api, 'get_transfer_tasks_execution') def test__get_replica_tasks_execution( self, - mock_get_replica_tasks_execution + mock_get_transfer_tasks_execution ): result = self.server._get_replica_tasks_execution( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=False, ) self.assertEqual( - mock_get_replica_tasks_execution.return_value, + mock_get_transfer_tasks_execution.return_value, result ) - mock_get_replica_tasks_execution.assert_called_once_with( + mock_get_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=False) - @mock.patch.object(db_api, 'get_replica_tasks_execution') + @mock.patch.object(db_api, 'get_transfer_tasks_execution') def test__get_replica_tasks_execution_no_execution( self, - mock_get_replica_tasks_execution + mock_get_transfer_tasks_execution ): - mock_get_replica_tasks_execution.return_value = None + mock_get_transfer_tasks_execution.return_value = None self.assertRaises( exception.NotFound, self.server._get_replica_tasks_execution, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=False, ) - mock_get_replica_tasks_execution.assert_called_once_with( + mock_get_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.execution_id, include_task_info=False, to_dict=False) - @mock.patch.object(db_api, 'get_replicas') - def test_get_replicas(self, mock_get_replicas): + @mock.patch.object(db_api, 'get_transfers') + def test_get_replicas(self, mock_get_transfers): result = self.server.get_replicas( mock.sentinel.context, include_tasks_executions=False, @@ -1635,10 +1635,10 @@ def test_get_replicas(self, mock_get_replicas): ) self.assertEqual( - mock_get_replicas.return_value, + mock_get_transfers.return_value, result ) - mock_get_replicas.assert_called_once_with( + mock_get_transfers.assert_called_once_with( mock.sentinel.context, False, include_task_info=False, @@ -1650,7 +1650,7 @@ def test_get_replica(self, mock_get_replica): result = testutils.get_wrapped_function(self.server.get_replica)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False ) @@ -1660,12 +1660,12 @@ def test_get_replica(self, mock_get_replica): ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False, to_dict=True ) - @mock.patch.object(db_api, 'delete_replica') + @mock.patch.object(db_api, 'delete_transfer') @mock.patch.object(server.ConductorServerEndpoint, '_check_delete_reservation_for_transfer') @mock.patch.object(server.ConductorServerEndpoint, @@ -1676,21 +1676,21 @@ def test_delete_replica( mock_get_replica, mock_check_replica_running_executions, mock_check_delete_reservation_for_transfer, - mock_delete_replica, + mock_delete_transfer, ): testutils.get_wrapped_function(self.server.delete_replica)( self.server, mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) mock_get_replica.assert_called_once_with( - mock.sentinel.context, mock.sentinel.replica_id) + mock.sentinel.context, mock.sentinel.transfer_id) mock_check_replica_running_executions.assert_called_once_with( mock.sentinel.context, mock_get_replica.return_value) mock_check_delete_reservation_for_transfer.assert_called_once_with( mock_get_replica.return_value) - mock_delete_replica.assert_called_once_with( - mock.sentinel.context, mock.sentinel.replica_id) + mock_delete_transfer.assert_called_once_with( + mock.sentinel.context, mock.sentinel.transfer_id) @mock.patch.object( server.ConductorServerEndpoint, @@ -1700,7 +1700,7 @@ def test_delete_replica( server.ConductorServerEndpoint, '_begin_tasks' ) - @mock.patch.object(db_api, "add_replica_tasks_execution") + @mock.patch.object(db_api, "add_transfer_tasks_execution") @mock.patch.object(db_api, "update_transfer_action_info_for_instance") @mock.patch.object( server.ConductorServerEndpoint, @@ -1731,7 +1731,7 @@ def test_delete_replica_disks( mock_deepcopy, mock_check_execution_tasks_sanity, mock_update_transfer_action_info_for_instance, - mock_add_replica_tasks_execution, + mock_add_transfer_tasks_execution, mock_begin_tasks, mock_get_replica_tasks_execution, ): @@ -1740,12 +1740,12 @@ def call_delete_replica_disks(): self.server.delete_replica_disks)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, # type: ignore + mock.sentinel.transfer_id, # type: ignore ) instances = [mock.Mock(), mock.Mock()] mock_replica = mock.Mock( instances=instances, - id=mock.sentinel.replica_id, + id=mock.sentinel.transfer_id, network_map=mock.sentinel.network_map, info={ instance: instance @@ -1774,7 +1774,7 @@ def create_task_side_effect( mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_check_replica_running_executions.assert_called_once_with( @@ -1825,7 +1825,7 @@ def create_task_side_effect( mock_tasks_execution.return_value, mock_replica.info, ) - mock_add_replica_tasks_execution.assert_called_once_with( + mock_add_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, mock_tasks_execution.return_value ) @@ -1897,27 +1897,27 @@ def test_check_endpoints_same_destination_connection_info(self): ) @mock.patch.object(server.ConductorServerEndpoint, 'get_replica') - @mock.patch.object(db_api, 'add_replica') + @mock.patch.object(db_api, 'add_transfer') @mock.patch.object(server.ConductorServerEndpoint, '_create_reservation_for_replica') @mock.patch.object(server.ConductorServerEndpoint, '_check_minion_pools_for_action') - @mock.patch.object(models, 'Replica') + @mock.patch.object(models, 'Transfer') @mock.patch.object(server.ConductorServerEndpoint, '_check_endpoints') @mock.patch.object(server.ConductorServerEndpoint, 'get_endpoint') def test_create_instances_replica( self, mock_get_endpoint, mock_check_endpoints, - mock_replica, + mock_transfer, mock_check_minion_pools_for_action, mock_create_reservation_for_replica, - mock_add_replica, + mock_add_transfer, mock_get_replica ): mock_get_endpoint.side_effect = mock.sentinel.origin_endpoint_id, \ mock.sentinel.destination_endpoint_id - mock_replica.return_value = mock.Mock() + mock_transfer.return_value = mock.Mock() result = self.server.create_instances_replica( mock.sentinel.context, constants.REPLICA_SCENARIO_REPLICA, @@ -1949,18 +1949,18 @@ def test_create_instances_replica( ) self.assertEqual( ( - mock_replica.return_value.origin_endpoint_id, - mock_replica.return_value.destination_endpoint_id, - mock_replica.return_value.destination_endpoint_id, - mock_replica.return_value.origin_minion_pool_id, - mock_replica.return_value.destination_minion_pool_id, - (mock_replica.return_value. - instance_osmorphing_minion_pool_mappings), - mock_replica.return_value.source_environment, - mock_replica.return_value.destination_environment, - mock_replica.return_value.info, - mock_replica.return_value.notes, - mock_replica.return_value.user_scripts), + mock_transfer.return_value.origin_endpoint_id, + mock_transfer.return_value.destination_endpoint_id, + mock_transfer.return_value.destination_endpoint_id, + mock_transfer.return_value.origin_minion_pool_id, + mock_transfer.return_value.destination_minion_pool_id, + (mock_transfer.return_value. + instance_osmorphing_minion_pool_mappings), + mock_transfer.return_value.source_environment, + mock_transfer.return_value.destination_environment, + mock_transfer.return_value.info, + mock_transfer.return_value.notes, + mock_transfer.return_value.user_scripts), ( mock.sentinel.origin_endpoint_id, mock.sentinel.destination_endpoint_id, @@ -1977,19 +1977,19 @@ def test_create_instances_replica( {}) ) mock_check_minion_pools_for_action.assert_called_once_with( - mock.sentinel.context, mock_replica.return_value) + mock.sentinel.context, mock_transfer.return_value) mock_create_reservation_for_replica.assert_called_once_with( - mock_replica.return_value) - mock_add_replica.assert_called_once_with( - mock.sentinel.context, mock_replica.return_value) + mock_transfer.return_value) + mock_add_transfer.assert_called_once_with( + mock.sentinel.context, mock_transfer.return_value) mock_get_replica.assert_called_once_with( - mock.sentinel.context, mock_replica.return_value.id) + mock.sentinel.context, mock_transfer.return_value.id) - @mock.patch.object(db_api, 'get_replica') + @mock.patch.object(db_api, 'get_transfer') def test__get_replica(self, mock_get_replica): result = self.server._get_replica( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False, to_dict=False ) @@ -1999,25 +1999,25 @@ def test__get_replica(self, mock_get_replica): ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False, to_dict=False ) - @mock.patch.object(db_api, 'get_replica') - def test__get_replica_not_found(self, mock_get_replica): - mock_get_replica.return_value = None + @mock.patch.object(db_api, 'get_transfer') + def test__get_replica_not_found(self, mock_get_transfer): + mock_get_transfer.return_value = None self.assertRaises( exception.NotFound, self.server._get_replica, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False, to_dict=False ) - mock_get_replica.assert_called_once_with( + mock_get_transfer.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=False, to_dict=False ) @@ -2041,10 +2041,10 @@ def test_get_migration(self, mock_get_migration): to_dict=True ) - @mock.patch.object(db_api, 'get_replica_migrations') + @mock.patch.object(db_api, 'get_transfer_deployments') def test_check_running_replica_migrations( self, - mock_get_replica_migrations + mock_get_transfer_deployments ): migration_1 = mock.Mock() migration_2 = mock.Mock() @@ -2055,20 +2055,20 @@ def test_check_running_replica_migrations( migration_2.executions[0].status = \ constants.EXECUTION_STATUS_ERROR migrations = [migration_1, migration_2] - mock_get_replica_migrations.return_value = migrations + mock_get_transfer_deployments.return_value = migrations self.server._check_running_replica_migrations( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) - mock_get_replica_migrations.assert_called_once_with( + mock_get_transfer_deployments.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) - @mock.patch.object(db_api, 'get_replica_migrations') + @mock.patch.object(db_api, 'get_transfer_deployments') def test_check_running_replica_migrations_invalid_replica_state( self, - mock_get_replica_migrations + mock_get_transfer_deployments ): migration_1 = mock.Mock() migration_2 = mock.Mock() @@ -2078,16 +2078,16 @@ def test_check_running_replica_migrations_invalid_replica_state( migration_2.executions[0].status = \ constants.EXECUTION_STATUS_COMPLETED migrations = [migration_1, migration_2] - mock_get_replica_migrations.return_value = migrations + mock_get_transfer_deployments.return_value = migrations self.assertRaises( exception.InvalidReplicaState, self.server._check_running_replica_migrations, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) - mock_get_replica_migrations.assert_called_once_with( + mock_get_transfer_deployments.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) def test_check_running_executions(self): @@ -2239,7 +2239,7 @@ def test_get_provider_types(self, mock_get_available_providers): server.ConductorServerEndpoint, '_get_provider_types' ) - @mock.patch.object(models, "Migration") + @mock.patch.object(models, "Deployment") @mock.patch.object(uuid, "uuid4", return_value="migration_id") @mock.patch.object(copy, "deepcopy") @mock.patch.object( @@ -2259,7 +2259,7 @@ def test_get_provider_types(self, mock_get_available_providers): server.ConductorServerEndpoint, '_check_execution_tasks_sanity' ) - @mock.patch.object(db_api, 'add_migration') + @mock.patch.object(db_api, 'add_deployment') @mock.patch.object(lockutils, 'lock') @mock.patch.object( server.ConductorServerEndpoint, @@ -2286,7 +2286,7 @@ def test_deploy_replica_instance( mock_set_tasks_execution_status, mock_minion_manager_client, mock_lock, - mock_add_migration, + mock_add_deployment, mock_check_execution_tasks_sanity, mock_create_task, mock_get_instance_scripts, @@ -2294,7 +2294,7 @@ def test_deploy_replica_instance( mock_check_minion_pools_for_action, mock_deepcopy, mock_uuid4, - mock_migration, + mock_deployment, mock_get_provider_types, mock_get_endpoint, mock_check_valid_replica_tasks_execution, @@ -2337,7 +2337,7 @@ def test_deploy_replica_instance( def call_deploy_replica_instance(): return self.server.deploy_replica_instances( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, clone_disks=clone_disks, force=False, instance_osmorphing_minion_pool_mappings=( @@ -2359,7 +2359,7 @@ def call_deploy_replica_instance(): mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True, ) mock_check_replica_running_executions.assert_called_once_with( @@ -2405,7 +2405,7 @@ def create_task_side_effect( mock_check_minion_pools_for_action.assert_called_once_with( mock.sentinel.context, - mock_migration.return_value + mock_deployment.return_value ) mock_check_reservation_for_replica.assert_called_once_with( mock_get_replica.return_value) @@ -2449,25 +2449,25 @@ def create_task_side_effect( mock_check_execution_tasks_sanity.assert_called_once_with( mock_tasks_execution.return_value, - mock_migration.return_value.info, + mock_deployment.return_value.info, ) - mock_add_migration.assert_called_once_with( + mock_add_deployment.assert_called_once_with( mock.sentinel.context, - mock_migration.return_value, + mock_deployment.return_value, ) if not skip_os_morphing and has_os_morphing_minion: mock_lock.assert_any_call( constants.MIGRATION_LOCK_NAME_FORMAT - % mock_migration.return_value.id, + % mock_deployment.return_value.id, external=True, ) mock_minion_manager_client\ .allocate_minion_machines_for_migration\ .assert_called_once_with( mock.sentinel.context, - mock_migration.return_value, + mock_deployment.return_value, include_transfer_minions=False, include_osmorphing_minions=True ) @@ -2479,13 +2479,13 @@ def create_task_side_effect( else: mock_begin_tasks.assert_called_once_with( mock.sentinel.context, - mock_migration.return_value, + mock_deployment.return_value, mock_tasks_execution.return_value, ) mock_get_migration.assert_called_once_with( mock.sentinel.context, - mock_migration.return_value.id, + mock_deployment.return_value.id, ) self.assertEqual( @@ -2810,7 +2810,7 @@ def test_get_execution_for_migration( ) @mock.patch.object(server.ConductorServerEndpoint, '_begin_tasks') - @mock.patch.object(db_api, 'get_replica_tasks_execution') + @mock.patch.object(db_api, 'get_transfer_tasks_execution') @mock.patch.object(server.ConductorServerEndpoint, '_update_task_info_for_minion_allocations') @mock.patch.object(server.ConductorServerEndpoint, @@ -2821,7 +2821,7 @@ def test_confirm_replica_minions_allocation( mock_get_replica, mock_get_last_execution_for_replica, mock_update_task_info_for_minion_allocations, - mock_get_replica_tasks_execution, + mock_get_transfer_tasks_execution, mock_begin_tasks ): mock_get_replica.return_value.last_execution_status = \ @@ -2831,13 +2831,13 @@ def test_confirm_replica_minions_allocation( self.server.confirm_replica_minions_allocation)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_machine_allocations ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_get_last_execution_for_replica.assert_called_once_with( @@ -2850,7 +2850,7 @@ def test_confirm_replica_minions_allocation( mock_get_replica.return_value, mock.sentinel.minion_machine_allocations ) - mock_get_replica_tasks_execution.assert_called_once_with( + mock_get_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, mock_get_replica.return_value.id, mock_get_last_execution_for_replica.return_value.id @@ -2858,11 +2858,11 @@ def test_confirm_replica_minions_allocation( mock_begin_tasks.assert_called_once_with( mock.sentinel.context, mock_get_replica.return_value, - mock_get_replica_tasks_execution.return_value + mock_get_transfer_tasks_execution.return_value ) @mock.patch.object(server.ConductorServerEndpoint, '_begin_tasks') - @mock.patch.object(db_api, 'get_replica_tasks_execution') + @mock.patch.object(db_api, 'get_transfer_tasks_execution') @mock.patch.object(server.ConductorServerEndpoint, '_update_task_info_for_minion_allocations') @mock.patch.object(server.ConductorServerEndpoint, @@ -2873,7 +2873,7 @@ def test_confirm_replica_minions_allocation_unexpected_status( mock_get_replica, mock_get_last_execution_for_replica, mock_update_task_info_for_minion_allocations, - mock_get_replica_tasks_execution, + mock_get_transfer_tasks_execution, mock_begin_tasks ): mock_get_replica.return_value.last_execution_status = \ @@ -2885,18 +2885,18 @@ def test_confirm_replica_minions_allocation_unexpected_status( self.server.confirm_replica_minions_allocation), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_machine_allocations ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_get_last_execution_for_replica.assert_not_called() mock_update_task_info_for_minion_allocations.assert_not_called() - mock_get_replica_tasks_execution.assert_not_called() + mock_get_transfer_tasks_execution.assert_not_called() mock_begin_tasks.assert_not_called() @mock.patch.object(server.ConductorServerEndpoint, @@ -2920,13 +2920,13 @@ def test_report_replica_minions_allocation_error( self.server.report_replica_minions_allocation_error)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_allocation_error_details ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) mock_get_last_execution_for_replica.assert_called_once_with( mock.sentinel.context, @@ -2967,13 +2967,13 @@ def test_report_replica_minions_allocation_error_unexpected_status( self.server.report_replica_minions_allocation_error), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_allocation_error_details ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) mock_get_last_execution_for_replica.assert_not_called() mock_cancel_tasks_execution.assert_not_called() @@ -2999,13 +2999,13 @@ def test_confirm_migration_minions_allocation( self.server.confirm_migration_minions_allocation)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_machine_allocations ) mock_get_migration.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_get_execution_for_migration.assert_called_once_with( @@ -3046,13 +3046,13 @@ def test_confirm_migration_minions_allocation_unexpected_status( self.server.confirm_migration_minions_allocation), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_machine_allocations ) mock_get_migration.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_get_execution_for_migration.assert_not_called() @@ -3081,13 +3081,13 @@ def test_report_migration_minions_allocation_error( self.server.report_migration_minions_allocation_error)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_allocation_error_details ) mock_get_migration.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) mock_get_execution_for_migration.assert_called_once_with( mock.sentinel.context, @@ -3128,13 +3128,13 @@ def test_report_migration_minions_allocation_error_unexpected_status( self.server.report_migration_minions_allocation_error), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.minion_allocation_error_details ) mock_get_migration.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) mock_get_execution_for_migration.assert_not_called() mock_cancel_tasks_execution.assert_not_called() @@ -3246,10 +3246,10 @@ def call_cancel_tasks_execution( exception_details=mock.ANY, ) - @mock.patch.object(db_api, 'get_migration') + @mock.patch.object(db_api, 'get_deployment') def test__get_migration( self, - mock_get_migration + mock_get_deployment ): result = self.server._get_migration( mock.sentinel.context, @@ -3258,18 +3258,18 @@ def test__get_migration( to_dict=False ) self.assertEqual( - mock_get_migration.return_value, + mock_get_deployment.return_value, result ) - mock_get_migration.assert_called_once_with( + mock_get_deployment.assert_called_once_with( mock.sentinel.context, mock.sentinel.migration_id, include_task_info=False, to_dict=False ) - mock_get_migration.reset_mock() - mock_get_migration.return_value = None + mock_get_deployment.reset_mock() + mock_get_deployment.return_value = None self.assertRaises( exception.NotFound, @@ -3280,7 +3280,7 @@ def test__get_migration( to_dict=False ) - mock_get_migration.assert_called_once_with( + mock_get_deployment.assert_called_once_with( mock.sentinel.context, mock.sentinel.migration_id, include_task_info=False, @@ -4003,14 +4003,14 @@ def test_update_replica_volumes_info( ): self.server._update_replica_volumes_info( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.instance, mock.sentinel.updated_task_info ) mock_update_transfer_action_info_for_instance.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.instance, mock.sentinel.updated_task_info ) @@ -4018,15 +4018,15 @@ def test_update_replica_volumes_info( @mock.patch.object(server.ConductorServerEndpoint, '_update_replica_volumes_info') @mock.patch.object(lockutils, 'lock') - @mock.patch.object(db_api, 'get_migration') + @mock.patch.object(db_api, 'get_deployment') def test_update_volumes_info_for_migration_parent_replica( self, - mock_get_migration, + mock_get_deployment, mock_lock, mock_update_replica_volumes_info ): - migration = mock.Mock() - mock_get_migration.return_value = migration + deployment = mock.Mock() + mock_get_deployment.return_value = deployment self.server._update_volumes_info_for_migration_parent_replica( mock.sentinel.context, @@ -4035,18 +4035,18 @@ def test_update_volumes_info_for_migration_parent_replica( mock.sentinel.updated_task_info ) - mock_get_migration.assert_called_once_with( + mock_get_deployment.assert_called_once_with( mock.sentinel.context, mock.sentinel.migration_id ) mock_lock.assert_called_once_with( constants.REPLICA_LOCK_NAME_FORMAT % - mock_get_migration.return_value.replica_id, + mock_get_deployment.return_value.transfer_id, external=True ) mock_update_replica_volumes_info.assert_called_once_with( mock.sentinel.context, - mock_get_migration.return_value.replica_id, + mock_get_deployment.return_value.transfer_id, mock.sentinel.instance, mock.sentinel.updated_task_info ) @@ -4056,7 +4056,7 @@ def test_update_volumes_info_for_migration_parent_replica( '_minion_manager_client' ) @mock.patch.object(db_api, 'update_minion_machine') - @mock.patch.object(db_api, 'update_replica') + @mock.patch.object(db_api, 'update_transfer') @mock.patch.object( server.ConductorServerEndpoint, '_update_replica_volumes_info' @@ -4073,7 +4073,7 @@ def test_handle_post_task_actions( mock_validate_value, mock_set_transfer_action_result, mock_update_replica_volumes_info, - mock_update_replica, + mock_update_transfer, mock_update_minion_machine, mock_minion_manager_client, ): @@ -4212,7 +4212,7 @@ def call_handle_post_task_actions(): # execution has active tasks task.type = constants.TASK_TYPE_UPDATE_DESTINATION_REPLICA call_handle_post_task_actions() - mock_update_replica.assert_not_called() + mock_update_transfer.assert_not_called() # execution has no active tasks execution.tasks = [ @@ -4222,12 +4222,12 @@ def call_handle_post_task_actions(): ) ] call_handle_post_task_actions() - mock_update_replica.assert_called_once_with( + mock_update_transfer.assert_called_once_with( mock.sentinel.context, mock.sentinel.action_id, task_info ) - mock_update_replica.reset_mock() + mock_update_transfer.reset_mock() # TASK_TYPE_ATTACH_VOLUMES_TO_SOURCE_MINION # TASK_TYPE_DETACH_VOLUMES_FROM_SOURCE_MINION @@ -4336,7 +4336,7 @@ def call_handle_post_task_actions(): # for any other type of task nothing is called task.task_type = constants.TASK_TYPE_COLLECT_OSMORPHING_INFO call_handle_post_task_actions() - mock_update_replica.assert_not_called() + mock_update_transfer.assert_not_called() mock_update_minion_machine.assert_not_called() mock_minion_manager_client.deallocate_minion_machine\ .assert_not_called() @@ -4732,69 +4732,69 @@ def test_update_task_progress_update( new_message=mock.sentinel.new_message, ) - @mock.patch.object(db_api, "get_replica_schedule") + @mock.patch.object(db_api, "get_transfer_schedule") def test__get_replica_schedule( self, - mock_get_replica_schedule + mock_get_transfer_schedule ): result = self.server._get_replica_schedule( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=True ) self.assertEqual( - mock_get_replica_schedule.return_value, + mock_get_transfer_schedule.return_value, result ) - mock_get_replica_schedule.assert_called_once_with( + mock_get_transfer_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=True ) - mock_get_replica_schedule.reset_mock() - mock_get_replica_schedule.return_value = None + mock_get_transfer_schedule.reset_mock() + mock_get_transfer_schedule.return_value = None self.assertRaises( exception.NotFound, self.server._get_replica_schedule, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=False ) - mock_get_replica_schedule.assert_called_once_with( + mock_get_transfer_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=False ) @mock.patch.object(server.ConductorServerEndpoint, "get_replica_schedule") - @mock.patch.object(db_api, "add_replica_schedule") - @mock.patch.object(models, "ReplicaSchedule") + @mock.patch.object(db_api, "add_transfer_schedule") + @mock.patch.object(models, "TransferSchedule") @mock.patch.object(server.ConductorServerEndpoint, "_get_replica") @mock.patch.object(keystone, "create_trust") def test_create_replica_schedule( self, mock_create_trust, mock_get_replica, - mock_ReplicaSchedule, - mock_add_replica_schedule, + mock_transfer_schedule, + mock_add_transfer_schedule, mock_get_replica_schedule ): context = mock.Mock() - replica_schedule = mock.Mock() + transfer_schedule = mock.Mock() context.trust_id = mock.sentinel.trust_id - mock_ReplicaSchedule.return_value = replica_schedule + mock_transfer_schedule.return_value = transfer_schedule result = self.server.create_replica_schedule( context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule, mock.sentinel.enabled, mock.sentinel.exp_date, @@ -4807,17 +4807,17 @@ def test_create_replica_schedule( ) self.assertEqual( ( - replica_schedule.replica, - replica_schedule.replica_id, - replica_schedule.schedule, - replica_schedule.expiration_date, - replica_schedule.enabled, - replica_schedule.shutdown_instance, - replica_schedule.trust_id + transfer_schedule.transfer, + transfer_schedule.transfer_id, + transfer_schedule.schedule, + transfer_schedule.expiration_date, + transfer_schedule.enabled, + transfer_schedule.shutdown_instance, + transfer_schedule.trust_id ), ( mock_get_replica.return_value, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule, mock.sentinel.exp_date, mock.sentinel.enabled, @@ -4828,32 +4828,32 @@ def test_create_replica_schedule( mock_create_trust.assert_called_once_with(context) mock_get_replica.assert_called_once_with( context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, ) - mock_ReplicaSchedule.assert_called_once() - mock_add_replica_schedule.assert_called_once_with( + mock_transfer_schedule.assert_called_once() + mock_add_transfer_schedule.assert_called_once_with( context, - replica_schedule, + transfer_schedule, mock.ANY ) mock_get_replica_schedule.assert_called_once_with( context, - mock.sentinel.replica_id, - replica_schedule.id + mock.sentinel.transfer_id, + transfer_schedule.id ) @mock.patch.object(server.ConductorServerEndpoint, "_get_replica_schedule") - @mock.patch.object(db_api, "update_replica_schedule") + @mock.patch.object(db_api, "update_transfer_schedule") def test_update_replica_schedule( self, - mock_update_replica_schedule, + mock_update_transfer_schedule, mock_get_replica_schedule ): result = testutils.get_wrapped_function( self.server.update_replica_schedule)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, mock.sentinel.updated_values, ) @@ -4862,9 +4862,9 @@ def test_update_replica_schedule( mock_get_replica_schedule.return_value, result ) - mock_update_replica_schedule.assert_called_once_with( + mock_update_transfer_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, mock.sentinel.updated_values, None, @@ -4872,7 +4872,7 @@ def test_update_replica_schedule( ) mock_get_replica_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, ) @@ -4917,12 +4917,12 @@ def test_cleanup_schedule_resources( mock_delete_trust.assert_called_once_with( mock_get_admin_context.return_value) - @mock.patch.object(db_api, "delete_replica_schedule") + @mock.patch.object(db_api, "delete_transfer_schedule") @mock.patch.object(server.ConductorServerEndpoint, "_get_replica") def test_delete_replica_schedule( self, mock_get_replica, - mock_delete_replica_schedule + mock_delete_transfer_schedule ): replica = mock.Mock() replica.last_execution_status = constants.EXECUTION_STATUS_COMPLETED @@ -4931,24 +4931,24 @@ def test_delete_replica_schedule( testutils.get_wrapped_function(self.server.delete_replica_schedule)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) - mock_delete_replica_schedule.assert_called_once_with( + mock_delete_transfer_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, None, mock.ANY ) mock_get_replica.reset_mock() - mock_delete_replica_schedule.reset_mock() + mock_delete_transfer_schedule.reset_mock() replica.last_execution_status = constants.EXECUTION_STATUS_RUNNING self.assertRaises( @@ -4957,18 +4957,18 @@ def test_delete_replica_schedule( self.server.delete_replica_schedule), self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id + mock.sentinel.transfer_id ) - mock_delete_replica_schedule.assert_not_called() + mock_delete_transfer_schedule.assert_not_called() - @mock.patch.object(db_api, "get_replica_schedules") - def test_get_replica_schedules(self, mock_get_replica_schedules): + @mock.patch.object(db_api, "get_transfer_schedules") + def test_get_replica_schedules(self, mock_get_transfer_schedules): result = testutils.get_wrapped_function( self.server.get_replica_schedules)( self.server, @@ -4978,33 +4978,33 @@ def test_get_replica_schedules(self, mock_get_replica_schedules): ) self.assertEqual( - mock_get_replica_schedules.return_value, + mock_get_transfer_schedules.return_value, result ) - mock_get_replica_schedules.assert_called_once_with( + mock_get_transfer_schedules.assert_called_once_with( mock.sentinel.context, - replica_id=None, + transfer_id=None, expired=True ) - @mock.patch.object(db_api, "get_replica_schedule") - def test_get_replica_schedule(self, mock_get_replica_schedule): + @mock.patch.object(db_api, "get_transfer_schedule") + def test_get_replica_schedule(self, mock_get_transfer_schedule): result = testutils.get_wrapped_function( self.server.get_replica_schedule)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=True ) self.assertEqual( - mock_get_replica_schedule.return_value, + mock_get_transfer_schedule.return_value, result ) - mock_get_replica_schedule.assert_called_once_with( + mock_get_transfer_schedule.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, mock.sentinel.schedule_id, expired=True ) @@ -5012,7 +5012,7 @@ def test_get_replica_schedule(self, mock_get_replica_schedule): @mock.patch.object(server.ConductorServerEndpoint, "get_replica_tasks_execution") @mock.patch.object(server.ConductorServerEndpoint, "_begin_tasks") - @mock.patch.object(db_api, "add_replica_tasks_execution") + @mock.patch.object(db_api, "add_transfer_tasks_execution") @mock.patch.object(db_api, "update_transfer_action_info_for_instance") @mock.patch.object(server.ConductorServerEndpoint, "_check_execution_tasks_sanity") @@ -5025,14 +5025,14 @@ def test_get_replica_schedule(self, mock_get_replica_schedule): "_check_replica_running_executions") @mock.patch.object(server.ConductorServerEndpoint, "_check_minion_pools_for_action") - @mock.patch.object(models, "Replica") + @mock.patch.object(models, "Transfer") @mock.patch.object(server.ConductorServerEndpoint, "_get_replica") @ddt.file_data("data/update_replica_config.yml") @ddt.unpack def test_update_replica( self, mock_get_replica, - mock_Replica, + mock_transfer, mock_check_minion_pools_for_action, mock_check_replica_running_executions, mock_check_valid_replica_tasks_execution, @@ -5041,27 +5041,27 @@ def test_update_replica( mock_create_task, mock_check_execution_tasks_sanity, mock_update_transfer_action_info_for_instance, - mock_add_replica_tasks_execution, + mock_add_transfer_tasks_execution, mock_begin_tasks, mock_get_replica_tasks_execution, config, has_updated_values, has_replica_instance ): - replica = mock.Mock() + transfer = mock.Mock() dummy = mock.Mock() execution = mock.Mock() - replica.instances = config['replica'].get("instances", []) - replica.info = config['replica'].get("info", {}) - mock_get_replica.return_value = replica - mock_Replica.return_value = dummy + transfer.instances = config['replica'].get("instances", []) + transfer.info = config['replica'].get("info", {}) + mock_get_replica.return_value = transfer + mock_transfer.return_value = dummy mock_TasksExecution.return_value = execution updated_properties = config.get("updated_properties", {}) result = testutils.get_wrapped_function(self.server.update_replica)( self.server, mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, updated_properties ) @@ -5071,7 +5071,7 @@ def test_update_replica( ) mock_get_replica.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, include_task_info=True ) mock_check_replica_running_executions.assert_called_once_with( @@ -5088,20 +5088,20 @@ def test_update_replica( ) mock_check_execution_tasks_sanity.assert_called_once_with( execution, - replica.info + transfer.info ) - mock_add_replica_tasks_execution.assert_called_once_with( + mock_add_transfer_tasks_execution.assert_called_once_with( mock.sentinel.context, execution ) mock_begin_tasks.assert_called_once_with( mock.sentinel.context, - replica, + transfer, execution ) mock_get_replica_tasks_execution.assert_called_once_with( mock.sentinel.context, - mock.sentinel.replica_id, + mock.sentinel.transfer_id, execution.id ) if has_updated_values: @@ -5119,7 +5119,7 @@ def test_update_replica( expected_sanitize_task_info_calls.append( mock.call(mock.ANY)) expected_sanitize_task_info_calls.append( - mock.call(replica.info[instance])) + mock.call(transfer.info[instance])) create_task_calls.append(mock.call( instance, constants.TASK_TYPE_GET_INSTANCE_INFO, @@ -5136,9 +5136,9 @@ def test_update_replica( update_transfer_action_info_for_instance_calls.append( mock.call( mock.sentinel.context, - replica.id, + transfer.id, instance, - replica.info[instance]) + transfer.info[instance]) ) mock_sanitize_task_info.assert_has_calls( expected_sanitize_task_info_calls) diff --git a/coriolis/tests/replica_cron/rpc/test_server.py b/coriolis/tests/replica_cron/rpc/test_server.py index ba06523a9..1fdb3ca38 100644 --- a/coriolis/tests/replica_cron/rpc/test_server.py +++ b/coriolis/tests/replica_cron/rpc/test_server.py @@ -27,10 +27,10 @@ def test__trigger_replica(self): result = server._trigger_replica( mock.sentinel.ctxt, mock_conductor_client, - mock.sentinel.replica_id, False) + mock.sentinel.transfer_id, False) mock_conductor_client.execute_replica_tasks.assert_called_once_with( - mock.sentinel.ctxt, mock.sentinel.replica_id, False) + mock.sentinel.ctxt, mock.sentinel.transfer_id, False) self.assertEqual( result, 'Execution %s for Replica %s' % ( diff --git a/coriolis/tests/replica_cron/test_api.py b/coriolis/tests/replica_cron/test_api.py index a78434e46..a770b4e24 100644 --- a/coriolis/tests/replica_cron/test_api.py +++ b/coriolis/tests/replica_cron/test_api.py @@ -16,7 +16,7 @@ def setUp(self): self.rpc_client = mock.MagicMock() self.api._rpc_client = self.rpc_client self.ctxt = mock.sentinel.ctxt - self.replica_id = mock.sentinel.replica_id + self.replica_id = mock.sentinel.transfer_id self.schedule_id = mock.sentinel.schedule_id def test_create(self): diff --git a/coriolis/tests/replica_tasks_executions/test_api.py b/coriolis/tests/replica_tasks_executions/test_api.py index 3ae28f414..077e2876d 100644 --- a/coriolis/tests/replica_tasks_executions/test_api.py +++ b/coriolis/tests/replica_tasks_executions/test_api.py @@ -16,7 +16,7 @@ def setUp(self): self.rpc_client = mock.MagicMock() self.api._rpc_client = self.rpc_client self.ctxt = mock.sentinel.ctxt - self.replica_id = mock.sentinel.replica_id + self.replica_id = mock.sentinel.transfer_id self.execution_id = mock.sentinel.execution_id def test_create(self): diff --git a/coriolis/tests/replicas/test_api.py b/coriolis/tests/replicas/test_api.py index 3611ffb95..a948da8f1 100644 --- a/coriolis/tests/replicas/test_api.py +++ b/coriolis/tests/replicas/test_api.py @@ -16,7 +16,7 @@ def setUp(self): self.rpc_client = mock.MagicMock() self.api._rpc_client = self.rpc_client self.ctxt = mock.sentinel.ctxt - self.replica_id = mock.sentinel.replica_id + self.replica_id = mock.sentinel.transfer_id def test_create(self): origin_endpoint_id = mock.sentinel.origin_endpoint_id