flake8: Enable H210

Use autospec=True in majority of tests and autospec=Pecan.request
in pecan related tests.

Change-Id: I2823e10c07c1b2b7c39b5c63aace8c3bf7b3deb1
Signed-off-by: Michal Nasiadka <mnasiadka@gmail.com>
Signed-off-by: Jakub Darmach <jakub.darmach@gmail.com>
This commit is contained in:
Michal Nasiadka authored and Jakub Darmach committed 2026-09-24 04:55:14 +00:00
1 parent e86a59e901
commit 547639b13e
52 files changed
+547 -452

No files matched your search

+1 -1
View File
@@ -100,7 +100,7 @@ class TestCase(base.BaseTestCase):
return magnum_context.RequestContext.from_dict(context.to_dict())
p = mock.patch.object(magnum_context, 'make_context',
side_effect=make_context)
side_effect=make_context, autospec=True)
self.global_mocks['magnum.common.context.make_context'] = p
+2 -1
View File
@@ -62,7 +62,8 @@ class FunctionalTest(base.DbTestCase):
# Controller._check_version is needed in some tests,
# must be mocked in others. Enable the mock when needed.
self.patch_check_version = mock.patch(
'magnum.api.controllers.v1.Controller._check_version')
'magnum.api.controllers.v1.Controller._check_version',
autospec=True)
def _verify_attrs(self, attrs, response, positive=True):
if positive is True:
@@ -12,6 +12,7 @@
from unittest import mock
import pecan
from webob import exc
from magnum.api.controllers import base
@@ -153,7 +154,8 @@ class TestVersion(test_base.TestCase):
self.a.minor = 0
self.assertRaises(ValueError, self.a.matches, self.b, self.c)
@mock.patch('magnum.api.controllers.versions.Version.parse_headers')
@mock.patch(
'magnum.api.controllers.versions.Version.parse_headers', autospec=True)
def test_init(self, mock_parse):
a = mock.Mock()
b = mock.Mock()
@@ -164,14 +166,16 @@ class TestVersion(test_base.TestCase):
self.assertEqual(a, v.major)
self.assertEqual(b, v.minor)
@mock.patch('magnum.api.controllers.versions.Version.parse_headers')
@mock.patch(
'magnum.api.controllers.versions.Version.parse_headers', autospec=True)
def test_repr(self, mock_parse):
mock_parse.return_value = (123, 456)
v = versions.Version('test', mock.ANY, mock.ANY)
result = "%s" % v
self.assertEqual('123.456', result)
@mock.patch('magnum.api.controllers.versions.Version.parse_headers')
@mock.patch(
'magnum.api.controllers.versions.Version.parse_headers', autospec=True)
def test_repr_with_strings(self, mock_parse):
mock_parse.return_value = ('abc', 'def')
v = versions.Version('test', mock.ANY, mock.ANY)
@@ -367,7 +371,7 @@ class TestController(test_base.TestCase):
result = api2_list[1].func(controller)
self.assertEqual('API2_1.0_2.0', result)
@mock.patch('pecan.request')
@mock.patch('pecan.request', autospec=pecan.Request)
def test_controller_get_attribute(self, mock_pecan_request):
class MyController(base.Controller):
@@ -388,7 +392,7 @@ class TestController(test_base.TestCase):
result = method()
self.assertEqual('API1_1.2_1.3', result)
@mock.patch('pecan.request')
@mock.patch('pecan.request', autospec=pecan.Request)
def test_controller_get_attr_version_not_found(self,
mock_pecan_request):
@@ -115,11 +115,11 @@ class TestRootController(api_base.FunctionalTest):
def test_api_paste_file_not_exist(self):
cfg.CONF.set_override('api_paste_config', 'non-existent-file',
group='api')
with mock.patch.object(cfg.CONF, 'find_file') as ff:
with mock.patch.object(cfg.CONF, 'find_file', autospec=True) as ff:
ff.return_value = None
self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app)
@mock.patch('magnum.api.app.deploy')
@mock.patch('magnum.api.app.deploy', autospec=True)
def test_api_paste_file_not_exist_not_abs(self, mock_deploy):
path = self.get_path(cfg.CONF['api']['api_paste_config'] + 'test')
cfg.CONF.set_override('api_paste_config', path, group='api')
@@ -230,6 +230,7 @@ class TestV1Routing(api_base.FunctionalTest):
self._check_version = self.patch_check_version.start()
self.get_json('/')
self._check_version.assert_called_once_with(mock.ANY,
mock.ANY,
mock.ANY)
self.patch_check_version.stop()
@@ -33,7 +33,7 @@ HEADERS = {
class TestCertObject(base.TestCase):
@mock.patch('magnum.api.utils.get_resource')
@mock.patch('magnum.api.utils.get_resource', autospec=True)
def test_cert_init(self, mock_get_resource):
cert_dict = api_utils.cert_post_data()
mock_cluster = mock.MagicMock()
@@ -53,7 +53,8 @@ class TestGetCaCertificate(api_base.FunctionalTest):
super(TestGetCaCertificate, self).setUp()
self.cluster = obj_utils.create_test_cluster(self.context)
conductor_api_patcher = mock.patch('magnum.conductor.api.API')
conductor_api_patcher = mock.patch(
'magnum.conductor.api.API', autospec=True)
self.conductor_api_class = conductor_api_patcher.start()
self.conductor_api = mock.MagicMock()
self.conductor_api_class.return_value = self.conductor_api
@@ -132,7 +133,8 @@ class TestPost(api_base.FunctionalTest):
super(TestPost, self).setUp()
self.cluster = obj_utils.create_test_cluster(self.context)
conductor_api_patcher = mock.patch('magnum.conductor.api.API')
conductor_api_patcher = mock.patch(
'magnum.conductor.api.API', autospec=True)
self.conductor_api_class = conductor_api_patcher.start()
self.conductor_api = mock.MagicMock()
self.conductor_api_class.return_value = self.conductor_api
@@ -187,13 +189,14 @@ class TestRotateCaCertificate(api_base.FunctionalTest):
self.context, cluster_distro='ubuntu')
self.cluster = obj_utils.create_test_cluster(self.context)
conductor_api_patcher = mock.patch('magnum.conductor.api.API')
conductor_api_patcher = mock.patch(
'magnum.conductor.api.API', autospec=True)
self.conductor_api_class = conductor_api_patcher.start()
self.conductor_api = mock.MagicMock()
self.conductor_api_class.return_value = self.conductor_api
self.addCleanup(conductor_api_patcher.stop)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_rotate_ca_cert(self, mock_policy):
mock_policy.return_value = True
fake_cert = api_utils.cert_post_data()
@@ -215,13 +218,14 @@ class TestRotateCaCertificateNonTls(api_base.FunctionalTest):
self.context, tls_disabled=True)
self.cluster = obj_utils.create_test_cluster(self.context)
conductor_api_patcher = mock.patch('magnum.conductor.api.API')
conductor_api_patcher = mock.patch(
'magnum.conductor.api.API', autospec=True)
self.conductor_api_class = conductor_api_patcher.start()
self.conductor_api = mock.MagicMock()
self.conductor_api_class.return_value = self.conductor_api
self.addCleanup(conductor_api_patcher.stop)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_rotate_ca_cert_non_tls(self, mock_policy):
mock_policy.return_value = True
fake_cert = api_utils.cert_post_data()
@@ -150,8 +150,8 @@ class TestListCluster(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_one_by_uuid_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=temp_uuid,
@@ -186,10 +186,10 @@ class TestListCluster(api_base.FunctionalTest):
self.assertEqual(cluster_list[-1].uuid,
response['clusters'][0]['uuid'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.objects.Cluster.obj_load_attr")
@mock.patch("magnum.objects.Cluster.cluster_template")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
@mock.patch("magnum.objects.Cluster.obj_load_attr", autospec=True)
@mock.patch("magnum.objects.Cluster.cluster_template", autospec=True)
def test_get_all_with_all_projects(self, mock_context, mock_policy,
mock_load, mock_template):
for id_ in range(4):
@@ -339,12 +339,13 @@ class TestPatch(api_base.FunctionalTest):
self.cluster_obj = obj_utils.create_test_cluster(
self.context, name='cluster_example_A', node_count=3,
health_status='UNKNOWN', health_status_reason={})
p = mock.patch.object(rpcapi.API, 'cluster_update_async')
p = mock.patch.object(
rpcapi.API, 'cluster_update_async', autospec=False)
self.mock_cluster_update = p.start()
self.mock_cluster_update.side_effect = self._sim_rpc_cluster_update
self.addCleanup(p.stop)
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
@@ -359,7 +360,7 @@ class TestPatch(api_base.FunctionalTest):
cluster.save()
return cluster
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_ok(self, mock_utcnow):
new_node_count = 4
test_time = datetime.datetime(2000, 1, 1, 0, 0)
@@ -382,7 +383,7 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(self.cluster_obj.cluster_template_id,
response['cluster_template_id'])
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_health_status_ok(self, mock_utcnow):
new_health_status = 'HEALTHY'
new_health_status_reason = {'api': 'ok'}
@@ -418,7 +419,7 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(self.cluster_obj.cluster_template_id,
response['cluster_template_id'])
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_ok_by_name(self, mock_utcnow):
new_node_count = 4
test_time = datetime.datetime(2000, 1, 1, 0, 0)
@@ -635,8 +636,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual(400, response.status_code)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_update_cluster_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=temp_uuid)
@@ -654,18 +655,20 @@ class TestPost(api_base.FunctionalTest):
super(TestPost, self).setUp()
self.cluster_template = obj_utils.create_test_cluster_template(
self.context)
p = mock.patch.object(rpcapi.API, 'cluster_create_async')
p = mock.patch.object(
rpcapi.API, 'cluster_create_async', autospec=False)
self.mock_cluster_create = p.start()
self.mock_cluster_create.side_effect = self._simulate_cluster_create
self.addCleanup(p.stop)
p = mock.patch.object(attr_validator, 'validate_os_resources')
p = mock.patch.object(
attr_validator, 'validate_os_resources', autospec=True)
self.mock_valid_os_res = p.start()
self.addCleanup(p.stop)
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@@ -1198,7 +1201,8 @@ class TestDelete(api_base.FunctionalTest):
self.cluster_template = obj_utils.create_test_cluster_template(
self.context)
self.cluster = obj_utils.create_test_cluster(self.context)
p = mock.patch.object(rpcapi.API, 'cluster_delete_async')
p = mock.patch.object(
rpcapi.API, 'cluster_delete_async', autospec=False)
self.mock_cluster_delete = p.start()
self.mock_cluster_delete.side_effect = self._simulate_cluster_delete
self.addCleanup(p.stop)
@@ -1243,8 +1247,8 @@ class TestDelete(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_delete_cluster_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=temp_uuid)
@@ -1258,7 +1262,7 @@ class TestClusterPolicyEnforcement(api_base.FunctionalTest):
def setUp(self):
super(TestClusterPolicyEnforcement, self).setUp()
obj_utils.create_test_cluster_template(self.context)
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@@ -1312,7 +1316,7 @@ class TestClusterPolicyEnforcement(api_base.FunctionalTest):
ng.destroy()
def test_policy_disallow_delete(self):
p = mock.patch.object(rpcapi.API, 'cluster_delete')
p = mock.patch.object(rpcapi.API, 'cluster_delete', autospec=False)
self.mock_cluster_delete = p.start()
self.mock_cluster_delete.side_effect = self._simulate_cluster_delete
self.addCleanup(p.stop)
@@ -29,7 +29,8 @@ class TestClusterResize(api_base.FunctionalTest):
super(TestClusterResize, self).setUp()
self.cluster_obj = obj_utils.create_test_cluster(
self.context, name='cluster_example_A', node_count=3)
p = mock.patch.object(rpcapi.API, 'cluster_resize_async')
p = mock.patch.object(
rpcapi.API, 'cluster_resize_async', autospec=False)
self.mock_cluster_resize = p.start()
self.mock_cluster_resize.side_effect = self._sim_rpc_cluster_resize
self.addCleanup(p.stop)
@@ -201,7 +202,7 @@ class TestClusterUpgrade(api_base.FunctionalTest):
uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
project_id=self.cluster_obj.project_id,
is_default=False)
p = mock.patch.object(rpcapi.API, 'cluster_upgrade')
p = mock.patch.object(rpcapi.API, 'cluster_upgrade', autospec=False)
self.mock_cluster_upgrade = p.start()
self.mock_cluster_upgrade.side_effect = self._sim_rpc_cluster_upgrade
self.addCleanup(p.stop)
@@ -118,8 +118,8 @@ class TestListClusterTemplate(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_one_by_uuid_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster_template(self.context, uuid=temp_uuid,
@@ -139,8 +139,8 @@ class TestListClusterTemplate(api_base.FunctionalTest):
'/clustertemplates/%s' % temp_uuid, expect_errors=True)
self.assertEqual(404, response.status_int)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_one_hidden_admin_succeeds(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster_template(
@@ -184,8 +184,8 @@ class TestListClusterTemplate(api_base.FunctionalTest):
self.assertEqual(bm_list[-1].uuid,
response['clustertemplates'][0]['uuid'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_with_all_projects(self, mock_context, mock_policy):
for id_ in range(4):
obj_utils.create_test_cluster_template(
@@ -277,7 +277,8 @@ class TestPatch(api_base.FunctionalTest):
def setUp(self):
super(TestPatch, self).setUp()
p = mock.patch.object(attr_validator, 'validate_os_resources')
p = mock.patch.object(
attr_validator, 'validate_os_resources', autospec=True)
self.mock_valid_os_res = p.start()
self.addCleanup(p.stop)
self.cluster_template = obj_utils.create_test_cluster_template(
@@ -298,7 +299,7 @@ class TestPatch(api_base.FunctionalTest):
hidden=False
)
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
@@ -343,7 +344,7 @@ class TestPatch(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(200, response.status_int)
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_public_cluster_template_success(self, mock_policy):
mock_policy.return_value = True
response = self.patch_json('/clustertemplates/%s' %
@@ -357,7 +358,7 @@ class TestPatch(api_base.FunctionalTest):
self.cluster_template.uuid)
self.assertTrue(response['public'])
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_public_cluster_template_fail(self, mock_policy):
mock_policy.return_value = False
self.assertRaises(AppError, self.patch_json,
@@ -365,7 +366,7 @@ class TestPatch(api_base.FunctionalTest):
[{'path': '/public', 'value': True,
'op': 'replace'}])
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_cluster_template_with_cluster_allow_update(self,
mock_policy):
mock_policy.return_value = True
@@ -383,7 +384,7 @@ class TestPatch(api_base.FunctionalTest):
self.cluster_template.uuid)
self.assertEqual(response['public'], True)
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_hidden_cluster_template_success(self, mock_policy):
mock_policy.return_value = True
response = self.patch_json('/clustertemplates/%s' %
@@ -397,7 +398,7 @@ class TestPatch(api_base.FunctionalTest):
self.cluster_template.uuid)
self.assertTrue(response['hidden'])
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_hidden_cluster_template_fail(self, mock_policy):
mock_policy.return_value = False
self.assertRaises(AppError, self.patch_json,
@@ -405,7 +406,7 @@ class TestPatch(api_base.FunctionalTest):
[{'path': '/hidden', 'value': True,
'op': 'replace'}])
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_update_cluster_template_hidden_with_cluster_allow_update(
self, mock_policy):
mock_policy.return_value = True
@@ -460,7 +461,7 @@ class TestPatch(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(400, response.status_code)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_singular(self, mock_utcnow):
name = 'cluster_model_example_B'
test_time = datetime.datetime(2000, 1, 1, 0, 0)
@@ -655,8 +656,8 @@ class TestPatch(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_update_cluster_template_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster_template(self.context, uuid=temp_uuid,
@@ -674,20 +675,21 @@ class TestPost(api_base.FunctionalTest):
def setUp(self):
super(TestPost, self).setUp()
p = mock.patch.object(attr_validator, 'validate_os_resources')
p = mock.patch.object(
attr_validator, 'validate_os_resources', autospec=True)
self.mock_valid_os_res = p.start()
self.addCleanup(p.stop)
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_create_cluster_template(self, mock_utcnow,
mock_image_data):
bdict = apiutils.cluster_template_post_data()
@@ -709,7 +711,7 @@ class TestPost(api_base.FunctionalTest):
response.json['created_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_created_at)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_set_project_id_and_user_id(
self, mock_image_data):
with mock.patch.object(
@@ -725,7 +727,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(self.context.user_id,
cc_mock.call_args[0][0]['user_id'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_doesnt_contain_id(self,
mock_image_data):
with mock.patch.object(
@@ -745,7 +747,8 @@ class TestPost(api_base.FunctionalTest):
with mock.patch.object(
self.dbapi, 'create_cluster_template',
wraps=self.dbapi.create_cluster_template) as cc_mock, \
mock.patch('magnum.api.attr_validator.validate_image')\
mock.patch(
'magnum.api.attr_validator.validate_image', autospec=True)\
as mock_image_data:
mock_image_data.return_value = {'name': 'mock_name',
'os_distro': 'ubuntu'}
@@ -800,7 +803,7 @@ class TestPost(api_base.FunctionalTest):
self._create_model_raises_app_error(apiserver_port=1023)
self._create_model_raises_app_error(apiserver_port='not an int')
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_labels(self, mock_image_data):
with mock.patch.object(
self.dbapi, 'create_cluster_template',
@@ -815,7 +818,7 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_without_labels(self, mock_image_data):
with mock.patch.object(
self.dbapi, 'create_cluster_template',
@@ -830,7 +833,7 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_docker_volume_size(self,
mock_image_data):
with mock.patch.object(
@@ -845,7 +848,7 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_overlay(self, mock_image_data):
with mock.patch.object(
self.dbapi, 'create_cluster_template',
@@ -862,7 +865,7 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def _test_create_cluster_template_network_driver_attr(
self,
cluster_template_dict,
@@ -946,7 +949,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors_flag,
expect_default_driver_flag)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_volume_driver(self,
mock_image_data):
with mock.patch.object(
@@ -961,7 +964,7 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_no_volume_driver(self,
mock_image_data):
with mock.patch.object(
@@ -976,8 +979,8 @@ class TestPost(api_base.FunctionalTest):
cc_mock.assert_called_once_with(mock.ANY)
self.assertNotIn('id', cc_mock.call_args[0][0])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_create_cluster_template_public_success(self, mock_policy,
mock_image_data):
with mock.patch.object(
@@ -996,8 +999,8 @@ class TestPost(api_base.FunctionalTest):
self.assertNotIn('id', cc_mock.call_args[0][0])
self.assertTrue(cc_mock.call_args[0][0]['public'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_create_cluster_template_public_fail(self, mock_policy,
mock_image_data):
with mock.patch.object(self.dbapi, 'create_cluster_template',
@@ -1010,8 +1013,8 @@ class TestPost(api_base.FunctionalTest):
self.assertRaises(AppError, self.post_json, '/clustertemplates',
bdict)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_create_cluster_template_public_not_set(self, mock_policy,
mock_image_data):
with mock.patch.object(
@@ -1028,8 +1031,8 @@ class TestPost(api_base.FunctionalTest):
self.assertNotIn('id', cc_mock.call_args[0][0])
self.assertFalse(cc_mock.call_args[0][0]['public'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_create_cluster_template_hidden_success(self, mock_policy,
mock_image_data):
with mock.patch.object(
@@ -1048,8 +1051,8 @@ class TestPost(api_base.FunctionalTest):
self.assertNotIn('id', cc_mock.call_args[0][0])
self.assertTrue(cc_mock.call_args[0][0]['hidden'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch.object(magnum_policy, 'enforce')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch.object(magnum_policy, 'enforce', autospec=True)
def test_create_cluster_template_hidden_fail(self, mock_policy,
mock_image_data):
with mock.patch.object(self.dbapi, 'create_cluster_template',
@@ -1062,7 +1065,7 @@ class TestPost(api_base.FunctionalTest):
self.assertRaises(AppError, self.post_json, '/clustertemplates',
bdict)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_no_os_distro_image(self,
mock_image_data):
mock_image_data.side_effect = exception.OSDistroFieldNotFound('img')
@@ -1072,7 +1075,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(400, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_os_distro_image(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1083,7 +1086,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(201, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_image_name(self,
mock_image_data):
mock_image = {'name': 'mock_name',
@@ -1095,7 +1098,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(201, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_no_exist_image_name(self,
mock_image_data):
mock_image_data.side_effect = exception.ResourceNotFound('test-img')
@@ -1105,7 +1108,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(404, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_multi_image_name(self,
mock_image_data):
mock_image_data.side_effect = exception.Conflict('Multiple images')
@@ -1122,7 +1125,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(400, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_without_keypair_id(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1132,7 +1135,7 @@ class TestPost(api_base.FunctionalTest):
response = self.post_json('/clustertemplates', bdict)
self.assertEqual(201, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_dns(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1143,7 +1146,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(bdict['dns_nameserver'],
response.json['dns_nameserver'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_no_exist_keypair(self,
mock_image_data):
self.mock_valid_os_res.side_effect = exception.KeyPairNotFound("Test")
@@ -1154,7 +1157,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(404, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_flavor(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1167,7 +1170,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(bdict['master_flavor_id'],
response.json['master_flavor_id'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_without_flavor(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1180,7 +1183,7 @@ class TestPost(api_base.FunctionalTest):
self.assertIsNone(response.json['flavor_id'])
self.assertIsNone(response.json['master_flavor_id'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_no_exist_flavor(self,
mock_image_data):
self.mock_valid_os_res.side_effect = exception.FlavorNotFound("flavor")
@@ -1191,7 +1194,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(400, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_invalid_flavor(
self,
mock_image_data
@@ -1206,7 +1209,7 @@ class TestPost(api_base.FunctionalTest):
self.assertTrue(self.mock_valid_flavor_disk.called)
self.assertEqual(400, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_external_network(self,
mock_image_data):
mock_image_data.return_value = {'name': 'mock_name',
@@ -1217,7 +1220,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(bdict['external_network_id'],
response.json['external_network_id'])
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_no_exist_external_network(
self, mock_image_data):
self.mock_valid_os_res.side_effect = exception.ExternalNetworkNotFound(
@@ -1229,7 +1232,7 @@ class TestPost(api_base.FunctionalTest):
expect_errors=True)
self.assertEqual(400, response.status_int)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_without_name(self, mock_image_data):
with mock.patch.object(self.dbapi, 'create_cluster_template',
wraps=self.dbapi.create_cluster_template):
@@ -1249,8 +1252,8 @@ class TestPost(api_base.FunctionalTest):
self.assertRaises(AppError, self.post_json, '/clustertemplates',
bdict)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_create_cluster_template_with_multi_dns(self, mock_utcnow,
mock_image_data):
bdict = apiutils.cluster_template_post_data(
@@ -1273,7 +1276,7 @@ class TestPost(api_base.FunctionalTest):
response.json['created_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_created_at)
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_with_driver_name(self, mock_image_data):
mock_image = {'name': 'mock_name',
'os_distro': 'ubuntu',
@@ -1285,7 +1288,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(resp.json['driver'],
mock_image.get('magnum_driver'))
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_driver_from_user(self, mock_image_data):
"""User-provided driver takes precedence over image magnum_driver."""
mock_image_data.return_value = {'name': 'mock_name',
@@ -1296,8 +1299,10 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(201, resp.status_int)
self.assertEqual('user_driver', resp.json['driver'])
@mock.patch('magnum.drivers.common.driver.Driver.get_default_driver')
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_default_driver',
autospec=True)
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_driver_from_config(
self, mock_image_data, mock_get_default):
"""Config default_driver used when no user or image driver."""
@@ -1309,8 +1314,10 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(201, resp.status_int)
self.assertEqual('conf_driver', resp.json['driver'])
@mock.patch('magnum.drivers.common.driver.Driver.get_default_driver')
@mock.patch('magnum.api.attr_validator.validate_image')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_default_driver',
autospec=True)
@mock.patch('magnum.api.attr_validator.validate_image', autospec=True)
def test_create_cluster_template_driver_none_when_no_drivers(
self, mock_image_data, mock_get_default):
"""Driver is None when no user, image, or available drivers."""
@@ -1382,8 +1389,8 @@ class TestDelete(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_delete_cluster_template_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster_template(self.context, uuid=temp_uuid,
@@ -1398,7 +1405,7 @@ class TestClusterTemplatePolicyEnforcement(api_base.FunctionalTest):
def setUp(self):
super(TestClusterTemplatePolicyEnforcement, self).setUp()
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@@ -37,7 +37,7 @@ class TestPatch(CredentialControllerTest):
def setUp(self):
super(TestPatch, self).setUp()
self.cluster = obj_utils.create_test_cluster(self.context)
p = mock.patch.object(rpcapi.API, 'credential_rotate')
p = mock.patch.object(rpcapi.API, 'credential_rotate', autospec=False)
self.mock_rotate = p.start()
self.mock_rotate.side_effect = self._simulate_credential_rotate
self.addCleanup(p.stop)
@@ -182,7 +182,8 @@ class TestListFederation(api_base.FunctionalTest):
class TestPatch(api_base.FunctionalTest):
def setUp(self):
super(TestPatch, self).setUp()
p = mock.patch.object(rpcapi.API, 'federation_update_async')
p = mock.patch.object(
rpcapi.API, 'federation_update_async', autospec=False)
self.mock_federation_update = p.start()
self.mock_federation_update.side_effect = \
self._sim_rpc_federation_update
@@ -274,7 +275,8 @@ class TestPatch(api_base.FunctionalTest):
class TestPost(api_base.FunctionalTest):
def setUp(self):
super(TestPost, self).setUp()
p = mock.patch.object(rpcapi.API, 'federation_create_async')
p = mock.patch.object(
rpcapi.API, 'federation_create_async', autospec=False)
self.mock_fed_create = p.start()
self.mock_fed_create.side_effect = self._simulate_federation_create
self.addCleanup(p.stop)
@@ -373,7 +375,8 @@ class TestDelete(api_base.FunctionalTest):
self.federation = obj_utils.create_test_federation(
self.context, name='federation-example',
uuid=uuidutils.generate_uuid())
p = mock.patch.object(rpcapi.API, 'federation_delete_async')
p = mock.patch.object(
rpcapi.API, 'federation_delete_async', autospec=False)
self.mock_federation_delete = p.start()
self.mock_federation_delete.side_effect = \
self._simulate_federation_delete
@@ -44,7 +44,7 @@ class db_rec(object):
class TestMagnumServiceController(api_base.FunctionalTest):
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_empty(self, mock_policy):
mock_policy.return_value = True
response = self.get_json('/mservices')
@@ -59,9 +59,10 @@ class TestMagnumServiceController(api_base.FunctionalTest):
reclist.append(rec)
return reclist
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(objects.MagnumService, 'list')
@mock.patch.object(servicegroup.ServiceGroup, 'service_is_up')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(objects.MagnumService, 'list', autospec=True)
@mock.patch.object(
servicegroup.ServiceGroup, 'service_is_up', autospec=True)
def test_get_one(self, svc_up, rpc_patcher, mock_policy):
mock_policy.return_value = True
rpc_patcher.return_value = self._rpc_api_reply()
@@ -71,9 +72,10 @@ class TestMagnumServiceController(api_base.FunctionalTest):
self.assertEqual(1, len(response['mservices']))
self.assertEqual(1, response['mservices'][0]['id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(objects.MagnumService, 'list')
@mock.patch.object(servicegroup.ServiceGroup, 'service_is_up')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(objects.MagnumService, 'list', autospec=True)
@mock.patch.object(
servicegroup.ServiceGroup, 'service_is_up', autospec=True)
def test_get_many(self, svc_up, rpc_patcher, mock_policy):
mock_policy.return_value = True
svc_num = 5
@@ -155,8 +155,8 @@ class TestListNodegroups(NodeGroupControllerTest):
filters = {'role': 'non-existent'}
self._test_list_nodegroups(self.cluster.name, filters=filters)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=temp_uuid,
@@ -224,8 +224,8 @@ class TestListNodegroups(NodeGroupControllerTest):
response = self.get_json(url, expect_errors=True)
self.assertEqual(404, response.status_code)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_one_as_admin(self, mock_context, mock_policy):
temp_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=temp_uuid,
@@ -279,13 +279,14 @@ class TestPost(NodeGroupControllerTest):
self.context)
self.cluster = obj_utils.create_test_cluster(self.context)
self.cluster.refresh()
p = mock.patch.object(rpcapi.API, 'nodegroup_create_async')
p = mock.patch.object(
rpcapi.API, 'nodegroup_create_async', autospec=False)
self.mock_ng_create = p.start()
self.mock_ng_create.side_effect = self._simulate_nodegroup_create
self.addCleanup(p.stop)
self.url = "/clusters/%s/nodegroups" % self.cluster.uuid
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
@@ -520,14 +521,14 @@ class TestPost(NodeGroupControllerTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_int)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_create_master_ng(self, mock_utcnow):
ng_dict = apiutils.nodegroup_post_data(role='master')
response = self.post_json(self.url, ng_dict, expect_errors=True)
self.assertEqual('application/json', response.content_type)
self.assertEqual(400, response.status_int)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_create_ng_same_name(self, mock_utcnow):
existing_name = self.cluster.default_ng_master.name
ng_dict = apiutils.nodegroup_post_data(name=existing_name)
@@ -535,7 +536,7 @@ class TestPost(NodeGroupControllerTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(409, response.status_int)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_create_ng_wrong_microversion(self, mock_utcnow):
headers = {"Openstack-Api-Version": "container-infra 1.8"}
ng_dict = apiutils.nodegroup_post_data(name="new_ng")
@@ -607,7 +608,8 @@ class TestDelete(NodeGroupControllerTest):
self.cluster.refresh()
self.nodegroup = obj_utils.create_test_nodegroup(
self.context, cluster_id=self.cluster.uuid, is_default=False)
p = mock.patch.object(rpcapi.API, 'nodegroup_delete_async')
p = mock.patch.object(
rpcapi.API, 'nodegroup_delete_async', autospec=False)
self.mock_ng_delete = p.start()
self.mock_ng_delete.side_effect = self._simulate_nodegroup_delete
self.addCleanup(p.stop)
@@ -654,8 +656,8 @@ class TestDelete(NodeGroupControllerTest):
self.assertEqual('application/json', response.content_type)
self.assertIsNotNone(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_delete_nodegroup_as_admin(self, mock_context, mock_policy):
cluster_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=cluster_uuid,
@@ -687,13 +689,14 @@ class TestPatch(NodeGroupControllerTest):
self.nodegroup = obj_utils.create_test_nodegroup(
self.context, cluster_id=self.cluster.uuid, is_default=False,
min_node_count=2, max_node_count=5, node_count=2)
p = mock.patch.object(rpcapi.API, 'nodegroup_update_async')
p = mock.patch.object(
rpcapi.API, 'nodegroup_update_async', autospec=False)
self.mock_ng_update = p.start()
self.mock_ng_update.side_effect = self._simulate_nodegroup_update
self.addCleanup(p.stop)
self.url = "/clusters/%s/nodegroups/" % self.cluster.uuid
p = mock.patch.object(
attr_validator, 'validate_flavor_root_volume_size')
attr_validator, 'validate_flavor_root_volume_size', autospec=True)
self.mock_valid_flavor_disk = p.start()
self.addCleanup(p.stop)
@@ -701,7 +704,7 @@ class TestPatch(NodeGroupControllerTest):
nodegroup.save()
return nodegroup
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_ok(self, mock_utcnow):
max_node_count = 4
test_time = datetime.datetime(2000, 1, 1, 0, 0)
@@ -720,7 +723,7 @@ class TestPatch(NodeGroupControllerTest):
response['updated_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_updated_at)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_replace_ok_by_name(self, mock_utcnow):
max_node_count = 4
test_time = datetime.datetime(2000, 1, 1, 0, 0)
@@ -824,7 +827,7 @@ class TestPatch(NodeGroupControllerTest):
self.assertEqual(409, response.status_code)
self.assertIsNotNone(response.json['errors'])
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_remove_ok(self, mock_utcnow):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time
@@ -841,7 +844,7 @@ class TestPatch(NodeGroupControllerTest):
response['updated_at']).replace(tzinfo=None)
self.assertEqual(test_time, return_updated_at)
@mock.patch('oslo_utils.timeutils.utcnow')
@mock.patch('oslo_utils.timeutils.utcnow', autospec=True)
def test_remove_min_node_count(self, mock_utcnow):
test_time = datetime.datetime(2000, 1, 1, 0, 0)
mock_utcnow.return_value = test_time
@@ -875,8 +878,8 @@ class TestPatch(NodeGroupControllerTest):
self.assertEqual(400, response.status_code)
self.assertIsNotNone(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_update_nodegroup_as_admin(self, mock_context, mock_policy):
cluster_uuid = uuidutils.generate_uuid()
obj_utils.create_test_cluster(self.context, uuid=cluster_uuid,
@@ -39,13 +39,13 @@ class TestQuota(api_base.FunctionalTest):
def setUp(self):
super(TestQuota, self).setUp()
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_empty(self, mock_policy):
mock_policy.return_value = True
response = self.get_json('/quotas')
self.assertEqual([], response['quotas'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_one(self, mock_policy):
mock_policy.return_value = True
quota = obj_utils.create_test_quota(self.context)
@@ -53,7 +53,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(quota.project_id, response['quotas'][0]["project_id"])
self._verify_attrs(self._quota_attrs, response['quotas'][0])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_get_one(self, mock_policy):
mock_policy.return_value = True
quota = obj_utils.create_test_quota(self.context)
@@ -62,7 +62,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(quota.project_id, response['project_id'])
self.assertEqual(quota.resource, response['resource'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_get_one_no_config_default(self, mock_policy):
mock_policy.return_value = True
response = self.get_json(
@@ -73,7 +73,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(CONF.quotas.max_clusters_per_project,
response.json['hard_limit'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_get_one_with_config_default(self, mock_policy):
mock_policy.return_value = True
quota = 15
@@ -94,8 +94,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual('application/json', response.content_type)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_admin_all_tenants(self, mock_context, mock_policy):
mock_context.return_value = self.context
quota_list = []
@@ -111,8 +111,8 @@ class TestQuota(api_base.FunctionalTest):
res_proj_ids = [r['project_id'] for r in response['quotas']]
self.assertEqual(sorted(expected), sorted(res_proj_ids))
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_with_non_admin_context(self, mock_context, mock_policy):
mock_context.return_value = self.context
quota_list = []
@@ -125,8 +125,8 @@ class TestQuota(api_base.FunctionalTest):
response = self.get_json('/quotas?all_tenants=True')
self.assertEqual(0, len(response['quotas']))
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_admin_not_all_tenants(self, mock_context, mock_policy):
mock_context.return_value = self.context
quota_list = []
@@ -141,8 +141,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(1, len(response['quotas']))
self.assertEqual('proj-id-1', response['quotas'][0]['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_with_pagination_limit(self, mock_context,
mock_policy):
mock_context.return_value = self.context
@@ -164,8 +164,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertIn('limit=2', response['next'])
self.assertIn('marker=%s' % quota_list[1].id, response['next'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_admin_all_with_pagination_marker(self, mock_context,
mock_policy):
mock_context.return_value = self.context
@@ -182,8 +182,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(quota_list[-1].project_id,
response['quotas'][0]['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_get_all_admin_all_tenants_false(self, mock_context, mock_policy):
mock_context.return_value = self.context
quota_list = []
@@ -198,7 +198,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(1, len(response['quotas']))
self.assertEqual('proj-id-1', response['quotas'][0]['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.policy.enforce", autospec=True)
def test_get_all_non_admin(self, mock_policy):
mock_policy.return_value = True
quota_list = []
@@ -212,8 +212,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(1, len(response['quotas']))
self.assertEqual('proj-id-2', response['quotas'][0]['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_quota(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data()
@@ -222,8 +222,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(201, response.status_int)
self.assertEqual(quota_dict['project_id'], response.json['project_id'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_zero_quota(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data(hard_limit=0)
@@ -233,7 +233,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(quota_dict['project_id'], response.json['project_id'])
self.assertEqual(quota_dict['hard_limit'], response.json['hard_limit'])
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_quota_project_id_not_found(self, mock_keystone):
keystone = mock.MagicMock()
keystone.client.get_project\
@@ -245,7 +245,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(404, response.status_int)
self.assertTrue(response.json['errors'])
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_quota_invalid_resource(self, mock_keystone):
quota_dict = apiutils.quota_post_data()
quota_dict['resource'] = 'invalid-res'
@@ -254,7 +254,7 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['errors'])
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_quota_invalid_hard_limit(self, mock_keystone):
quota_dict = apiutils.quota_post_data()
quota_dict['hard_limit'] = -10
@@ -263,8 +263,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_quota_no_project_id(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data()
@@ -274,8 +274,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(400, response.status_int)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_patch_quota(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data(hard_limit=5)
@@ -291,8 +291,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(202, response.status_int)
self.assertEqual(20, response.json['hard_limit'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_patch_quota_not_found(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data()
@@ -309,8 +309,8 @@ class TestQuota(api_base.FunctionalTest):
self.assertEqual(404, response.status_int)
self.assertTrue(response.json['errors'])
@mock.patch("magnum.common.policy.enforce")
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_delete_quota(self, mock_keystone, mock_policy):
mock_policy.return_value = True
quota_dict = apiutils.quota_post_data()
@@ -37,8 +37,8 @@ class TestStatsController(api_base.FunctionalTest):
expected = {u'clusters': 0, u'nodes': 0}
self.assertEqual(expected, response)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_admin_get_all_stats(self, mock_context, mock_policy):
obj_utils.create_test_cluster(self.context,
project_id=123,
@@ -50,8 +50,8 @@ class TestStatsController(api_base.FunctionalTest):
expected = {u'clusters': 2, u'nodes': 12}
self.assertEqual(expected, response)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_admin_get_tenant_stats(self, mock_context, mock_policy):
obj_utils.create_test_cluster(self.context,
project_id=123,
@@ -65,8 +65,8 @@ class TestStatsController(api_base.FunctionalTest):
expected = {u'clusters': 1, u'nodes': 6}
self.assertEqual(expected, response)
@mock.patch("magnum.common.policy.enforce")
@mock.patch("magnum.common.context.make_context")
@mock.patch("magnum.common.policy.enforce", autospec=True)
@mock.patch("magnum.common.context.make_context", autospec=False)
def test_admin_get_invalid_tenant_stats(self, mock_context, mock_policy):
obj_utils.create_test_cluster(self.context,
project_id=123,
@@ -29,13 +29,13 @@ from magnum.tests.unit.api import base
class TestDNSListType(base.FunctionalTest):
def test_valid_single_dns(self):
test_dns = "8.8.8.8"
with mock.patch.object(utils, 'validate_dns') as m_mock:
with mock.patch.object(utils, 'validate_dns', autospec=True) as m_mock:
types.DNSListType.validate(test_dns)
m_mock.assert_called_once_with(test_dns)
def test_valid_multi_dns(self):
test_dns = "8.8.8.8,114.114.114.114"
with mock.patch.object(utils, 'validate_dns') as m_mock:
with mock.patch.object(utils, 'validate_dns', autospec=True) as m_mock:
types.DNSListType.validate(test_dns)
m_mock.assert_called_once_with(test_dns)
@@ -48,7 +48,8 @@ class TestMacAddressType(base.FunctionalTest):
def test_valid_mac_addr(self):
test_mac = 'aa:bb:cc:11:22:33'
with mock.patch.object(utils, 'validate_and_normalize_mac') as m_mock:
with mock.patch.object(
utils, 'validate_and_normalize_mac', autospec=True) as m_mock:
types.MacAddressType.validate(test_mac)
m_mock.assert_called_once_with(test_mac)
@@ -58,7 +59,8 @@ class TestMacAddressType(base.FunctionalTest):
def test_frombasetype(self):
test_mac = 'aa:bb:cc:11:22:33'
with mock.patch.object(utils, 'validate_and_normalize_mac') as m_mock:
with mock.patch.object(
utils, 'validate_and_normalize_mac', autospec=True) as m_mock:
types.MacAddressType.frombasetype(test_mac)
m_mock.assert_called_once_with(test_mac)
@@ -71,7 +73,8 @@ class TestUuidType(base.FunctionalTest):
def test_valid_uuid(self):
test_uuid = '1a1a1a1a-2b2b-3c3c-4d4d-5e5e5e5e5e5e'
with mock.patch.object(uuidutils, 'is_uuid_like') as uuid_mock:
with mock.patch.object(
uuidutils, 'is_uuid_like', autospec=True) as uuid_mock:
types.UuidType.validate(test_uuid)
uuid_mock.assert_called_once_with(test_uuid)
@@ -17,6 +17,7 @@ import jsonpatch
from unittest import mock
from oslo_utils import uuidutils
import pecan
import wsme
from magnum.api import utils
@@ -53,14 +54,15 @@ class TestApiUtils(base.FunctionalTest):
utils.validate_sort_dir,
'fake-sort')
@mock.patch('pecan.request')
@mock.patch('magnum.objects.Cluster.get_by_name')
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.objects.Cluster.get_by_name', autospec=True)
@mock.patch('magnum.objects.Cluster.get_by_uuid', autospec=True)
def test_get_resource_with_uuid(
self,
mock_get_by_uuid,
mock_get_by_name,
mock_request):
mock_request.context = mock.Mock()
mock_cluster = mock.MagicMock
mock_get_by_uuid.return_value = mock_cluster
uuid = uuidutils.generate_uuid()
@@ -71,14 +73,15 @@ class TestApiUtils(base.FunctionalTest):
self.assertFalse(mock_get_by_name.called)
self.assertEqual(mock_cluster, returned_cluster)
@mock.patch('pecan.request')
@mock.patch('magnum.objects.Cluster.get_by_name')
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.objects.Cluster.get_by_name', autospec=True)
@mock.patch('magnum.objects.Cluster.get_by_uuid', autospec=True)
def test_get_resource_with_name(
self,
mock_get_by_uuid,
mock_get_by_name,
mock_request):
mock_request.context = mock.Mock()
mock_cluster = mock.MagicMock
mock_get_by_name.return_value = mock_cluster
@@ -89,7 +92,8 @@ class TestApiUtils(base.FunctionalTest):
'fake-name')
self.assertEqual(mock_cluster, returned_cluster)
@mock.patch.object(uuidutils, 'is_uuid_like', return_value=True)
@mock.patch.object(
uuidutils, 'is_uuid_like', return_value=True, autospec=True)
def test_get_openstack_resource_by_uuid(self, fake_is_uuid_like):
fake_manager = mock.MagicMock()
fake_manager.get.return_value = 'fake_resource_data'
@@ -98,7 +102,8 @@ class TestApiUtils(base.FunctionalTest):
'fake_resource_type')
self.assertEqual('fake_resource_data', resource_data)
@mock.patch.object(uuidutils, 'is_uuid_like', return_value=False)
@mock.patch.object(
uuidutils, 'is_uuid_like', return_value=False, autospec=True)
def test_get_openstack_resource_by_name(self, fake_is_uuid_like):
fake_manager = mock.MagicMock()
fake_manager.list.return_value = ['fake_resource_data']
@@ -107,7 +112,8 @@ class TestApiUtils(base.FunctionalTest):
'fake_resource_type')
self.assertEqual('fake_resource_data', resource_data)
@mock.patch.object(uuidutils, 'is_uuid_like', return_value=False)
@mock.patch.object(
uuidutils, 'is_uuid_like', return_value=False, autospec=True)
def test_get_openstack_resource_non_exist(self, fake_is_uuid_like):
fake_manager = mock.MagicMock()
fake_manager.list.return_value = []
@@ -115,7 +121,8 @@ class TestApiUtils(base.FunctionalTest):
utils.get_openstack_resource,
fake_manager, 'fake_resource', 'fake_resource_type')
@mock.patch.object(uuidutils, 'is_uuid_like', return_value=False)
@mock.patch.object(
uuidutils, 'is_uuid_like', return_value=False, autospec=True)
def test_get_openstack_resource_multi_exist(self, fake_is_uuid_like):
fake_manager = mock.MagicMock()
fake_manager.list.return_value = ['fake_resource_data1',
@@ -124,7 +131,7 @@ class TestApiUtils(base.FunctionalTest):
utils.get_openstack_resource,
fake_manager, 'fake_resource', 'fake_resource_type')
@mock.patch.object(jsonpatch, 'apply_patch')
@mock.patch.object(jsonpatch, 'apply_patch', autospec=True)
def test_apply_jsonpatch(self, mock_jsonpatch):
doc = {'cluster_uuid': 'id', 'node_count': 1}
patch = [{"path": "/node_count", "value": 2, "op": "replace"}]
+6 -6
View File
@@ -280,7 +280,7 @@ class TestAttrValidator(base.BaseTestCase):
attr_validator.validate_image,
mock_os_cli, 'ubuntu-24.04')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_validate_os_resources_with_invalid_flavor(self,
mock_os_cli):
mock_cluster_template = {'flavor_id': 'test_flavor'}
@@ -296,8 +296,8 @@ class TestAttrValidator(base.BaseTestCase):
attr_validator.validate_os_resources,
mock_context, mock_cluster_template)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.api.attr_validator.validators')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
@mock.patch('magnum.api.attr_validator.validators', autospec=True)
def test_validate_os_resources_without_validator(self, mock_validators,
mock_os_cli):
mock_cluster_template = {}
@@ -305,7 +305,7 @@ class TestAttrValidator(base.BaseTestCase):
attr_validator.validate_os_resources(mock_context,
mock_cluster_template)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_validate_os_resources_with_valid_fixed_subnet(self,
os_clients_klass):
mock_cluster_template = {'fixed_network': 'test_net',
@@ -326,7 +326,7 @@ class TestAttrValidator(base.BaseTestCase):
attr_validator.validate_os_resources(mock_context,
mock_cluster_template)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_validate_os_resources_with_invalid_fixed_subnet(self,
os_clients_klass):
mock_cluster_template = {'fixed_network': 'test_net',
@@ -348,7 +348,7 @@ class TestAttrValidator(base.BaseTestCase):
attr_validator.validate_os_resources, mock_context,
mock_cluster_template)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_validate_os_resources_with_cluster(self, mock_os_cli):
mock_cluster_template = {}
mock_cluster = {
+2 -2
View File
@@ -18,12 +18,12 @@ from magnum.tests import base
class TestExpose(base.BaseTestCase):
@mock.patch('wsmeext.pecan.wsexpose')
@mock.patch('wsmeext.pecan.wsexpose', autospec=True)
def test_expose_with_rest_content_types(self, mock_pecan):
self.assertTrue(expose.expose(rest_content_types='json'))
mock_pecan.assert_called_with(rest_content_types='json')
@mock.patch('wsmeext.pecan.wsexpose')
@mock.patch('wsmeext.pecan.wsexpose', autospec=True)
def test_expose_without_rest_content_types(self, mock_pecan):
self.assertTrue(expose.expose())
mock_pecan.assert_called_once_with(rest_content_types=('json',))
+3 -3
View File
@@ -32,7 +32,7 @@ class TestContextHook(base.BaseTestCase):
super(TestContextHook, self).setUp()
self.app = fakes.FakeApp()
@mock.patch("magnum.common.policy.check_is_admin")
@mock.patch("magnum.common.policy.check_is_admin", autospec=True)
def test_context_hook_before_method(self, m_c):
state = mock.Mock(request=fakes.FakePecanRequest())
hook = hooks.ContextHook()
@@ -55,7 +55,7 @@ class TestContextHook(base.BaseTestCase):
ctx.user_domain_id)
self.assertIsNone(ctx.auth_token_info)
@mock.patch("magnum.common.policy.check_is_admin")
@mock.patch("magnum.common.policy.check_is_admin", autospec=True)
def test_context_hook_before_method_auth_info(self, c_m):
state = mock.Mock(request=fakes.FakePecanRequest())
state.request.environ['keystone.token_info'] = 'assert_this'
@@ -81,7 +81,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
def setUp(self):
super(TestNoExceptionTracebackHook, self).setUp()
p = mock.patch.object(root.Root, 'convert')
p = mock.patch.object(root.Root, 'convert', autospec=True)
self.root_convert_mock = p.start()
self.addCleanup(p.stop)
+66 -39
View File
@@ -17,6 +17,7 @@ import importlib
from unittest import mock
from openstack import exceptions as sdk_exceptions
import pecan
from magnum.api import validation as v
from magnum.common import exception
@@ -33,6 +34,7 @@ class TestValidation(base.BaseTestCase):
def _test_enforce_cluster_type_supported(
self, mock_cluster_template_get, mock_cluster_get_by_uuid,
mock_pecan_request, cluster_type, assert_raised=False):
mock_pecan_request.context = mock.Mock()
@v.enforce_cluster_type_supported()
def test(self, cluster):
@@ -55,10 +57,11 @@ class TestValidation(base.BaseTestCase):
else:
self.assertIsNone(test(self, cluster))
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch('pecan.request')
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.objects.Cluster.get_by_uuid', autospec=True)
@mock.patch('magnum.objects.ClusterTemplate.get', autospec=True)
def test_enforce_cluster_type_supported(
self, mock_cluster_template_get, mock_cluster_get_by_uuid,
mock_pecan_request, mock_get_driver):
@@ -69,9 +72,9 @@ class TestValidation(base.BaseTestCase):
mock_cluster_template_get, mock_cluster_get_by_uuid,
mock_pecan_request, cluster_type)
@mock.patch('pecan.request')
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.objects.Cluster.get_by_uuid', autospec=True)
@mock.patch('magnum.objects.ClusterTemplate.get', autospec=True)
def test_enforce_cluster_type_not_supported(
self, mock_cluster_template_get, mock_cluster_get_by_uuid,
mock_pecan_request):
@@ -175,8 +178,8 @@ class TestValidation(base.BaseTestCase):
assert_raised=True,
)
@mock.patch('pecan.request')
@mock.patch('magnum.api.utils.get_resource')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.api.utils.get_resource', autospec=True)
def _test_enforce_network_driver_types_update(
self,
mock_get_resource,
@@ -185,6 +188,8 @@ class TestValidation(base.BaseTestCase):
validator_allowed_network_drivers=None,
assert_raised=False,
):
mock_pecan_request.context = mock.Mock()
@v.enforce_network_driver_types_update()
def test(self, cluster_template_ident, patch):
pass
@@ -309,8 +314,8 @@ class TestValidation(base.BaseTestCase):
server_type='invalid',
assert_raised=True)
@mock.patch('pecan.request')
@mock.patch('magnum.api.utils.get_resource')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.api.utils.get_resource', autospec=True)
def _test_enforce_volume_driver_types_update(
self,
mock_get_resource,
@@ -318,6 +323,7 @@ class TestValidation(base.BaseTestCase):
volume_driver_type,
op,
assert_raised=False):
mock_pecan_request.context = mock.Mock()
@v.enforce_volume_driver_types_update()
def test(self, cluster_template_ident, patch):
@@ -389,10 +395,11 @@ class TestValidation(base.BaseTestCase):
self.assertRaises(exception.InvalidParameterValue,
v.validate_cluster_properties, set([field]))
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_image_not_found(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -409,10 +416,11 @@ class TestValidation(base.BaseTestCase):
self.assertRaises(exception.ImageNotFound,
test, self, cluster_template)
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_image_not_found_sdk(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -428,10 +436,11 @@ class TestValidation(base.BaseTestCase):
self.assertRaises(exception.ImageNotFound,
test, self, cluster_template)
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_image_forbidden(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -447,10 +456,11 @@ class TestValidation(base.BaseTestCase):
self.assertRaises(exception.ImageNotAuthorized,
test, self, cluster_template)
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_image_os_distro_unset(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -466,7 +476,8 @@ class TestValidation(base.BaseTestCase):
self.assertRaises(exception.OSDistroFieldNotFound,
test, self, cluster_template)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
def test_enforce_driver_supported_user_driver_skips_image(
self, mock_get_driver):
"""When driver and cluster_distro are set, image is not fetched."""
@@ -487,14 +498,18 @@ class TestValidation(base.BaseTestCase):
mock_get_driver.assert_called_once_with('vm', 'ubuntu', 'kubernetes',
'user_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_default_driver')
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
@mock.patch(
'magnum.drivers.common.driver.Driver.get_default_driver',
autospec=True)
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_falls_back_to_default(
self, mock_os_clients, mock_pecan_request,
mock_get_default, mock_get_driver):
"""get_default_driver() is used when no driver from image or user."""
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -519,14 +534,18 @@ class TestValidation(base.BaseTestCase):
mock_get_driver.assert_called_once_with('vm', 'ubuntu', 'kubernetes',
'default_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_default_driver')
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
@mock.patch(
'magnum.drivers.common.driver.Driver.get_default_driver',
autospec=True)
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_image_driver_skips_default(
self, mock_os_clients, mock_pecan_request,
mock_get_default, mock_get_driver):
"""get_default_driver() is not called when image provides a driver."""
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -550,12 +569,14 @@ class TestValidation(base.BaseTestCase):
mock_get_driver.assert_called_once_with('vm', 'ubuntu', 'kubernetes',
'image_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_user_driver_preserved_without_distro(
self, mock_os_clients, mock_pecan_request, mock_get_driver):
"""User-supplied driver is not overwritten even when image has one."""
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -580,14 +601,18 @@ class TestValidation(base.BaseTestCase):
'user_driver')
self.assertEqual('user_driver', cluster_template.driver)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver')
@mock.patch('magnum.drivers.common.driver.Driver.get_default_driver')
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver', autospec=True)
@mock.patch(
'magnum.drivers.common.driver.Driver.get_default_driver',
autospec=True)
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_driver_supported_writes_resolved_driver_back(
self, mock_os_clients, mock_pecan_request,
mock_get_default, mock_get_driver):
"""Resolved driver is written back to cluster_template.driver."""
mock_pecan_request.context = mock.Mock()
@v.enforce_driver_supported()
def test(self, cluster_template):
@@ -610,10 +635,11 @@ class TestValidation(base.BaseTestCase):
self.assertEqual('default_driver', cluster_template.driver)
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_valid_project_id_on_create_success(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_valid_project_id_on_create()
def test(self, quota):
@@ -631,10 +657,11 @@ class TestValidation(base.BaseTestCase):
mock_os_clients.return_value.keystone.return_value\
.client.get_project.assert_called_once_with('valid-project-id')
@mock.patch('pecan.request')
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('pecan.request', autospec=pecan.Request)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_enforce_valid_project_id_on_create_project_not_found(
self, mock_os_clients, mock_pecan_request):
mock_pecan_request.context = mock.Mock()
@v.enforce_valid_project_id_on_create()
def test(self, quota):
+19 -19
View File
@@ -22,12 +22,12 @@ from magnum.tests import base
# NOTE(hieulq): need to mock MagnumObject, otherwise other test cases
# will be failed because of setting wrong ovo indirection api
@mock.patch('magnum.objects.base.MagnumObject')
@mock.patch('magnum.objects.base.MagnumObject', autospec=True)
class TestMagnumAPI(base.TestCase):
@mock.patch('werkzeug.serving.run_simple')
@mock.patch.object(api, 'api_app')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('werkzeug.serving.run_simple', autospec=True)
@mock.patch.object(api, 'api_app', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_api_http(self, mock_prep, mock_app, mock_run, mock_base):
api.main()
@@ -40,9 +40,9 @@ class TestMagnumAPI(base.TestCase):
app, processes=workers,
ssl_context=None)
@mock.patch('werkzeug.serving.run_simple')
@mock.patch.object(api, 'api_app')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('werkzeug.serving.run_simple', autospec=True)
@mock.patch.object(api, 'api_app', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_api_http_config_workers(self, mock_prep, mock_app,
mock_run, mock_base):
fake_workers = 8
@@ -57,10 +57,10 @@ class TestMagnumAPI(base.TestCase):
app, processes=fake_workers,
ssl_context=None)
@mock.patch('os.path.exists')
@mock.patch('werkzeug.serving.run_simple')
@mock.patch.object(api, 'api_app')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('os.path.exists', autospec=True)
@mock.patch('werkzeug.serving.run_simple', autospec=True)
@mock.patch.object(api, 'api_app', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_api_https_no_cert(self, mock_prep, mock_app, mock_run,
mock_exist, mock_base):
self.config(enabled_ssl=True,
@@ -74,10 +74,10 @@ class TestMagnumAPI(base.TestCase):
mock_run.assert_not_called()
mock_exist.assert_called_once_with('tmp_crt')
@mock.patch('os.path.exists')
@mock.patch('werkzeug.serving.run_simple')
@mock.patch.object(api, 'api_app')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('os.path.exists', autospec=True)
@mock.patch('werkzeug.serving.run_simple', autospec=True)
@mock.patch.object(api, 'api_app', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_api_https_no_key(self, mock_prep, mock_app, mock_run,
mock_exist, mock_base):
self.config(enabled_ssl=True,
@@ -93,10 +93,10 @@ class TestMagnumAPI(base.TestCase):
mock_exist.assert_has_calls([mock.call('tmp_crt'),
mock.call('tmp_key')])
@mock.patch('os.path.exists')
@mock.patch('werkzeug.serving.run_simple')
@mock.patch.object(api, 'api_app')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('os.path.exists', autospec=True)
@mock.patch('werkzeug.serving.run_simple', autospec=True)
@mock.patch.object(api, 'api_app', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_api_https(self, mock_prep, mock_app, mock_run,
mock_exist, mock_base):
self.config(enabled_ssl=True,
+6 -6
View File
@@ -22,9 +22,9 @@ from magnum.tests import base
class TestMagnumConductor(base.TestCase):
@mock.patch('oslo_service.service.launch')
@mock.patch.object(conductor, 'rpc_service')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('oslo_service.service.launch', autospec=True)
@mock.patch.object(conductor, 'rpc_service', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_conductor(self, mock_prep, mock_rpc, mock_launch):
conductor.main()
@@ -39,9 +39,9 @@ class TestMagnumConductor(base.TestCase):
workers=workers)
launcher.wait.assert_called_once_with()
@mock.patch('oslo_service.service.launch')
@mock.patch.object(conductor, 'rpc_service')
@mock.patch('magnum.common.service.prepare_service')
@mock.patch('oslo_service.service.launch', autospec=True)
@mock.patch.object(conductor, 'rpc_service', autospec=True)
@mock.patch('magnum.common.service.prepare_service', autospec=True)
def test_conductor_config_workers(self, mock_prep, mock_rpc, mock_launch):
fake_workers = 8
self.config(workers=fake_workers, group='conductor')
+4 -4
View File
@@ -31,7 +31,7 @@ class TestMagnumDbManage(base.TestCase):
clear_conf()
self.addCleanup(clear_conf)
@mock.patch('magnum.db.migration.version')
@mock.patch('magnum.db.migration.version', autospec=True)
@mock.patch('sys.argv', ['magnum-db-manage', 'version'])
def test_db_manage_version(self, mock_version):
with mock.patch('sys.stdout', new=io.StringIO()) as fakeOutput:
@@ -41,19 +41,19 @@ class TestMagnumDbManage(base.TestCase):
fakeOutput.getvalue())
mock_version.assert_called_once_with()
@mock.patch('magnum.db.migration.upgrade')
@mock.patch('magnum.db.migration.upgrade', autospec=True)
@mock.patch('sys.argv', ['magnum-db-manage', 'upgrade'])
def test_db_manage_upgrade(self, mock_upgrade):
db_manage.main()
mock_upgrade.assert_called_once_with(base.CONF.command.revision)
@mock.patch('magnum.db.migration.stamp')
@mock.patch('magnum.db.migration.stamp', autospec=True)
@mock.patch('sys.argv', ['magnum-db-manage', 'stamp', 'foo bar'])
def test_db_manage_stamp(self, mock_stamp):
db_manage.main()
mock_stamp.assert_called_once_with('foo bar')
@mock.patch('magnum.db.migration.revision')
@mock.patch('magnum.db.migration.revision', autospec=True)
@mock.patch('sys.argv', ['magnum-db-manage', 'revision', '-m', 'foo bar'])
def test_db_manage_revision(self, mock_revision):
db_manage.main()
+10 -8
View File
@@ -36,37 +36,39 @@ class TestMagnumDriverManage(base.TestCase):
yield fake_entry, fake_cls
num_of_entries -= 1
@mock.patch.object(driver_manage.DriverManager, 'run')
@mock.patch.object(driver_manage.DriverManager, 'run', autospec=True)
@mock.patch('sys.argv', ['foo', 'bar'])
def test_none_arg(self, mock_run):
args = None
driver_manage.main(args)
mock_run.assert_called_once_with(['bar'])
mock_run.assert_called_once_with(mock.ANY, ['bar'])
# NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
# produce_output in order to assert with fake value
@mock.patch('magnum.cmd.driver_manage.DriverList.produce_output')
@mock.patch('magnum.drivers.common.driver.Driver')
@mock.patch(
'magnum.cmd.driver_manage.DriverList.produce_output', autospec=True)
@mock.patch('magnum.drivers.common.driver.Driver', autospec=True)
def test_correct_arg_with_details_and_path(self, mock_driver,
mock_produce):
args = ['list-drivers', '-d', '-p']
mock_driver.load_entry_points.return_value = self._fake_entry(1)
driver_manage.main(args)
mock_driver.load_entry_points.assert_called_once_with()
mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
mock_produce.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY,
[('magnum_test_foo_bar',
'test',
'bar', 'foo', 'fake_path')])
# NOTE(hieulq): we fake the entrypoints then we need to mock the cliff
# produce_output in order to assert with fake value
@mock.patch('magnum.cmd.driver_manage.DriverList.produce_output')
@mock.patch('magnum.drivers.common.driver.Driver')
@mock.patch(
'magnum.cmd.driver_manage.DriverList.produce_output', autospec=True)
@mock.patch('magnum.drivers.common.driver.Driver', autospec=True)
def test_correct_arg_without_details_and_path(self, mock_driver,
mock_produce):
args = ['list-drivers']
mock_driver.load_entry_points.return_value = self._fake_entry(1)
driver_manage.main(args)
mock_driver.load_entry_points.assert_called_once_with()
mock_produce.assert_called_once_with(mock.ANY, mock.ANY,
mock_produce.assert_called_once_with(mock.ANY, mock.ANY, mock.ANY,
[('magnum_test_foo_bar',)])
@@ -39,7 +39,7 @@ class FakeCert(cert_manager_iface.Cert):
class TestCert(base.BaseTestCase):
@mock.patch.object(cert_manager_iface, 'operations')
@mock.patch.object(cert_manager_iface, 'operations', autospec=True)
def test_get_decrypted_private_key(self, mock_x509_ops):
mock_x509_ops.decrypt_key.return_value = 'fake-key'
fake_cert = FakeCert()
@@ -65,7 +65,7 @@ class TestLocalManager(base.BaseTestCase):
if self.private_key_passphrase is None and ext == '.pass':
return False
return True
isfile_patcher = mock.patch('os.path.isfile')
isfile_patcher = mock.patch('os.path.isfile', autospec=True)
self.mock_isfile = isfile_patcher.start()
self.addCleanup(isfile_patcher.stop)
self.mock_isfile.side_effect = _mock_isfile
@@ -187,7 +187,7 @@ class TestLocalManager(base.BaseTestCase):
def test_store_cert(self):
self._store_cert()
@mock.patch('builtins.open', create=True)
@mock.patch('builtins.open', create=True, autospec=True)
def test_store_cert_with_io_error(self, file_mock):
file_mock.side_effect = IOError
@@ -32,7 +32,8 @@ class TestCertifiactePolicy(base.PolicyFunctionalTest):
super(TestCertifiactePolicy, self).setUp()
self.cluster = obj_utils.create_test_cluster(self.context)
conductor_api_patcher = mock.patch('magnum.conductor.api.API')
conductor_api_patcher = mock.patch(
'magnum.conductor.api.API', autospec=True)
self.conductor_api_class = conductor_api_patcher.start()
self.conductor_api = mock.MagicMock()
self.conductor_api_class.return_value = self.conductor_api
@@ -26,7 +26,7 @@ class TestClusterPolicy(base.PolicyFunctionalTest):
self.cluster = obj_utils.create_test_cluster(
self.context, name='cluster_example_A', node_count=3
)
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@@ -26,7 +26,7 @@ class TestClusterTemplatePolicy(base.PolicyFunctionalTest):
self.clustertemplate = obj_utils.create_test_cluster_template(
self.context
)
p = mock.patch.object(driver.Driver, 'get_driver')
p = mock.patch.object(driver.Driver, 'get_driver', autospec=True)
self.mock_driver_get = p.start()
self.mock_driver_get.return_value = mock.MagicMock()
self.addCleanup(p.stop)
@@ -38,7 +38,7 @@ class TestQuotaPolicy(base.PolicyFunctionalTest):
headers=self.member_headers)
self.assertIn("403 Forbidden", str(exc))
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_create_no_permission(self, mock_keystone):
exc = self.assertRaises(
AppError, self.post_json,
@@ -46,9 +46,9 @@ class TestQuotaPolicy(base.PolicyFunctionalTest):
headers=self.reader_headers)
self.assertIn("403 Forbidden", str(exc))
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_update_no_permission(self, mock_keystone):
with mock.patch("magnum.common.policy.enforce"):
with mock.patch("magnum.common.policy.enforce", autospec=True):
quota_dict = apiutils.quota_post_data(hard_limit=5)
self.post_json('/quotas', quota_dict)
quota_dict['hard_limit'] = 20
@@ -57,9 +57,9 @@ class TestQuotaPolicy(base.PolicyFunctionalTest):
headers=self.reader_headers)
self.assertIn("403 Forbidden", str(exc))
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_delete_no_permission(self, mock_keystone):
with mock.patch("magnum.common.policy.enforce"):
with mock.patch("magnum.common.policy.enforce", autospec=True):
quota_dict = apiutils.quota_post_data()
response = self.post_json('/quotas', quota_dict)
self.assertEqual('application/json', response.content_type)
+34 -34
View File
@@ -26,7 +26,7 @@ class ClientsTest(base.BaseTestCase):
def setUp(self):
super(ClientsTest, self).setUp()
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_url_for(self, mock_keystone):
obj = clients.OpenStackClients(None)
obj.url_for(service_type='fake_service', interface='fake_endpoint')
@@ -35,7 +35,7 @@ class ClientsTest(base.BaseTestCase):
mock_endpoint.assert_called_once_with(service_type='fake_service',
interface='fake_endpoint')
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
def test_magnum_url(self, mock_keystone):
fake_region = 'fake_region'
fake_endpoint = 'fake_endpoint'
@@ -51,9 +51,9 @@ class ClientsTest(base.BaseTestCase):
service_type='container-infra',
interface=fake_endpoint)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def _test_clients_glance(self, expected_region_name, mock_url,
mock_conn, mock_keystone):
con = mock.MagicMock()
@@ -69,8 +69,8 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'image_endpoint_override': 'url_from_keystone'})
mock_keystone.assert_called_once_with()
mock_url.assert_called_once_with(service_type='image',
mock_keystone.assert_called_once_with(obj)
mock_url.assert_called_once_with(obj, service_type='image',
interface='publicURL',
region_name=expected_region_name)
@@ -94,9 +94,9 @@ class ClientsTest(base.BaseTestCase):
obj._glance = None
self.assertRaises(exception.AuthorizationFailure, obj.glance)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def test_clients_glance_cached(self, mock_url, mock_conn, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
@@ -113,9 +113,9 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'image_endpoint_override': 'url_from_keystone'})
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def _test_clients_barbican(self, expected_region_name, mock_url,
mock_conn, mock_keystone):
con = mock.MagicMock()
@@ -131,8 +131,8 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'key_manager_endpoint_override': 'url_from_keystone'})
mock_keystone.assert_called_once_with()
mock_url.assert_called_once_with(service_type='key-manager',
mock_keystone.assert_called_once_with(obj)
mock_url.assert_called_once_with(obj, service_type='key-manager',
interface='publicURL',
region_name=expected_region_name)
@@ -157,9 +157,9 @@ class ClientsTest(base.BaseTestCase):
obj._barbican = None
self.assertRaises(exception.AuthorizationFailure, obj.barbican)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def test_clients_barbican_cached(self, mock_url, mock_conn, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
@@ -176,9 +176,9 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'key_manager_endpoint_override': 'url_from_keystone'})
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def _test_clients_nova(self, expected_region_name, mock_url,
mock_conn, mock_keystone):
con = mock.MagicMock()
@@ -194,8 +194,8 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'compute_endpoint_override': 'url_from_keystone'})
mock_keystone.assert_called_once_with()
mock_url.assert_called_once_with(service_type='compute',
mock_keystone.assert_called_once_with(obj)
mock_url.assert_called_once_with(obj, service_type='compute',
interface='publicURL',
region_name=expected_region_name)
@@ -216,9 +216,9 @@ class ClientsTest(base.BaseTestCase):
obj._nova = None
self.assertRaises(exception.AuthorizationFailure, obj.nova)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def test_clients_nova_cached(self, mock_url, mock_conn, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
@@ -235,9 +235,9 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'compute_endpoint_override': 'url_from_keystone'})
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def _test_clients_neutron(self, expected_region_name, mock_url,
mock_conn, mock_keystone):
fake_endpoint_type = 'fake_endpoint_type'
@@ -256,8 +256,8 @@ class ClientsTest(base.BaseTestCase):
session=keystone.session,
**{'network_endpoint_override': 'url_from_keystone'})
mock_keystone.assert_called_once_with()
mock_url.assert_called_once_with(service_type='network',
mock_keystone.assert_called_once_with(obj)
mock_url.assert_called_once_with(obj, service_type='network',
interface=fake_endpoint_type,
region_name=expected_region_name)
@@ -279,9 +279,9 @@ class ClientsTest(base.BaseTestCase):
obj._neutron = None
self.assertRaises(exception.AuthorizationFailure, obj.neutron)
@mock.patch.object(clients.OpenStackClients, 'keystone')
@mock.patch.object(sdk_connection, 'Connection')
@mock.patch.object(clients.OpenStackClients, 'url_for')
@mock.patch.object(clients.OpenStackClients, 'keystone', autospec=True)
@mock.patch.object(sdk_connection, 'Connection', autospec=True)
@mock.patch.object(clients.OpenStackClients, 'url_for', autospec=True)
def test_clients_neutron_cached(self, mock_url, mock_conn, mock_keystone):
con = mock.MagicMock()
con.auth_url = "keystone_url"
+3 -3
View File
@@ -26,7 +26,7 @@ from magnum.tests import utils
CONF = magnum.conf.CONF
@mock.patch('magnum.common.keystone.sdk_connection.Connection')
@mock.patch('magnum.common.keystone.sdk_connection.Connection', autospec=True)
class KeystoneClientTest(base.TestCase):
def setUp(self):
@@ -59,7 +59,7 @@ class KeystoneClientTest(base.TestCase):
mock_conn.assert_called_once_with(session=session)
self.assertIsInstance(auth_plugin, ka_identity.Password)
@mock.patch('magnum.common.keystone.ka_access')
@mock.patch('magnum.common.keystone.ka_access', autospec=True)
def test_client_with_access_info(self, mock_access, mock_conn):
self.ctx.auth_token_info = mock.MagicMock()
ks_client = keystone.KeystoneClientV3(self.ctx)
@@ -71,7 +71,7 @@ class KeystoneClientTest(base.TestCase):
mock_conn.assert_called_once_with(session=session)
self.assertIsInstance(auth_plugin, ka_identity.access.AccessInfoPlugin)
@mock.patch('magnum.common.keystone.ka_v3')
@mock.patch('magnum.common.keystone.ka_v3', autospec=True)
def test_client_with_token(self, mock_v3, mock_conn):
ks_client = keystone.KeystoneClientV3(self.ctx)
ks_client.client
+11 -11
View File
@@ -33,7 +33,7 @@ class NeutronTest(base.TestCase):
objects.NodeGroup(self.context, **nodegroups_dict['worker'])
]
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_floatingip(self, mock_clients):
mock_nclient = mock.MagicMock()
fake_port_id = "b4518944-c2cf-4c69-a1e3-774041fd5d14"
@@ -54,7 +54,7 @@ class NeutronTest(base.TestCase):
mock_nclient.ips.assert_called_once_with(port_id=fake_port_id)
mock_nclient.delete_ip.assert_called_once_with(fake_fip_id)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_floatingip_empty(self, mock_clients):
mock_nclient = mock.MagicMock()
fake_port_id = "b4518944-c2cf-4c69-a1e3-774041fd5d14"
@@ -68,7 +68,7 @@ class NeutronTest(base.TestCase):
self.assertFalse(mock_nclient.delete_ip.called)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_floatingip_exception(self, mock_clients):
mock_nclient = mock.MagicMock()
fake_port_id = "b4518944-c2cf-4c69-a1e3-774041fd5d14"
@@ -93,7 +93,7 @@ class NeutronTest(base.TestCase):
self.cluster
)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_external_network_id(self, mock_clients):
fake_name = "fake_network"
fake_id = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -111,7 +111,7 @@ class NeutronTest(base.TestCase):
self.assertEqual(fake_id, network_id)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_external_network_id_notfound(self, mock_clients):
fake_name = "fake_network"
fake_id = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -132,7 +132,7 @@ class NeutronTest(base.TestCase):
"another_network"
)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_external_network_id_conflict(self, mock_clients):
fake_name = "fake_network"
fake_id_1 = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -157,7 +157,7 @@ class NeutronTest(base.TestCase):
fake_name
)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_fixed_network_name(self, mock_clients):
fake_name = "fake_network"
fake_id = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -175,7 +175,7 @@ class NeutronTest(base.TestCase):
self.assertEqual(fake_name, network_name)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_fixed_network_name_notfound(self, mock_clients):
fake_name = "fake_network"
fake_id = "24fe5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -197,7 +197,7 @@ class NeutronTest(base.TestCase):
another_fake_id
)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_fixed_subnet_id(self, mock_clients):
fake_name = "fake_subnet"
fake_id = "35ee5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -215,7 +215,7 @@ class NeutronTest(base.TestCase):
self.assertEqual(fake_id, subnet_id)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_fixed_subnet_id_notfound(self, mock_clients):
fake_name = "fake_subnet"
fake_id = "35ee5da0-1ac0-11e9-84cd-00224d6b7bc1"
@@ -236,7 +236,7 @@ class NeutronTest(base.TestCase):
"another_subnet"
)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_get_fixed_subnet_id_conflict(self, mock_clients):
fake_name = "fake_subnet"
fake_id_1 = "35ee5da0-1ac0-11e9-84cd-00224d6b7bc1"
+5 -5
View File
@@ -43,8 +43,8 @@ class OctaviaTest(base.TestCase):
objects.NodeGroup(self.context, **nodegroups_dict['worker'])
]
@mock.patch("magnum.common.neutron.delete_floatingip")
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch("magnum.common.neutron.delete_floatingip", autospec=True)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_loadbalancers(self, mock_clients, mock_delete_fip):
lb1 = make_lb(
id="fake_id_1",
@@ -82,7 +82,7 @@ class OctaviaTest(base.TestCase):
]
mock_octavia_client.delete_load_balancer.assert_has_calls(calls)
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_loadbalancers_no_candidate(self, mock_clients):
mock_octavia_client = mock.MagicMock()
mock_octavia_client.load_balancers.return_value = []
@@ -95,8 +95,8 @@ class OctaviaTest(base.TestCase):
self.assertFalse(mock_octavia_client.delete_load_balancer.called)
@mock.patch("magnum.common.neutron.delete_floatingip")
@mock.patch('magnum.common.clients.OpenStackClients')
@mock.patch("magnum.common.neutron.delete_floatingip", autospec=True)
@mock.patch('magnum.common.clients.OpenStackClients', autospec=True)
def test_delete_loadbalancers_timeout(self, mock_clients, mock_delete_fip):
# don't wait the full 60 seconds for a unit test
self.config(pre_delete_lb_timeout=1, group="cluster")
+2 -2
View File
@@ -62,7 +62,7 @@ class TestProfiler(base.TestCase):
self.assertTrue(getattr(obj, '__traced__', False), obj)
@mock.patch.object(profiler_init, 'init_from_conf')
@mock.patch.object(profiler_init, 'init_from_conf', autospec=True)
def test_setup_profiler(self, mock_init):
self.config(enabled=True,
group='profiler')
@@ -75,7 +75,7 @@ class TestProfiler(base.TestCase):
service='foo',
host='localhost')
@mock.patch.object(profiler_init, 'init_from_conf')
@mock.patch.object(profiler_init, 'init_from_conf', autospec=True)
@mock.patch.object(conf, 'CONF', new=cfg.ConfigOpts())
def test_setup_profiler_without_osprofiler(self, mock_init):
profiler.setup('foo', 'localhost')
+15 -14
View File
@@ -26,8 +26,8 @@ from magnum.tests import base
class TestRpc(base.TestCase):
@mock.patch.object(rpc, 'profiler', None)
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'get_rpc_client')
@mock.patch.object(rpc, 'RequestContextSerializer', autospec=True)
@mock.patch.object(messaging, 'get_rpc_client', autospec=True)
def test_get_client(self, mock_get, mock_ser):
rpc.TRANSPORT = mock.Mock()
tgt = mock.Mock()
@@ -44,8 +44,8 @@ class TestRpc(base.TestCase):
self.assertEqual('client', client)
@mock.patch.object(rpc, 'profiler', mock.Mock())
@mock.patch.object(rpc, 'ProfilerRequestContextSerializer')
@mock.patch.object(messaging, 'get_rpc_client')
@mock.patch.object(rpc, 'ProfilerRequestContextSerializer', autospec=True)
@mock.patch.object(messaging, 'get_rpc_client', autospec=True)
def test_get_client_profiler_enabled(self, mock_get, mock_ser):
rpc.TRANSPORT = mock.Mock()
tgt = mock.Mock()
@@ -62,8 +62,8 @@ class TestRpc(base.TestCase):
self.assertEqual('client', client)
@mock.patch.object(rpc, 'profiler', None)
@mock.patch.object(rpc, 'RequestContextSerializer')
@mock.patch.object(messaging, 'get_rpc_server')
@mock.patch.object(rpc, 'RequestContextSerializer', autospec=True)
@mock.patch.object(messaging, 'get_rpc_server', autospec=True)
def test_get_server(self, mock_get, mock_ser):
rpc.TRANSPORT = mock.Mock()
ser = mock.Mock()
@@ -80,8 +80,8 @@ class TestRpc(base.TestCase):
self.assertEqual('server', server)
@mock.patch.object(rpc, 'profiler', mock.Mock())
@mock.patch.object(rpc, 'ProfilerRequestContextSerializer')
@mock.patch.object(messaging, 'get_rpc_server')
@mock.patch.object(rpc, 'ProfilerRequestContextSerializer', autospec=True)
@mock.patch.object(messaging, 'get_rpc_server', autospec=True)
def test_get_server_profiler_enabled(self, mock_get, mock_ser):
rpc.TRANSPORT = mock.Mock()
ser = mock.Mock()
@@ -98,7 +98,7 @@ class TestRpc(base.TestCase):
access_policy=access_policy)
self.assertEqual('server', server)
@mock.patch.object(messaging, 'TransportURL')
@mock.patch.object(messaging, 'TransportURL', autospec=True)
def test_get_transport_url(self, mock_url):
conf = mock.Mock()
rpc.CONF = conf
@@ -109,7 +109,7 @@ class TestRpc(base.TestCase):
self.assertEqual('foo', url)
mock_url.parse.assert_called_once_with(conf, 'bar')
@mock.patch.object(messaging, 'TransportURL')
@mock.patch.object(messaging, 'TransportURL', autospec=True)
def test_get_transport_url_null(self, mock_url):
conf = mock.Mock()
rpc.CONF = conf
@@ -157,7 +157,8 @@ class TestRpc(base.TestCase):
self.assertEqual(0, len(rpc.EXTRA_EXMODS))
def test_serialize_entity(self):
with mock.patch.object(jsonutils, 'to_primitive') as mock_prim:
with mock.patch.object(
jsonutils, 'to_primitive', autospec=True) as mock_prim:
rpc.JsonPayloadSerializer.serialize_entity('context', 'entity')
mock_prim.assert_called_once_with('entity', convert_instances=True)
@@ -205,7 +206,7 @@ class TestRequestContextSerializer(base.TestCase):
context.to_dict.assert_called_once_with()
@mock.patch.object(context, 'RequestContext')
@mock.patch.object(context, 'RequestContext', autospec=True)
def test_deserialize_context(self, mock_req):
self.ser.deserialize_context('context')
@@ -217,7 +218,7 @@ class TestProfilerRequestContextSerializer(base.TestCase):
super(TestProfilerRequestContextSerializer, self).setUp()
self.ser = rpc.ProfilerRequestContextSerializer(mock.Mock())
@mock.patch('magnum.common.rpc.profiler')
@mock.patch('magnum.common.rpc.profiler', autospec=True)
def test_serialize_context(self, mock_profiler):
prof = mock_profiler.get.return_value
prof.hmac_key = 'swordfish'
@@ -236,7 +237,7 @@ class TestProfilerRequestContextSerializer(base.TestCase):
}
}, self.ser.serialize_context(context))
@mock.patch('magnum.common.rpc.profiler')
@mock.patch('magnum.common.rpc.profiler', autospec=True)
def test_deserialize_context(self, mock_profiler):
serialized = {'project_id': 'test',
'trace_info': {
+8 -8
View File
@@ -21,10 +21,10 @@ from magnum.tests import base
class TestMagnumService(base.BaseTestCase):
@mock.patch.object(logging, 'register_options')
@mock.patch.object(logging, 'setup')
@mock.patch('magnum.common.config.set_config_defaults')
@mock.patch('magnum.common.config.parse_args')
@mock.patch.object(logging, 'register_options', autospec=True)
@mock.patch.object(logging, 'setup', autospec=True)
@mock.patch('magnum.common.config.set_config_defaults', autospec=True)
@mock.patch('magnum.common.config.parse_args', autospec=True)
def test_prepare_service_with_argv_not_none(self, mock_parse, mock_set,
mock_setup, mock_reg):
argv = 'foo'
@@ -37,10 +37,10 @@ class TestMagnumService(base.BaseTestCase):
mock_reg.assert_called_once_with(base.CONF)
mock_set.assert_called_once_with()
@mock.patch.object(logging, 'register_options')
@mock.patch.object(logging, 'setup')
@mock.patch('magnum.common.config.set_config_defaults')
@mock.patch('magnum.common.config.parse_args')
@mock.patch.object(logging, 'register_options', autospec=True)
@mock.patch.object(logging, 'setup', autospec=True)
@mock.patch('magnum.common.config.set_config_defaults', autospec=True)
@mock.patch('magnum.common.config.parse_args', autospec=True)
def test_prepare_service_with_argv_none(self, mock_parse, mock_set,
mock_setup, mock_reg):
argv = None
+18 -14
View File
@@ -157,15 +157,15 @@ grep foo
os.unlink(tmpfilename)
os.unlink(tmpfilename2)
@mock.patch.object(processutils, 'execute')
@mock.patch.object(os.environ, 'copy', return_value={})
@mock.patch.object(processutils, 'execute', autospec=True)
@mock.patch.object(os.environ, 'copy', return_value={}, autospec=True)
def test_execute_use_standard_locale_no_env_variables(self, env_mock,
execute_mock):
utils.execute('foo', use_standard_locale=True)
execute_mock.assert_called_once_with('foo',
env_variables={'LC_ALL': 'C'})
@mock.patch.object(processutils, 'execute')
@mock.patch.object(processutils, 'execute', autospec=True)
def test_execute_use_standard_locale_with_env_variables(self,
execute_mock):
utils.execute('foo', use_standard_locale=True,
@@ -174,7 +174,7 @@ grep foo
env_variables={'LC_ALL': 'C',
'foo': 'bar'})
@mock.patch.object(processutils, 'execute')
@mock.patch.object(processutils, 'execute', autospec=True)
def test_execute_not_use_standard_locale(self, execute_mock):
utils.execute('foo', use_standard_locale=False,
env_variables={'foo': 'bar'})
@@ -182,26 +182,30 @@ grep foo
env_variables={'foo': 'bar'})
def test_execute_get_root_helper(self):
with mock.patch.object(processutils, 'execute') as execute_mock:
with mock.patch.object(
processutils, 'execute', autospec=True) as execute_mock:
helper = utils._get_root_helper()
utils.execute('foo', run_as_root=True)
execute_mock.assert_called_once_with('foo', run_as_root=True,
root_helper=helper)
def test_execute_without_root_helper(self):
with mock.patch.object(processutils, 'execute') as execute_mock:
with mock.patch.object(
processutils, 'execute', autospec=True) as execute_mock:
utils.execute('foo', run_as_root=False)
execute_mock.assert_called_once_with('foo', run_as_root=False)
def test_validate_and_normalize_mac(self):
mac = 'AA:BB:CC:DD:EE:FF'
with mock.patch.object(netutils, 'is_valid_mac') as m_mock:
with mock.patch.object(
netutils, 'is_valid_mac', autospec=True) as m_mock:
m_mock.return_value = True
self.assertEqual(mac.lower(),
utils.validate_and_normalize_mac(mac))
def test_validate_and_normalize_mac_invalid_format(self):
with mock.patch.object(netutils, 'is_valid_mac') as m_mock:
with mock.patch.object(
netutils, 'is_valid_mac', autospec=True) as m_mock:
m_mock.return_value = False
self.assertRaises(exception.InvalidMAC,
utils.validate_and_normalize_mac, 'invalid-mac')
@@ -234,13 +238,13 @@ class TempFilesTestCase(base.TestCase):
dirname = tempdir
self.assertFalse(os.path.exists(dirname))
@mock.patch.object(shutil, 'rmtree')
@mock.patch.object(tempfile, 'mkdtemp')
@mock.patch.object(shutil, 'rmtree', autospec=True)
@mock.patch.object(tempfile, 'mkdtemp', autospec=True)
def test_tempdir_mocked(self, mkdtemp_mock, rmtree_mock):
self.config(tempdir='abc')
mkdtemp_mock.return_value = 'temp-dir'
kwargs = {'a': 'b'}
kwargs = {'prefix': 'b'}
with utils.tempdir(**kwargs) as tempdir:
self.assertEqual('temp-dir', tempdir)
@@ -249,9 +253,9 @@ class TempFilesTestCase(base.TestCase):
mkdtemp_mock.assert_called_once_with(**kwargs)
rmtree_mock.assert_called_once_with(tempdir_created)
@mock.patch.object(utils, 'LOG')
@mock.patch.object(shutil, 'rmtree')
@mock.patch.object(tempfile, 'mkdtemp')
@mock.patch.object(utils, 'LOG', autospec=True)
@mock.patch.object(shutil, 'rmtree', autospec=True)
@mock.patch.object(tempfile, 'mkdtemp', autospec=True)
def test_tempdir_mocked_error_on_rmtree(self, mkdtemp_mock, rmtree_mock,
log_mock):
@@ -23,8 +23,8 @@ class TestX509Operations(base.BaseTestCase):
def setUp(self):
super(TestX509Operations, self).setUp()
@mock.patch.object(serialization, 'NoEncryption')
@mock.patch.object(operations, '_load_pem_private_key')
@mock.patch.object(serialization, 'NoEncryption', autospec=True)
@mock.patch.object(operations, '_load_pem_private_key', autospec=True)
def test_decrypt_key(self, mock_load_pem_private_key,
mock_no_encryption_class):
mock_private_key = mock.MagicMock()
+3 -3
View File
@@ -205,7 +205,7 @@ class TestX509(base.BaseTestCase):
private_key = operations._load_pem_private_key(private_key)
self.assertIsInstance(private_key, rsa.RSAPrivateKey)
@mock.patch('cryptography.x509.load_pem_x509_csr')
@mock.patch('cryptography.x509.load_pem_x509_csr', autospec=True)
def test_sign_with_unicode_csr(self, mock_load_pem):
ca_key = self._generate_private_key()
private_key = self._generate_private_key()
@@ -217,7 +217,7 @@ class TestX509(base.BaseTestCase):
operations.sign(csr, self.issuer_name, ca_key,
skip_validation=True)
@mock.patch('cryptography.x509.load_pem_x509_csr')
@mock.patch('cryptography.x509.load_pem_x509_csr', autospec=True)
def test_sign_empty_chars(self, mock_load_pem):
ca_key = self._generate_private_key()
private_key = self._generate_private_key()
@@ -234,7 +234,7 @@ class TestX509(base.BaseTestCase):
certificate.strip())
# If a subject key identifier is given in the CSR, ensure it is added
@mock.patch('cryptography.x509.load_pem_x509_csr')
@mock.patch('cryptography.x509.load_pem_x509_csr', autospec=True)
def test_sign_subject_key_identifier(self, mock_load_pem):
ca_key = self._generate_private_key()
private_key = self._generate_private_key()
@@ -32,7 +32,8 @@ class CertManagerTestCase(base.BaseTestCase):
def setUp(self):
super(CertManagerTestCase, self).setUp()
cert_manager_patcher = mock.patch.object(cert_manager, 'cert_manager')
cert_manager_patcher = mock.patch.object(
cert_manager, 'cert_manager', autospec=True)
self.cert_manager = cert_manager_patcher.start()
self.addCleanup(cert_manager_patcher.stop)
@@ -42,8 +43,9 @@ class CertManagerTestCase(base.BaseTestCase):
self.cert_manager_backend.CertManager = mock.MagicMock()
self.CertManager = self.cert_manager_backend.CertManager
@mock.patch('magnum.common.x509.operations.generate_ca_certificate')
@mock.patch('magnum.common.short_id.generate_id')
@mock.patch(
'magnum.common.x509.operations.generate_ca_certificate', autospec=True)
@mock.patch('magnum.common.short_id.generate_id', autospec=True)
def test_generate_ca_cert(self, mock_generate_id, mock_generate_ca_cert):
expected_ca_name = 'ca-name'
expected_ca_password = 'password'
@@ -69,8 +71,10 @@ class CertManagerTestCase(base.BaseTestCase):
context=None
)
@mock.patch('magnum.common.x509.operations.generate_client_certificate')
@mock.patch('magnum.common.short_id.generate_id')
@mock.patch(
'magnum.common.x509.operations.generate_client_certificate',
autospec=True)
@mock.patch('magnum.common.short_id.generate_id', autospec=True)
def test_generate_client_cert(self, mock_generate_id, mock_generate_cert):
expected_name = 'admin'
expected_organization_name = 'system:masters'
@@ -138,9 +142,9 @@ class CertManagerTestCase(base.BaseTestCase):
context=None)
@mock.patch('magnum.conductor.handlers.common.cert_manager.'
'_generate_client_cert')
'_generate_client_cert', autospec=True)
@mock.patch('magnum.conductor.handlers.common.cert_manager.'
'_generate_ca_cert')
'_generate_ca_cert', autospec=True)
def test_generate_certificates(self, mock_generate_ca_cert,
mock_generate_client_cert):
expected_ca_name = 'ca-name'
@@ -153,9 +157,9 @@ class CertManagerTestCase(base.BaseTestCase):
mock_generate_client_cert)
@mock.patch('magnum.conductor.handlers.common.cert_manager.'
'_generate_client_cert')
'_generate_client_cert', autospec=True)
@mock.patch('magnum.conductor.handlers.common.cert_manager.'
'_generate_ca_cert')
'_generate_ca_cert', autospec=True)
def test_generate_certificates_without_name(self, mock_generate_ca_cert,
mock_generate_client_cert):
expected_ca_name = 'ca-uuid'
@@ -169,7 +173,7 @@ class CertManagerTestCase(base.BaseTestCase):
mock_generate_client_cert)
@mock.patch('magnum.conductor.handlers.common.cert_manager.'
'_get_issuer_name')
'_get_issuer_name', autospec=True)
def test_generate_certificates_with_error(self, mock_get_issuer_name):
mock_cluster = mock.MagicMock()
mock_get_issuer_name.side_effect = exception.MagnumException()
@@ -178,7 +182,7 @@ class CertManagerTestCase(base.BaseTestCase):
cert_manager.generate_certificates_to_cluster,
mock_cluster)
@mock.patch('magnum.common.x509.operations.sign')
@mock.patch('magnum.common.x509.operations.sign', autospec=True)
def test_sign_node_certificate(self, mock_x509_sign):
mock_cluster = mock.MagicMock()
mock_cluster.uuid = "mock_cluster_uuid"
@@ -200,7 +204,7 @@ class CertManagerTestCase(base.BaseTestCase):
passphrase)
self.assertEqual(mock.sentinel.signed_cert, cluster_ca_cert)
@mock.patch('magnum.common.x509.operations.sign')
@mock.patch('magnum.common.x509.operations.sign', autospec=True)
def test_sign_node_certificate_without_cluster_name(self, mock_x509_sign):
mock_cluster = mock.MagicMock()
mock_cluster.name = None
@@ -314,7 +318,8 @@ class CertManagerTestCase(base.BaseTestCase):
self.assertEqual(mock_cert.get_certificate.return_value,
cluster_magnum_cert.read())
@mock.patch('magnum.conductor.handlers.common.cert_manager.LOG')
@mock.patch(
'magnum.conductor.handlers.common.cert_manager.LOG', autospec=True)
def test_create_client_files_temp_no_dir(self, mock_logging):
mock_cluster = mock.MagicMock()
mock_cluster.uuid = "mock_cluster_uuid"
@@ -23,7 +23,7 @@ class TestSignConductor(base.TestCase):
super(TestSignConductor, self).setUp()
self.ca_handler = ca_conductor.Handler()
@mock.patch.object(ca_conductor, 'cert_manager')
@mock.patch.object(ca_conductor, 'cert_manager', autospec=True)
def test_sign_certificate(self, mock_cert_manager):
mock_cluster = mock.MagicMock()
mock_certificate = mock.MagicMock()
@@ -40,7 +40,7 @@ class TestSignConductor(base.TestCase):
)
self.assertEqual('fake-pem', actual_cert.pem)
@mock.patch.object(ca_conductor, 'cert_manager')
@mock.patch.object(ca_conductor, 'cert_manager', autospec=True)
def test_get_ca_certificate(self, mock_cert_manager):
mock_cluster = mock.MagicMock()
mock_cluster.uuid = 'cluster-uuid'
+6 -6
View File
@@ -59,7 +59,7 @@ class MonitorsTestCase(base.TestCase):
]
self.k8s_monitor = k8s_monitor.K8sMonitor(self.context, self.cluster)
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_pull_data_success(self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
@@ -178,7 +178,7 @@ class MonitorsTestCase(base.TestCase):
cpu_util = self.k8s_monitor.compute_cpu_util()
self.assertEqual(0, cpu_util)
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_health_healthy(self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
@@ -220,7 +220,7 @@ class MonitorsTestCase(base.TestCase):
self.assertEqual(self.k8s_monitor.data['health_status_reason'],
{'api': 'ok', 'k8s-cluster-node-0.Ready': True})
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_health_unhealthy_api(self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
@@ -262,7 +262,7 @@ class MonitorsTestCase(base.TestCase):
self.assertEqual(self.k8s_monitor.data['health_status_reason'],
{'api': 'failed'})
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_health_unhealthy_node(self, mock_create_client_files):
mock_create_client_files.return_value = (
tempfile.NamedTemporaryFile(),
@@ -318,7 +318,7 @@ class MonitorsTestCase(base.TestCase):
{'api': 'ok', 'k8s-cluster-node-0.Ready': False,
'k8s-cluster-node-1.Ready': True})
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_health_unreachable_cluster(
self, mock_create_client_files):
mock_create_client_files.return_value = (
@@ -343,7 +343,7 @@ class MonitorsTestCase(base.TestCase):
self.assertEqual(self.k8s_monitor.data['health_status'],
m_fields.ClusterHealthStatus.UNKNOWN)
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_k8s_monitor_health_unreachable_with_master_lb(
self, mock_create_client_files):
mock_create_client_files.return_value = (
+4 -2
View File
@@ -64,10 +64,12 @@ class RPCAPITestCase(base.DbTestCase):
if expected_retval:
return expected_retval
with mock.patch.object(rpcapi._client, "prepare") as mock_prepared:
with mock.patch.object(
rpcapi._client, "prepare", autospec=True) as mock_prepared:
mock_prepared.side_effect = _fake_prepare_method
with mock.patch.object(rpcapi._client, rpc_method) as mock_method:
with mock.patch.object(
rpcapi._client, rpc_method, autospec=True) as mock_method:
mock_method.side_effect = _fake_rpc_method
retval = getattr(rpcapi, method)(**kwargs)
self.assertEqual(expected_retval, retval)
@@ -27,8 +27,8 @@ class TestK8sScaleManager(base.TestCase):
super(TestK8sScaleManager, self).setUp()
self.requests_mock = self.useFixture(fixture.Fixture())
@mock.patch('magnum.objects.Cluster.get_by_uuid')
@mock.patch('magnum.conductor.k8s_api.create_client_files')
@mock.patch('magnum.objects.Cluster.get_by_uuid', autospec=True)
@mock.patch('magnum.conductor.k8s_api.create_client_files', autospec=True)
def test_get_hosts_with_container(
self, mock_create_client_files, mock_get):
mock_cluster = mock.MagicMock()
+6 -4
View File
@@ -33,26 +33,28 @@ class ConfTestCase(base.TestCase):
self.assertIsInstance(opt, cfg.Opt)
def test_list_module_name_invalid_mods(self):
with mock.patch('pkgutil.iter_modules') as mock_mods:
with mock.patch('pkgutil.iter_modules', autospec=True) as mock_mods:
mock_mods.return_value = [(None, 'foo', True),
(None, 'opts', False)]
self.assertEqual([], opts._list_module_names())
def test_list_module_name_valid_mods(self):
with mock.patch('pkgutil.iter_modules') as mock_mods:
with mock.patch('pkgutil.iter_modules', autospec=True) as mock_mods:
mock_mods.return_value = [(None, 'foo', False)]
self.assertEqual(['foo'], opts._list_module_names())
def test_import_mods_no_func(self):
modules = ['foo', 'bar']
with mock.patch('importlib.import_module') as mock_import:
with mock.patch(
'importlib.import_module', autospec=True) as mock_import:
mock_import.return_value = mock.sentinel.mods
self.assertRaises(AttributeError, opts._import_modules, modules)
mock_import.assert_called_once_with('magnum.conf.foo')
def test_import_mods_valid_func(self):
modules = ['foo', 'bar']
with mock.patch('importlib.import_module') as mock_import:
with mock.patch(
'importlib.import_module', autospec=True) as mock_import:
mock_mod = mock.MagicMock()
mock_import.return_value = mock_mod
self.assertEqual([mock_mod, mock_mod],
+4 -4
View File
@@ -25,7 +25,7 @@ class TestGetDefaultDriver(base.TestCase):
cls = mock.MagicMock()
return ep, cls
@mock.patch.object(driver.Driver, 'load_entry_points')
@mock.patch.object(driver.Driver, 'load_entry_points', autospec=True)
def test_get_default_driver_from_config(self, mock_load):
"""Returns CONF.drivers.default_driver"""
self.config(default_driver='heat-k8s', group='drivers')
@@ -34,7 +34,7 @@ class TestGetDefaultDriver(base.TestCase):
self.assertEqual('heat-k8s', result)
mock_load.assert_called_once()
@mock.patch.object(driver.Driver, 'load_entry_points')
@mock.patch.object(driver.Driver, 'load_entry_points', autospec=True)
def test_get_default_driver_from_config_not_registered(self, mock_load):
"""Raises ClusterDriverNotSupported when driver is absent."""
self.config(default_driver='typo-driver', group='drivers')
@@ -42,7 +42,7 @@ class TestGetDefaultDriver(base.TestCase):
self.assertRaises(exception.ClusterDriverNotSupported,
driver.Driver.get_default_driver)
@mock.patch.object(driver.Driver, 'load_entry_points')
@mock.patch.object(driver.Driver, 'load_entry_points', autospec=True)
def test_get_default_driver_first_sorted(self, mock_load):
"""Returns the alphabetically first driver when config is not set."""
mock_load.return_value = iter([
@@ -53,7 +53,7 @@ class TestGetDefaultDriver(base.TestCase):
result = driver.Driver.get_default_driver()
self.assertEqual('alpha_driver', result)
@mock.patch.object(driver.Driver, 'load_entry_points')
@mock.patch.object(driver.Driver, 'load_entry_points', autospec=True)
def test_get_default_driver_no_drivers(self, mock_load):
"""Returns None when no drivers are available and config is not set."""
mock_load.return_value = iter([])
+5 -5
View File
@@ -41,7 +41,7 @@ class TestClusterObject(base.DbTestCase):
self.fake_cluster['health_status'] = 'HEALTHY'
self.fake_cluster['health_status_reason'] = {}
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid', autospec=True)
def test_get_by_id(self, mock_cluster_template_get):
cluster_id = self.fake_cluster['id']
with mock.patch.object(self.dbapi, 'get_cluster_by_id',
@@ -54,7 +54,7 @@ class TestClusterObject(base.DbTestCase):
self.assertEqual(cluster.cluster_template_id,
cluster.cluster_template.uuid)
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid', autospec=True)
def test_get_by_uuid(self, mock_cluster_template_get):
uuid = self.fake_cluster['uuid']
with mock.patch.object(self.dbapi, 'get_cluster_by_uuid',
@@ -67,7 +67,7 @@ class TestClusterObject(base.DbTestCase):
self.assertEqual(cluster.cluster_template_id,
cluster.cluster_template.uuid)
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid', autospec=True)
def test_get_by_name(self, mock_cluster_template_get):
name = self.fake_cluster['name']
with mock.patch.object(self.dbapi, 'get_cluster_by_name',
@@ -84,7 +84,7 @@ class TestClusterObject(base.DbTestCase):
self.assertRaises(exception.InvalidIdentity,
objects.Cluster.get, self.context, 'not-a-uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid', autospec=True)
def test_list(self, mock_cluster_template_get):
with mock.patch.object(self.dbapi, 'get_cluster_list',
autospec=True) as mock_get_list:
@@ -98,7 +98,7 @@ class TestClusterObject(base.DbTestCase):
self.assertEqual(clusters[0].cluster_template_id,
clusters[0].cluster_template.uuid)
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid')
@mock.patch('magnum.objects.ClusterTemplate.get_by_uuid', autospec=True)
def test_list_all(self, mock_cluster_template_get):
with mock.patch.object(self.dbapi, 'get_cluster_list',
autospec=True) as mock_get_list:
+2 -1
View File
@@ -407,7 +407,8 @@ class TestObjectSerializer(test_base.TestCase):
for item in thing2:
self.assertIsInstance(item, MyObj)
@mock.patch('magnum.objects.base.MagnumObject.indirection_api')
@mock.patch(
'magnum.objects.base.MagnumObject.indirection_api', autospec=True)
def _test_deserialize_entity_newer(self, obj_version, backported_to,
mock_indirection_api,
my_version='1.6'):
+24 -17
View File
@@ -173,10 +173,12 @@ class PeriodicTestCase(base.TestCase):
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=fakes.FakeLoopingCall)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver_for_cluster')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch.object(dbapi.Connection, 'destroy_nodegroup')
@mock.patch.object(dbapi.Connection, 'destroy_cluster')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver_for_cluster',
autospec=True)
@mock.patch('magnum.objects.Cluster.list', autospec=True)
@mock.patch.object(dbapi.Connection, 'destroy_nodegroup', autospec=True)
@mock.patch.object(dbapi.Connection, 'destroy_cluster', autospec=True)
def test_sync_cluster_status_changes(self, mock_db_destroy,
mock_ng_destroy,
mock_cluster_list,
@@ -202,7 +204,8 @@ class PeriodicTestCase(base.TestCase):
self.cluster3.status)
self.assertEqual('fake_reason_33', self.cluster3.status_reason)
self.assertEqual(2, mock_ng_destroy.call_count)
mock_db_destroy.assert_called_once_with(self.cluster4.uuid)
mock_db_destroy.assert_called_once_with(mock.ANY,
self.cluster4.uuid)
self.assertEqual(cluster_status.ROLLBACK_COMPLETE,
self.cluster5.status)
self.assertEqual('fake_reason_55', self.cluster5.status_reason)
@@ -211,8 +214,10 @@ class PeriodicTestCase(base.TestCase):
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=fakes.FakeLoopingCall)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver_for_cluster')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver_for_cluster',
autospec=True)
@mock.patch('magnum.objects.Cluster.list', autospec=True)
def test_sync_cluster_status_not_changes(self, mock_cluster_list,
mock_get_driver):
@@ -243,10 +248,12 @@ class PeriodicTestCase(base.TestCase):
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=fakes.FakeLoopingCall)
@mock.patch('magnum.drivers.common.driver.Driver.get_driver_for_cluster')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch.object(dbapi.Connection, 'destroy_cluster')
@mock.patch.object(dbapi.Connection, 'destroy_nodegroup')
@mock.patch(
'magnum.drivers.common.driver.Driver.get_driver_for_cluster',
autospec=True)
@mock.patch('magnum.objects.Cluster.list', autospec=True)
@mock.patch.object(dbapi.Connection, 'destroy_cluster', autospec=True)
@mock.patch.object(dbapi.Connection, 'destroy_nodegroup', autospec=True)
def test_sync_cluster_status_stack_not_found(self, mock_ng_destroy,
mock_db_destroy,
mock_cluster_list,
@@ -271,8 +278,8 @@ class PeriodicTestCase(base.TestCase):
self.cluster5.status)
self.assertEqual('Stack 55 not found', self.cluster5.status_reason)
mock_db_destroy.assert_has_calls([
mock.call(self.cluster2.uuid),
mock.call(self.cluster4.uuid)
mock.call(mock.ANY, self.cluster2.uuid),
mock.call(mock.ANY, self.cluster4.uuid)
])
self.assertEqual(2, mock_db_destroy.call_count)
notifications = fake_notifier.NOTIFICATIONS
@@ -280,10 +287,10 @@ class PeriodicTestCase(base.TestCase):
@mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
new=fakes.FakeLoopingCall)
@mock.patch('magnum.conductor.monitors.create_monitor')
@mock.patch('magnum.objects.Cluster.list')
@mock.patch('magnum.common.rpc.get_notifier')
@mock.patch('magnum.common.context.make_admin_context')
@mock.patch('magnum.conductor.monitors.create_monitor', autospec=True)
@mock.patch('magnum.objects.Cluster.list', autospec=True)
@mock.patch('magnum.common.rpc.get_notifier', autospec=True)
@mock.patch('magnum.common.context.make_admin_context', autospec=True)
def test_sync_cluster_health_status(self, mock_make_admin_context,
mock_get_notifier, mock_cluster_list,
mock_create_monitor):
@@ -32,9 +32,10 @@ class MagnumServicePeriodicTestCase(base.TestCase):
self.fake_ms = FakeMS()
self.fake_ms_refresh = mock_magnum_service_refresh
@mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
@mock.patch.object(objects.MagnumService, 'create')
@mock.patch.object(objects.MagnumService, 'report_state_up')
@mock.patch.object(
objects.MagnumService, 'get_by_host_and_binary', autospec=True)
@mock.patch.object(objects.MagnumService, 'create', autospec=True)
@mock.patch.object(objects.MagnumService, 'report_state_up', autospec=True)
def test_update_magnum_service_firsttime(self,
mock_ms_refresh,
mock_ms_create,
@@ -48,11 +49,12 @@ class MagnumServicePeriodicTestCase(base.TestCase):
mock_ms_get.assert_called_once_with(mock.ANY, p_task.host,
p_task.binary)
mock_ms_create.assert_called_once_with()
mock_ms_refresh.assert_called_once_with()
mock_ms_create.assert_called_once_with(mock.ANY)
mock_ms_refresh.assert_called_once_with(mock.ANY)
@mock.patch.object(objects.MagnumService, 'get_by_host_and_binary')
@mock.patch.object(objects.MagnumService, 'create')
@mock.patch.object(
objects.MagnumService, 'get_by_host_and_binary', autospec=True)
@mock.patch.object(objects.MagnumService, 'create', autospec=True)
def test_update_magnum_service_on_restart(self,
mock_ms_create,
mock_ms_get):
+2 -1
View File
@@ -101,8 +101,9 @@ commands =
# H205 Use assert(Greater|Less)(Equal) for comparison
# H904 Delay string interpolations at logging calls
# H905 Do not import eventlet
# H210 Use autospec True or Pecan.request in majority of the tests
filename = *.py
enable-extensions = H106,H203,H204,H205,H904,H905
enable-extensions = H106,H203,H204,H205,H904,H905,H210
exclude = .venv,.git,.tox,dist,*lib/python*,*egg,build,tools,releasenotes
[flake8:local-plugins]