Merge "Modify Watcher start actionplan command"

This commit is contained in:
Zuul 2018-05-24 08:08:21 +00:00 committed by Gerrit Code Review
commit db012f1f8f
3 changed files with 29 additions and 4 deletions

View File

@ -134,6 +134,11 @@ class Manager(object):
def _delete(self, url):
self.api.raw_request('DELETE', url)
def _start(self, url, body=None, method='POST'):
resp, body = self.api.json_request(method, url, body={})
if body:
return self.resource_class(self, body)
class Resource(base.Resource):
"""Represents a particular instance of an object (tenant, user, etc).

View File

@ -38,6 +38,8 @@ ACTION_PLAN2 = {
UPDATED_ACTION_PLAN = copy.deepcopy(ACTION_PLAN1)
NEW_STATE = 'PENDING'
UPDATED_ACTION_PLAN['state'] = NEW_STATE
START_ACTION_PLAN = copy.deepcopy(ACTION_PLAN1)
START_ACTION_PLAN['state'] = NEW_STATE
fake_responses = {
'/v1/action_plans':
@ -69,6 +71,13 @@ fake_responses = {
UPDATED_ACTION_PLAN,
),
},
'/v1/action_plans/%s/start' % ACTION_PLAN1['uuid']:
{
'POST': (
{},
START_ACTION_PLAN,
),
},
'/v1/action_plans/detail?uuid=%s' % ACTION_PLAN1['uuid']:
{
'GET': (
@ -220,3 +229,10 @@ class ActionPlanManagerTest(testtools.TestCase):
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NEW_STATE, action_plan.state)
def test_action_plan_start(self):
action_plan = self.mgr.start(ACTION_PLAN1['uuid'])
expect = [('POST', '/v1/action_plans/%s/start'
% ACTION_PLAN1['uuid'], {}, {})]
self.assertEqual(expect, self.api.calls)
self.assertEqual(NEW_STATE, action_plan.state)

View File

@ -27,8 +27,13 @@ class ActionPlanManager(base.Manager):
resource_class = ActionPlan
@staticmethod
def _path(id=None):
return '/v1/action_plans/%s' % id if id else '/v1/action_plans'
def _path(id=None, q_param=None):
if id and q_param:
return '/v1/action_plans/%s/%s' % (id, q_param)
elif id:
return '/v1/action_plans/%s' % id
else:
return '/v1/action_plans'
def list(self, audit=None, limit=None, sort_key=None,
sort_dir=None, detail=False, marker=None):
@ -90,8 +95,7 @@ class ActionPlanManager(base.Manager):
return self._update(self._path(action_plan_id), patch)
def start(self, action_plan_id):
patch = [{'op': 'replace', 'value': 'PENDING', 'path': '/state'}]
return self._update(self._path(action_plan_id), patch)
return self._start(self._path(action_plan_id, 'start'))
def cancel(self, action_plan_id):
action_plan = self.get(action_plan_id)