Skip to content

Commit

Permalink
Add unit test for Coriolis api v1 views
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 committed Nov 16, 2023
1 parent 39b3696 commit 133b121
Show file tree
Hide file tree
Showing 46 changed files with 1,072 additions and 198 deletions.
2 changes: 1 addition & 1 deletion coriolis/api/v1/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def index(self, req):
diagnostics.get_diagnostics_policy_label("get"))

return diagnostic_view.collection(
req, self._diag_api.get(context))
self._diag_api.get(context))


def create_resource():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def index(self, req, endpoint_id):

return (endpoint_options_view.
destination_minion_pool_options_collection)(
req,
(self._minion_pool_options_api.
get_endpoint_destination_minion_pool_options)(
context, endpoint_id, env=env, option_names=options))
Expand Down
1 change: 0 additions & 1 deletion coriolis/api/v1/endpoint_destination_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def index(self, req, endpoint_id):
options = {}

return endpoint_options_view.destination_options_collection(
req,
self._destination_options_api.get_endpoint_destination_options(
context, endpoint_id, env=env, option_names=options))

Expand Down
4 changes: 2 additions & 2 deletions coriolis/api/v1/endpoint_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def index(self, req, endpoint_id):
env = {}

return endpoint_resources_view.instances_collection(
req, self._instance_api.get_endpoint_instances(
self._instance_api.get_endpoint_instances(
context, endpoint_id, env, marker, limit,
instance_name_pattern))

Expand All @@ -52,7 +52,7 @@ def show(self, req, endpoint_id, id):
env = {}

return endpoint_resources_view.instance_single(
req, self._instance_api.get_endpoint_instance(
self._instance_api.get_endpoint_instance(
req.environ['coriolis.context'], endpoint_id, env, id))


Expand Down
2 changes: 1 addition & 1 deletion coriolis/api/v1/endpoint_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index(self, req, endpoint_id):
env = {}

return endpoint_resources_view.networks_collection(
req, self._network_api.get_endpoint_networks(
self._network_api.get_endpoint_networks(
context, endpoint_id, env))


Expand Down
1 change: 0 additions & 1 deletion coriolis/api/v1/endpoint_source_minion_pool_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def index(self, req, endpoint_id):
options = {}

return endpoint_options_view.source_minion_pool_options_collection(
req,
(self._minion_pool_options_api.
get_endpoint_source_minion_pool_options)(
context, endpoint_id, env=env, option_names=options))
Expand Down
1 change: 0 additions & 1 deletion coriolis/api/v1/endpoint_source_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def index(self, req, endpoint_id):
options = {}

return endpoint_options_view.source_options_collection(
req,
self._source_options_api.get_endpoint_source_options(
context, endpoint_id, env=env, option_names=options))

Expand Down
2 changes: 1 addition & 1 deletion coriolis/api/v1/endpoint_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def index(self, req, endpoint_id):
env = {}

return endpoint_resources_view.storage_collection(
req, self._storage_api.get_endpoint_storage(
self._storage_api.get_endpoint_storage(
context, endpoint_id, env))


Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def show(self, req, id):
if not endpoint:
raise exc.HTTPNotFound()

return endpoint_view.single(req, endpoint)
return endpoint_view.single(endpoint)

def index(self, req):
context = req.environ["coriolis.context"]
context.can(endpoint_policies.get_endpoints_policy_label("list"))
return endpoint_view.collection(
req, self._endpoint_api.get_endpoints(context))
self._endpoint_api.get_endpoints(context))

@api_utils.format_keyerror_message(resource='endpoint', method='create')
def _validate_create_body(self, body):
Expand All @@ -52,7 +52,7 @@ def create(self, req, body):
context.can(endpoint_policies.get_endpoints_policy_label("create"))
(name, endpoint_type, description,
connection_info, mapped_regions) = self._validate_create_body(body)
return endpoint_view.single(req, self._endpoint_api.create(
return endpoint_view.single(self._endpoint_api.create(
context, name, endpoint_type, description, connection_info,
mapped_regions))

Expand All @@ -69,7 +69,7 @@ def update(self, req, id, body):
context = req.environ["coriolis.context"]
context.can(endpoint_policies.get_endpoints_policy_label("update"))
updated_values = self._validate_update_body(body)
return endpoint_view.single(req, self._endpoint_api.update(
return endpoint_view.single(self._endpoint_api.update(
req.environ['coriolis.context'], id, updated_values))

def delete(self, req, id):
Expand Down
6 changes: 3 additions & 3 deletions coriolis/api/v1/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def show(self, req, id):
if not migration:
raise exc.HTTPNotFound()

return migration_view.single(req, migration)
return migration_view.single(migration)

def _list(self, req):
show_deleted = api_utils._get_show_deleted(
Expand All @@ -50,7 +50,7 @@ def _list(self, req):
context.show_deleted = show_deleted
context.can(migration_policies.get_migrations_policy_label("list"))
return migration_view.collection(
req, self._migration_api.get_migrations(
self._migration_api.get_migrations(
context,
include_tasks=CONF.api.include_task_info_in_migrations_api,
include_task_info=CONF.api.include_task_info_in_migrations_api
Expand Down Expand Up @@ -173,7 +173,7 @@ def create(self, req, body):
skip_os_morphing=skip_os_morphing,
user_scripts=user_scripts)

return migration_view.single(req, migration)
return migration_view.single(migration)

def delete(self, req, id):
context = req.environ['coriolis.context']
Expand Down
6 changes: 3 additions & 3 deletions coriolis/api/v1/minion_pool_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _allocate_pool(self, req, id, body):
"allocate"))
try:
return minion_pool_view.single(
req, self.minion_pool_api.allocate_minion_pool(
self.minion_pool_api.allocate_minion_pool(
context, id))
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)
Expand All @@ -38,7 +38,7 @@ def _refresh_pool(self, req, id, body):
"refresh"))
try:
return minion_pool_view.single(
req, self.minion_pool_api.refresh_minion_pool(
self.minion_pool_api.refresh_minion_pool(
context, id))
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)
Expand All @@ -54,7 +54,7 @@ def _deallocate_pool(self, req, id, body):
force = (body["deallocate"] or {}).get("force", False)
try:
return minion_pool_view.single(
req, self.minion_pool_api.deallocate_minion_pool(
self.minion_pool_api.deallocate_minion_pool(
context, id, force=force))
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)
Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/minion_pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def show(self, req, id):
if not minion_pool:
raise exc.HTTPNotFound()

return minion_pool_view.single(req, minion_pool)
return minion_pool_view.single(minion_pool)

def index(self, req):
context = req.environ["coriolis.context"]
context.can(pools_policies.get_minion_pools_policy_label("list"))
return minion_pool_view.collection(
req, self._minion_pool_api.get_minion_pools(context))
self._minion_pool_api.get_minion_pools(context))

def _check_pool_retention_strategy(self, pool_retention_strategy):
if not pool_retention_strategy:
Expand Down Expand Up @@ -137,7 +137,7 @@ def create(self, req, body):
minimum_minions, maximum_minions, minion_max_idle_time,
minion_retention_strategy, notes, skip_allocation) = (
self._validate_create_body(context, body))
return minion_pool_view.single(req, self._minion_pool_api.create(
return minion_pool_view.single(self._minion_pool_api.create(
context, name, endpoint_id, pool_platform, pool_os_type,
environment_options, minimum_minions, maximum_minions,
minion_max_idle_time, minion_retention_strategy, notes=notes,
Expand Down Expand Up @@ -197,7 +197,7 @@ def update(self, req, id, body):
context.can(pools_policies.get_minion_pools_policy_label("update"))
updated_values = self._validate_update_body(id, context, body)
return minion_pool_view.single(
req, self._minion_pool_api.update(
self._minion_pool_api.update(
req.environ['coriolis.context'], id, updated_values))

def delete(self, req, id):
Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def show(self, req, id):
if not region:
raise exc.HTTPNotFound()

return region_view.single(req, region)
return region_view.single(region)

def index(self, req):
context = req.environ["coriolis.context"]
context.can(region_policies.get_regions_policy_label("list"))
return region_view.collection(
req, self._region_api.get_regions(context))
self._region_api.get_regions(context))

@api_utils.format_keyerror_message(resource='region', method='create')
def _validate_create_body(self, body):
Expand All @@ -46,7 +46,7 @@ def create(self, req, body):
context = req.environ["coriolis.context"]
context.can(region_policies.get_regions_policy_label("create"))
(name, description, enabled) = self._validate_create_body(body)
return region_view.single(req, self._region_api.create(
return region_view.single(self._region_api.create(
context, region_name=name, description=description,
enabled=enabled))

Expand All @@ -60,7 +60,7 @@ def update(self, req, id, body):
context = req.environ["coriolis.context"]
context.can(region_policies.get_regions_policy_label("update"))
updated_values = self._validate_update_body(body)
return region_view.single(req, self._region_api.update(
return region_view.single(self._region_api.update(
req.environ['coriolis.context'], id, updated_values))

def delete(self, req, id):
Expand Down
2 changes: 1 addition & 1 deletion coriolis/api/v1/replica_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _delete_disks(self, req, id, body):
replica_policies.get_replicas_policy_label("delete_disks"))
try:
return replica_tasks_execution_view.single(
req, self._replica_api.delete_disks(context, id))
self._replica_api.delete_disks(context, id))
except exception.NotFound as ex:
raise exc.HTTPNotFound(explanation=ex.msg)
except exception.InvalidParameterValue as ex:
Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/replica_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def show(self, req, replica_id, id):
if not schedule:
raise exc.HTTPNotFound()

return replica_schedule_view.single(req, schedule)
return replica_schedule_view.single(schedule)

def index(self, req, replica_id):
context = req.environ["coriolis.context"]
Expand All @@ -41,7 +41,7 @@ def index(self, req, replica_id):
show_expired = strutils.bool_from_string(
req.GET.get("show_expired", True), strict=True)
return replica_schedule_view.collection(
req, self._schedule_api.get_schedules(
self._schedule_api.get_schedules(
context, replica_id, expired=show_expired))

def _validate_schedule(self, schedule):
Expand Down Expand Up @@ -112,7 +112,7 @@ def create(self, req, replica_id, body):
except Exception as err:
raise exception.InvalidInput(err)

return replica_schedule_view.single(req, self._schedule_api.create(
return replica_schedule_view.single(self._schedule_api.create(
context, replica_id, schedule, enabled, exp_date, shutdown))

def update(self, req, replica_id, id, body):
Expand All @@ -128,7 +128,7 @@ def update(self, req, replica_id, id, body):
except Exception as err:
raise exception.InvalidInput(err)

return replica_schedule_view.single(req, self._schedule_api.update(
return replica_schedule_view.single(self._schedule_api.update(
context, replica_id, id, update_values))

def delete(self, req, replica_id, id):
Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/replica_tasks_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ def show(self, req, replica_id, id):
if not execution:
raise exc.HTTPNotFound()

return replica_tasks_execution_view.single(req, execution)
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(
req, self._replica_tasks_execution_api.get_executions(
self._replica_tasks_execution_api.get_executions(
context, replica_id, include_tasks=False))

def detail(self, req, replica_id):
Expand All @@ -41,7 +41,7 @@ def detail(self, req, replica_id):
executions_policies.get_replica_executions_policy_label("show"))

return replica_tasks_execution_view.collection(
req, self._replica_tasks_execution_api.get_executions(
self._replica_tasks_execution_api.get_executions(
context, replica_id, include_tasks=True))

def create(self, req, replica_id, body):
Expand All @@ -55,7 +55,7 @@ def create(self, req, replica_id, body):
shutdown_instances = execution_body.get("shutdown_instances", False)

return replica_tasks_execution_view.single(
req, self._replica_tasks_execution_api.create(
self._replica_tasks_execution_api.create(
context, replica_id, shutdown_instances))

def delete(self, req, replica_id, id):
Expand Down
10 changes: 5 additions & 5 deletions coriolis/api/v1/replicas.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def show(self, req, id):
if not replica:
raise exc.HTTPNotFound()

return replica_view.single(req, replica)
return replica_view.single(replica)

def _list(self, req):
show_deleted = api_utils._get_show_deleted(
Expand All @@ -51,7 +51,7 @@ def _list(self, req):
context.can(replica_policies.get_replicas_policy_label("list"))
include_task_info = CONF.api.include_task_info_in_replicas_api
return replica_view.collection(
req, self._replica_api.get_replicas(
self._replica_api.get_replicas(
context,
include_tasks_executions=include_task_info,
include_task_info=include_task_info))
Expand Down Expand Up @@ -135,7 +135,7 @@ def create(self, req, body):
instance_osmorphing_minion_pool_mappings, user_scripts) = (
self._validate_create_body(context, body))

return replica_view.single(req, self._replica_api.create(
return replica_view.single(self._replica_api.create(
context, origin_endpoint_id, destination_endpoint_id,
origin_minion_pool_id, destination_minion_pool_id,
instance_osmorphing_minion_pool_mappings, source_environment,
Expand Down Expand Up @@ -342,8 +342,8 @@ def update(self, req, id, body):
updated_values = self._validate_update_body(id, context, body)
try:
return replica_tasks_execution_view.single(
req, self._replica_api.update(req.environ['coriolis.context'],
id, updated_values))
self._replica_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:
Expand Down
8 changes: 4 additions & 4 deletions coriolis/api/v1/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def show(self, req, id):
if not service:
raise exc.HTTPNotFound()

return service_view.single(req, service)
return service_view.single(service)

def index(self, req):
context = req.environ["coriolis.context"]
context.can(service_policies.get_services_policy_label("list"))
return service_view.collection(
req, self._service_api.get_services(context))
self._service_api.get_services(context))

@api_utils.format_keyerror_message(resource='service', method='create')
def _validate_create_body(self, body):
Expand All @@ -49,7 +49,7 @@ def create(self, req, body):
context.can(service_policies.get_services_policy_label("create"))
(host, binary, topic, mapped_regions, enabled) = (
self._validate_create_body(body))
return service_view.single(req, self._service_api.create(
return service_view.single(self._service_api.create(
context, host=host, binary=binary, topic=topic,
mapped_regions=mapped_regions, enabled=enabled))

Expand All @@ -63,7 +63,7 @@ def update(self, req, id, body):
context = req.environ["coriolis.context"]
context.can(service_policies.get_services_policy_label("update"))
updated_values = self._validate_update_body(body)
return service_view.single(req, self._service_api.update(
return service_view.single(self._service_api.update(
req.environ['coriolis.context'], id, updated_values))

def delete(self, req, id):
Expand Down
4 changes: 2 additions & 2 deletions coriolis/api/v1/views/diagnostic_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# All Rights Reserved.


def single(req, diag):
def single(diag):
return {"diagnostic": diag}


def collection(req, diag):
def collection(diag):
return {'diagnostics': diag}
Loading

0 comments on commit 133b121

Please sign in to comment.