Remove 'priority' and 'level' from API layer
As we all agreed, we are removing priority and level support from API layer now. Change-Id: I62552b1540500554bc4a3483405e037a6f3ef6c1
This commit is contained in:
parent
7773f1eec1
commit
64b34dc47d
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
other:
|
||||
- The property 'priority' and 'level' are removed from policy create/update.
|
|
@ -25,34 +25,6 @@ from senlin.common import wsgi
|
|||
from senlin.rpc import client as rpc_client
|
||||
|
||||
|
||||
class PolicyData(object):
|
||||
'''The data accompanying a POST/PUT request to create/update a policy.'''
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
def name(self):
|
||||
if consts.POLICY_NAME not in self.data:
|
||||
raise exc.HTTPBadRequest(_("No policy name specified"))
|
||||
return self.data[consts.POLICY_NAME]
|
||||
|
||||
def spec(self):
|
||||
if consts.POLICY_SPEC not in self.data:
|
||||
raise exc.HTTPBadRequest(_("No policy spec provided"))
|
||||
return self.data[consts.POLICY_SPEC]
|
||||
|
||||
def level(self):
|
||||
value = self.data.get(consts.POLICY_LEVEL, None)
|
||||
if value is not None:
|
||||
value = utils.parse_int_param('level', value)
|
||||
return value
|
||||
|
||||
def cooldown(self):
|
||||
value = self.data.get(consts.POLICY_COOLDOWN, None)
|
||||
if value is not None:
|
||||
value = utils.parse_int_param('cooldown', value)
|
||||
return value
|
||||
|
||||
|
||||
class PolicyController(object):
|
||||
'''WSGI controller for policy resource in Senlin v1 API.'''
|
||||
|
||||
|
@ -71,8 +43,6 @@ class PolicyController(object):
|
|||
filter_whitelist = {
|
||||
'name': 'mixed',
|
||||
'type': 'mixed',
|
||||
'level': 'mixed',
|
||||
'cooldown': 'mixed',
|
||||
}
|
||||
param_whitelist = {
|
||||
'limit': 'single',
|
||||
|
@ -103,15 +73,18 @@ class PolicyController(object):
|
|||
|
||||
@util.policy_enforce
|
||||
def create(self, req, body):
|
||||
policy_data = body.get('policy', None)
|
||||
if policy_data is None:
|
||||
data = body.get('policy', None)
|
||||
if data is None:
|
||||
raise exc.HTTPBadRequest(_("Malformed request data, missing "
|
||||
"'policy' key in request body."))
|
||||
name = data.get(consts.POLICY_NAME, None)
|
||||
if not name:
|
||||
raise exc.HTTPBadRequest(_("No policy name specified"))
|
||||
spec = data.get(consts.POLICY_SPEC, None)
|
||||
if not spec:
|
||||
raise exc.HTTPBadRequest(_("No policy spec provided"))
|
||||
|
||||
data = PolicyData(policy_data)
|
||||
result = self.rpc_client.policy_create(req.context, data.name(),
|
||||
data.spec(), data.level(),
|
||||
data.cooldown())
|
||||
result = self.rpc_client.policy_create(req.context, name, spec)
|
||||
|
||||
return {'policy': result}
|
||||
|
||||
|
@ -122,29 +95,23 @@ class PolicyController(object):
|
|||
|
||||
@util.policy_enforce
|
||||
def update(self, req, policy_id, body):
|
||||
policy_data = body.get('policy', None)
|
||||
if policy_data is None:
|
||||
data = body.get('policy', None)
|
||||
if data is None:
|
||||
raise exc.HTTPBadRequest(_("Malformed request data, missing "
|
||||
"'policy' key in request body."))
|
||||
|
||||
spec = policy_data.get(consts.POLICY_SPEC)
|
||||
spec = data.get(consts.POLICY_SPEC)
|
||||
if spec is not None:
|
||||
msg = _("Updating the spec of a policy is not supported because "
|
||||
"it may cause state conflicts in engine.")
|
||||
raise exc.HTTPBadRequest(msg)
|
||||
|
||||
name = policy_data.get(consts.POLICY_NAME, None)
|
||||
# Name is the only property that can be updated
|
||||
name = data.get(consts.POLICY_NAME, None)
|
||||
if not name:
|
||||
raise exc.HTTPBadRequest(_("Policy name not specified."))
|
||||
|
||||
level = policy_data.get(consts.POLICY_LEVEL, None)
|
||||
if level is not None:
|
||||
level = utils.parse_int_param(consts.POLICY_LEVEL, level)
|
||||
|
||||
cooldown = policy_data.get(consts.POLICY_COOLDOWN, None)
|
||||
if cooldown is not None:
|
||||
cooldown = utils.parse_int_param(consts.POLICY_COOLDOWN, cooldown)
|
||||
|
||||
policy = self.rpc_client.policy_update(req.context, policy_id, name,
|
||||
level, cooldown)
|
||||
policy = self.rpc_client.policy_update(req.context, policy_id, name)
|
||||
|
||||
return {'policy': policy}
|
||||
|
||||
|
|
|
@ -120,20 +120,18 @@ class EngineClient(object):
|
|||
limit=limit, marker=marker, sort=sort,
|
||||
project_safe=project_safe))
|
||||
|
||||
def policy_create(self, ctxt, name, spec, level, cooldown):
|
||||
def policy_create(self, ctxt, name, spec):
|
||||
return self.call(ctxt,
|
||||
self.make_msg('policy_create', name=name, spec=spec,
|
||||
level=level, cooldown=cooldown))
|
||||
self.make_msg('policy_create', name=name, spec=spec))
|
||||
|
||||
def policy_get(self, ctxt, identity):
|
||||
return self.call(ctxt,
|
||||
self.make_msg('policy_get', identity=identity))
|
||||
|
||||
def policy_update(self, ctxt, identity, name, level, cooldown):
|
||||
def policy_update(self, ctxt, identity, name):
|
||||
return self.call(ctxt,
|
||||
self.make_msg('policy_update', identity=identity,
|
||||
name=name, level=level,
|
||||
cooldown=cooldown))
|
||||
name=name))
|
||||
|
||||
def policy_delete(self, ctxt, identity, cast=True):
|
||||
rpc_method = self.cast if cast else self.call
|
||||
|
|
|
@ -26,48 +26,6 @@ from senlin.tests.unit.apiv1 import shared
|
|||
from senlin.tests.unit.common import base
|
||||
|
||||
|
||||
class PolicyDataTest(base.SenlinTestCase):
|
||||
def test_policy_data(self):
|
||||
body = {
|
||||
'name': 'test_policy',
|
||||
'spec': {
|
||||
'type': 'policy_type',
|
||||
'version': '1.0',
|
||||
'properties': {
|
||||
'param1': 'value1',
|
||||
'param2': 'value2',
|
||||
}
|
||||
},
|
||||
'level': 10,
|
||||
'cooldown': 60,
|
||||
}
|
||||
|
||||
data = policies.PolicyData(body)
|
||||
self.assertEqual('test_policy', data.name())
|
||||
self.assertEqual(body['spec'], data.spec())
|
||||
self.assertEqual(10, data.level())
|
||||
self.assertEqual(60, data.cooldown())
|
||||
|
||||
def test_required_fields_missing(self):
|
||||
body = {'not a policy name': 'wibble'}
|
||||
|
||||
data = policies.PolicyData(body)
|
||||
self.assertRaises(exc.HTTPBadRequest, data.name)
|
||||
self.assertRaises(exc.HTTPBadRequest, data.spec)
|
||||
self.assertIsNone(data.level())
|
||||
self.assertIsNone(data.cooldown())
|
||||
|
||||
def test_level_invalid(self):
|
||||
body = {
|
||||
'name': 'test_policy',
|
||||
'level': -1,
|
||||
'cooldown': 'long',
|
||||
}
|
||||
data = policies.PolicyData(body)
|
||||
self.assertRaises(senlin_exc.InvalidParameter, data.level)
|
||||
self.assertRaises(senlin_exc.InvalidParameter, data.cooldown)
|
||||
|
||||
|
||||
@mock.patch.object(policy, 'enforce')
|
||||
class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
||||
def setUp(self):
|
||||
|
@ -96,10 +54,8 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
u'param_1': u'value1',
|
||||
u'param_2': u'value2',
|
||||
},
|
||||
u'level': 30,
|
||||
u'created_time': u'2015-02-24T19:17:22Z',
|
||||
u'updated_time': None,
|
||||
u'cooldown': 60,
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -122,8 +78,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
params = {
|
||||
'name': 'FAKE',
|
||||
'type': 'TYPE',
|
||||
'level': 40,
|
||||
'cooldown': 50,
|
||||
'limit': 20,
|
||||
'marker': 'fake marker',
|
||||
'sort': 'fake sorting string',
|
||||
|
@ -207,8 +161,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
'param_2': 2,
|
||||
}
|
||||
},
|
||||
'level': 30,
|
||||
'cooldown': 60,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,8 +176,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
'param_2': 2,
|
||||
},
|
||||
},
|
||||
'level': 30,
|
||||
'cooldown': 60,
|
||||
}
|
||||
|
||||
req = self._post('/policies', json.dumps(body))
|
||||
|
@ -243,8 +193,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
'version': '1.0',
|
||||
'properties': {'param_1': 'value1', 'param_2': 2}
|
||||
},
|
||||
'level': 30,
|
||||
'cooldown': 60
|
||||
})
|
||||
)
|
||||
|
||||
|
@ -290,8 +238,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
req, body=body)
|
||||
|
||||
expected_args = body['policy']
|
||||
expected_args['cooldown'] = None
|
||||
expected_args['level'] = None
|
||||
mock_call.assert_called_once_with(req.context,
|
||||
('policy_create', expected_args))
|
||||
self.assertEqual(400, resp.json['code'])
|
||||
|
@ -334,10 +280,8 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
u'param_2': u'value2',
|
||||
}
|
||||
},
|
||||
u'level': 30,
|
||||
u'created_time': u'2015-02-24T19:17:22Z',
|
||||
u'updated_time': None,
|
||||
u'cooldown': 60,
|
||||
}
|
||||
|
||||
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
|
||||
|
@ -385,8 +329,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
body = {
|
||||
'policy': {
|
||||
'name': 'policy-2',
|
||||
'level': 20,
|
||||
'cooldown': 70,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,10 +343,8 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
u'param_1': u'value1',
|
||||
u'param_2': u'value3',
|
||||
},
|
||||
u'level': 60,
|
||||
u'created_time': u'2015-02-25T16:20:13Z',
|
||||
u'updated_time': None,
|
||||
u'cooldown': 70,
|
||||
}
|
||||
|
||||
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
|
||||
|
@ -413,35 +353,28 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
|
||||
args = copy.deepcopy(body['policy'])
|
||||
args['identity'] = pid
|
||||
args['level'] = 20
|
||||
args['cooldown'] = 70
|
||||
mock_call.assert_called_with(req.context, ('policy_update', args))
|
||||
|
||||
expected = {'policy': engine_resp}
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_policy_update_with_no_level(self, mock_enforce):
|
||||
def test_policy_update_with_no_name(self, mock_enforce):
|
||||
self._mock_enforce_setup(mock_enforce, 'update', True)
|
||||
pid = 'aaaa-bbbb-cccc'
|
||||
body = {'policy': {'cooldown': 70}}
|
||||
body = {'policy': {}}
|
||||
|
||||
req = self._put('/policies/%(pid)s' % {'pid': pid}, json.dumps(body))
|
||||
|
||||
engine_resp = mock.Mock()
|
||||
mock_call = self.patchobject(rpc_client.EngineClient, 'call',
|
||||
return_value=engine_resp)
|
||||
result = self.controller.update(req, policy_id=pid, body=body)
|
||||
ex = self.assertRaises(exc.HTTPBadRequest,
|
||||
self.controller.update,
|
||||
req, policy_id=pid, body=body)
|
||||
|
||||
args = {
|
||||
'identity': pid,
|
||||
'name': None,
|
||||
'level': None,
|
||||
'cooldown': 70,
|
||||
}
|
||||
mock_call.assert_called_with(req.context, ('policy_update', args))
|
||||
|
||||
expected = {'policy': engine_resp}
|
||||
self.assertEqual(expected, result)
|
||||
self.assertEqual("Policy name not specified.",
|
||||
six.text_type(ex))
|
||||
self.assertFalse(mock_call.called)
|
||||
|
||||
def test_policy_update_with_bad_body(self, mock_enforce):
|
||||
self._mock_enforce_setup(mock_enforce, 'update', True)
|
||||
|
@ -462,7 +395,7 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
self._mock_enforce_setup(mock_enforce, 'update', True)
|
||||
pid = 'aaaa-bbbb-cccc'
|
||||
body = {
|
||||
'policy': {'spec': {'param_2': 'value3'}, 'level': 50}
|
||||
'policy': {'spec': {'param_2': 'value3'}}
|
||||
}
|
||||
|
||||
req = self._patch('/policies/%(policy_id)s' % {'policy_id': pid},
|
||||
|
@ -485,7 +418,6 @@ class PolicyControllerTest(shared.ControllerTest, base.SenlinTestCase):
|
|||
body = {
|
||||
'policy': {
|
||||
'name': 'new_policy',
|
||||
'level': 70,
|
||||
}
|
||||
}
|
||||
req = self._patch('/policies/%(policy_id)s' % {'policy_id': pid},
|
||||
|
|
|
@ -216,8 +216,6 @@ class EngineRpcAPITestCase(base.SenlinTestCase):
|
|||
default_args = {
|
||||
'name': mock.ANY,
|
||||
'spec': mock.ANY,
|
||||
'level': mock.ANY,
|
||||
'cooldown': mock.ANY,
|
||||
}
|
||||
self._test_engine_api('policy_create', 'call', **default_args)
|
||||
|
||||
|
@ -228,8 +226,6 @@ class EngineRpcAPITestCase(base.SenlinTestCase):
|
|||
default_args = {
|
||||
'identity': 'aaaa-bbbb-cccc',
|
||||
'name': mock.ANY,
|
||||
'level': mock.ANY,
|
||||
'cooldown': mock.ANY,
|
||||
}
|
||||
self._test_engine_api('policy_update', 'call', **default_args)
|
||||
|
||||
|
|
Loading…
Reference in New Issue