Refactor watcher API for Action Plan Start
Currently the REST API to start action plan in watcher is which is same as for update action plan. PATCH /v1/action_plans https://docs.openstack.org/watcher/latest/api/v1.html we need to make it easy to understand like : POST /v1/action_plans/{action_plan_uuid}/start the action should be start in above case. Change-Id: I5353e4aa58d1675d8afb94bea35d9b953514129a Closes-Bug: #1756274
This commit is contained in:
committed by
Deepak Mourya
parent
921584ac4b
commit
ff57eb73f9
@@ -137,6 +137,12 @@ class FunctionalTest(base.DbTestCase):
|
||||
headers=headers, extra_environ=extra_environ,
|
||||
status=status, method="put")
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
headers = kwargs.pop('headers', {})
|
||||
headers.setdefault('Accept', 'application/json')
|
||||
kwargs['headers'] = headers
|
||||
return self.app.post(*args, **kwargs)
|
||||
|
||||
def post_json(self, path, params, expect_errors=False, headers=None,
|
||||
extra_environ=None, status=None):
|
||||
"""Sends simulated HTTP POST request to Pecan test app.
|
||||
|
||||
@@ -357,6 +357,53 @@ class TestDelete(api_base.FunctionalTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
|
||||
class TestStart(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStart, self).setUp()
|
||||
obj_utils.create_test_goal(self.context)
|
||||
obj_utils.create_test_strategy(self.context)
|
||||
obj_utils.create_test_audit(self.context)
|
||||
self.action_plan = obj_utils.create_test_action_plan(
|
||||
self.context, state=objects.action_plan.State.RECOMMENDED)
|
||||
p = mock.patch.object(db_api.BaseConnection, 'update_action_plan')
|
||||
self.mock_action_plan_update = p.start()
|
||||
self.mock_action_plan_update.side_effect = \
|
||||
self._simulate_rpc_action_plan_update
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
def _simulate_rpc_action_plan_update(self, action_plan):
|
||||
action_plan.save()
|
||||
return action_plan
|
||||
|
||||
@mock.patch('watcher.common.policy.enforce')
|
||||
def test_start_action_plan_not_found(self, mock_policy):
|
||||
mock_policy.return_value = True
|
||||
uuid = utils.generate_uuid()
|
||||
response = self.post('/v1/action_plans/%s/%s' %
|
||||
(uuid, 'start'), expect_errors=True)
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
@mock.patch('watcher.common.policy.enforce')
|
||||
def test_start_action_plan(self, mock_policy):
|
||||
mock_policy.return_value = True
|
||||
action = obj_utils.create_test_action(
|
||||
self.context, id=1)
|
||||
self.action_plan.state = objects.action_plan.State.SUCCEEDED
|
||||
response = self.post('/v1/action_plans/%s/%s/'
|
||||
% (self.action_plan.uuid, 'start'),
|
||||
expect_errors=True)
|
||||
self.assertEqual(200, response.status_int)
|
||||
act_response = self.get_json(
|
||||
'/actions/%s' % action.uuid,
|
||||
expect_errors=True)
|
||||
self.assertEqual(200, act_response.status_int)
|
||||
self.assertEqual('PENDING', act_response.json['state'])
|
||||
self.assertEqual('application/json', act_response.content_type)
|
||||
|
||||
|
||||
class TestPatch(api_base.FunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
@@ -562,7 +609,6 @@ class TestPatchStateTransitionOk(api_base.FunctionalTest):
|
||||
'/action_plans/%s' % action_plan.uuid,
|
||||
[{'path': '/state', 'value': self.new_state, 'op': 'replace'}])
|
||||
updated_ap = self.get_json('/action_plans/%s' % action_plan.uuid)
|
||||
|
||||
self.assertNotEqual(self.new_state, initial_ap['state'])
|
||||
self.assertEqual(self.new_state, updated_ap['state'])
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
@@ -636,4 +682,5 @@ class TestActionPlanPolicyEnforcementWithAdminContext(TestListActionPlan,
|
||||
"action_plan:detail": "rule:default",
|
||||
"action_plan:get": "rule:default",
|
||||
"action_plan:get_all": "rule:default",
|
||||
"action_plan:update": "rule:default"})
|
||||
"action_plan:update": "rule:default",
|
||||
"action_plan:start": "rule:default"})
|
||||
|
||||
Reference in New Issue
Block a user