diff --git a/coriolis/api/v1/deployments.py b/coriolis/api/v1/deployments.py index 8b92743a3..bc682d9fb 100644 --- a/coriolis/api/v1/deployments.py +++ b/coriolis/api/v1/deployments.py @@ -65,13 +65,13 @@ def detail(self, req): def _validate_deployment_input(self, context, body): deployment = body["deployment"] - replica_id = deployment.get("replica_id", "") + transfer_id = deployment.get("transfer_id", "") - if not replica_id: + if not transfer_id: raise exc.HTTPBadRequest( - explanation="Missing 'replica_id' field from deployment " + explanation="Missing 'transfer_id' field from deployment " "body. A deployment can be created strictly " - "based on an existing Replica.") + "based on an existing Transfer.") clone_disks = deployment.get("clone_disks", True) force = deployment.get("force", False) @@ -84,7 +84,7 @@ def _validate_deployment_input(self, context, body): user_scripts, deployment.get("instances", [])) return ( - replica_id, force, clone_disks, skip_os_morphing, + transfer_id, force, clone_disks, skip_os_morphing, instance_osmorphing_minion_pool_mappings, user_scripts) @@ -92,15 +92,15 @@ def create(self, req, body): context = req.environ['coriolis.context'] context.can(deployment_policies.get_deployments_policy_label("create")) - (replica_id, force, clone_disks, skip_os_morphing, + (transfer_id, force, clone_disks, skip_os_morphing, instance_osmorphing_minion_pool_mappings, user_scripts) = self._validate_deployment_input( context, body) - # NOTE: destination environment for replica should have been + # NOTE: destination environment for transfer should have been # validated upon its creation. - deployment = self._deployment_api.deploy_replica_instances( - context, replica_id, instance_osmorphing_minion_pool_mappings, + deployment = self._deployment_api.deploy_transfer_instances( + context, transfer_id, instance_osmorphing_minion_pool_mappings, clone_disks, force, skip_os_morphing, user_scripts=user_scripts) diff --git a/coriolis/api/v1/replica_tasks_executions.py b/coriolis/api/v1/replica_tasks_executions.py deleted file mode 100644 index b755e4866..000000000 --- a/coriolis/api/v1/replica_tasks_executions.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2016 Cloudbase Solutions Srl -# All Rights Reserved. - -from coriolis.api.v1.views import replica_tasks_execution_view -from coriolis.api import wsgi as api_wsgi -from coriolis import exception -from coriolis.policies import replica_tasks_executions as executions_policies -from coriolis.replica_tasks_executions import api - -from webob import exc - - -class ReplicaTasksExecutionController(api_wsgi.Controller): - def __init__(self): - self._replica_tasks_execution_api = api.API() - super(ReplicaTasksExecutionController, self).__init__() - - def show(self, req, replica_id, id): - context = req.environ["coriolis.context"] - context.can( - executions_policies.get_replica_executions_policy_label("show")) - execution = self._replica_tasks_execution_api.get_execution( - context, replica_id, id) - if not execution: - raise exc.HTTPNotFound() - - return replica_tasks_execution_view.single(execution) - - def index(self, req, replica_id): - context = req.environ["coriolis.context"] - context.can( - executions_policies.get_replica_executions_policy_label("list")) - - return replica_tasks_execution_view.collection( - self._replica_tasks_execution_api.get_executions( - context, replica_id, include_tasks=False)) - - def detail(self, req, replica_id): - context = req.environ["coriolis.context"] - context.can( - executions_policies.get_replica_executions_policy_label("show")) - - return replica_tasks_execution_view.collection( - self._replica_tasks_execution_api.get_executions( - context, replica_id, include_tasks=True)) - - def create(self, req, replica_id, body): - context = req.environ["coriolis.context"] - context.can( - executions_policies.get_replica_executions_policy_label("create")) - - # TODO(alexpilotti): validate body - - execution_body = body.get("execution", {}) - shutdown_instances = execution_body.get("shutdown_instances", False) - - return replica_tasks_execution_view.single( - self._replica_tasks_execution_api.create( - context, replica_id, shutdown_instances)) - - def delete(self, req, replica_id, id): - context = req.environ["coriolis.context"] - context.can( - executions_policies.get_replica_executions_policy_label("delete")) - - try: - self._replica_tasks_execution_api.delete(context, replica_id, id) - raise exc.HTTPNoContent() - except exception.NotFound as ex: - raise exc.HTTPNotFound(explanation=ex.msg) - - -def create_resource(): - return api_wsgi.Resource(ReplicaTasksExecutionController()) diff --git a/coriolis/api/v1/router.py b/coriolis/api/v1/router.py index 28a44f7dd..352979571 100644 --- a/coriolis/api/v1/router.py +++ b/coriolis/api/v1/router.py @@ -21,12 +21,12 @@ from coriolis.api.v1 import provider_schemas from coriolis.api.v1 import providers from coriolis.api.v1 import regions -from coriolis.api.v1 import replica_actions -from coriolis.api.v1 import replica_schedules -from coriolis.api.v1 import replica_tasks_execution_actions -from coriolis.api.v1 import replica_tasks_executions -from coriolis.api.v1 import replicas from coriolis.api.v1 import services +from coriolis.api.v1 import transfer_actions +from coriolis.api.v1 import transfer_schedules +from coriolis.api.v1 import transfer_tasks_execution_actions +from coriolis.api.v1 import transfer_tasks_executions +from coriolis.api.v1 import transfers LOG = logging.getLogger(__name__) @@ -154,44 +154,46 @@ def _setup_routes(self, mapper, ext_mgr): action='action', conditions={'method': 'POST'}) - self.resources['replicas'] = replicas.create_resource() - mapper.resource('replica', 'replicas', - controller=self.resources['replicas'], + self.resources['transfers'] = transfers.create_resource() + mapper.resource('transfer', 'transfers', + controller=self.resources['transfers'], collection={'detail': 'GET'}, member={'action': 'POST'}) - replica_actions_resource = replica_actions.create_resource() - self.resources['replica_actions'] = replica_actions_resource - migration_path = '/{project_id}/replicas/{id}' - mapper.connect('replica_actions', + transfer_actions_resource = transfer_actions.create_resource() + self.resources['transfer_actions'] = transfer_actions_resource + migration_path = '/{project_id}/transfers/{id}' + mapper.connect('transfer_actions', migration_path + '/actions', - controller=self.resources['replica_actions'], + controller=self.resources['transfer_actions'], action='action', conditions={'method': 'POST'}) - self.resources['replica_tasks_executions'] = \ - replica_tasks_executions.create_resource() - mapper.resource('execution', 'replicas/{replica_id}/executions', - controller=self.resources['replica_tasks_executions'], + self.resources['transfer_tasks_executions'] = \ + transfer_tasks_executions.create_resource() + mapper.resource('execution', 'transfers/{transfer_id}/executions', + controller=self.resources['transfer_tasks_executions'], collection={'detail': 'GET'}, member={'action': 'POST'}) - replica_tasks_execution_actions_resource = \ - replica_tasks_execution_actions.create_resource() - self.resources['replica_tasks_execution_actions'] = \ - replica_tasks_execution_actions_resource - migration_path = '/{project_id}/replicas/{replica_id}/executions/{id}' - mapper.connect('replica_tasks_execution_actions', + transfer_tasks_execution_actions_resource = \ + transfer_tasks_execution_actions.create_resource() + self.resources['transfer_tasks_execution_actions'] = \ + transfer_tasks_execution_actions_resource + migration_path = ('/{project_id}/transfers/{transfer_id}/' + 'executions/{id}') + mapper.connect('transfer_tasks_execution_actions', migration_path + '/actions', controller=self.resources[ - 'replica_tasks_execution_actions'], + 'transfer_tasks_execution_actions'], action='action', conditions={'method': 'POST'}) - sched = replica_schedules.create_resource() - self.resources['replica_schedules'] = sched - mapper.resource('replica_schedule', 'replicas/{replica_id}/schedules', - controller=self.resources['replica_schedules'], + sched = transfer_schedules.create_resource() + self.resources['transfer_schedules'] = sched + mapper.resource('transfer_schedule', + 'transfers/{transfer_id}/schedules', + controller=self.resources['transfer_schedules'], collection={'index': 'GET'}, member={'action': 'POST'}) diff --git a/coriolis/api/v1/replica_actions.py b/coriolis/api/v1/transfer_actions.py similarity index 50% rename from coriolis/api/v1/replica_actions.py rename to coriolis/api/v1/transfer_actions.py index adb82a26f..487e00994 100644 --- a/coriolis/api/v1/replica_actions.py +++ b/coriolis/api/v1/transfer_actions.py @@ -1,28 +1,28 @@ # Copyright 2016 Cloudbase Solutions Srl # All Rights Reserved. -from coriolis.api.v1.views import replica_tasks_execution_view +from coriolis.api.v1.views import transfer_tasks_execution_view from coriolis.api import wsgi as api_wsgi from coriolis import exception -from coriolis.policies import replicas as replica_policies -from coriolis.replicas import api +from coriolis.policies import transfers as transfer_policies +from coriolis.transfers import api from webob import exc -class ReplicaActionsController(api_wsgi.Controller): +class TransferActionsController(api_wsgi.Controller): def __init__(self): - self._replica_api = api.API() - super(ReplicaActionsController, self).__init__() + self._transfer_api = api.API() + super(TransferActionsController, self).__init__() @api_wsgi.action('delete-disks') def _delete_disks(self, req, id, body): context = req.environ['coriolis.context'] context.can( - replica_policies.get_replicas_policy_label("delete_disks")) + transfer_policies.get_transfers_policy_label("delete_disks")) try: - return replica_tasks_execution_view.single( - self._replica_api.delete_disks(context, id)) + return transfer_tasks_execution_view.single( + self._transfer_api.delete_disks(context, id)) except exception.NotFound as ex: raise exc.HTTPNotFound(explanation=ex.msg) except exception.InvalidParameterValue as ex: @@ -30,4 +30,4 @@ def _delete_disks(self, req, id, body): def create_resource(): - return api_wsgi.Resource(ReplicaActionsController()) + return api_wsgi.Resource(TransferActionsController()) diff --git a/coriolis/api/v1/replica_schedules.py b/coriolis/api/v1/transfer_schedules.py similarity index 69% rename from coriolis/api/v1/replica_schedules.py rename to coriolis/api/v1/transfer_schedules.py index 53edf7c3d..2ea70ce9f 100644 --- a/coriolis/api/v1/replica_schedules.py +++ b/coriolis/api/v1/transfer_schedules.py @@ -1,10 +1,10 @@ # Copyright 2017 Cloudbase Solutions Srl # All Rights Reserved. -from coriolis.api.v1.views import replica_schedule_view +from coriolis.api.v1.views import transfer_schedule_view from coriolis.api import wsgi as api_wsgi from coriolis import exception -from coriolis.policies import replica_schedules as schedules_policies +from coriolis.policies import transfer_schedules as schedules_policies from coriolis import schemas from coriolis.transfer_cron import api @@ -18,31 +18,31 @@ LOG = logging.getLogger(__name__) -class ReplicaScheduleController(api_wsgi.Controller): +class TransferScheduleController(api_wsgi.Controller): def __init__(self): self._schedule_api = api.API() - super(ReplicaScheduleController, self).__init__() + super(TransferScheduleController, self).__init__() - def show(self, req, replica_id, id): + def show(self, req, transfer_id, id): context = req.environ["coriolis.context"] context.can( - schedules_policies.get_replica_schedules_policy_label("show")) - schedule = self._schedule_api.get_schedule(context, replica_id, id) + schedules_policies.get_transfer_schedules_policy_label("show")) + schedule = self._schedule_api.get_schedule(context, transfer_id, id) if not schedule: raise exc.HTTPNotFound() - return replica_schedule_view.single(schedule) + return transfer_schedule_view.single(schedule) - def index(self, req, replica_id): + def index(self, req, transfer_id): context = req.environ["coriolis.context"] context.can( - schedules_policies.get_replica_schedules_policy_label("list")) + schedules_policies.get_transfer_schedules_policy_label("list")) show_expired = strutils.bool_from_string( req.GET.get("show_expired", True), strict=True) - return replica_schedule_view.collection( + return transfer_schedule_view.collection( self._schedule_api.get_schedules( - context, replica_id, expired=show_expired)) + context, transfer_id, expired=show_expired)) def _validate_schedule(self, schedule): schema = schemas.SCHEDULE_API_BODY_SCHEMA["properties"]["schedule"] @@ -100,45 +100,45 @@ def _validate_update_body(self, update_body): body["expiration_date"] = exp return body - def create(self, req, replica_id, body): + def create(self, req, transfer_id, body): context = req.environ["coriolis.context"] context.can( - schedules_policies.get_replica_schedules_policy_label("create")) + schedules_policies.get_transfer_schedules_policy_label("create")) - LOG.debug("Got request: %r %r %r" % (req, replica_id, body)) + LOG.debug("Got request: %r %r %r" % (req, transfer_id, body)) try: schedule, enabled, exp_date, shutdown = self._validate_create_body( body) except Exception as err: raise exception.InvalidInput(err) - return replica_schedule_view.single(self._schedule_api.create( - context, replica_id, schedule, enabled, exp_date, shutdown)) + return transfer_schedule_view.single(self._schedule_api.create( + context, transfer_id, schedule, enabled, exp_date, shutdown)) - def update(self, req, replica_id, id, body): + def update(self, req, transfer_id, id, body): context = req.environ["coriolis.context"] context.can( - schedules_policies.get_replica_schedules_policy_label("update")) + schedules_policies.get_transfer_schedules_policy_label("update")) LOG.debug("Got request: %r %r %r %r" % ( - req, replica_id, id, body)) + req, transfer_id, id, body)) try: update_values = self._validate_update_body(body) except Exception as err: raise exception.InvalidInput(err) - return replica_schedule_view.single(self._schedule_api.update( - context, replica_id, id, update_values)) + return transfer_schedule_view.single(self._schedule_api.update( + context, transfer_id, id, update_values)) - def delete(self, req, replica_id, id): + def delete(self, req, transfer_id, id): context = req.environ["coriolis.context"] context.can( - schedules_policies.get_replica_schedules_policy_label("delete")) + schedules_policies.get_transfer_schedules_policy_label("delete")) - self._schedule_api.delete(context, replica_id, id) + self._schedule_api.delete(context, transfer_id, id) raise exc.HTTPNoContent() def create_resource(): - return api_wsgi.Resource(ReplicaScheduleController()) + return api_wsgi.Resource(TransferScheduleController()) diff --git a/coriolis/api/v1/replica_tasks_execution_actions.py b/coriolis/api/v1/transfer_tasks_execution_actions.py similarity index 50% rename from coriolis/api/v1/replica_tasks_execution_actions.py rename to coriolis/api/v1/transfer_tasks_execution_actions.py index b7bcca857..27998046d 100644 --- a/coriolis/api/v1/replica_tasks_execution_actions.py +++ b/coriolis/api/v1/transfer_tasks_execution_actions.py @@ -5,25 +5,25 @@ from coriolis.api import wsgi as api_wsgi from coriolis import exception -from coriolis.policies import replica_tasks_executions as execution_policies -from coriolis.replica_tasks_executions import api +from coriolis.policies import transfer_tasks_executions as execution_policies +from coriolis.transfer_tasks_executions import api -class ReplicaTasksExecutionActionsController(api_wsgi.Controller): +class TransferTasksExecutionActionsController(api_wsgi.Controller): def __init__(self): - self._replica_tasks_execution_api = api.API() - super(ReplicaTasksExecutionActionsController, self).__init__() + self._transfer_tasks_execution_api = api.API() + super(TransferTasksExecutionActionsController, self).__init__() @api_wsgi.action('cancel') - def _cancel(self, req, replica_id, id, body): + def _cancel(self, req, transfer_id, id, body): context = req.environ['coriolis.context'] context.can( - execution_policies.get_replica_executions_policy_label('cancel')) + execution_policies.get_transfer_executions_policy_label('cancel')) try: force = (body["cancel"] or {}).get("force", False) - self._replica_tasks_execution_api.cancel( - context, replica_id, id, force) + self._transfer_tasks_execution_api.cancel( + context, transfer_id, id, force) raise exc.HTTPNoContent() except exception.NotFound as ex: raise exc.HTTPNotFound(explanation=ex.msg) @@ -32,4 +32,4 @@ def _cancel(self, req, replica_id, id, body): def create_resource(): - return api_wsgi.Resource(ReplicaTasksExecutionActionsController()) + return api_wsgi.Resource(TransferTasksExecutionActionsController()) diff --git a/coriolis/api/v1/transfer_tasks_executions.py b/coriolis/api/v1/transfer_tasks_executions.py new file mode 100644 index 000000000..68f029e2e --- /dev/null +++ b/coriolis/api/v1/transfer_tasks_executions.py @@ -0,0 +1,74 @@ +# Copyright 2016 Cloudbase Solutions Srl +# All Rights Reserved. + +from coriolis.api.v1.views import transfer_tasks_execution_view +from coriolis.api import wsgi as api_wsgi +from coriolis import exception +from coriolis.policies import transfer_tasks_executions as executions_policies +from coriolis.transfer_tasks_executions import api + +from webob import exc + + +class TransferTasksExecutionController(api_wsgi.Controller): + def __init__(self): + self._transfer_tasks_execution_api = api.API() + super(TransferTasksExecutionController, self).__init__() + + def show(self, req, transfer_id, id): + context = req.environ["coriolis.context"] + context.can( + executions_policies.get_transfer_executions_policy_label("show")) + execution = self._transfer_tasks_execution_api.get_execution( + context, transfer_id, id) + if not execution: + raise exc.HTTPNotFound() + + return transfer_tasks_execution_view.single(execution) + + def index(self, req, transfer_id): + context = req.environ["coriolis.context"] + context.can( + executions_policies.get_transfer_executions_policy_label("list")) + + return transfer_tasks_execution_view.collection( + self._transfer_tasks_execution_api.get_executions( + context, transfer_id, include_tasks=False)) + + def detail(self, req, transfer_id): + context = req.environ["coriolis.context"] + context.can( + executions_policies.get_transfer_executions_policy_label("show")) + + return transfer_tasks_execution_view.collection( + self._transfer_tasks_execution_api.get_executions( + context, transfer_id, include_tasks=True)) + + def create(self, req, transfer_id, body): + context = req.environ["coriolis.context"] + context.can( + executions_policies.get_transfer_executions_policy_label("create")) + + # TODO(alexpilotti): validate body + + execution_body = body.get("execution", {}) + shutdown_instances = execution_body.get("shutdown_instances", False) + + return transfer_tasks_execution_view.single( + self._transfer_tasks_execution_api.create( + context, transfer_id, shutdown_instances)) + + def delete(self, req, transfer_id, id): + context = req.environ["coriolis.context"] + context.can( + executions_policies.get_transfer_executions_policy_label("delete")) + + try: + self._transfer_tasks_execution_api.delete(context, transfer_id, id) + raise exc.HTTPNoContent() + except exception.NotFound as ex: + raise exc.HTTPNotFound(explanation=ex.msg) + + +def create_resource(): + return api_wsgi.Resource(TransferTasksExecutionController()) diff --git a/coriolis/api/v1/replicas.py b/coriolis/api/v1/transfers.py similarity index 72% rename from coriolis/api/v1/replicas.py rename to coriolis/api/v1/transfers.py index 197d80e84..511cfd2d8 100644 --- a/coriolis/api/v1/replicas.py +++ b/coriolis/api/v1/transfers.py @@ -2,61 +2,61 @@ # All Rights Reserved. from coriolis.api.v1 import utils as api_utils -from coriolis.api.v1.views import replica_tasks_execution_view -from coriolis.api.v1.views import replica_view +from coriolis.api.v1.views import transfer_tasks_execution_view +from coriolis.api.v1.views import transfer_view from coriolis.api import wsgi as api_wsgi from coriolis import constants from coriolis.endpoints import api as endpoints_api from coriolis import exception -from coriolis.policies import replicas as replica_policies -from coriolis.replicas import api +from coriolis.policies import transfers as transfer_policies +from coriolis.transfers import api from oslo_config import cfg as conf from oslo_log import log as logging from webob import exc -REPLICA_API_OPTS = [ - conf.BoolOpt("include_task_info_in_replicas_api", +TRANSFER_API_OPTS = [ + conf.BoolOpt("include_task_info_in_transfers_api", default=False, help="Whether or not to expose the internal 'info' field of " - "a Replica as part of a `GET` request.")] + "a Transfer as part of a `GET` request.")] CONF = conf.CONF -CONF.register_opts(REPLICA_API_OPTS, 'api') +CONF.register_opts(TRANSFER_API_OPTS, 'api') LOG = logging.getLogger(__name__) -SUPPORTED_REPLICA_SCENARIOS = [ +SUPPORTED_TRANSFER_SCENARIOS = [ constants.TRANSFER_SCENARIO_REPLICA, constants.TRANSFER_SCENARIO_LIVE_MIGRATION] -class ReplicaController(api_wsgi.Controller): +class TransferController(api_wsgi.Controller): def __init__(self): - self._replica_api = api.API() + self._transfer_api = api.API() self._endpoints_api = endpoints_api.API() - super(ReplicaController, self).__init__() + super(TransferController, self).__init__() def show(self, req, id): context = req.environ["coriolis.context"] - context.can(replica_policies.get_replicas_policy_label("show")) - replica = self._replica_api.get_replica( + context.can(transfer_policies.get_transfers_policy_label("show")) + transfer = self._transfer_api.get_transfer( context, id, - include_task_info=CONF.api.include_task_info_in_replicas_api) - if not replica: + include_task_info=CONF.api.include_task_info_in_transfers_api) + if not transfer: raise exc.HTTPNotFound() - return replica_view.single(replica) + return transfer_view.single(transfer) def _list(self, req): show_deleted = api_utils._get_show_deleted( req.GET.get("show_deleted", None)) context = req.environ["coriolis.context"] context.show_deleted = show_deleted - context.can(replica_policies.get_replicas_policy_label("list")) - include_task_info = CONF.api.include_task_info_in_replicas_api - return replica_view.collection( - self._replica_api.get_replicas( + context.can(transfer_policies.get_transfers_policy_label("list")) + include_task_info = CONF.api.include_task_info_in_transfers_api + return transfer_view.collection( + self._transfer_api.get_transfers( context, include_tasks_executions=include_task_info, include_task_info=include_task_info)) @@ -67,41 +67,41 @@ def index(self, req): def detail(self, req): return self._list(req) - @api_utils.format_keyerror_message(resource='replica', method='create') + @api_utils.format_keyerror_message(resource='transfer', method='create') def _validate_create_body(self, context, body): - replica = body["replica"] + transfer = body["transfer"] - scenario = replica.get("scenario", "") + scenario = transfer.get("scenario", "") if scenario: - if scenario not in SUPPORTED_REPLICA_SCENARIOS: + if scenario not in SUPPORTED_TRANSFER_SCENARIOS: raise exc.HTTPBadRequest( - explanation=f"Unsupported Replica creation scenario " + explanation=f"Unsupported Transfer creation scenario " f"'{scenario}', must be one of: " - f"{SUPPORTED_REPLICA_SCENARIOS}") + f"{SUPPORTED_TRANSFER_SCENARIOS}") else: scenario = constants.TRANSFER_SCENARIO_REPLICA LOG.warn( - "No Replica 'scenario' field set in Replica body, " + "No Transfer 'scenario' field set in Transfer body, " f"defaulting to: '{scenario}'") - origin_endpoint_id = replica["origin_endpoint_id"] - destination_endpoint_id = replica["destination_endpoint_id"] - destination_environment = replica.get( + origin_endpoint_id = transfer["origin_endpoint_id"] + destination_endpoint_id = transfer["destination_endpoint_id"] + destination_environment = transfer.get( "destination_environment", {}) instances = api_utils.validate_instances_list_for_transfer( - replica.get('instances')) + transfer.get('instances')) - notes = replica.get("notes") + notes = transfer.get("notes") - source_environment = replica.get("source_environment", {}) + source_environment = transfer.get("source_environment", {}) self._endpoints_api.validate_source_environment( context, origin_endpoint_id, source_environment) - origin_minion_pool_id = replica.get( + origin_minion_pool_id = transfer.get( 'origin_minion_pool_id') - destination_minion_pool_id = replica.get( + destination_minion_pool_id = transfer.get( 'destination_minion_pool_id') - instance_osmorphing_minion_pool_mappings = replica.get( + instance_osmorphing_minion_pool_mappings = transfer.get( 'instance_osmorphing_minion_pool_mappings', {}) extras = [ instance @@ -111,18 +111,18 @@ def _validate_create_body(self, context, body): raise ValueError( "One or more instance OSMorphing pool mappings were " "provided for instances (%s) which are not part of the " - "Replicas's declared instances (%s)" % (extras, instances)) + "Transfer's declared instances (%s)" % (extras, instances)) # TODO(aznashwan): until the provider plugin interface is updated # to have separate 'network_map' and 'storage_mappings' fields, # we add them as part of the destination environment: - network_map = replica.get("network_map", {}) + network_map = transfer.get("network_map", {}) api_utils.validate_network_map(network_map) destination_environment['network_map'] = network_map self._endpoints_api.validate_target_environment( context, destination_endpoint_id, destination_environment) - user_scripts = replica.get('user_scripts', {}) + user_scripts = transfer.get('user_scripts', {}) api_utils.validate_user_scripts(user_scripts) user_scripts = api_utils.normalize_user_scripts( user_scripts, instances) @@ -131,7 +131,7 @@ def _validate_create_body(self, context, body): # import provider before appending the 'storage_mappings' parameter # for plugins with strict property name checks which do not yet # support storage mapping features: - storage_mappings = replica.get("storage_mappings", {}) + storage_mappings = transfer.get("storage_mappings", {}) api_utils.validate_storage_mappings(storage_mappings) destination_environment['storage_mappings'] = storage_mappings @@ -144,7 +144,7 @@ def _validate_create_body(self, context, body): def create(self, req, body): context = req.environ["coriolis.context"] - context.can(replica_policies.get_replicas_policy_label("create")) + context.can(transfer_policies.get_transfers_policy_label("create")) (scenario, origin_endpoint_id, destination_endpoint_id, source_environment, destination_environment, instances, network_map, @@ -153,7 +153,7 @@ def create(self, req, body): instance_osmorphing_minion_pool_mappings, user_scripts) = ( self._validate_create_body(context, body)) - return replica_view.single(self._replica_api.create( + return transfer_view.single(self._transfer_api.create( context, scenario, origin_endpoint_id, destination_endpoint_id, origin_minion_pool_id, destination_minion_pool_id, instance_osmorphing_minion_pool_mappings, source_environment, @@ -162,9 +162,9 @@ def create(self, req, body): def delete(self, req, id): context = req.environ["coriolis.context"] - context.can(replica_policies.get_replicas_policy_label("delete")) + context.can(transfer_policies.get_transfers_policy_label("delete")) try: - self._replica_api.delete(context, id) + self._transfer_api.delete(context, id) raise exc.HTTPNoContent() except exception.NotFound as ex: raise exc.HTTPNotFound(explanation=ex.msg) @@ -234,8 +234,8 @@ def _get_updated_user_scripts(original_user_scripts, new_user_scripts): return user_scripts - def _get_merged_replica_values(self, replica, updated_values): - """ Looks for the following keys in the original replica body and + def _get_merged_transfer_values(self, transfer, updated_values): + """ Looks for the following keys in the original transfer body and updated values (preferring the updated values where needed, but using `.update()` on dicts): "source_environment", "destination_environment", "network_map", "notes" @@ -249,9 +249,9 @@ def _get_merged_replica_values(self, replica, updated_values): for option in [ "source_environment", "destination_environment", "network_map"]: - before = replica.get(option) + before = transfer.get(option) after = updated_values.get(option) - # NOTE: for Replicas created before the separation of these fields + # NOTE: for Transfers created before the separation of these fields # in the DB there is the chance that some of these may be NULL: if before is None: before = {} @@ -261,7 +261,7 @@ def _get_merged_replica_values(self, replica, updated_values): final_values[option] = before - original_storage_mappings = replica.get('storage_mappings') + original_storage_mappings = transfer.get('storage_mappings') if original_storage_mappings is None: original_storage_mappings = {} new_storage_mappings = updated_values.get('storage_mappings') @@ -271,7 +271,7 @@ def _get_merged_replica_values(self, replica, updated_values): original_storage_mappings, new_storage_mappings) original_user_scripts = api_utils.validate_user_scripts( - replica.get('user_scripts', {})) + transfer.get('user_scripts', {})) new_user_scripts = api_utils.validate_user_scripts( updated_values.get('user_scripts', {})) final_values['user_scripts'] = self._get_updated_user_scripts( @@ -280,7 +280,7 @@ def _get_merged_replica_values(self, replica, updated_values): if 'notes' in updated_values: final_values['notes'] = updated_values.get('notes', '') else: - final_values['notes'] = replica.get('notes', '') + final_values['notes'] = transfer.get('notes', '') # NOTE: until the provider plugin interface is updated # to have separate 'network_map' and 'storage_mappings' fields, @@ -304,48 +304,48 @@ def _get_merged_replica_values(self, replica, updated_values): return final_values - @api_utils.format_keyerror_message(resource='replica', method='update') + @api_utils.format_keyerror_message(resource='transfer', method='update') def _validate_update_body(self, id, context, body): - replica = self._replica_api.get_replica(context, id) + transfer = self._transfer_api.get_transfer(context, id) scenario = body.get("scenario", "") - if scenario and scenario != replica["scenario"]: + if scenario and scenario != transfer["scenario"]: raise exc.HTTPBadRequest( - explanation=f"Changing Replica creation scenario is not " + explanation=f"Changing Transfer creation scenario is not " f"supported (original scenario is " - f"{replica['scenario']}, received '{scenario}')") + f"{transfer['scenario']}, received '{scenario}')") - replica_body = body['replica'] - origin_endpoint_id = replica_body.get('origin_endpoint_id', None) - destination_endpoint_id = replica_body.get( + transfer_body = body['transfer'] + origin_endpoint_id = transfer_body.get('origin_endpoint_id', None) + destination_endpoint_id = transfer_body.get( 'destination_endpoint_id', None) - instances = body['replica'].get('instances', None) + instances = body['transfer'].get('instances', None) if origin_endpoint_id or destination_endpoint_id: raise exc.HTTPBadRequest( explanation="The source or destination endpoints for a " - "Coriolis Replica cannot be updated after its " + "Coriolis Transfer cannot be updated after its " "creation. If the credentials of any of the " - "Replica's endpoints need updating, please update " - "the endpoints themselves.") + "Transfer's endpoints need updating, please " + "update the endpoints themselves.") if instances: raise exc.HTTPBadRequest( - explanation="The list of instances of a Replica cannot be " + explanation="The list of instances of a Transfer cannot be " "updated") - merged_body = self._get_merged_replica_values( - replica, replica_body) + merged_body = self._get_merged_transfer_values( + transfer, transfer_body) - replica_origin_endpoint_id = replica["origin_endpoint_id"] - replica_destination_endpoint_id = replica[ + transfer_origin_endpoint_id = transfer["origin_endpoint_id"] + transfer_destination_endpoint_id = transfer[ "destination_endpoint_id"] self._endpoints_api.validate_source_environment( - context, replica_origin_endpoint_id, + context, transfer_origin_endpoint_id, merged_body["source_environment"]) destination_environment = merged_body["destination_environment"] self._endpoints_api.validate_target_environment( - context, replica_destination_endpoint_id, + context, transfer_destination_endpoint_id, destination_environment) api_utils.validate_network_map(merged_body["network_map"]) @@ -356,19 +356,19 @@ def _validate_update_body(self, id, context, body): user_scripts = merged_body['user_scripts'] api_utils.validate_user_scripts(user_scripts) merged_body['user_scripts'] = api_utils.normalize_user_scripts( - user_scripts, replica.get('instances', [])) + user_scripts, transfer.get('instances', [])) return merged_body def update(self, req, id, body): context = req.environ["coriolis.context"] - context.can(replica_policies.get_replicas_policy_label("update")) + context.can(transfer_policies.get_transfers_policy_label("update")) updated_values = self._validate_update_body(id, context, body) try: - return replica_tasks_execution_view.single( - self._replica_api.update(req.environ['coriolis.context'], - id, updated_values)) + return transfer_tasks_execution_view.single( + self._transfer_api.update(req.environ['coriolis.context'], + id, updated_values)) except exception.NotFound as ex: raise exc.HTTPNotFound(explanation=ex.msg) except exception.InvalidParameterValue as ex: @@ -376,4 +376,4 @@ def update(self, req, id, body): def create_resource(): - return api_wsgi.Resource(ReplicaController()) + return api_wsgi.Resource(TransferController()) diff --git a/coriolis/api/v1/views/deployment_view.py b/coriolis/api/v1/views/deployment_view.py index fb4186f33..1a32f562f 100644 --- a/coriolis/api/v1/views/deployment_view.py +++ b/coriolis/api/v1/views/deployment_view.py @@ -1,7 +1,7 @@ # Copyright 2024 Cloudbase Solutions Srl # All Rights Reserved. -from coriolis.api.v1.views import replica_tasks_execution_view as view +from coriolis.api.v1.views import transfer_tasks_execution_view as view from coriolis.api.v1.views import utils as view_utils @@ -9,7 +9,7 @@ def _format_deployment(deployment, keys=None): deployment_dict = view_utils.format_opt(deployment, keys) if len(deployment_dict.get("executions", [])): - execution = view.format_replica_tasks_execution( + execution = view.format_transfer_tasks_execution( deployment_dict["executions"][0], keys) del deployment_dict["executions"] else: diff --git a/coriolis/api/v1/views/migration_view.py b/coriolis/api/v1/views/migration_view.py deleted file mode 100644 index f130a3df8..000000000 --- a/coriolis/api/v1/views/migration_view.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2016 Cloudbase Solutions Srl -# All Rights Reserved. - -from coriolis.api.v1.views import replica_tasks_execution_view as view -from coriolis.api.v1.views import utils as view_utils - - -def _format_migration(migration, keys=None): - migration_dict = view_utils.format_opt(migration, keys) - - if len(migration_dict.get("executions", [])): - execution = view.format_replica_tasks_execution( - migration_dict["executions"][0], keys) - del migration_dict["executions"] - else: - execution = {} - - tasks = execution.get("tasks") - if tasks: - migration_dict["tasks"] = tasks - - return migration_dict - - -def single(migration, keys=None): - return {"migration": _format_migration(migration, keys)} - - -def collection(migrations, keys=None): - formatted_migrations = [_format_migration(m, keys) - for m in migrations] - return {'migrations': formatted_migrations} diff --git a/coriolis/api/v1/views/replica_view.py b/coriolis/api/v1/views/replica_view.py deleted file mode 100644 index abc38f2da..000000000 --- a/coriolis/api/v1/views/replica_view.py +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2016 Cloudbase Solutions Srl -# All Rights Reserved. - -from coriolis.api.v1.views import replica_tasks_execution_view as view -from coriolis.api.v1.views import utils as view_utils - - -def _format_replica(replica, keys=None): - replica_dict = view_utils.format_opt(replica, keys) - - executions = replica_dict.get('executions', []) - replica_dict['executions'] = [ - view.format_replica_tasks_execution(ex) - for ex in executions] - - return replica_dict - - -def single(replica, keys=None): - return {"replica": _format_replica(replica, keys)} - - -def collection(replicas, keys=None): - formatted_replicas = [_format_replica(m, keys) - for m in replicas] - return {'replicas': formatted_replicas} diff --git a/coriolis/api/v1/views/replica_schedule_view.py b/coriolis/api/v1/views/transfer_schedule_view.py similarity index 100% rename from coriolis/api/v1/views/replica_schedule_view.py rename to coriolis/api/v1/views/transfer_schedule_view.py diff --git a/coriolis/api/v1/views/replica_tasks_execution_view.py b/coriolis/api/v1/views/transfer_tasks_execution_view.py similarity index 82% rename from coriolis/api/v1/views/replica_tasks_execution_view.py rename to coriolis/api/v1/views/transfer_tasks_execution_view.py index 96359a18f..3873d1874 100644 --- a/coriolis/api/v1/views/replica_tasks_execution_view.py +++ b/coriolis/api/v1/views/transfer_tasks_execution_view.py @@ -25,7 +25,7 @@ def _sort_tasks(tasks, filter_error_only_tasks=True): tasks, key=lambda t: t.get('index', 0)) -def format_replica_tasks_execution(execution, keys=None): +def format_transfer_tasks_execution(execution, keys=None): if "tasks" in execution: execution["tasks"] = _sort_tasks(execution["tasks"]) @@ -35,10 +35,10 @@ def format_replica_tasks_execution(execution, keys=None): def single(execution, keys=None): - return {"execution": format_replica_tasks_execution(execution, keys)} + return {"execution": format_transfer_tasks_execution(execution, keys)} def collection(executions, keys=None): - formatted_executions = [format_replica_tasks_execution(m, keys) + formatted_executions = [format_transfer_tasks_execution(m, keys) for m in executions] return {'executions': formatted_executions} diff --git a/coriolis/api/v1/views/transfer_view.py b/coriolis/api/v1/views/transfer_view.py new file mode 100644 index 000000000..2fcefe4f1 --- /dev/null +++ b/coriolis/api/v1/views/transfer_view.py @@ -0,0 +1,25 @@ +# Copyright 2016 Cloudbase Solutions Srl +# All Rights Reserved. + +from coriolis.api.v1.views import transfer_tasks_execution_view as view +from coriolis.api.v1.views import utils as view_utils + + +def _format_transfer(transfer, keys=None): + transfer_dict = view_utils.format_opt(transfer, keys) + + executions = transfer_dict.get('executions', []) + transfer_dict['executions'] = [ + view.format_transfer_tasks_execution(ex) + for ex in executions] + + return transfer_dict + + +def single(transfer, keys=None): + return {"transfer": _format_transfer(transfer, keys)} + + +def collection(transfers, keys=None): + formatted_transfers = [_format_transfer(t, keys) for t in transfers] + return {'transfers': formatted_transfers} diff --git a/coriolis/cmd/replica_cron.py b/coriolis/cmd/transfer_cron.py similarity index 92% rename from coriolis/cmd/replica_cron.py rename to coriolis/cmd/transfer_cron.py index 80eafc5b0..3605389c4 100644 --- a/coriolis/cmd/replica_cron.py +++ b/coriolis/cmd/transfer_cron.py @@ -20,7 +20,7 @@ def main(): server = service.MessagingService( constants.TRANSFER_CRON_MAIN_MESSAGING_TOPIC, - [rpc_server.ReplicaCronServerEndpoint()], + [rpc_server.TransferCronServerEndpoint()], rpc_server.VERSION, worker_count=1) launcher = service.service.launch( CONF, server, workers=server.get_workers_count()) diff --git a/coriolis/deployments/api.py b/coriolis/deployments/api.py index dbb4fe954..8cc21eec6 100644 --- a/coriolis/deployments/api.py +++ b/coriolis/deployments/api.py @@ -8,12 +8,12 @@ class API(object): def __init__(self): self._rpc_client = rpc_client.ConductorClient() - def deploy_replica_instances(self, ctxt, replica_id, - instance_osmorphing_minion_pool_mappings, - clone_disks=False, force=False, - skip_os_morphing=False, user_scripts=None): + def deploy_transfer_instances(self, ctxt, transfer_id, + instance_osmorphing_minion_pool_mappings, + clone_disks=False, force=False, + skip_os_morphing=False, user_scripts=None): return self._rpc_client.deploy_transfer_instances( - ctxt, replica_id, instance_osmorphing_minion_pool_mappings=( + ctxt, transfer_id, instance_osmorphing_minion_pool_mappings=( instance_osmorphing_minion_pool_mappings), clone_disks=clone_disks, force=force, skip_os_morphing=skip_os_morphing, diff --git a/coriolis/minion_manager/rpc/client.py b/coriolis/minion_manager/rpc/client.py index 1de89e2db..5253dc458 100644 --- a/coriolis/minion_manager/rpc/client.py +++ b/coriolis/minion_manager/rpc/client.py @@ -68,16 +68,16 @@ def validate_minion_pool_selections_for_action(self, ctxt, action): action=action) def allocate_minion_machines_for_transfer( - self, ctxt, replica): + self, ctxt, transfer): return self._cast( - ctxt, 'allocate_minion_machines_for_replica', replica=replica) + ctxt, 'allocate_minion_machines_for_transfer', transfer=transfer) def allocate_minion_machines_for_deployment( - self, ctxt, migration, include_transfer_minions=True, + self, ctxt, deployment, include_transfer_minions=True, include_osmorphing_minions=True): return self._cast( - ctxt, 'allocate_minion_machines_for_migration', - migration=migration, + ctxt, 'allocate_minion_machines_for_deployment', + deployment=deployment, include_transfer_minions=include_transfer_minions, include_osmorphing_minions=include_osmorphing_minions) diff --git a/coriolis/minion_manager/rpc/server.py b/coriolis/minion_manager/rpc/server.py index 761a10a10..3d74552f0 100644 --- a/coriolis/minion_manager/rpc/server.py +++ b/coriolis/minion_manager/rpc/server.py @@ -67,7 +67,7 @@ def __init__(self): self._scheduler_client_instance = None self._worker_client_instance = None self._conductor_client_instance = None - self._replica_cron_client_instance = None + self._transfer_cron_client_instance = None self._minion_manager_client_instance = None try: self._cron = cron.Cron() @@ -510,53 +510,53 @@ def _check_pool_minion_count( "Successfully validated minion pool selections for action '%s' " "with properties: %s", action['id'], action) - def allocate_minion_machines_for_replica( - self, ctxt, replica): + def allocate_minion_machines_for_transfer( + self, ctxt, transfer): try: self._run_machine_allocation_subflow_for_action( - ctxt, replica, + ctxt, transfer, constants.TRANSFER_ACTION_TYPE_TRANSFER, include_transfer_minions=True, include_osmorphing_minions=False) except Exception as ex: LOG.warn( "Error occurred while allocating minion machines for " - "Replica with ID '%s'. Removing all allocations. " + "Transfer with ID '%s'. Removing all allocations. " "Error was: %s" % ( - replica['id'], utils.get_exception_details())) + transfer['id'], utils.get_exception_details())) self._cleanup_machines_with_statuses_for_action( - ctxt, replica['id'], + ctxt, transfer['id'], [constants.MINION_MACHINE_STATUS_UNINITIALIZED]) self.deallocate_minion_machines_for_action( - ctxt, replica['id']) + ctxt, transfer['id']) (self._rpc_conductor_client .report_transfer_minions_allocation_error( - ctxt, replica['id'], str(ex))) + ctxt, transfer['id'], str(ex))) raise - def allocate_minion_machines_for_migration( - self, ctxt, migration, include_transfer_minions=True, + def allocate_minion_machines_for_deployment( + self, ctxt, deployment, include_transfer_minions=True, include_osmorphing_minions=True): try: self._run_machine_allocation_subflow_for_action( - ctxt, migration, + ctxt, deployment, constants.TRANSFER_ACTION_TYPE_DEPLOYMENT, include_transfer_minions=include_transfer_minions, include_osmorphing_minions=include_osmorphing_minions) except Exception as ex: LOG.warn( "Error occurred while allocating minion machines for " - "Migration with ID '%s'. Removing all allocations. " + "Deployment with ID '%s'. Removing all allocations. " "Error was: %s" % ( - migration['id'], utils.get_exception_details())) + deployment['id'], utils.get_exception_details())) self._cleanup_machines_with_statuses_for_action( - ctxt, migration['id'], + ctxt, deployment['id'], [constants.MINION_MACHINE_STATUS_UNINITIALIZED]) self.deallocate_minion_machines_for_action( - ctxt, migration['id']) + ctxt, deployment['id']) (self._rpc_conductor_client .report_deployment_minions_allocation_error( - ctxt, migration['id'], str(ex))) + ctxt, deployment['id'], str(ex))) raise def _make_minion_machine_allocation_subflow_for_action( diff --git a/coriolis/policies/deployments.py b/coriolis/policies/deployments.py index 77e20bb08..a24c9d411 100644 --- a/coriolis/policies/deployments.py +++ b/coriolis/policies/deployments.py @@ -54,7 +54,7 @@ def get_deployments_policy_label(rule_label): policy.DocumentedRuleDefault( get_deployments_policy_label('cancel'), DEPLOYMENTS_POLICY_DEFAULT_RULE, - "Cancel a running Migration", + "Cancel a running Deployment", [ { "path": "/deployments/{deployment_id}/actions/", @@ -65,7 +65,7 @@ def get_deployments_policy_label(rule_label): policy.DocumentedRuleDefault( get_deployments_policy_label('delete'), DEPLOYMENTS_POLICY_DEFAULT_RULE, - "Delete Migration", + "Delete Deployment", [ { "path": "/deployment/{deployment_id}", diff --git a/coriolis/policies/migrations.py b/coriolis/policies/migrations.py deleted file mode 100644 index f1570b0ba..000000000 --- a/coriolis/policies/migrations.py +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2018 Cloudbase Solutions Srl -# All Rights Reserved. - -from oslo_policy import policy - -from coriolis.policies import base - - -MIGRATIONS_POLICY_PREFIX = "%s:migrations" % base.CORIOLIS_POLICIES_PREFIX -MIGRATIONS_POLICY_DEFAULT_RULE = "rule:admin_or_owner" - - -def get_migrations_policy_label(rule_label): - return "%s:%s" % ( - MIGRATIONS_POLICY_PREFIX, rule_label) - - -MIGRATIONS_POLICY_DEFAULT_RULES = [ - policy.DocumentedRuleDefault( - get_migrations_policy_label('create'), - MIGRATIONS_POLICY_DEFAULT_RULE, - "Create a migration", - [ - { - "path": "/migrations", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_migrations_policy_label('list'), - MIGRATIONS_POLICY_DEFAULT_RULE, - "List migrations", - [ - { - "path": "/migrations", - "method": "GET" - } - ] - ), - policy.DocumentedRuleDefault( - get_migrations_policy_label('show'), - MIGRATIONS_POLICY_DEFAULT_RULE, - "Show details for a migration", - [ - { - "path": "/migrations/{migration_id}", - "method": "GET" - } - ] - ), - # TODO(aznashwan): migration actions should ideally be - # declared in a separate module - policy.DocumentedRuleDefault( - get_migrations_policy_label('cancel'), - MIGRATIONS_POLICY_DEFAULT_RULE, - "Cancel a running Migration", - [ - { - "path": "/migrations/{migration_id}/actions", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_migrations_policy_label('delete'), - MIGRATIONS_POLICY_DEFAULT_RULE, - "Delete Migration", - [ - { - "path": "/migrations/{migration_id}", - "method": "DELETE" - } - ] - ) -] - - -def list_rules(): - return MIGRATIONS_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/replica_schedules.py b/coriolis/policies/replica_schedules.py deleted file mode 100644 index 430883830..000000000 --- a/coriolis/policies/replica_schedules.py +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2018 Cloudbase Solutions Srl -# All Rights Reserved. - -from oslo_policy import policy - -from coriolis.policies import base - - -REPLICA_SCHEDULES_POLICY_PREFIX = "%s:replica_schedules" % ( - base.CORIOLIS_POLICIES_PREFIX) -REPLICA_SCHEDULES_POLICY_DEFAULT_RULE = "rule:admin_or_owner" - - -def get_replica_schedules_policy_label(rule_label): - return "%s:%s" % ( - REPLICA_SCHEDULES_POLICY_PREFIX, rule_label) - - -REPLICA_SCHEDULES_POLICY_DEFAULT_RULES = [ - policy.DocumentedRuleDefault( - get_replica_schedules_policy_label('create'), - REPLICA_SCHEDULES_POLICY_DEFAULT_RULE, - "Create a new execution schedule for a given Replica", - [ - { - "path": "/replicas/{replica_id}/schedules", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_schedules_policy_label('list'), - REPLICA_SCHEDULES_POLICY_DEFAULT_RULE, - "List execution schedules for a given Replica", - [ - { - "path": "/replicas/{replica_id}/schedules", - "method": "GET" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_schedules_policy_label('show'), - REPLICA_SCHEDULES_POLICY_DEFAULT_RULE, - "Show details for an execution schedule for a given Replica", - [ - { - "path": "/replicas/{replica_id}/schedules/{schedule_id}", - "method": "GET" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_schedules_policy_label('update'), - REPLICA_SCHEDULES_POLICY_DEFAULT_RULE, - "Update an existing execution schedule for a given Replica", - [ - { - "path": ( - "/replicas/{replica_id}/schedules/{schedule_id}"), - "method": "PUT" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_schedules_policy_label('delete'), - REPLICA_SCHEDULES_POLICY_DEFAULT_RULE, - "Delete an execution schedule for a given Replica", - [ - { - "path": "/replicas/{replica_id}/schedules/{schedule_id}", - "method": "DELETE" - } - ] - ) -] - - -def list_rules(): - return REPLICA_SCHEDULES_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/replica_tasks_executions.py b/coriolis/policies/replica_tasks_executions.py deleted file mode 100644 index f30a299ba..000000000 --- a/coriolis/policies/replica_tasks_executions.py +++ /dev/null @@ -1,83 +0,0 @@ -# Copyright 2018 Cloudbase Solutions Srl -# All Rights Reserved. - -from oslo_policy import policy - -from coriolis.policies import base - - -REPLICA_EXECUTIONS_POLICY_PREFIX = "%s:replica_executions" % ( - base.CORIOLIS_POLICIES_PREFIX) -REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE = "rule:admin_or_owner" - - -def get_replica_executions_policy_label(rule_label): - return "%s:%s" % ( - REPLICA_EXECUTIONS_POLICY_PREFIX, rule_label) - - -REPLICA_EXECUTIONS_POLICY_DEFAULT_RULES = [ - policy.DocumentedRuleDefault( - get_replica_executions_policy_label('create'), - REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE, - "Create a new execution for a given Replica", - [ - { - "path": "/replicas/{replica_id}/executions", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_executions_policy_label('list'), - REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE, - "List Executions for a given Replica", - [ - { - "path": "/replicas/{replica_id}/executions", - "method": "GET" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_executions_policy_label('show'), - REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE, - "Show details for Replica execution", - [ - { - "path": "/replicas/{replica_id}/executions/{execution_id}", - "method": "GET" - } - ] - ), - # TODO(aznashwan): replica actions should ideally be - # declared in a separate module - policy.DocumentedRuleDefault( - get_replica_executions_policy_label('cancel'), - REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE, - "Cancel a Replica execution", - [ - { - "path": ( - "/replicas/{replica_id}/executions/" - "{execution_id}/actions"), - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_replica_executions_policy_label('delete'), - REPLICA_EXECUTIONS_POLICY_DEFAULT_RULE, - "Delete an execution for a given Replica", - [ - { - "path": "/replicas/{replica_id}/executions/{execution_id}", - "method": "DELETE" - } - ] - ) -] - - -def list_rules(): - return REPLICA_EXECUTIONS_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/replicas.py b/coriolis/policies/replicas.py deleted file mode 100644 index a48f517dc..000000000 --- a/coriolis/policies/replicas.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright 2018 Cloudbase Solutions Srl -# All Rights Reserved. - -from oslo_policy import policy - -from coriolis.policies import base - - -REPLICAS_POLICY_PREFIX = "%s:replicas" % base.CORIOLIS_POLICIES_PREFIX -REPLICAS_POLICY_DEFAULT_RULE = "rule:admin_or_owner" - - -def get_replicas_policy_label(rule_label): - return "%s:%s" % ( - REPLICAS_POLICY_PREFIX, rule_label) - - -REPLICAS_POLICY_DEFAULT_RULES = [ - policy.DocumentedRuleDefault( - get_replicas_policy_label('create'), - REPLICAS_POLICY_DEFAULT_RULE, - "Create a Replica", - [ - { - "path": "/replicas", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_replicas_policy_label('list'), - REPLICAS_POLICY_DEFAULT_RULE, - "List Replicas", - [ - { - "path": "/replicas", - "method": "GET" - } - ] - ), - policy.DocumentedRuleDefault( - get_replicas_policy_label('show'), - REPLICAS_POLICY_DEFAULT_RULE, - "Show details for Replica", - [ - { - "path": "/replicas/{replica_id}", - "method": "GET" - } - ] - ), - # TODO(aznashwan): replica actions should ideally be - # declared in a separate module - policy.DocumentedRuleDefault( - get_replicas_policy_label('delete_disks'), - REPLICAS_POLICY_DEFAULT_RULE, - "Delete Replica Disks", - [ - { - "path": "/replicas/{replica_id}/actions", - "method": "POST" - } - ] - ), - policy.DocumentedRuleDefault( - get_replicas_policy_label('delete'), - REPLICAS_POLICY_DEFAULT_RULE, - "Delete Replica", - [ - { - "path": "/replicas/{replica_id}", - "method": "DELETE" - } - ] - ), - policy.DocumentedRuleDefault( - get_replicas_policy_label('update'), - REPLICAS_POLICY_DEFAULT_RULE, - "Update Replica", - [ - { - "path": "/replicas/{replica_id}", - "method": "POST" - } - ] - ) - -] - - -def list_rules(): - return REPLICAS_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/transfer_schedules.py b/coriolis/policies/transfer_schedules.py new file mode 100644 index 000000000..409518727 --- /dev/null +++ b/coriolis/policies/transfer_schedules.py @@ -0,0 +1,80 @@ +# Copyright 2018 Cloudbase Solutions Srl +# All Rights Reserved. + +from oslo_policy import policy + +from coriolis.policies import base + + +TRANSFER_SCHEDULES_POLICY_PREFIX = "%s:transfer_schedules" % ( + base.CORIOLIS_POLICIES_PREFIX) +TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE = "rule:admin_or_owner" + + +def get_transfer_schedules_policy_label(rule_label): + return "%s:%s" % ( + TRANSFER_SCHEDULES_POLICY_PREFIX, rule_label) + + +TRANSFER_SCHEDULES_POLICY_DEFAULT_RULES = [ + policy.DocumentedRuleDefault( + get_transfer_schedules_policy_label('create'), + TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE, + "Create a new execution schedule for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/schedules", + "method": "POST" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_schedules_policy_label('list'), + TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE, + "List execution schedules for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/schedules", + "method": "GET" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_schedules_policy_label('show'), + TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE, + "Show details for an execution schedule for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/schedules/{schedule_id}", + "method": "GET" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_schedules_policy_label('update'), + TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE, + "Update an existing execution schedule for a given Transfer", + [ + { + "path": ( + "/transfers/{transfer_id}/schedules/{schedule_id}"), + "method": "PUT" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_schedules_policy_label('delete'), + TRANSFER_SCHEDULES_POLICY_DEFAULT_RULE, + "Delete an execution schedule for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/schedules/{schedule_id}", + "method": "DELETE" + } + ] + ) +] + + +def list_rules(): + return TRANSFER_SCHEDULES_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/transfer_tasks_executions.py b/coriolis/policies/transfer_tasks_executions.py new file mode 100644 index 000000000..b653149b3 --- /dev/null +++ b/coriolis/policies/transfer_tasks_executions.py @@ -0,0 +1,83 @@ +# Copyright 2018 Cloudbase Solutions Srl +# All Rights Reserved. + +from oslo_policy import policy + +from coriolis.policies import base + + +TRANSFER_EXECUTIONS_POLICY_PREFIX = "%s:transfer_executions" % ( + base.CORIOLIS_POLICIES_PREFIX) +TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE = "rule:admin_or_owner" + + +def get_transfer_executions_policy_label(rule_label): + return "%s:%s" % ( + TRANSFER_EXECUTIONS_POLICY_PREFIX, rule_label) + + +TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULES = [ + policy.DocumentedRuleDefault( + get_transfer_executions_policy_label('create'), + TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE, + "Create a new execution for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/executions", + "method": "POST" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_executions_policy_label('list'), + TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE, + "List Executions for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/executions", + "method": "GET" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_executions_policy_label('show'), + TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE, + "Show details for Transfer execution", + [ + { + "path": "/transfers/{transfer_id}/executions/{execution_id}", + "method": "GET" + } + ] + ), + # TODO(aznashwan): transfer actions should ideally be + # declared in a separate module + policy.DocumentedRuleDefault( + get_transfer_executions_policy_label('cancel'), + TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE, + "Cancel a Transfer execution", + [ + { + "path": ( + "/transfers/{transfer_id}/executions/" + "{execution_id}/actions"), + "method": "POST" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfer_executions_policy_label('delete'), + TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULE, + "Delete an execution for a given Transfer", + [ + { + "path": "/transfers/{transfer_id}/executions/{execution_id}", + "method": "DELETE" + } + ] + ) +] + + +def list_rules(): + return TRANSFER_EXECUTIONS_POLICY_DEFAULT_RULES diff --git a/coriolis/policies/transfers.py b/coriolis/policies/transfers.py new file mode 100644 index 000000000..85978d5af --- /dev/null +++ b/coriolis/policies/transfers.py @@ -0,0 +1,92 @@ +# Copyright 2018 Cloudbase Solutions Srl +# All Rights Reserved. + +from oslo_policy import policy + +from coriolis.policies import base + + +TRANSFERS_POLICY_PREFIX = "%s:transfers" % base.CORIOLIS_POLICIES_PREFIX +TRANSFERS_POLICY_DEFAULT_RULE = "rule:admin_or_owner" + + +def get_transfers_policy_label(rule_label): + return "%s:%s" % ( + TRANSFERS_POLICY_PREFIX, rule_label) + + +TRANSFERS_POLICY_DEFAULT_RULES = [ + policy.DocumentedRuleDefault( + get_transfers_policy_label('create'), + TRANSFERS_POLICY_DEFAULT_RULE, + "Create a Transfer", + [ + { + "path": "/transfers", + "method": "POST" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfers_policy_label('list'), + TRANSFERS_POLICY_DEFAULT_RULE, + "List Transfers", + [ + { + "path": "/transfers", + "method": "GET" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfers_policy_label('show'), + TRANSFERS_POLICY_DEFAULT_RULE, + "Show details for Transfer", + [ + { + "path": "/transfers/{transfer_id}", + "method": "GET" + } + ] + ), + # TODO(aznashwan): transfer actions should ideally be + # declared in a separate module + policy.DocumentedRuleDefault( + get_transfers_policy_label('delete_disks'), + TRANSFERS_POLICY_DEFAULT_RULE, + "Delete Transfer Disks", + [ + { + "path": "/transfers/{transfer_id}/actions", + "method": "POST" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfers_policy_label('delete'), + TRANSFERS_POLICY_DEFAULT_RULE, + "Delete Transfer", + [ + { + "path": "/transfers/{transfer_id}", + "method": "DELETE" + } + ] + ), + policy.DocumentedRuleDefault( + get_transfers_policy_label('update'), + TRANSFERS_POLICY_DEFAULT_RULE, + "Update Transfer", + [ + { + "path": "/transfers/{transfer_id}", + "method": "POST" + } + ] + ) + +] + + +def list_rules(): + return TRANSFERS_POLICY_DEFAULT_RULES diff --git a/coriolis/policy.py b/coriolis/policy.py index 37ad18f3e..297a4c92e 100644 --- a/coriolis/policy.py +++ b/coriolis/policy.py @@ -13,13 +13,12 @@ from coriolis.policies import diagnostics from coriolis.policies import endpoints from coriolis.policies import general -from coriolis.policies import migrations from coriolis.policies import minion_pools from coriolis.policies import regions -from coriolis.policies import replica_schedules -from coriolis.policies import replica_tasks_executions -from coriolis.policies import replicas from coriolis.policies import services +from coriolis.policies import transfer_schedules +from coriolis.policies import transfer_tasks_executions +from coriolis.policies import transfers from coriolis import utils @@ -29,8 +28,8 @@ _ENFORCER = None DEFAULT_POLICIES_MODULES = [ - base, deployments, endpoints, general, migrations, replicas, - replica_schedules, replica_tasks_executions, diagnostics, regions, + base, deployments, endpoints, general, transfers, + transfer_schedules, transfer_tasks_executions, diagnostics, regions, services, minion_pools] diff --git a/coriolis/replica_tasks_executions/api.py b/coriolis/replica_tasks_executions/api.py deleted file mode 100644 index 234e785a3..000000000 --- a/coriolis/replica_tasks_executions/api.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2016 Cloudbase Solutions Srl -# All Rights Reserved. - -from coriolis.conductor.rpc import client as rpc_client - - -class API(object): - def __init__(self): - self._rpc_client = rpc_client.ConductorClient() - - def create(self, ctxt, replica_id, shutdown_instances): - return self._rpc_client.execute_transfer_tasks( - ctxt, replica_id, shutdown_instances) - - def delete(self, ctxt, replica_id, execution_id): - self._rpc_client.delete_transfer_tasks_execution( - ctxt, replica_id, execution_id) - - def cancel(self, ctxt, replica_id, execution_id, force): - self._rpc_client.cancel_transfer_tasks_execution( - ctxt, replica_id, execution_id, force) - - def get_executions(self, ctxt, replica_id, include_tasks=False): - return self._rpc_client.get_transfer_tasks_executions( - ctxt, replica_id, include_tasks) - - def get_execution(self, ctxt, replica_id, execution_id): - return self._rpc_client.get_transfer_tasks_execution( - ctxt, replica_id, execution_id) diff --git a/coriolis/schemas.py b/coriolis/schemas.py index 278a25dd4..3a84be732 100644 --- a/coriolis/schemas.py +++ b/coriolis/schemas.py @@ -31,7 +31,7 @@ _CORIOLIS_VM_INSTANCE_INFO_SCHEMA_NAME = "vm_instance_info_schema.json" _CORIOLIS_OS_MORPHING_RES_SCHEMA_NAME = "os_morphing_resources_schema.json" _CORIOLIS_VM_NETWORK_SCHEMA_NAME = "vm_network_schema.json" -_SCHEDULE_API_BODY_SCHEMA_NAME = "replica_schedule_schema.json" +_SCHEDULE_API_BODY_SCHEMA_NAME = "transfer_schedule_schema.json" _CORIOLIS_DESTINATION_OPTIONS_SCHEMA_NAME = "destination_options_schema.json" _CORIOLIS_SOURCE_OPTIONS_SCHEMA_NAME = "source_options_schema.json" _CORIOLIS_NETWORK_MAP_SCHEMA_NAME = "network_map_schema.json" diff --git a/coriolis/schemas/disk_sync_resources_info_schema.json b/coriolis/schemas/disk_sync_resources_info_schema.json index 0aa0becbb..4a86c3752 100644 --- a/coriolis/schemas/disk_sync_resources_info_schema.json +++ b/coriolis/schemas/disk_sync_resources_info_schema.json @@ -1,7 +1,7 @@ { "$schema": "http://cloudbase.it/coriolis/schemas/disk_sync_resources_info#", "type": "object", - "description": "Information returned after the 'DEPLOY_REPLICA_TARGET_RESOURCES' task and passed to 'REPLICATE_DISKS', as well as for 'DEPLOY_DISK_COPY_RESOURCES' and 'COPY_DISKS_DATA'. The only required property is the 'volumes_info', and the provider plugins may freely declare and use any other fields.", + "description": "Information returned after the 'DEPLOY_TRANSFER_DISKS' task and passed to 'DEPLOY_TRANSFER_TARGET_RESOURCES' and 'REPLICATE_DISKS'. The only required property is the 'volumes_info', and the provider plugins may freely declare and use any other fields.", "properties": { "volumes_info": { "type": "array", diff --git a/coriolis/schemas/replica_schedule_schema.json b/coriolis/schemas/transfer_schedule_schema.json similarity index 93% rename from coriolis/schemas/replica_schedule_schema.json rename to coriolis/schemas/transfer_schedule_schema.json index 89dba79a5..b7c6285dd 100644 --- a/coriolis/schemas/replica_schedule_schema.json +++ b/coriolis/schemas/transfer_schedule_schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://cloudbase.it/coriolis/schemas/replica_schedule_schema#", + "$schema": "http://cloudbase.it/coriolis/schemas/transfer_schedule_schema#", "type": "object", "properties": { "schedule": { diff --git a/coriolis/tests/api/v1/data/migration_create.yml b/coriolis/tests/api/v1/data/migration_create.yml deleted file mode 100644 index dd220e230..000000000 --- a/coriolis/tests/api/v1/data/migration_create.yml +++ /dev/null @@ -1,28 +0,0 @@ - -- config: - migration: - user_scripts: - mock_user_scripts: null - instances: ["mock_instance1", "mock_instance2"] - replica_id: 'mock_replica_id' - clone_disks: True - force: False - skip_os_morphing: False - instance_osmorphing_minion_pool_mappings: - mock_mapping: "mock_value" - expected_api_method: "deploy_replica_instances" - validation_expected: False - -- config: - migration: - user_scripts: - mock_user_scripts: null - instances: ["mock_instance1", "mock_instance2"] - replica_id: null - clone_disks: True - force: False - skip_os_morphing: False - instance_osmorphing_minion_pool_mappings: - mock_mapping: "mock_value" - expected_api_method: "migrate_instances" - validation_expected: True diff --git a/coriolis/tests/api/v1/data/migration_validate_input.yml b/coriolis/tests/api/v1/data/migration_validate_input.yml deleted file mode 100644 index d8f7d680f..000000000 --- a/coriolis/tests/api/v1/data/migration_validate_input.yml +++ /dev/null @@ -1,48 +0,0 @@ - -- config: - migration: - origin_endpoint_id: "mock_origin_endpoint_id" - destination_endpoint_id: "mock_destination_endpoint_id" - origin_minion_pool_id: "mock_origin_minion_pool_id" - destination_minion_pool_id: "mock_destination_minion_pool_id" - instance_osmorphing_minion_pool_mappings: - mock_instance_1: "mock_pool" - mock_instance_2: "mock_pool" - instances: ['mock_instance_1', 'mock_instance_2'] - notes: "mock_notes" - skip_os_morphing: false - shutdown_instances: false - replication_count: 2 - source_environment: {} - network_map: {} - destination_environment: - network_map: {} - storage_mappings: {} - storage_mappings: {} - raises_value_error: false - -- config: - migration: - origin_endpoint_id: "mock_origin_endpoint_id" - destination_endpoint_id: "mock_destination_endpoint_id" - origin_minion_pool_id: "mock_origin_minion_pool_id" - destination_minion_pool_id: "mock_destination_minion_pool_id" - instance_osmorphing_minion_pool_mappings: - mock_instance_1: "mock_pool" - mock_instance_2: "mock_pool" - instances: ['mock_instance_1', 'mock_instance_3'] - raises_value_error: true - - -- config: - migration: - origin_endpoint_id: "mock_origin_endpoint_id" - destination_endpoint_id: "mock_destination_endpoint_id" - origin_minion_pool_id: "mock_origin_minion_pool_id" - destination_minion_pool_id: "mock_destination_minion_pool_id" - instance_osmorphing_minion_pool_mappings: - mock_instance_1: "mock_pool" - mock_instance_2: "mock_pool" - instances: ['mock_instance_1', 'mock_instance_2'] - replication_count: 13 - raises_value_error: true \ No newline at end of file diff --git a/coriolis/tests/api/v1/data/replica_task_execution_actions_cancel.yml b/coriolis/tests/api/v1/data/transfer_task_execution_actions_cancel.yml similarity index 100% rename from coriolis/tests/api/v1/data/replica_task_execution_actions_cancel.yml rename to coriolis/tests/api/v1/data/transfer_task_execution_actions_cancel.yml diff --git a/coriolis/tests/api/v1/data/replicas_get_merged_replica_values.yml b/coriolis/tests/api/v1/data/transfers_get_merged_transfer_values.yml similarity index 98% rename from coriolis/tests/api/v1/data/replicas_get_merged_replica_values.yml rename to coriolis/tests/api/v1/data/transfers_get_merged_transfer_values.yml index 83d5a4a52..83f2abe21 100644 --- a/coriolis/tests/api/v1/data/replicas_get_merged_replica_values.yml +++ b/coriolis/tests/api/v1/data/transfers_get_merged_transfer_values.yml @@ -1,6 +1,6 @@ - config: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" destination_endpoint_id: "mock_destination_endpoint_id" source_environment: {'mock_source_key': 'mock_source_value'} @@ -14,7 +14,7 @@ instance_osmorphing_minion_pool_mappings: mock_instance_1: "mock_pool_1" mock_instance_2: "mock_pool_2" - updated_values: + updated_values: source_environment: {'mock_updated_source_key': 'mock_updated_source_value'} destination_environment: storage_mappings: {'mock_updated_destination_key': 'mock_updated_destination_value'} @@ -47,7 +47,7 @@ mock_instance_2: "mock_updated_pool_2" - config: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" destination_endpoint_id: "mock_destination_endpoint_id" source_environment: {'mock_source_key': 'mock_source_value'} @@ -75,7 +75,7 @@ notes: "mock_notes" - config: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" destination_endpoint_id: "mock_destination_endpoint_id" user_scripts: {'mock_scripts_key': 'mock_scripts_value'} diff --git a/coriolis/tests/api/v1/data/replicas_update_storage_mappings.yml b/coriolis/tests/api/v1/data/transfers_update_storage_mappings.yml similarity index 100% rename from coriolis/tests/api/v1/data/replicas_update_storage_mappings.yml rename to coriolis/tests/api/v1/data/transfers_update_storage_mappings.yml diff --git a/coriolis/tests/api/v1/data/replicas_validate_create_body.yml b/coriolis/tests/api/v1/data/transfers_validate_create_body.yml similarity index 98% rename from coriolis/tests/api/v1/data/replicas_validate_create_body.yml rename to coriolis/tests/api/v1/data/transfers_validate_create_body.yml index dacd4d9cd..9e2291865 100644 --- a/coriolis/tests/api/v1/data/replicas_validate_create_body.yml +++ b/coriolis/tests/api/v1/data/transfers_validate_create_body.yml @@ -1,7 +1,7 @@ - config: body: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" destination_endpoint_id: "mock_destination_endpoint_id" source_environment: "mock_source_environment" @@ -36,7 +36,7 @@ - config: body: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" destination_endpoint_id: "mock_destination_endpoint_id" source_environment: "mock_source_environment" diff --git a/coriolis/tests/api/v1/data/replicas_validate_update_body.yml b/coriolis/tests/api/v1/data/transfers_validate_update_body.yml similarity index 98% rename from coriolis/tests/api/v1/data/replicas_validate_update_body.yml rename to coriolis/tests/api/v1/data/transfers_validate_update_body.yml index 5b763f1ca..2448e5171 100644 --- a/coriolis/tests/api/v1/data/replicas_validate_update_body.yml +++ b/coriolis/tests/api/v1/data/transfers_validate_update_body.yml @@ -1,7 +1,7 @@ - config: body: - replica: + transfer: source_environment: "mock_source_environment" destination_environment: "mock_destination_environment" storage_mappings: {'mock_updated_destination_key': 'mock_updated_destination_value'} @@ -13,7 +13,7 @@ instance_osmorphing_minion_pool_mappings: mock_instance_1: "mock_updated_pool_1" mock_instance_2: "mock_updated_pool_2" - replica: + transfer: destination_endpoint_id: "mock_destination_endpoint_id" origin_endpoint_id: "mock_origin_endpoint_id" instances: "mock_instances" diff --git a/coriolis/tests/api/v1/data/replicas_validate_update_body_raises.yml b/coriolis/tests/api/v1/data/transfers_validate_update_body_raises.yml similarity index 80% rename from coriolis/tests/api/v1/data/replicas_validate_update_body_raises.yml rename to coriolis/tests/api/v1/data/transfers_validate_update_body_raises.yml index 37dfd585f..bd246ffb5 100644 --- a/coriolis/tests/api/v1/data/replicas_validate_update_body_raises.yml +++ b/coriolis/tests/api/v1/data/transfers_validate_update_body_raises.yml @@ -1,13 +1,13 @@ - body: - replica: + transfer: origin_endpoint_id: "mock_origin_endpoint_id" - body: - replica: + transfer: destination_endpoint_id: "mock_destination_endpoint_id" - body: - replica: + transfer: instances: "instances" diff --git a/coriolis/tests/api/v1/test_router.py b/coriolis/tests/api/v1/test_router.py index c945ec8e7..3dc145496 100644 --- a/coriolis/tests/api/v1/test_router.py +++ b/coriolis/tests/api/v1/test_router.py @@ -20,13 +20,13 @@ from coriolis.api.v1 import provider_schemas from coriolis.api.v1 import providers from coriolis.api.v1 import regions -from coriolis.api.v1 import replica_actions -from coriolis.api.v1 import replica_schedules -from coriolis.api.v1 import replica_tasks_execution_actions -from coriolis.api.v1 import replica_tasks_executions -from coriolis.api.v1 import replicas from coriolis.api.v1 import router from coriolis.api.v1 import services +from coriolis.api.v1 import transfer_actions +from coriolis.api.v1 import transfer_schedules +from coriolis.api.v1 import transfer_tasks_execution_actions +from coriolis.api.v1 import transfer_tasks_executions +from coriolis.api.v1 import transfers from coriolis.tests import test_base @@ -40,11 +40,11 @@ def setUp(self): @mock.patch.object(deployments, 'create_resource') @mock.patch.object(deployment_actions, 'create_resource') @mock.patch.object(diagnostics, 'create_resource') - @mock.patch.object(replica_schedules, 'create_resource') - @mock.patch.object(replica_tasks_execution_actions, 'create_resource') - @mock.patch.object(replica_tasks_executions, 'create_resource') - @mock.patch.object(replica_actions, 'create_resource') - @mock.patch.object(replicas, 'create_resource') + @mock.patch.object(transfer_schedules, 'create_resource') + @mock.patch.object(transfer_tasks_execution_actions, 'create_resource') + @mock.patch.object(transfer_tasks_executions, 'create_resource') + @mock.patch.object(transfer_actions, 'create_resource') + @mock.patch.object(transfers, 'create_resource') @mock.patch.object(provider_schemas, 'create_resource') @mock.patch.object(endpoint_source_options, 'create_resource') @mock.patch.object(endpoint_destination_options, 'create_resource') @@ -78,11 +78,11 @@ def test_setup_routes( mock_endpoint_destination_options_create_resource, mock_endpoint_source_options_create_resource, mock_provider_schemas_create_resource, - mock_replicas_create_resource, - mock_replica_actions_create_resource, - mock_replica_tasks_executions_create_resource, - mock_replica_tasks_execution_actions_create_resource, - mock_replica_schedules_create_resource, + mock_transfers_create_resource, + mock_transfer_actions_create_resource, + mock_transfer_tasks_executions_create_resource, + mock_transfer_tasks_execution_actions_create_resource, + mock_transfer_schedules_create_resource, mock_diagnostics_create_resource, mock_deployment_actions_create_resource, mock_deployments_create_resource @@ -161,24 +161,24 @@ def test_setup_routes( controller=mock_provider_schemas_create_resource.return_value, ), mock.call( - 'replica', 'replicas', - controller=mock_replicas_create_resource.return_value, + 'transfer', 'transfers', + controller=mock_transfers_create_resource.return_value, collection={'detail': 'GET'}, member={'action': 'POST'} ), mock.call( 'execution', - 'replicas/{replica_id}/executions', + 'transfers/{transfer_id}/executions', controller= - mock_replica_tasks_executions_create_resource.return_value, + mock_transfer_tasks_executions_create_resource.return_value, collection={'detail': 'GET'}, member={'action': 'POST'} ), mock.call( - 'replica_schedule', - 'replicas/{replica_id}/schedules', + 'transfer_schedule', + 'transfers/{transfer_id}/schedules', controller= - mock_replica_schedules_create_resource.return_value, + mock_transfer_schedules_create_resource.return_value, collection={'index': 'GET'}, member={'action': 'POST'} ), @@ -212,17 +212,18 @@ def test_setup_routes( conditions={'method': 'POST'} ), mock.call( - 'replica_actions', - '/{project_id}/replicas/{id}/actions', - controller=mock_replica_actions_create_resource.return_value, + 'transfer_actions', + '/{project_id}/transfers/{id}/actions', + controller=mock_transfer_actions_create_resource.return_value, action='action', conditions={'method': 'POST'} ), mock.call( - 'replica_tasks_execution_actions', - '/{project_id}/replicas/{replica_id}/executions/{id}/actions', + 'transfer_tasks_execution_actions', + '/{project_id}/transfers/{transfer_id}/' + 'executions/{id}/actions', controller= - mock_replica_tasks_execution_actions_create_resource. + mock_transfer_tasks_execution_actions_create_resource. return_value, action='action', conditions={'method': 'POST'} diff --git a/coriolis/tests/api/v1/test_replica_actions.py b/coriolis/tests/api/v1/test_transfer_actions.py similarity index 70% rename from coriolis/tests/api/v1/test_replica_actions.py rename to coriolis/tests/api/v1/test_transfer_actions.py index f4b3a8896..bbfc4aaae 100644 --- a/coriolis/tests/api/v1/test_replica_actions.py +++ b/coriolis/tests/api/v1/test_transfer_actions.py @@ -5,22 +5,22 @@ from webob import exc -from coriolis.api.v1 import replica_actions -from coriolis.api.v1.views import replica_tasks_execution_view +from coriolis.api.v1 import transfer_actions +from coriolis.api.v1.views import transfer_tasks_execution_view from coriolis import exception -from coriolis.replicas import api from coriolis.tests import test_base from coriolis.tests import testutils +from coriolis.transfers import api -class ReplicaActionsControllerTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis Replica Actions v1 API""" +class TransferActionsControllerTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis Transfer Actions v1 API""" def setUp(self): - super(ReplicaActionsControllerTestCase, self).setUp() - self.replica_actions = replica_actions.ReplicaActionsController() + super(TransferActionsControllerTestCase, self).setUp() + self.transfer_actions = transfer_actions.TransferActionsController() - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'delete_disks') def test_delete_disks( self, @@ -34,7 +34,7 @@ def test_delete_disks( body = mock.sentinel.body result = testutils.get_wrapped_function( - self.replica_actions._delete_disks)( + self.transfer_actions._delete_disks)( mock_req, id, body @@ -46,11 +46,11 @@ def test_delete_disks( ) mock_context.can.assert_called_once_with( - "migration:replicas:delete_disks") + "migration:transfers:delete_disks") mock_delete_disks.assert_called_once_with(mock_context, id) mock_single.assert_called_once_with(mock_delete_disks.return_value) - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'delete_disks') def test_delete_disks_not_found( self, @@ -66,18 +66,19 @@ def test_delete_disks_not_found( self.assertRaises( exc.HTTPNotFound, - testutils.get_wrapped_function(self.replica_actions._delete_disks), + testutils.get_wrapped_function( + self.transfer_actions._delete_disks), req=mock_req, id=id, body=body ) mock_context.can.assert_called_once_with( - "migration:replicas:delete_disks") + "migration:transfers:delete_disks") mock_delete_disks.assert_called_once_with(mock_context, id) mock_single.assert_not_called() - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'delete_disks') def test_delete_disks_invalid_parameter_value( self, @@ -93,13 +94,14 @@ def test_delete_disks_invalid_parameter_value( self.assertRaises( exc.HTTPNotFound, - testutils.get_wrapped_function(self.replica_actions._delete_disks), + testutils.get_wrapped_function( + self.transfer_actions._delete_disks), req=mock_req, id=id, body=body ) mock_context.can.assert_called_once_with( - "migration:replicas:delete_disks") + "migration:transfers:delete_disks") mock_delete_disks.assert_called_once_with(mock_context, id) mock_single.assert_not_called() diff --git a/coriolis/tests/api/v1/test_replica_schedules.py b/coriolis/tests/api/v1/test_transfer_schedules.py similarity index 73% rename from coriolis/tests/api/v1/test_replica_schedules.py rename to coriolis/tests/api/v1/test_transfer_schedules.py index 0fcaec7e8..d143f7daa 100644 --- a/coriolis/tests/api/v1/test_replica_schedules.py +++ b/coriolis/tests/api/v1/test_transfer_schedules.py @@ -7,22 +7,23 @@ import jsonschema from webob import exc -from coriolis.api.v1 import replica_schedules -from coriolis.api.v1.views import replica_schedule_view +from coriolis.api.v1 import transfer_schedules +from coriolis.api.v1.views import transfer_schedule_view from coriolis import exception from coriolis import schemas from coriolis.tests import test_base from coriolis.transfer_cron import api -class ReplicaScheduleControllerTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis Replica Schedule v1 API""" +class TransferScheduleControllerTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis Transfer Schedule v1 API""" def setUp(self): - super(ReplicaScheduleControllerTestCase, self).setUp() - self.replica_schedules = replica_schedules.ReplicaScheduleController() + super(TransferScheduleControllerTestCase, self).setUp() + self.transfer_schedules = ( + transfer_schedules.TransferScheduleController()) - @mock.patch.object(replica_schedule_view, 'single') + @mock.patch.object(transfer_schedule_view, 'single') @mock.patch.object(api.API, 'get_schedule') def test_show( self, @@ -33,9 +34,9 @@ def test_show( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id - result = self.replica_schedules.show(mock_req, replica_id, id) + result = self.transfer_schedules.show(mock_req, transfer_id, id) self.assertEqual( mock_single.return_value, @@ -43,11 +44,12 @@ def test_show( ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:show") - mock_get_schedule.assert_called_once_with(mock_context, replica_id, id) + "migration:transfer_schedules:show") + mock_get_schedule.assert_called_once_with( + mock_context, transfer_id, id) mock_single.assert_called_once_with(mock_get_schedule.return_value) - @mock.patch.object(replica_schedule_view, 'single') + @mock.patch.object(transfer_schedule_view, 'single') @mock.patch.object(api.API, 'get_schedule') def test_show_not_found( self, @@ -58,23 +60,24 @@ def test_show_not_found( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id mock_get_schedule.return_value = None self.assertRaises( exc.HTTPNotFound, - self.replica_schedules.show, + self.transfer_schedules.show, mock_req, - replica_id, + transfer_id, id ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:show") - mock_get_schedule.assert_called_once_with(mock_context, replica_id, id) + "migration:transfer_schedules:show") + mock_get_schedule.assert_called_once_with( + mock_context, transfer_id, id) mock_single.assert_not_called() - @mock.patch.object(replica_schedule_view, 'collection') + @mock.patch.object(transfer_schedule_view, 'collection') @mock.patch.object(api.API, 'get_schedules') def test_index( self, @@ -84,20 +87,20 @@ def test_index( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id mock_req.GET = {"show_expired": "False"} - result = self.replica_schedules.index(mock_req, replica_id) + result = self.transfer_schedules.index(mock_req, transfer_id) self.assertEqual( mock_collection.return_value, result ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:list") + "migration:transfer_schedules:list") mock_get_schedules.assert_called_once_with( mock_context, - replica_id, + transfer_id, expired=False ) mock_collection.assert_called_once_with( @@ -112,7 +115,7 @@ def test_validate_schedule( ): schedule = mock.sentinel.schedule - result = self.replica_schedules._validate_schedule(schedule) + result = self.transfer_schedules._validate_schedule(schedule) self.assertEqual( schedule, @@ -127,7 +130,7 @@ def test_validate_expiration_date_is_none( ): expiration_date = None - result = self.replica_schedules._validate_expiration_date( + result = self.transfer_schedules._validate_expiration_date( expiration_date) self.assertEqual( @@ -142,7 +145,7 @@ def test_validate_expiration_date_past( self.assertRaises( exception.InvalidInput, - self.replica_schedules._validate_expiration_date, + self.transfer_schedules._validate_expiration_date, expiration_date ) @@ -151,7 +154,7 @@ def test_validate_expiration_date( ): expiration_date = '9999-12-31' - result = self.replica_schedules._validate_expiration_date( + result = self.transfer_schedules._validate_expiration_date( expiration_date) self.assertEqual( @@ -159,11 +162,11 @@ def test_validate_expiration_date( result ) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_expiration_date') @mock.patch.object(schemas, 'validate_value') @mock.patch.object(jsonschema, 'FormatChecker') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_schedule') def test_validate_create_body( self, @@ -187,7 +190,7 @@ def test_validate_create_body( True ) - result = self.replica_schedules._validate_create_body(mock_body) + result = self.transfer_schedules._validate_create_body(mock_body) self.assertEqual( expected_result, @@ -201,11 +204,11 @@ def test_validate_create_body( ) mock_validate_expiration_date.assert_called_once_with(date) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_expiration_date') @mock.patch.object(schemas, 'validate_value') @mock.patch.object(jsonschema, 'FormatChecker') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_schedule') def test_validate_create_body_no_expiration_date( self, @@ -227,7 +230,7 @@ def test_validate_create_body_no_expiration_date( True ) - result = self.replica_schedules._validate_create_body(mock_body) + result = self.transfer_schedules._validate_create_body(mock_body) self.assertEqual( expected_result, @@ -249,15 +252,15 @@ def test_validate_create_body_no_schedule( self.assertRaises( exception.InvalidInput, - self.replica_schedules._validate_create_body, + self.transfer_schedules._validate_create_body, mock_body ) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_expiration_date') @mock.patch.object(schemas, 'validate_value') @mock.patch.object(jsonschema, 'FormatChecker') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_schedule') def test_validate_update_body( self, @@ -281,7 +284,8 @@ def test_validate_update_body( "shutdown_instance": True } - result = self.replica_schedules._validate_update_body(mock_update_body) + result = self.transfer_schedules._validate_update_body( + mock_update_body) self.assertEqual( expected_result, @@ -295,11 +299,11 @@ def test_validate_update_body( ) mock_validate_expiration_date.assert_called_once_with(date) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_expiration_date') @mock.patch.object(schemas, 'validate_value') @mock.patch.object(jsonschema, 'FormatChecker') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_schedule') def test_validate_update_body_none( self, @@ -311,7 +315,8 @@ def test_validate_update_body_none( mock_update_body = {} expected_result = {} - result = self.replica_schedules._validate_update_body(mock_update_body) + result = self.transfer_schedules._validate_update_body( + mock_update_body) self.assertEqual( expected_result, @@ -325,9 +330,9 @@ def test_validate_update_body_none( ) mock_validate_expiration_date.assert_not_called() - @mock.patch.object(replica_schedule_view, 'single') + @mock.patch.object(transfer_schedule_view, 'single') @mock.patch.object(api.API, 'create') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_create_body') def test_create( self, @@ -338,14 +343,14 @@ def test_create( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id body = mock.sentinel.body schedule = mock.sentinel.schedule exp_date = mock.sentinel.exp_date mock_validate_create_body.return_value = ( schedule, False, exp_date, True) - result = self.replica_schedules.create(mock_req, replica_id, body) + result = self.transfer_schedules.create(mock_req, transfer_id, body) self.assertEqual( mock_single.return_value, @@ -353,13 +358,13 @@ def test_create( ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:create") + "migration:transfer_schedules:create") mock_validate_create_body.assert_called_once_with(body) mock_create.assert_called_once_with( - mock_context, replica_id, schedule, False, exp_date, True) + mock_context, transfer_id, schedule, False, exp_date, True) mock_single.assert_called_once_with(mock_create.return_value) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_create_body') def test_create_except( self, @@ -368,25 +373,25 @@ def test_create_except( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id body = mock.sentinel.body mock_validate_create_body.side_effect = Exception("err") self.assertRaises( exception.InvalidInput, - self.replica_schedules.create, + self.transfer_schedules.create, mock_req, - replica_id, + transfer_id, body ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:create") + "migration:transfer_schedules:create") mock_validate_create_body.assert_called_once_with(body) - @mock.patch.object(replica_schedule_view, 'single') + @mock.patch.object(transfer_schedule_view, 'single') @mock.patch.object(api.API, 'update') - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_update_body') def test_update( self, @@ -397,11 +402,12 @@ def test_update( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id body = mock.sentinel.body - result = self.replica_schedules.update(mock_req, replica_id, id, body) + result = self.transfer_schedules.update( + mock_req, transfer_id, id, body) self.assertEqual( mock_single.return_value, @@ -409,14 +415,14 @@ def test_update( ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:update") + "migration:transfer_schedules:update") mock_validate_update_body.assert_called_once_with(body) mock_update.assert_called_once_with( - mock_context, replica_id, id, + mock_context, transfer_id, id, mock_validate_update_body.return_value) mock_single.assert_called_once_with(mock_update.return_value) - @mock.patch.object(replica_schedules.ReplicaScheduleController, + @mock.patch.object(transfer_schedules.TransferScheduleController, '_validate_update_body') def test_update_except( self, @@ -425,22 +431,22 @@ def test_update_except( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id body = mock.sentinel.body mock_validate_update_body.side_effect = Exception("err") self.assertRaises( exception.InvalidInput, - self.replica_schedules.update, + self.transfer_schedules.update, mock_req, - replica_id, + transfer_id, id, body ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:update") + "migration:transfer_schedules:update") mock_validate_update_body.assert_called_once_with(body) @mock.patch.object(api.API, 'delete') @@ -451,17 +457,17 @@ def test_delete( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id self.assertRaises( exc.HTTPNoContent, - self.replica_schedules.delete, + self.transfer_schedules.delete, mock_req, - replica_id, + transfer_id, id ) mock_context.can.assert_called_once_with( - "migration:replica_schedules:delete") - mock_delete.assert_called_once_with(mock_context, replica_id, id) + "migration:transfer_schedules:delete") + mock_delete.assert_called_once_with(mock_context, transfer_id, id) diff --git a/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py b/coriolis/tests/api/v1/test_transfer_tasks_execution_actions.py similarity index 57% rename from coriolis/tests/api/v1/test_replica_tasks_execution_actions.py rename to coriolis/tests/api/v1/test_transfer_tasks_execution_actions.py index 2ed8e2fd9..bddfb363c 100644 --- a/coriolis/tests/api/v1/test_replica_tasks_execution_actions.py +++ b/coriolis/tests/api/v1/test_transfer_tasks_execution_actions.py @@ -6,25 +6,26 @@ import ddt from webob import exc -from coriolis.api.v1 import replica_tasks_execution_actions as replica_api +from coriolis.api.v1 import transfer_tasks_execution_actions as transfer_api from coriolis import exception -from coriolis.replica_tasks_executions import api from coriolis.tests import test_base from coriolis.tests import testutils +from coriolis.transfer_tasks_executions import api @ddt.ddt -class ReplicaTasksExecutionActionsControllerTestCase( +class TransferTasksExecutionActionsControllerTestCase( test_base.CoriolisBaseTestCase ): - """Test suite for the Coriolis Replica Tasks Execution Actions v1 API""" + """Test suite for the Coriolis Transfer Tasks Execution Actions v1 API""" def setUp(self): - super(ReplicaTasksExecutionActionsControllerTestCase, self).setUp() - self.replica_api = replica_api.ReplicaTasksExecutionActionsController() + super(TransferTasksExecutionActionsControllerTestCase, self).setUp() + self.transfer_api = ( + transfer_api.TransferTasksExecutionActionsController()) @mock.patch.object(api.API, 'cancel') - @ddt.file_data('data/replica_task_execution_actions_cancel.yml') + @ddt.file_data('data/transfer_task_execution_actions_cancel.yml') def test_cancel( self, mock_cancel, @@ -37,7 +38,7 @@ def test_cancel( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id body = config["body"] if exception_raised: mock_cancel.side_effect = getattr(exception, exception_raised)( @@ -45,14 +46,14 @@ def test_cancel( self.assertRaises( getattr(exc, expected_result), - testutils.get_wrapped_function(self.replica_api._cancel), + testutils.get_wrapped_function(self.transfer_api._cancel), mock_req, - replica_id, + transfer_id, id, body ) mock_context.can.assert_called_once_with( - "migration:replica_executions:cancel") + "migration:transfer_executions:cancel") mock_cancel.assert_called_once_with( - mock_context, replica_id, id, expected_force) + mock_context, transfer_id, id, expected_force) diff --git a/coriolis/tests/api/v1/test_replica_tasks_executions.py b/coriolis/tests/api/v1/test_transfer_tasks_executions.py similarity index 63% rename from coriolis/tests/api/v1/test_replica_tasks_executions.py rename to coriolis/tests/api/v1/test_transfer_tasks_executions.py index b1b2b11bb..de607b2e5 100644 --- a/coriolis/tests/api/v1/test_replica_tasks_executions.py +++ b/coriolis/tests/api/v1/test_transfer_tasks_executions.py @@ -5,21 +5,21 @@ from webob import exc -from coriolis.api.v1 import replica_tasks_executions as replica_api -from coriolis.api.v1.views import replica_tasks_execution_view +from coriolis.api.v1 import transfer_tasks_executions as transfer_api +from coriolis.api.v1.views import transfer_tasks_execution_view from coriolis import exception -from coriolis.replica_tasks_executions import api from coriolis.tests import test_base +from coriolis.transfer_tasks_executions import api -class ReplicaTasksExecutionControllerTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis Replica Tasks Execution v1 API""" +class TransferTasksExecutionControllerTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis Transfer Tasks Execution v1 API""" def setUp(self): - super(ReplicaTasksExecutionControllerTestCase, self).setUp() - self.replica_api = replica_api.ReplicaTasksExecutionController() + super(TransferTasksExecutionControllerTestCase, self).setUp() + self.transfer_api = transfer_api.TransferTasksExecutionController() - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'get_execution') def test_show( self, @@ -29,10 +29,10 @@ def test_show( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id - result = self.replica_api.show(mock_req, replica_id, id) + result = self.transfer_api.show(mock_req, transfer_id, id) self.assertEqual( mock_single.return_value, @@ -40,12 +40,12 @@ def test_show( ) mock_context.can.assert_called_once_with( - "migration:replica_executions:show") + "migration:transfer_executions:show") mock_get_execution.assert_called_once_with( - mock_context, replica_id, id) + mock_context, transfer_id, id) mock_single.assert_called_once_with(mock_get_execution.return_value) - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'get_execution') def test_show_not_found( self, @@ -55,25 +55,25 @@ def test_show_not_found( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id mock_get_execution.return_value = None self.assertRaises( exc.HTTPNotFound, - self.replica_api.show, + self.transfer_api.show, mock_req, - replica_id, + transfer_id, id ) mock_context.can.assert_called_once_with( - "migration:replica_executions:show") + "migration:transfer_executions:show") mock_get_execution.assert_called_once_with( - mock_context, replica_id, id) + mock_context, transfer_id, id) mock_single.assert_not_called() - @mock.patch.object(replica_tasks_execution_view, 'collection') + @mock.patch.object(transfer_tasks_execution_view, 'collection') @mock.patch.object(api.API, 'get_executions') def test_index( self, @@ -83,9 +83,9 @@ def test_index( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id - result = self.replica_api.index(mock_req, replica_id) + result = self.transfer_api.index(mock_req, transfer_id) self.assertEqual( mock_collection.return_value, @@ -93,13 +93,13 @@ def test_index( ) mock_context.can.assert_called_once_with( - "migration:replica_executions:list") + "migration:transfer_executions:list") mock_get_executions.assert_called_once_with( - mock_context, replica_id, include_tasks=False) + mock_context, transfer_id, include_tasks=False) mock_collection.assert_called_once_with( mock_get_executions.return_value) - @mock.patch.object(replica_tasks_execution_view, 'collection') + @mock.patch.object(transfer_tasks_execution_view, 'collection') @mock.patch.object(api.API, 'get_executions') def test_detail( self, @@ -109,9 +109,9 @@ def test_detail( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id - result = self.replica_api.detail(mock_req, replica_id) + result = self.transfer_api.detail(mock_req, transfer_id) self.assertEqual( mock_collection.return_value, @@ -119,13 +119,13 @@ def test_detail( ) mock_context.can.assert_called_once_with( - "migration:replica_executions:show") + "migration:transfer_executions:show") mock_get_executions.assert_called_once_with( - mock_context, replica_id, include_tasks=True) + mock_context, transfer_id, include_tasks=True) mock_collection.assert_called_once_with( mock_get_executions.return_value) - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'create') def test_create( self, @@ -135,11 +135,11 @@ def test_create( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id execution = {"shutdown_instances": True} mock_body = {"execution": execution} - result = self.replica_api.create(mock_req, replica_id, mock_body) + result = self.transfer_api.create(mock_req, transfer_id, mock_body) self.assertEqual( mock_single.return_value, @@ -147,12 +147,12 @@ def test_create( ) mock_context.can.assert_called_once_with( - "migration:replica_executions:create") + "migration:transfer_executions:create") mock_create.assert_called_once_with( - mock_context, replica_id, True) + mock_context, transfer_id, True) mock_single.assert_called_once_with(mock_create.return_value) - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'create') def test_create_no_executions( self, @@ -162,10 +162,10 @@ def test_create_no_executions( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id mock_body = {} - result = self.replica_api.create(mock_req, replica_id, mock_body) + result = self.transfer_api.create(mock_req, transfer_id, mock_body) self.assertEqual( mock_single.return_value, @@ -173,9 +173,9 @@ def test_create_no_executions( ) mock_context.can.assert_called_once_with( - "migration:replica_executions:create") + "migration:transfer_executions:create") mock_create.assert_called_once_with( - mock_context, replica_id, False) + mock_context, transfer_id, False) mock_single.assert_called_once_with(mock_create.return_value) @mock.patch.object(api.API, 'delete') @@ -186,20 +186,20 @@ def test_delete( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id self.assertRaises( exc.HTTPNoContent, - self.replica_api.delete, + self.transfer_api.delete, mock_req, - replica_id, + transfer_id, id ) mock_context.can.assert_called_once_with( - "migration:replica_executions:delete") - mock_delete.assert_called_once_with(mock_context, replica_id, id) + "migration:transfer_executions:delete") + mock_delete.assert_called_once_with(mock_context, transfer_id, id) @mock.patch.object(api.API, 'delete') def test_delete_not_found( @@ -209,18 +209,18 @@ def test_delete_not_found( mock_req = mock.Mock() mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - replica_id = mock.sentinel.transfer_id + transfer_id = mock.sentinel.transfer_id id = mock.sentinel.id mock_delete.side_effect = exception.NotFound() self.assertRaises( exc.HTTPNotFound, - self.replica_api.delete, + self.transfer_api.delete, mock_req, - replica_id, + transfer_id, id ) mock_context.can.assert_called_once_with( - "migration:replica_executions:delete") - mock_delete.assert_called_once_with(mock_context, replica_id, id) + "migration:transfer_executions:delete") + mock_delete.assert_called_once_with(mock_context, transfer_id, id) diff --git a/coriolis/tests/api/v1/test_replicas.py b/coriolis/tests/api/v1/test_transfers.py similarity index 67% rename from coriolis/tests/api/v1/test_replicas.py rename to coriolis/tests/api/v1/test_transfers.py index 4f9bdbe0d..f2fa60812 100644 --- a/coriolis/tests/api/v1/test_replicas.py +++ b/coriolis/tests/api/v1/test_transfers.py @@ -6,31 +6,31 @@ import ddt from webob import exc -from coriolis.api.v1 import replicas +from coriolis.api.v1 import transfers from coriolis.api.v1 import utils as api_utils -from coriolis.api.v1.views import replica_tasks_execution_view -from coriolis.api.v1.views import replica_view +from coriolis.api.v1.views import transfer_tasks_execution_view +from coriolis.api.v1.views import transfer_view from coriolis.endpoints import api as endpoints_api from coriolis import exception -from coriolis.replicas import api from coriolis.tests import test_base from coriolis.tests import testutils +from coriolis.transfers import api @ddt.ddt -class ReplicaControllerTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis Replica Controller v1 API""" +class TransferControllerTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis Transfer Controller v1 API""" def setUp(self): - super(ReplicaControllerTestCase, self).setUp() - self.replicas = replicas.ReplicaController() + super(TransferControllerTestCase, self).setUp() + self.transfers = transfers.TransferController() - @mock.patch('coriolis.api.v1.replicas.CONF') - @mock.patch.object(replica_view, 'single') - @mock.patch.object(api.API, 'get_replica') + @mock.patch('coriolis.api.v1.transfers.CONF') + @mock.patch.object(transfer_view, 'single') + @mock.patch.object(api.API, 'get_transfer') def test_show( self, - mock_get_replica, + mock_get_transfer, mock_single, mock_conf ): @@ -38,26 +38,26 @@ def test_show( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - mock_conf.api.include_task_info_in_replicas_api = True + mock_conf.api.include_task_info_in_transfers_api = True - result = self.replicas.show(mock_req, id) + result = self.transfers.show(mock_req, id) self.assertEqual( mock_single.return_value, result ) - mock_context.can.assert_called_once_with("migration:replicas:show") - mock_get_replica.assert_called_once_with( + mock_context.can.assert_called_once_with("migration:transfers:show") + mock_get_transfer.assert_called_once_with( mock_context, id, include_task_info=True) - mock_single.assert_called_once_with(mock_get_replica.return_value) + mock_single.assert_called_once_with(mock_get_transfer.return_value) - @mock.patch('coriolis.api.v1.replicas.CONF') - @mock.patch.object(replica_view, 'single') - @mock.patch.object(api.API, 'get_replica') - def test_show_no_replica( + @mock.patch('coriolis.api.v1.transfers.CONF') + @mock.patch.object(transfer_view, 'single') + @mock.patch.object(api.API, 'get_transfer') + def test_show_no_transfer( self, - mock_get_replica, + mock_get_transfer, mock_single, mock_conf ): @@ -65,29 +65,29 @@ def test_show_no_replica( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} id = mock.sentinel.id - mock_conf.api.include_task_info_in_replicas_api = True - mock_get_replica.return_value = None + mock_conf.api.include_task_info_in_transfers_api = True + mock_get_transfer.return_value = None self.assertRaises( exc.HTTPNotFound, - self.replicas.show, + self.transfers.show, mock_req, id ) - mock_context.can.assert_called_once_with("migration:replicas:show") - mock_get_replica.assert_called_once_with( + mock_context.can.assert_called_once_with("migration:transfers:show") + mock_get_transfer.assert_called_once_with( mock_context, id, include_task_info=True) mock_single.assert_not_called() - @mock.patch('coriolis.api.v1.replicas.CONF') - @mock.patch.object(replica_view, 'collection') - @mock.patch.object(api.API, 'get_replicas') + @mock.patch('coriolis.api.v1.transfers.CONF') + @mock.patch.object(transfer_view, 'collection') + @mock.patch.object(api.API, 'get_transfers') @mock.patch.object(api_utils, '_get_show_deleted') def test_list( self, mock_get_show_deleted, - mock_get_replicas, + mock_get_transfers, mock_collection, mock_conf ): @@ -95,7 +95,7 @@ def test_list( mock_context = mock.Mock() mock_req.environ = {'coriolis.context': mock_context} - result = self.replicas._list(mock_req) + result = self.transfers._list(mock_req) self.assertEqual( mock_collection.return_value, @@ -104,14 +104,15 @@ def test_list( mock_get_show_deleted.assert_called_once_with( mock_req.GET.get.return_value) - mock_context.can.assert_called_once_with("migration:replicas:list") - mock_get_replicas.assert_called_once_with( + mock_context.can.assert_called_once_with("migration:transfers:list") + mock_get_transfers.assert_called_once_with( mock_context, include_tasks_executions= - mock_conf.api.include_task_info_in_replicas_api, - include_task_info=mock_conf.api.include_task_info_in_replicas_api + mock_conf.api.include_task_info_in_transfers_api, + include_task_info=mock_conf.api.include_task_info_in_transfers_api ) - mock_collection.assert_called_once_with(mock_get_replicas.return_value) + mock_collection.assert_called_once_with( + mock_get_transfers.return_value) @mock.patch.object(api_utils, 'validate_instances_list_for_transfer') @mock.patch.object(endpoints_api.API, 'validate_source_environment') @@ -120,7 +121,7 @@ def test_list( @mock.patch.object(api_utils, 'validate_user_scripts') @mock.patch.object(api_utils, 'normalize_user_scripts') @mock.patch.object(api_utils, 'validate_storage_mappings') - @ddt.file_data('data/replicas_validate_create_body.yml') + @ddt.file_data('data/transfers_validate_create_body.yml') def test_validate_create_body( self, mock_validate_storage_mappings, @@ -136,15 +137,15 @@ def test_validate_create_body( ): ctxt = {} body = config["body"] - replica = body["replica"] - origin_endpoint_id = replica.get('origin_endpoint_id') - source_environment = replica.get('source_environment') - network_map = replica.get('network_map') - destination_endpoint_id = replica.get('destination_endpoint_id') - destination_environment = replica.get('destination_environment') - user_scripts = replica.get('user_scripts') - instances = replica.get('instances') - storage_mappings = replica.get('storage_mappings') + transfer = body["transfer"] + origin_endpoint_id = transfer.get('origin_endpoint_id') + source_environment = transfer.get('source_environment') + network_map = transfer.get('network_map') + destination_endpoint_id = transfer.get('destination_endpoint_id') + destination_environment = transfer.get('destination_environment') + user_scripts = transfer.get('user_scripts') + instances = transfer.get('instances') + storage_mappings = transfer.get('storage_mappings') mock_validate_instances_list_for_transfer.return_value = instances mock_normalize_user_scripts.return_value = user_scripts @@ -153,8 +154,8 @@ def test_validate_create_body( Exception, exception_raised, testutils.get_wrapped_function( - self.replicas._validate_create_body), - self.replicas, + self.transfers._validate_create_body), + self.transfers, ctxt, body ) @@ -162,8 +163,8 @@ def test_validate_create_body( mock_validate_network_map.assert_not_called() else: result = testutils.get_wrapped_function( - self.replicas._validate_create_body)( - self.replicas, + self.transfers._validate_create_body)( + self.transfers, ctxt, body, ) @@ -187,9 +188,9 @@ def test_validate_create_body( mock_validate_instances_list_for_transfer.assert_called_once_with( instances) - @mock.patch.object(replica_view, 'single') + @mock.patch.object(transfer_view, 'single') @mock.patch.object(api.API, 'create') - @mock.patch.object(replicas.ReplicaController, '_validate_create_body') + @mock.patch.object(transfers.TransferController, '_validate_create_body') def test_create( self, mock_validate_create_body, @@ -202,7 +203,7 @@ def test_create( mock_body = {} mock_validate_create_body.return_value = (mock.sentinel.value,) * 13 - result = self.replicas.create(mock_req, mock_body) + result = self.transfers.create(mock_req, mock_body) self.assertEqual( mock_single.return_value, @@ -210,7 +211,7 @@ def test_create( ) mock_context.can.assert_called_once_with( - "migration:replicas:create") + "migration:transfers:create") mock_validate_create_body.assert_called_once_with( mock_context, mock_body) mock_create.assert_called_once() @@ -228,7 +229,7 @@ def test_delete( self.assertRaises( exc.HTTPNoContent, - self.replicas.delete, + self.transfers.delete, mock_req, id ) @@ -248,15 +249,15 @@ def test_delete_not_found( self.assertRaises( exc.HTTPNotFound, - self.replicas.delete, + self.transfers.delete, mock_req, id ) - mock_context.can.assert_called_once_with("migration:replicas:delete") + mock_context.can.assert_called_once_with("migration:transfers:delete") mock_delete.assert_called_once_with(mock_context, id) - @ddt.file_data('data/replicas_update_storage_mappings.yml') + @ddt.file_data('data/transfers_update_storage_mappings.yml') def test_update_storage_mappings( self, config, @@ -267,11 +268,11 @@ def test_update_storage_mappings( new_storage_mappings = config['new_storage_mappings'] if logs_expected: - with self.assertLogs('coriolis.api.v1.replicas', level='INFO'): - result = self.replicas._update_storage_mappings( + with self.assertLogs('coriolis.api.v1.transfers', level='INFO'): + result = self.transfers._update_storage_mappings( original_storage_mappings, new_storage_mappings) else: - result = self.replicas._update_storage_mappings( + result = self.transfers._update_storage_mappings( original_storage_mappings, new_storage_mappings) self.assertEqual( @@ -296,7 +297,7 @@ def test_get_updated_user_scripts( "mock_global_scripts_2": "mock_value"}, 'instances': {"mock_instance_scripts": "mock_new_value"} } - result = self.replicas._get_updated_user_scripts( + result = self.transfers._get_updated_user_scripts( original_user_scripts, new_user_scripts) self.assertEqual( @@ -314,7 +315,7 @@ def test_get_updated_user_scripts_new_user_scripts_empty( } new_user_scripts = {} - result = self.replicas._get_updated_user_scripts( + result = self.transfers._get_updated_user_scripts( original_user_scripts, new_user_scripts) self.assertEqual( @@ -322,11 +323,13 @@ def test_get_updated_user_scripts_new_user_scripts_empty( result ) - @mock.patch.object(replicas.ReplicaController, '_get_updated_user_scripts') + @mock.patch.object(transfers.TransferController, + '_get_updated_user_scripts') @mock.patch.object(api_utils, 'validate_user_scripts') - @mock.patch.object(replicas.ReplicaController, '_update_storage_mappings') - @ddt.file_data('data/replicas_get_merged_replica_values.yml') - def test_get_merged_replica_values( + @mock.patch.object(transfers.TransferController, + '_update_storage_mappings') + @ddt.file_data('data/transfers_get_merged_transfer_values.yml') + def test_get_merged_transfer_values( self, mock_update_storage_mappings, mock_validate_user_scripts, @@ -334,10 +337,10 @@ def test_get_merged_replica_values( config, expected_result ): - replica = config['replica'] + transfer = config['transfer'] updated_values = config['updated_values'] - original_storage_mapping = replica.get('storage_mappings', {}) - replica_user_scripts = replica.get('user_scripts', {}) + original_storage_mapping = transfer.get('storage_mappings', {}) + transfer_user_scripts = transfer.get('user_scripts', {}) updated_user_scripts = updated_values.get('user_scripts', {}) new_storage_mappings = updated_values.get('storage_mappings', {}) expected_result['storage_mappings'] = \ @@ -349,8 +352,8 @@ def test_get_merged_replica_values( mock_validate_user_scripts.side_effect = ["mock_scripts", "mock_new_scripts"] - result = self.replicas._get_merged_replica_values( - replica, updated_values) + result = self.transfers._get_merged_transfer_values( + transfer, updated_values) self.assertEqual( expected_result, @@ -360,7 +363,8 @@ def test_get_merged_replica_values( mock_update_storage_mappings.assert_called_once_with( original_storage_mapping, new_storage_mappings) mock_validate_user_scripts.assert_has_calls( - [mock.call(replica_user_scripts), mock.call(updated_user_scripts)]) + [mock.call(transfer_user_scripts), + mock.call(updated_user_scripts)]) mock_get_updated_user_scripts.assert_called_once_with( "mock_scripts", "mock_new_scripts") @@ -370,14 +374,14 @@ def test_get_merged_replica_values( @mock.patch.object(api_utils, 'validate_network_map') @mock.patch.object(endpoints_api.API, 'validate_target_environment') @mock.patch.object(endpoints_api.API, 'validate_source_environment') - @mock.patch.object(replicas.ReplicaController, - '_get_merged_replica_values') - @mock.patch.object(api.API, 'get_replica') - @ddt.file_data('data/replicas_validate_update_body.yml') + @mock.patch.object(transfers.TransferController, + '_get_merged_transfer_values') + @mock.patch.object(api.API, 'get_transfer') + @ddt.file_data('data/transfers_validate_update_body.yml') def test_validate_update_body( self, - mock_get_replica, - mock_get_merged_replica_values, + mock_get_transfer, + mock_get_merged_transfer_values, mock_validate_source_environment, mock_validate_target_environment, mock_validate_network_map, @@ -388,17 +392,18 @@ def test_validate_update_body( expected_result ): body = config['body'] - replica = config['replica'] - replica_body = body['replica'] + transfer = config['transfer'] + transfer_body = body['transfer'] context = mock.sentinel.context id = mock.sentinel.id - mock_get_replica.return_value = replica - mock_get_merged_replica_values.return_value = replica_body - mock_normalize_user_scripts.return_value = replica_body['user_scripts'] + mock_get_transfer.return_value = transfer + mock_get_merged_transfer_values.return_value = transfer_body + mock_normalize_user_scripts.return_value = transfer_body[ + 'user_scripts'] result = testutils.get_wrapped_function( - self.replicas._validate_update_body)( - self.replicas, + self.transfers._validate_update_body)( + self.transfers, id, context, body @@ -409,29 +414,29 @@ def test_validate_update_body( result ) - mock_get_replica.assert_called_once_with(context, id) - mock_get_merged_replica_values.assert_called_once_with( - replica, replica_body) + mock_get_transfer.assert_called_once_with(context, id) + mock_get_merged_transfer_values.assert_called_once_with( + transfer, transfer_body) mock_validate_source_environment.assert_called_once_with( - context, replica['origin_endpoint_id'], - replica_body['source_environment']) + context, transfer['origin_endpoint_id'], + transfer_body['source_environment']) mock_validate_target_environment.assert_called_once_with( - context, replica['destination_endpoint_id'], - replica_body['destination_environment']) + context, transfer['destination_endpoint_id'], + transfer_body['destination_environment']) mock_validate_network_map.assert_called_once_with( - replica_body['network_map']) + transfer_body['network_map']) mock_validate_storage_mappings.assert_called_once_with( - replica_body['storage_mappings']) + transfer_body['storage_mappings']) mock_validate_user_scripts.assert_called_once_with( - replica_body['user_scripts']) + transfer_body['user_scripts']) mock_normalize_user_scripts.assert_called_once_with( - replica_body['user_scripts'], replica['instances']) + transfer_body['user_scripts'], transfer['instances']) - @mock.patch.object(api.API, 'get_replica') - @ddt.file_data('data/replicas_validate_update_body_raises.yml') + @mock.patch.object(api.API, 'get_transfer') + @ddt.file_data('data/transfers_validate_update_body_raises.yml') def test_validate_update_body_raises( self, - mock_get_replica, + mock_get_transfer, body, ): context = mock.sentinel.context @@ -440,18 +445,18 @@ def test_validate_update_body_raises( self.assertRaises( exc.HTTPBadRequest, testutils.get_wrapped_function( - self.replicas._validate_update_body), - self.replicas, + self.transfers._validate_update_body), + self.transfers, id, context, body ) - mock_get_replica.assert_called_once_with(context, id) + mock_get_transfer.assert_called_once_with(context, id) - @mock.patch.object(replica_tasks_execution_view, 'single') + @mock.patch.object(transfer_tasks_execution_view, 'single') @mock.patch.object(api.API, 'update') - @mock.patch.object(replicas.ReplicaController, '_validate_update_body') + @mock.patch.object(transfers.TransferController, '_validate_update_body') def test_update( self, mock_validate_update_body, @@ -464,7 +469,7 @@ def test_update( id = mock.sentinel.id body = mock.sentinel.body - result = self.replicas.update(mock_req, id, body) + result = self.transfers.update(mock_req, id, body) self.assertEqual( mock_single.return_value, @@ -472,7 +477,7 @@ def test_update( ) mock_context.can.assert_called_once_with( - "migration:replicas:update") + "migration:transfers:update") mock_validate_update_body.assert_called_once_with( id, mock_context, body) mock_update.assert_called_once_with( @@ -481,7 +486,7 @@ def test_update( mock_single.assert_called_once_with(mock_update.return_value) @mock.patch.object(api.API, 'update') - @mock.patch.object(replicas.ReplicaController, '_validate_update_body') + @mock.patch.object(transfers.TransferController, '_validate_update_body') def test_update_not_found( self, mock_validate_update_body, @@ -496,14 +501,14 @@ def test_update_not_found( self.assertRaises( exc.HTTPNotFound, - self.replicas.update, + self.transfers.update, mock_req, id, body ) mock_context.can.assert_called_once_with( - "migration:replicas:update") + "migration:transfers:update") mock_validate_update_body.assert_called_once_with( id, mock_context, body) mock_update.assert_called_once_with( @@ -511,7 +516,7 @@ def test_update_not_found( mock_validate_update_body.return_value) @mock.patch.object(api.API, 'update') - @mock.patch.object(replicas.ReplicaController, '_validate_update_body') + @mock.patch.object(transfers.TransferController, '_validate_update_body') def test_update_not_invalid_parameter_value( self, mock_validate_update_body, @@ -526,14 +531,14 @@ def test_update_not_invalid_parameter_value( self.assertRaises( exc.HTTPNotFound, - self.replicas.update, + self.transfers.update, mock_req, id, body ) mock_context.can.assert_called_once_with( - "migration:replicas:update") + "migration:transfers:update") mock_validate_update_body.assert_called_once_with( id, mock_context, body) mock_update.assert_called_once_with( diff --git a/coriolis/tests/api/v1/views/__init__py b/coriolis/tests/api/v1/views/__init__py deleted file mode 100644 index e69de29bb..000000000 diff --git a/coriolis/tests/api/v1/views/test_migration_view.py b/coriolis/tests/api/v1/views/test_migration_view.py deleted file mode 100644 index a803aac45..000000000 --- a/coriolis/tests/api/v1/views/test_migration_view.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2023 Cloudbase Solutions Srl -# All Rights Reserved. - -from unittest import mock - -from coriolis.api.v1.views import migration_view -from coriolis.api.v1.views import replica_tasks_execution_view as view -from coriolis.api.v1.views import utils as view_utils -from coriolis.tests import test_base - - -class MigrationViewTestCase(test_base.CoriolisApiViewsTestCase): - """Test suite for the Coriolis api v1 views.""" - - @mock.patch.object(view, 'format_replica_tasks_execution') - @mock.patch.object(view_utils, 'format_opt') - def test_format_migration( - self, - mock_format_opt, - mock_format_replica_tasks_execution - ): - mock_execution = {'tasks': 'mock_id1'} - mock_format_opt.return_value = { - "executions": [mock_execution], - 'tasks': 'mock_id2', - 'mock_key': 'mock_value' - } - mock_format_replica_tasks_execution.return_value = mock_execution - - expected_result = { - 'tasks': 'mock_id1', - 'mock_key': 'mock_value' - } - - endpoint = mock.sentinel.endpoint - keys = mock.sentinel.keys - result = migration_view._format_migration(endpoint, keys) - - mock_format_replica_tasks_execution.assert_called_once_with( - mock_execution, keys - ) - mock_format_opt.assert_called_once_with(endpoint, keys) - - self.assertEqual( - expected_result, - result - ) - - @mock.patch.object(view_utils, 'format_opt') - def test_format_migration_no_tasks( - self, - mock_format_opt, - ): - mock_format_opt.return_value = { - 'mock_key': 'mock_value' - } - - endpoint = mock.sentinel.endpoint - keys = mock.sentinel.keys - result = migration_view._format_migration(endpoint, keys) - - mock_format_opt.assert_called_once_with(endpoint, keys) - - self.assertEqual( - mock_format_opt.return_value, - result - ) - - @mock.patch.object(view_utils, 'format_opt') - def test_format_migration_migration_dict_has_tasks( - self, - mock_format_opt, - ): - mock_format_opt.return_value = { - 'tasks': 'mock_id1', - 'mock_key': 'mock_value' - } - - endpoint = mock.sentinel.endpoint - keys = mock.sentinel.keys - result = migration_view._format_migration(endpoint, keys) - - mock_format_opt.assert_called_once_with(endpoint, keys) - - self.assertEqual( - mock_format_opt.return_value, - result - ) - - def test_single(self): - fun = getattr(migration_view, 'single') - self._single_view_test(fun, 'migration') - - def test_collection(self): - fun = getattr(migration_view, 'collection') - self._collection_view_test(fun, 'migrations') diff --git a/coriolis/tests/api/v1/views/test_replica_view.py b/coriolis/tests/api/v1/views/test_replica_view.py deleted file mode 100644 index ec5ffe3e5..000000000 --- a/coriolis/tests/api/v1/views/test_replica_view.py +++ /dev/null @@ -1,112 +0,0 @@ -# Copyright 2023 Cloudbase Solutions Srl -# All Rights Reserved. - -from unittest import mock - -from coriolis.api.v1.views import replica_tasks_execution_view as view -from coriolis.api.v1.views import replica_view -from coriolis.api.v1.views import utils as view_utils -from coriolis.tests import test_base - - -class ReplicaViewTestCase(test_base.CoriolisApiViewsTestCase): - """Test suite for the Coriolis api v1 views.""" - - def setUp(self): - super(ReplicaViewTestCase, self).setUp() - self._format_fun = replica_view._format_replica - - @mock.patch.object(view, 'format_replica_tasks_execution') - @mock.patch.object(view_utils, 'format_opt') - def test_format_replica(self, mock_format_opt, - mock_format_replica_tasks_execution): - mock_format_opt.return_value = { - "executions": [{'id': 'mock_id1'}, {'id': 'mock_id2'}], - "mock_key": "mock_value" - } - - expected_calls = [ - mock.call.mock_format_replica_tasks_execution( - {'id': 'mock_id1'}), - mock.call.mock_format_replica_tasks_execution( - {'id': 'mock_id2'})] - expected_result = { - "executions": - [mock_format_replica_tasks_execution.return_value, - mock_format_replica_tasks_execution.return_value], - 'mock_key': 'mock_value' - } - - replica = mock.sentinel.replica - keys = mock.sentinel.keys - result = replica_view._format_replica(replica, keys) - - mock_format_opt.assert_called_once_with(replica, keys) - mock_format_replica_tasks_execution.assert_has_calls( - expected_calls - ) - self.assertEqual( - expected_result, - result - ) - - @mock.patch.object(view, 'format_replica_tasks_execution') - @mock.patch.object(view_utils, 'format_opt') - def test_format_replica_no_keys(self, mock_format_opt, - mock_format_replica_tasks_execution): - mock_format_opt.return_value = { - "executions": [{'id': 'mock_id1'}, {'id': 'mock_id2'}], - } - - expected_calls = [ - mock.call.mock_format_replica_tasks_execution( - {'id': 'mock_id1'}), - mock.call.mock_format_replica_tasks_execution( - {'id': 'mock_id2'})] - expected_result = { - "executions": - [mock_format_replica_tasks_execution.return_value, - mock_format_replica_tasks_execution.return_value], - } - - replica = mock.sentinel.replica - keys = mock.sentinel.keys - result = replica_view._format_replica(replica, keys) - - mock_format_opt.assert_called_once_with(replica, keys) - mock_format_replica_tasks_execution.assert_has_calls( - expected_calls - ) - self.assertEqual( - expected_result, - result - ) - - @mock.patch.object(view_utils, 'format_opt') - def test_format_replica_no_executions(self, mock_format_opt): - mock_format_opt.return_value = { - "mock_key": "mock_value" - } - - expected_result = { - 'executions': [], - 'mock_key': 'mock_value' - } - - replica = mock.sentinel.replica - keys = mock.sentinel.keys - result = replica_view._format_replica(replica, keys) - - mock_format_opt.assert_called_once_with(replica, keys) - self.assertEqual( - expected_result, - result - ) - - def test_single(self): - fun = getattr(replica_view, 'single') - self._single_view_test(fun, 'replica') - - def test_collection(self): - fun = getattr(replica_view, 'collection') - self._collection_view_test(fun, 'replicas') diff --git a/coriolis/tests/api/v1/views/test_replica_schedule_view.py b/coriolis/tests/api/v1/views/test_transfer_schedule_view.py similarity index 57% rename from coriolis/tests/api/v1/views/test_replica_schedule_view.py rename to coriolis/tests/api/v1/views/test_transfer_schedule_view.py index 3baffaad3..6f3e29443 100644 --- a/coriolis/tests/api/v1/views/test_replica_schedule_view.py +++ b/coriolis/tests/api/v1/views/test_transfer_schedule_view.py @@ -1,17 +1,17 @@ # Copyright 2023 Cloudbase Solutions Srl # All Rights Reserved. -from coriolis.api.v1.views import replica_schedule_view +from coriolis.api.v1.views import transfer_schedule_view from coriolis.tests import test_base -class ReplicaViewTestCase(test_base.CoriolisApiViewsTestCase): +class TransferViewTestCase(test_base.CoriolisApiViewsTestCase): """Test suite for the Coriolis api v1 views.""" def test_single(self): - fun = getattr(replica_schedule_view, 'single') + fun = getattr(transfer_schedule_view, 'single') self._single_view_test(fun, 'schedule') def test_collection(self): - fun = getattr(replica_schedule_view, 'collection') + fun = getattr(transfer_schedule_view, 'collection') self._collection_view_test(fun, 'schedules') diff --git a/coriolis/tests/api/v1/views/test_replica_task_execution_view.py b/coriolis/tests/api/v1/views/test_transfer_task_execution_view.py similarity index 88% rename from coriolis/tests/api/v1/views/test_replica_task_execution_view.py rename to coriolis/tests/api/v1/views/test_transfer_task_execution_view.py index 9e9dbfd91..4cf58ff51 100644 --- a/coriolis/tests/api/v1/views/test_replica_task_execution_view.py +++ b/coriolis/tests/api/v1/views/test_transfer_task_execution_view.py @@ -3,18 +3,18 @@ from unittest import mock -from coriolis.api.v1.views import replica_tasks_execution_view as view +from coriolis.api.v1.views import transfer_tasks_execution_view as view from coriolis.api.v1.views import utils as view_utils from coriolis import constants from coriolis.tests import test_base -class ReplicaTaskExecutionViewTestCase(test_base.CoriolisApiViewsTestCase): +class TransferTaskExecutionViewTestCase(test_base.CoriolisApiViewsTestCase): """Test suite for the Coriolis api v1 views.""" @mock.patch.object(view, '_sort_tasks') @mock.patch.object(view_utils, 'format_opt') - def test_format_replica_tasks_execution( + def test_format_transfer_tasks_execution( self, mock_format_opt, mock_sort_tasks @@ -27,7 +27,7 @@ def test_format_replica_tasks_execution( mock_sort_tasks.return_value = mock_execution keys = mock.sentinel.keys - result = view.format_replica_tasks_execution(mock_execution, keys) + result = view.format_transfer_tasks_execution(mock_execution, keys) mock_sort_tasks.assert_called_once_with(mock_tasks) mock_format_opt.assert_called_once_with(mock_execution["tasks"], keys) @@ -38,7 +38,7 @@ def test_format_replica_tasks_execution( @mock.patch.object(view, '_sort_tasks') @mock.patch.object(view_utils, 'format_opt') - def test_format_replica_tasks_execution_no_tasks( + def test_format_transfer_tasks_execution_no_tasks( self, mock_format_opt, mock_sort_tasks @@ -48,7 +48,7 @@ def test_format_replica_tasks_execution_no_tasks( } keys = mock.sentinel.keys - result = view.format_replica_tasks_execution(mock_execution, keys) + result = view.format_transfer_tasks_execution(mock_execution, keys) mock_sort_tasks.assert_not_called() mock_format_opt.assert_called_once_with(mock_execution, keys) diff --git a/coriolis/tests/api/v1/views/test_transfer_view.py b/coriolis/tests/api/v1/views/test_transfer_view.py new file mode 100644 index 000000000..cbcdc9570 --- /dev/null +++ b/coriolis/tests/api/v1/views/test_transfer_view.py @@ -0,0 +1,112 @@ +# Copyright 2023 Cloudbase Solutions Srl +# All Rights Reserved. + +from unittest import mock + +from coriolis.api.v1.views import transfer_tasks_execution_view as view +from coriolis.api.v1.views import transfer_view +from coriolis.api.v1.views import utils as view_utils +from coriolis.tests import test_base + + +class TransferViewTestCase(test_base.CoriolisApiViewsTestCase): + """Test suite for the Coriolis api v1 views.""" + + def setUp(self): + super(TransferViewTestCase, self).setUp() + self._format_fun = transfer_view._format_transfer + + @mock.patch.object(view, 'format_transfer_tasks_execution') + @mock.patch.object(view_utils, 'format_opt') + def test_format_transfer(self, mock_format_opt, + mock_format_transfer_tasks_execution): + mock_format_opt.return_value = { + "executions": [{'id': 'mock_id1'}, {'id': 'mock_id2'}], + "mock_key": "mock_value" + } + + expected_calls = [ + mock.call.mock_format_transfer_tasks_execution( + {'id': 'mock_id1'}), + mock.call.mock_format_transfer_tasks_execution( + {'id': 'mock_id2'})] + expected_result = { + "executions": + [mock_format_transfer_tasks_execution.return_value, + mock_format_transfer_tasks_execution.return_value], + 'mock_key': 'mock_value' + } + + transfer = mock.sentinel.transfer + keys = mock.sentinel.keys + result = transfer_view._format_transfer(transfer, keys) + + mock_format_opt.assert_called_once_with(transfer, keys) + mock_format_transfer_tasks_execution.assert_has_calls( + expected_calls + ) + self.assertEqual( + expected_result, + result + ) + + @mock.patch.object(view, 'format_transfer_tasks_execution') + @mock.patch.object(view_utils, 'format_opt') + def test_format_transfer_no_keys(self, mock_format_opt, + mock_format_transfer_tasks_execution): + mock_format_opt.return_value = { + "executions": [{'id': 'mock_id1'}, {'id': 'mock_id2'}], + } + + expected_calls = [ + mock.call.mock_format_transfer_tasks_execution( + {'id': 'mock_id1'}), + mock.call.mock_format_transfer_tasks_execution( + {'id': 'mock_id2'})] + expected_result = { + "executions": + [mock_format_transfer_tasks_execution.return_value, + mock_format_transfer_tasks_execution.return_value], + } + + transfer = mock.sentinel.transfer + keys = mock.sentinel.keys + result = transfer_view._format_transfer(transfer, keys) + + mock_format_opt.assert_called_once_with(transfer, keys) + mock_format_transfer_tasks_execution.assert_has_calls( + expected_calls + ) + self.assertEqual( + expected_result, + result + ) + + @mock.patch.object(view_utils, 'format_opt') + def test_format_transfer_no_executions(self, mock_format_opt): + mock_format_opt.return_value = { + "mock_key": "mock_value" + } + + expected_result = { + 'executions': [], + 'mock_key': 'mock_value' + } + + transfer = mock.sentinel.transfer + keys = mock.sentinel.keys + result = transfer_view._format_transfer(transfer, keys) + + mock_format_opt.assert_called_once_with(transfer, keys) + self.assertEqual( + expected_result, + result + ) + + def test_single(self): + fun = getattr(transfer_view, 'single') + self._single_view_test(fun, 'transfer') + + def test_collection(self): + fun = getattr(transfer_view, 'collection') + self._collection_view_test(fun, 'transfers') diff --git a/coriolis/tests/cmd/test_replica_cron.py b/coriolis/tests/cmd/test_replica_cron.py index 131ee0750..03097e279 100644 --- a/coriolis/tests/cmd/test_replica_cron.py +++ b/coriolis/tests/cmd/test_replica_cron.py @@ -4,7 +4,7 @@ import sys from unittest import mock -from coriolis.cmd import replica_cron +from coriolis.cmd import transfer_cron from coriolis import constants from coriolis import service from coriolis.tests import test_base @@ -12,33 +12,33 @@ from coriolis import utils -class ReplicaCronTestCase(test_base.CoriolisBaseTestCase): +class TransferCronTestCase(test_base.CoriolisBaseTestCase): """Test suite for the Coriolis transfer_cron CMD""" @mock.patch.object(service, 'service') @mock.patch.object(service, 'MessagingService') - @mock.patch.object(rpc_server, 'ReplicaCronServerEndpoint') + @mock.patch.object(rpc_server, 'TransferCronServerEndpoint') @mock.patch.object(utils, 'setup_logging') - @mock.patch('coriolis.cmd.replica_cron.CONF') + @mock.patch('coriolis.cmd.transfer_cron.CONF') @mock.patch.object(sys, 'argv') def test_main( self, mock_argv, mock_conf, mock_setup_logging, - mock_ReplicaCronServerEndpoint, + mock_TransferCronServerEndpoint, mock_MessagingService, mock_service ): - replica_cron.main() + transfer_cron.main() mock_conf.assert_called_once_with( mock_argv[1:], project='coriolis', version="1.0.0") mock_setup_logging.assert_called_once() - mock_ReplicaCronServerEndpoint.assert_called_once() + mock_TransferCronServerEndpoint.assert_called_once() mock_MessagingService.assert_called_once_with( constants.TRANSFER_CRON_MAIN_MESSAGING_TOPIC, - [mock_ReplicaCronServerEndpoint.return_value], + [mock_TransferCronServerEndpoint.return_value], rpc_server.VERSION, worker_count=1) mock_service.launch.assert_called_once_with( diff --git a/coriolis/tests/minion_manager/rpc/test_client.py b/coriolis/tests/minion_manager/rpc/test_client.py index 6ed7e3b3b..ac7c91591 100644 --- a/coriolis/tests/minion_manager/rpc/test_client.py +++ b/coriolis/tests/minion_manager/rpc/test_client.py @@ -122,24 +122,24 @@ def test_validate_minion_pool_selections_for_action(self): self.client.validate_minion_pool_selections_for_action, args ) - def test_allocate_minion_machines_for_replica(self): - args = {"replica": "test_replica"} + def test_allocate_minion_machines_for_transfer(self): + args = {"transfer": "test_transfer"} self._test( self.client.allocate_minion_machines_for_transfer, args, rpc_op='_cast', - server_fun_name='allocate_minion_machines_for_replica' + server_fun_name='allocate_minion_machines_for_transfer' ) - def test_allocate_minion_machines_for_migration(self): + def test_allocate_minion_machines_for_deployment(self): args = { - "migration": "test_migration", + "deployment": "test_deployment", "include_transfer_minions": True, "include_osmorphing_minions": True } self._test( self.client.allocate_minion_machines_for_deployment, args, rpc_op='_cast', - server_fun_name='allocate_minion_machines_for_migration' + server_fun_name='allocate_minion_machines_for_deployment' ) def test_deallocate_minion_machine(self): diff --git a/coriolis/tests/transfer_cron/rpc/test_server.py b/coriolis/tests/transfer_cron/rpc/test_server.py index a0270b46c..9481f6e5a 100644 --- a/coriolis/tests/transfer_cron/rpc/test_server.py +++ b/coriolis/tests/transfer_cron/rpc/test_server.py @@ -13,10 +13,10 @@ from coriolis.transfer_cron.rpc import server -class TriggerReplicaTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis _trigger_replica function.""" +class TriggerTransferTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis _trigger_transfer function.""" - def test__trigger_replica(self): + def test__trigger_transfer(self): mock_conductor_client = mock.MagicMock() mock_conductor_client.execute_transfer_tasks.return_value = { @@ -24,7 +24,7 @@ def test__trigger_replica(self): 'action_id': mock.sentinel.action_id } - result = server._trigger_replica( + result = server._trigger_transfer( mock.sentinel.ctxt, mock_conductor_client, mock.sentinel.transfer_id, False) @@ -33,10 +33,10 @@ def test__trigger_replica(self): mock.sentinel.ctxt, mock.sentinel.transfer_id, False) self.assertEqual( - result, 'Execution %s for Replica %s' % ( + result, 'Execution %s for Transfer %s' % ( mock.sentinel.id, mock.sentinel.action_id)) - def test__trigger_transfer_invalid_replica_state(self): + def test__trigger_transfer_invalid_transfer_state(self): mock_conductor_client = mock.MagicMock() mock_conductor_client.execute_transfer_tasks.side_effect = ( @@ -44,20 +44,20 @@ def test__trigger_transfer_invalid_replica_state(self): with self.assertLogs('coriolis.transfer_cron.rpc.server', level=logging.INFO): - server._trigger_replica( + server._trigger_transfer( mock.sentinel.ctxt, mock_conductor_client, mock.sentinel.action_id, False) @ddt.ddt -class ReplicaCronServerEndpointTestCase(test_base.CoriolisBaseTestCase): - """Test suite for the Coriolis ReplicaCronServerEndpoint class.""" +class TransferCronServerEndpointTestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis TransferCronServerEndpoint class.""" - @mock.patch.object(server.ReplicaCronServerEndpoint, '_init_cron') + @mock.patch.object(server.TransferCronServerEndpoint, '_init_cron') def setUp(self, _): - super(ReplicaCronServerEndpointTestCase, self).setUp() - self.server = server.ReplicaCronServerEndpoint() + super(TransferCronServerEndpointTestCase, self).setUp() + self.server = server.TransferCronServerEndpoint() @ddt.data( { @@ -75,16 +75,16 @@ def test__deserialize_schedule(self, data): result = self.server._deserialize_schedule(data['input']) self.assertEqual(result, data['expected']) - @mock.patch.object(server.ReplicaCronServerEndpoint, + @mock.patch.object(server.TransferCronServerEndpoint, '_deserialize_schedule') - @mock.patch.object(server, '_trigger_replica') + @mock.patch.object(server, '_trigger_transfer') @mock.patch.object(server.timeutils, 'utcnow') @mock.patch.object(server.context, 'get_admin_context') @mock.patch.object(server.cron, 'CronJob') @mock.patch.object(server.cron.Cron, 'register') def test__register_schedule(self, mock_register, mock_cron_job, mock_get_admin_context, mock_utcnow, - mock_trigger_replica, + mock_trigger_transfer, mock_deserialize_schedule): mock_get_admin_context.return_value = 'test_admin_context' mock_utcnow.return_value = datetime.datetime(2022, 1, 1) @@ -96,7 +96,7 @@ def test__register_schedule(self, mock_register, mock_cron_job, } test_schedule = { 'trust_id': 'test_schedule_trust_id', - 'replica_id': 'test_schedule_replica_id', + 'transfer_id': 'test_schedule_transfer_id', 'shutdown_instance': 'test_schedule_shutdown_instance' } @@ -108,12 +108,12 @@ def test__register_schedule(self, mock_register, mock_cron_job, mock_cron_job.assert_called_once_with( 'test_id', 'Scheduled job for test_id', 'test_schedule', True, datetime.datetime(2022, 12, 31), None, None, - mock_trigger_replica, 'test_admin_context', - self.server._rpc_client, 'test_schedule_replica_id', + mock_trigger_transfer, 'test_admin_context', + self.server._rpc_client, 'test_schedule_transfer_id', 'test_schedule_shutdown_instance') mock_register.assert_called_once() - @mock.patch.object(server.ReplicaCronServerEndpoint, + @mock.patch.object(server.TransferCronServerEndpoint, '_deserialize_schedule') @mock.patch.object(server.timeutils, 'utcnow') def test__register_schedule_expired(self, mock_utcnow, @@ -127,7 +127,7 @@ def test__register_schedule_expired(self, mock_utcnow, } test_schedule = { 'trust_id': 'test_schedule_trust_id', - 'replica_id': 'test_schedule_replica_id', + 'transfer_id': 'test_schedule_transfer_id', 'shutdown_instance': 'test_schedule_shutdown_instance' } @@ -138,8 +138,8 @@ def test__register_schedule_expired(self, mock_utcnow, mock_deserialize_schedule.assert_called_once_with(test_schedule) @mock.patch.object(server.timeutils, 'utcnow') - @mock.patch.object(server.ReplicaCronServerEndpoint, '_get_all_schedules') - @mock.patch.object(server.ReplicaCronServerEndpoint, '_register_schedule') + @mock.patch.object(server.TransferCronServerEndpoint, '_get_all_schedules') + @mock.patch.object(server.TransferCronServerEndpoint, '_register_schedule') @mock.patch.object(server.cron.Cron, 'start') def test__init_cron(self, mock_cron_start, mock_register_schedule, mock_get_all_schedules, mock_utcnow): @@ -160,8 +160,8 @@ def test__init_cron(self, mock_cron_start, mock_register_schedule, ]) mock_cron_start.assert_called_once() - @mock.patch.object(server.ReplicaCronServerEndpoint, '_get_all_schedules') - @mock.patch.object(server.ReplicaCronServerEndpoint, '_register_schedule') + @mock.patch.object(server.TransferCronServerEndpoint, '_get_all_schedules') + @mock.patch.object(server.TransferCronServerEndpoint, '_register_schedule') def test__init_cron_with_exception(self, mock_register_schedule, mock_get_all_schedules): mock_get_all_schedules.return_value = [ @@ -189,7 +189,7 @@ def test__get_all_schedules(self, mock_get_transfer_schedules): self.assertEqual(result, mock_get_transfer_schedules.return_value) - @mock.patch.object(server.ReplicaCronServerEndpoint, '_register_schedule') + @mock.patch.object(server.TransferCronServerEndpoint, '_register_schedule') @mock.patch.object(server.timeutils, 'utcnow') def test_register(self, mock_utcnow, mock_register_schedule): mock_utcnow.return_value = datetime.datetime(2022, 1, 1) diff --git a/coriolis/replica_tasks_executions/__init__.py b/coriolis/tests/transfer_tasks_executions/__init__.py similarity index 100% rename from coriolis/replica_tasks_executions/__init__.py rename to coriolis/tests/transfer_tasks_executions/__init__.py diff --git a/coriolis/tests/replica_tasks_executions/test_api.py b/coriolis/tests/transfer_tasks_executions/test_api.py similarity index 95% rename from coriolis/tests/replica_tasks_executions/test_api.py rename to coriolis/tests/transfer_tasks_executions/test_api.py index 1a216295e..614dad7cc 100644 --- a/coriolis/tests/replica_tasks_executions/test_api.py +++ b/coriolis/tests/transfer_tasks_executions/test_api.py @@ -3,8 +3,8 @@ from unittest import mock -from coriolis.replica_tasks_executions import api as replicas_module from coriolis.tests import test_base +from coriolis.transfer_tasks_executions import api as transfers_module class APITestCase(test_base.CoriolisBaseTestCase): @@ -12,7 +12,7 @@ class APITestCase(test_base.CoriolisBaseTestCase): def setUp(self): super(APITestCase, self).setUp() - self.api = replicas_module.API() + self.api = transfers_module.API() self.rpc_client = mock.MagicMock() self.api._rpc_client = self.rpc_client self.ctxt = mock.sentinel.ctxt diff --git a/coriolis/replicas/__init__.py b/coriolis/tests/transfers/__init__.py similarity index 100% rename from coriolis/replicas/__init__.py rename to coriolis/tests/transfers/__init__.py diff --git a/coriolis/tests/replicas/test_api.py b/coriolis/tests/transfers/test_api.py similarity index 92% rename from coriolis/tests/replicas/test_api.py rename to coriolis/tests/transfers/test_api.py index 69d1fedec..8e415dea0 100644 --- a/coriolis/tests/replicas/test_api.py +++ b/coriolis/tests/transfers/test_api.py @@ -3,8 +3,8 @@ from unittest import mock -from coriolis.replicas import api as replicas_module from coriolis.tests import test_base +from coriolis.transfers import api as transfers_module class APITestCase(test_base.CoriolisBaseTestCase): @@ -12,7 +12,7 @@ class APITestCase(test_base.CoriolisBaseTestCase): def setUp(self): super(APITestCase, self).setUp() - self.api = replicas_module.API() + self.api = transfers_module.API() self.rpc_client = mock.MagicMock() self.api._rpc_client = self.rpc_client self.ctxt = mock.sentinel.ctxt @@ -64,16 +64,16 @@ def test_delete(self): self.rpc_client.delete_transfer.assert_called_once_with( self.ctxt, self.transfer_id) - def test_get_replicas(self): - result = self.api.get_replicas( + def test_get_transfers(self): + result = self.api.get_transfers( self.ctxt, include_tasks_executions=False, include_task_info=False) self.rpc_client.get_transfers.assert_called_once_with( self.ctxt, False, include_task_info=False) self.assertEqual(result, self.rpc_client.get_transfers.return_value) - def test_get_replica(self): - result = self.api.get_replica(self.ctxt, self.transfer_id) + def test_get_transfer(self): + result = self.api.get_transfer(self.ctxt, self.transfer_id) self.rpc_client.get_transfer.assert_called_once_with( self.ctxt, self.transfer_id, include_task_info=False) diff --git a/coriolis/transfer_cron/api.py b/coriolis/transfer_cron/api.py index 6fc037302..101c0eb48 100644 --- a/coriolis/transfer_cron/api.py +++ b/coriolis/transfer_cron/api.py @@ -8,24 +8,24 @@ class API(object): def __init__(self): self._rpc_client = rpc_client.ConductorClient() - def create(self, ctxt, replica_id, schedule, enabled, + def create(self, ctxt, transfer_id, schedule, enabled, exp_date, shutdown_instance): return self._rpc_client.create_transfer_schedule( - ctxt, replica_id, schedule, enabled, exp_date, + ctxt, transfer_id, schedule, enabled, exp_date, shutdown_instance) - def get_schedules(self, ctxt, replica_id, expired=True): + def get_schedules(self, ctxt, transfer_id, expired=True): return self._rpc_client.get_transfer_schedules( - ctxt, replica_id, expired=expired) + ctxt, transfer_id, expired=expired) - def get_schedule(self, ctxt, replica_id, schedule_id, expired=True): + def get_schedule(self, ctxt, transfer_id, schedule_id, expired=True): return self._rpc_client.get_transfer_schedule( - ctxt, replica_id, schedule_id, expired=expired) + ctxt, transfer_id, schedule_id, expired=expired) - def update(self, ctxt, replica_id, schedule_id, update_values): + def update(self, ctxt, transfer_id, schedule_id, update_values): return self._rpc_client.update_transfer_schedule( - ctxt, replica_id, schedule_id, update_values) + ctxt, transfer_id, schedule_id, update_values) - def delete(self, ctxt, replica_id, schedule_id): + def delete(self, ctxt, transfer_id, schedule_id): self._rpc_client.delete_transfer_schedule( - ctxt, replica_id, schedule_id) + ctxt, transfer_id, schedule_id) diff --git a/coriolis/transfer_cron/rpc/server.py b/coriolis/transfer_cron/rpc/server.py index 9b13a6ae6..7ea9aab15 100644 --- a/coriolis/transfer_cron/rpc/server.py +++ b/coriolis/transfer_cron/rpc/server.py @@ -17,11 +17,11 @@ VERSION = "1.0" -def _trigger_replica(ctxt, conductor_client, replica_id, shutdown_instance): +def _trigger_transfer(ctxt, conductor_client, transfer_id, shutdown_instance): try: execution = conductor_client.execute_transfer_tasks( - ctxt, replica_id, shutdown_instance) - result_msg = 'Execution %s for Replica %s' % ( + ctxt, transfer_id, shutdown_instance) + result_msg = 'Execution %s for Transfer %s' % ( execution.get('id'), execution.get('action_id')) return result_msg except (exception.InvalidTransferState, @@ -29,7 +29,7 @@ def _trigger_replica(ctxt, conductor_client, replica_id, shutdown_instance): LOG.info("A replica or migration already running") -class ReplicaCronServerEndpoint(object): +class TransferCronServerEndpoint(object): def __init__(self): self._rpc_client = rpc_client.ConductorClient() @@ -61,8 +61,8 @@ def _register_schedule(self, schedule, date=None): job = cron.CronJob( sched["id"], description, sched["schedule"], sched["enabled"], sched["expiration_date"], - None, None, _trigger_replica, trust_ctxt, - self._rpc_client, schedule["replica_id"], + None, None, _trigger_transfer, trust_ctxt, + self._rpc_client, schedule["transfer_id"], schedule["shutdown_instance"]) self._cron.register(job) diff --git a/coriolis/tests/replica_tasks_executions/__init__.py b/coriolis/transfer_tasks_executions/__init__.py similarity index 100% rename from coriolis/tests/replica_tasks_executions/__init__.py rename to coriolis/transfer_tasks_executions/__init__.py diff --git a/coriolis/transfer_tasks_executions/api.py b/coriolis/transfer_tasks_executions/api.py new file mode 100644 index 000000000..ab293e03a --- /dev/null +++ b/coriolis/transfer_tasks_executions/api.py @@ -0,0 +1,29 @@ +# Copyright 2016 Cloudbase Solutions Srl +# All Rights Reserved. + +from coriolis.conductor.rpc import client as rpc_client + + +class API(object): + def __init__(self): + self._rpc_client = rpc_client.ConductorClient() + + def create(self, ctxt, transfer_id, shutdown_instances): + return self._rpc_client.execute_transfer_tasks( + ctxt, transfer_id, shutdown_instances) + + def delete(self, ctxt, transfer_id, execution_id): + self._rpc_client.delete_transfer_tasks_execution( + ctxt, transfer_id, execution_id) + + def cancel(self, ctxt, transfer_id, execution_id, force): + self._rpc_client.cancel_transfer_tasks_execution( + ctxt, transfer_id, execution_id, force) + + def get_executions(self, ctxt, transfer_id, include_tasks=False): + return self._rpc_client.get_transfer_tasks_executions( + ctxt, transfer_id, include_tasks) + + def get_execution(self, ctxt, transfer_id, execution_id): + return self._rpc_client.get_transfer_tasks_execution( + ctxt, transfer_id, execution_id) diff --git a/coriolis/tests/replicas/__init__.py b/coriolis/transfers/__init__.py similarity index 100% rename from coriolis/tests/replicas/__init__.py rename to coriolis/transfers/__init__.py diff --git a/coriolis/replicas/api.py b/coriolis/transfers/api.py similarity index 63% rename from coriolis/replicas/api.py rename to coriolis/transfers/api.py index f66422027..119e73a66 100644 --- a/coriolis/replicas/api.py +++ b/coriolis/transfers/api.py @@ -8,36 +8,36 @@ class API(object): def __init__(self): self._rpc_client = rpc_client.ConductorClient() - def create(self, ctxt, replica_scenario, + def create(self, ctxt, transfer_scenario, origin_endpoint_id, destination_endpoint_id, origin_minion_pool_id, destination_minion_pool_id, instance_osmorphing_minion_pool_mappings, source_environment, destination_environment, instances, network_map, storage_mappings, notes=None, user_scripts=None): return self._rpc_client.create_instances_transfer( - ctxt, replica_scenario, + ctxt, transfer_scenario, origin_endpoint_id, destination_endpoint_id, origin_minion_pool_id, destination_minion_pool_id, instance_osmorphing_minion_pool_mappings, source_environment, destination_environment, instances, network_map, storage_mappings, notes, user_scripts) - def update(self, ctxt, replica_id, updated_properties): + def update(self, ctxt, transfer_id, updated_properties): return self._rpc_client.update_transfer( - ctxt, replica_id, updated_properties) + ctxt, transfer_id, updated_properties) - def delete(self, ctxt, replica_id): - self._rpc_client.delete_transfer(ctxt, replica_id) + def delete(self, ctxt, transfer_id): + self._rpc_client.delete_transfer(ctxt, transfer_id) - def get_replicas(self, ctxt, include_tasks_executions=False, - include_task_info=False): + def get_transfers(self, ctxt, include_tasks_executions=False, + include_task_info=False): return self._rpc_client.get_transfers( ctxt, include_tasks_executions, include_task_info=include_task_info) - def get_replica(self, ctxt, replica_id, include_task_info=False): + def get_transfer(self, ctxt, transfer_id, include_task_info=False): return self._rpc_client.get_transfer( - ctxt, replica_id, include_task_info=include_task_info) + ctxt, transfer_id, include_task_info=include_task_info) - def delete_disks(self, ctxt, replica_id): - return self._rpc_client.delete_transfer_disks(ctxt, replica_id) + def delete_disks(self, ctxt, transfer_id): + return self._rpc_client.delete_transfer_disks(ctxt, transfer_id)