Merge "Add execute_strategy method in base class"
This commit is contained in:
commit
fd2565e3de
@ -435,3 +435,79 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
||||
if action_plan.get('state') not in self.AP_FINISHED_STATES:
|
||||
return False
|
||||
return True
|
||||
|
||||
def execute_strategy(self, goal_name, strategy_name, **audit_kwargs):
|
||||
"""Execute an action plan based on the specific strategy
|
||||
|
||||
- create an audit template with the specific strategy
|
||||
- run the audit to create an action plan
|
||||
- get the action plan
|
||||
- run the action plan
|
||||
- get results and make sure it succeeded
|
||||
"""
|
||||
_, goal = self.client.show_goal(goal_name)
|
||||
_, strategy = self.client.show_strategy(strategy_name)
|
||||
_, audit_template = self.create_audit_template(
|
||||
goal['uuid'], strategy=strategy['uuid'])
|
||||
|
||||
self.assertTrue(test_utils.call_until_true(
|
||||
func=functools.partial(
|
||||
self.has_action_plans_finished),
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
))
|
||||
|
||||
audit_type = audit_kwargs.pop('audit_type', 'ONESHOT')
|
||||
state = audit_kwargs.pop('state', None)
|
||||
interval = audit_kwargs.pop('interval', None)
|
||||
parameters = audit_kwargs.pop('parameters', None)
|
||||
_, audit = self.create_audit(
|
||||
audit_template['uuid'],
|
||||
audit_type=audit_type,
|
||||
state=state,
|
||||
interval=interval,
|
||||
parameters=parameters)
|
||||
|
||||
try:
|
||||
self.assertTrue(test_utils.call_until_true(
|
||||
func=functools.partial(
|
||||
self.has_audit_finished, audit['uuid']),
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
))
|
||||
except ValueError:
|
||||
self.fail("The audit has failed!")
|
||||
|
||||
_, finished_audit = self.client.show_audit(audit['uuid'])
|
||||
if finished_audit.get('state') in ('FAILED', 'CANCELLED', 'SUSPENDED'):
|
||||
self.fail("The audit ended in unexpected state: %s!"
|
||||
% finished_audit.get('state'))
|
||||
|
||||
_, action_plans = self.client.list_action_plans(
|
||||
audit_uuid=audit['uuid'])
|
||||
action_plan = action_plans['action_plans'][0]
|
||||
|
||||
_, action_plan = self.client.show_action_plan(action_plan['uuid'])
|
||||
|
||||
if action_plan['state'] in ('SUPERSEDED', 'SUCCEEDED'):
|
||||
# This means the action plan is superseded so we cannot trigger it,
|
||||
# or it is empty.
|
||||
return
|
||||
|
||||
# Execute the action by changing its state to PENDING
|
||||
_, updated_ap = self.client.start_action_plan(action_plan['uuid'])
|
||||
|
||||
self.assertTrue(test_utils.call_until_true(
|
||||
func=functools.partial(
|
||||
self.has_action_plan_finished, action_plan['uuid']),
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
))
|
||||
_, finished_ap = self.client.show_action_plan(action_plan['uuid'])
|
||||
_, action_list = self.client.list_actions(
|
||||
action_plan_uuid=finished_ap["uuid"])
|
||||
self.assertIn(updated_ap['state'], ('PENDING', 'ONGOING'))
|
||||
self.assertIn(finished_ap['state'], ('SUCCEEDED', 'SUPERSEDED'))
|
||||
|
||||
for action in action_list['actions']:
|
||||
self.assertEqual('SUCCEEDED', action.get('state'))
|
||||
|
Loading…
Reference in New Issue
Block a user