-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1209a56
commit fdd764c
Showing
17 changed files
with
1,795 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- config: | ||
'exception_raised': NotFound | ||
|
||
- config: | ||
'exception_raised': InvalidParameterValue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2023 Cloudbase Solutions Srl | ||
# All Rights Reserved. | ||
|
||
from unittest import mock | ||
|
||
from coriolis.api.v1 import diagnostics as diag | ||
from coriolis.api.v1.views import diagnostic_view | ||
from coriolis.diagnostics import api | ||
from coriolis.tests import test_base | ||
|
||
|
||
class DiagnosticsControllerTestCase(test_base.CoriolisBaseTestCase): | ||
"""Test suite for the Coriolis Diagnostics v1 API""" | ||
|
||
def setUp(self): | ||
super(DiagnosticsControllerTestCase, self).setUp() | ||
self.diag_api = diag.DiagnosticsController() | ||
|
||
@mock.patch.object(api.API, 'get') | ||
@mock.patch.object(diagnostic_view, 'collection') | ||
def test_index( | ||
self, | ||
mock_collection, | ||
mock_get | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
|
||
result = self.diag_api.index(mock_req) | ||
|
||
mock_context.can.assert_called_once_with("migration:diagnostics:get") | ||
mock_get.assert_called_once_with(mock_context) | ||
mock_collection.assert_called_once_with(mock_get.return_value) | ||
self.assertEqual(result, mock_collection.return_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
# Copyright 2023 Cloudbase Solutions Srl | ||
# All Rights Reserved. | ||
|
||
from unittest import mock | ||
|
||
from webob import exc | ||
|
||
from coriolis.api.v1 import endpoint_actions | ||
from coriolis.endpoints import api | ||
from coriolis import exception | ||
from coriolis.tests import test_base | ||
from coriolis.tests import testutils | ||
|
||
|
||
class EndpointActionsControllerTestCase(test_base.CoriolisBaseTestCase): | ||
"""Test suite for the Coriolis Endpoint Actions v1 API""" | ||
|
||
def setUp(self): | ||
super(EndpointActionsControllerTestCase, self).setUp() | ||
self.endpoint_api = endpoint_actions.EndpointActionsController() | ||
|
||
@mock.patch.object(api.API, 'validate_connection') | ||
def test_validate_connection( | ||
self, | ||
mock_validate_connection | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
is_valid = True | ||
message = 'mock_message' | ||
mock_validate_connection.return_value = (is_valid, message) | ||
|
||
expected_result = { | ||
"validate-connection": | ||
{"valid": is_valid, "message": message} | ||
} | ||
result = testutils.get_wrapped_function( | ||
self.endpoint_api._validate_connection)( | ||
mock_req, | ||
id, | ||
body # type: ignore | ||
) | ||
|
||
mock_validate_connection.assert_called_once_with(mock_context, id) | ||
self.assertEqual( | ||
expected_result, | ||
result | ||
) | ||
|
||
@mock.patch.object(api.API, 'validate_connection') | ||
def test_validate_connection_except_not_found( | ||
self, | ||
mock_validate_connection | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
mock_validate_connection.side_effect = exception.NotFound | ||
|
||
self.assertRaises( | ||
exc.HTTPNotFound, | ||
testutils.get_wrapped_function( | ||
self.endpoint_api._validate_connection), | ||
mock_req, | ||
id, | ||
body | ||
) | ||
mock_validate_connection.assert_called_once_with(mock_context, id) | ||
|
||
@mock.patch.object(api.API, 'validate_connection') | ||
def test_validate_connection_except_invalid_parameter_value( | ||
self, | ||
mock_validate_connection | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
id = mock.sentinel.id | ||
body = mock.sentinel.body | ||
mock_validate_connection.side_effect = exception.InvalidParameterValue( | ||
"mock_err" | ||
) | ||
|
||
self.assertRaises( | ||
exc.HTTPNotFound, | ||
testutils.get_wrapped_function( | ||
self.endpoint_api._validate_connection), | ||
mock_req, | ||
id, | ||
body | ||
) | ||
mock_validate_connection.assert_called_once_with(mock_context, id) |
105 changes: 105 additions & 0 deletions
105
coriolis/tests/api/v1/test_endpoint_destination_minion_pool_options.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright 2023 Cloudbase Solutions Srl | ||
# All Rights Reserved. | ||
|
||
from unittest import mock | ||
|
||
from coriolis.api.v1 import endpoint_destination_minion_pool_options \ | ||
as endpoint | ||
from coriolis.api.v1.views import endpoint_options_view | ||
from coriolis.endpoint_options import api | ||
from coriolis.tests import test_base | ||
from coriolis import utils | ||
|
||
|
||
class EndpointDestinationMinionPoolOptionsControllerTestCase( | ||
test_base.CoriolisBaseTestCase | ||
): | ||
""" | ||
Test suite for the Coriolis Endpoint Destination Minion Pool Options v1 API | ||
""" | ||
|
||
def setUp(self): | ||
super( | ||
EndpointDestinationMinionPoolOptionsControllerTestCase, | ||
self | ||
).setUp() | ||
self.minion_api = \ | ||
endpoint.EndpointDestinationMinionPoolOptionsController() | ||
|
||
@mock.patch.object(utils, 'decode_base64_param') | ||
@mock.patch.object(endpoint_options_view, | ||
'destination_minion_pool_options_collection') | ||
@mock.patch.object(api.API, | ||
'get_endpoint_destination_minion_pool_options') | ||
def test_index( | ||
self, | ||
mock_get_endpoint_destination_minion_pool_options, | ||
mock_destination_minion_pool_options_collection, | ||
mock_decode_base64_param, | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
endpoint_id = mock.sentinel.endpoint_id | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
env = mock.sentinel.env | ||
options = mock.sentinel.options | ||
mock_req.GET = { | ||
'env': env, | ||
'options': options | ||
} | ||
mock_decode_base64_param.side_effect = [env, options] | ||
|
||
expected_calls = [ | ||
mock.call.mock_get_diagnostics_policy_label(env, is_json=True), | ||
mock.call.mock_get_diagnostics_policy_label(options, is_json=True)] | ||
|
||
result = self.minion_api.index(mock_req, endpoint_id) | ||
|
||
mock_context.can.assert_called_once_with( | ||
'migration:endpoints:list_destination_minion_pool_options') | ||
mock_decode_base64_param.has_calls(expected_calls) | ||
(mock_get_endpoint_destination_minion_pool_options. | ||
assert_called_once_with)( | ||
mock_context, endpoint_id, | ||
env=env, | ||
option_names=options) | ||
(mock_destination_minion_pool_options_collection. | ||
assert_called_once_with)( | ||
mock_get_endpoint_destination_minion_pool_options.return_value) | ||
self.assertEqual( | ||
mock_destination_minion_pool_options_collection.return_value, | ||
result | ||
) | ||
|
||
@mock.patch.object(utils, 'decode_base64_param') | ||
@mock.patch.object(endpoint_options_view, | ||
'destination_minion_pool_options_collection') | ||
@mock.patch.object(api.API, | ||
'get_endpoint_destination_minion_pool_options') | ||
def test_index_no_env_and_options( | ||
self, | ||
mock_get_endpoint_destination_minion_pool_options, | ||
mock_destination_minion_pool_options_collection, | ||
mock_decode_base64_param, | ||
): | ||
mock_req = mock.Mock() | ||
mock_context = mock.Mock() | ||
endpoint_id = mock.sentinel.endpoint_id | ||
mock_req.environ = {'coriolis.context': mock_context} | ||
mock_req.GET = {} | ||
|
||
result = self.minion_api.index(mock_req, endpoint_id) | ||
|
||
mock_decode_base64_param.assert_not_called() | ||
(mock_get_endpoint_destination_minion_pool_options. | ||
assert_called_once_with)( | ||
mock_context, endpoint_id, | ||
env={}, | ||
option_names={}) | ||
(mock_destination_minion_pool_options_collection. | ||
assert_called_once_with)( | ||
mock_get_endpoint_destination_minion_pool_options.return_value) | ||
self.assertEqual( | ||
mock_destination_minion_pool_options_collection.return_value, | ||
result | ||
) |
Oops, something went wrong.