Remove unused enforce_cluster_types decorator
Closes-Bug: #1659587 Change-Id: I14e83e4d72cddffb86173317320864dbe49500f3
This commit is contained in:
parent
25aa5b06ff
commit
2e521c2ebc
|
@ -15,7 +15,6 @@
|
|||
|
||||
import decorator
|
||||
|
||||
from oslo_utils import uuidutils
|
||||
import pecan
|
||||
|
||||
from magnum.api import utils as api_utils
|
||||
|
@ -29,38 +28,6 @@ CONF = magnum.conf.CONF
|
|||
cluster_update_allowed_properties = set(['node_count'])
|
||||
|
||||
|
||||
def enforce_cluster_types(*cluster_types):
|
||||
"""Enforce that cluster_type is in supported list."""
|
||||
@decorator.decorator
|
||||
def wrapper(func, *args, **kwargs):
|
||||
# Note(eliqiao): This decorator has some assumptions
|
||||
# args[1] should be an APIBase instance or
|
||||
# args[2] should be a cluster_ident
|
||||
obj = args[1]
|
||||
if hasattr(obj, 'cluster_uuid'):
|
||||
cluster = objects.Cluster.get_by_uuid(pecan.request.context,
|
||||
obj.cluster_uuid)
|
||||
else:
|
||||
cluster_ident = args[2]
|
||||
if uuidutils.is_uuid_like(cluster_ident):
|
||||
cluster = objects.Cluster.get_by_uuid(pecan.request.context,
|
||||
cluster_ident)
|
||||
else:
|
||||
cluster = objects.Cluster.get_by_name(pecan.request.context,
|
||||
cluster_ident)
|
||||
|
||||
if cluster.cluster_template.coe not in cluster_types:
|
||||
raise exception.InvalidParameterValue(_(
|
||||
'Cannot fulfill request with a %(cluster_type)s cluster, '
|
||||
'expecting a %(supported_cluster_types)s cluster.') %
|
||||
{'cluster_type': cluster.cluster_template.coe,
|
||||
'supported_cluster_types': '/'.join(cluster_types)})
|
||||
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def enforce_network_driver_types_create():
|
||||
@decorator.decorator
|
||||
def wrapper(func, *args, **kwargs):
|
||||
|
|
|
@ -28,149 +28,6 @@ CONF = magnum.conf.CONF
|
|||
|
||||
class TestValidation(base.BaseTestCase):
|
||||
|
||||
def _test_enforce_cluster_types(
|
||||
self,
|
||||
mock_cluster_get_by_uuid,
|
||||
mock_pecan_request,
|
||||
cluster_type,
|
||||
allowed_cluster_types,
|
||||
assert_raised=False,
|
||||
*args):
|
||||
|
||||
@v.enforce_cluster_types(*allowed_cluster_types)
|
||||
def test(self, *args):
|
||||
if hasattr(args[0], 'cluster_uuid'):
|
||||
return args[0].name
|
||||
else:
|
||||
return args[1]
|
||||
|
||||
context = mock_pecan_request.context
|
||||
cluster = mock.MagicMock()
|
||||
cluster.cluster_template_id = 'cluster_template_id'
|
||||
cluster_template = obj_utils.get_test_cluster_template(
|
||||
context, uuid='cluster_template_id', coe=cluster_type)
|
||||
cluster.cluster_template = cluster_template
|
||||
|
||||
mock_cluster_get_by_uuid.return_value = cluster
|
||||
|
||||
if assert_raised:
|
||||
self.assertRaises(
|
||||
exception.InvalidParameterValue, test, self, *args)
|
||||
else:
|
||||
ret = test(self, *args)
|
||||
if hasattr(args[0], 'cluster_uuid'):
|
||||
mock_cluster_get_by_uuid.assert_called_once_with(
|
||||
context, args[0].cluster_uuid)
|
||||
self.assertEqual(args[0].name, ret)
|
||||
else:
|
||||
mock_cluster_get_by_uuid.assert_called_once_with(
|
||||
context, args[1])
|
||||
self.assertEqual(args[1], ret)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_uuid')
|
||||
def test_enforce_cluster_types_one_allowed(
|
||||
self,
|
||||
mock_cluster_get_by_uuid,
|
||||
mock_pecan_request):
|
||||
|
||||
obj = mock.MagicMock()
|
||||
obj.name = 'test_object'
|
||||
obj.cluster_uuid = 'cluster_uuid'
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['swarm']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, False, obj)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_uuid')
|
||||
def test_enforce_cluster_types_two_allowed(
|
||||
self,
|
||||
mock_cluster_get_by_uuid,
|
||||
mock_pecan_request):
|
||||
|
||||
obj = mock.MagicMock()
|
||||
obj.name = 'test_object'
|
||||
obj.cluster_uuid = 'cluster_uuid'
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['swarm', 'mesos']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, False, obj)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_uuid')
|
||||
def test_enforce_cluster_types_not_allowed(
|
||||
self,
|
||||
mock_cluster_get_by_uuid,
|
||||
mock_pecan_request):
|
||||
|
||||
obj = mock.MagicMock()
|
||||
obj.name = 'test_object'
|
||||
obj.cluster_uuid = 'cluster_uuid'
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['mesos']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types,
|
||||
True, obj)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_uuid')
|
||||
def test_enforce_cluster_types_with_cluster_uuid(self,
|
||||
mock_cluster_get_by_uuid,
|
||||
mock_pecan_request):
|
||||
|
||||
cluster_ident = 'e74c40e0-d825-11e2-a28f-0800200c9a66'
|
||||
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['swarm']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, False,
|
||||
None, cluster_ident)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_uuid')
|
||||
def test_enforce_cluster_types_with_cluster_uuid_not_allowed(
|
||||
self, mock_cluster_get_by_uuid, mock_pecan_request):
|
||||
|
||||
cluster_ident = 'e74c40e0-d825-11e2-a28f-0800200c9a66'
|
||||
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['mesos']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, True,
|
||||
None, cluster_ident)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_name')
|
||||
def test_enforce_cluster_types_with_cluster_name(
|
||||
self, mock_cluster_get_by_uuid, mock_pecan_request):
|
||||
|
||||
cluster_ident = 'cluster_name'
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['swarm']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, False,
|
||||
None, cluster_ident)
|
||||
|
||||
@mock.patch('pecan.request')
|
||||
@mock.patch('magnum.objects.Cluster.get_by_name')
|
||||
def test_enforce_cluster_types_with_cluster_name_not_allowed(
|
||||
self, mock_cluster_get_by_uuid, mock_pecan_request):
|
||||
|
||||
cluster_ident = 'cluster_name'
|
||||
cluster_type = 'swarm'
|
||||
allowed_cluster_types = ['mesos']
|
||||
self._test_enforce_cluster_types(
|
||||
mock_cluster_get_by_uuid, mock_pecan_request,
|
||||
cluster_type, allowed_cluster_types, True,
|
||||
None, cluster_ident)
|
||||
|
||||
def _test_enforce_network_driver_types_create(
|
||||
self,
|
||||
network_driver_type,
|
||||
|
|
Loading…
Reference in New Issue