Add nested action to template tests
Add @nested_action decorator To combine some actions into one use @nested_action for method which returns list of sub actions. Implement blueprint template-based-testcases Change-Id: Iac85df6ddaaa83ae2966d3a4e0963aa534c38877
This commit is contained in:
parent
631b19054d
commit
f5adbdfbde
|
@ -38,6 +38,11 @@ def action(method):
|
|||
return method
|
||||
|
||||
|
||||
def nested_action(method):
|
||||
setattr(method, '_nested_action_method_', True)
|
||||
return staticmethod(method)
|
||||
|
||||
|
||||
def step_start_stop(func):
|
||||
@functools.wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
|
|
|
@ -26,6 +26,7 @@ from system_test.tests import base_actions_factory
|
|||
from system_test.helpers.decorators import make_snapshot_if_step_fail
|
||||
from system_test.helpers.decorators import deferred_decorator
|
||||
from system_test.helpers.decorators import action
|
||||
from system_test.helpers.decorators import nested_action
|
||||
|
||||
|
||||
class PrepareBase(base_actions_factory.BaseActionsFactory):
|
||||
|
@ -125,6 +126,16 @@ class PrepareBase(base_actions_factory.BaseActionsFactory):
|
|||
snapshot_name = "ready_with_{}_slaves".format(slaves)
|
||||
self.env.revert_snapshot(snapshot_name)
|
||||
|
||||
@nested_action
|
||||
def prepare_admin_node_with_slaves():
|
||||
"""Combine preparation steps in alias"""
|
||||
return [
|
||||
'setup_master',
|
||||
'config_release',
|
||||
'make_slaves',
|
||||
'revert_slaves',
|
||||
]
|
||||
|
||||
|
||||
class ActionsBase(PrepareBase):
|
||||
"""Basic actions for acceptance cases
|
||||
|
|
|
@ -29,20 +29,33 @@ class BaseActionsFactory(base_test_case.TestBasic):
|
|||
"""Return all action methods"""
|
||||
return {m: getattr(cls, m) for m in
|
||||
dir(cls) if m.startswith('_action_') or
|
||||
getattr(getattr(cls, m), '_action_method_', False)}
|
||||
getattr(getattr(cls, m), '_action_method_', False) or
|
||||
getattr(getattr(cls, m), '_nested_action_method_', False)}
|
||||
|
||||
@classmethod
|
||||
def get_actions_order(cls):
|
||||
"""Get order of actions"""
|
||||
if cls.actions_order is None:
|
||||
raise LookupError
|
||||
return cls.actions_order
|
||||
if getattr(cls, 'actions_order', None) is None:
|
||||
raise LookupError("Actions order doesn't exist")
|
||||
|
||||
actions_method = cls.get_actions()
|
||||
linear_order = []
|
||||
for action in cls.actions_order:
|
||||
if getattr(actions_method[action],
|
||||
'_nested_action_method_', None):
|
||||
linear_order.extend(actions_method[action]())
|
||||
else:
|
||||
linear_order.append(action)
|
||||
|
||||
steps = [{"action": step, "method": actions_method[step]} for
|
||||
step in linear_order]
|
||||
|
||||
return steps
|
||||
|
||||
@classmethod
|
||||
def caseclass_factory(cls, case_group):
|
||||
"""Create new cloned cls class contains only action methods"""
|
||||
test_steps, scenario = {}, []
|
||||
actions_method = cls.get_actions()
|
||||
|
||||
# Generate human readable class_name, if was method docstring not
|
||||
# described, use generated name
|
||||
|
@ -51,14 +64,15 @@ class BaseActionsFactory(base_test_case.TestBasic):
|
|||
# Make methods for new testcase class, following by order
|
||||
scenario.append(" Scenario:")
|
||||
for step, action in enumerate(cls.get_actions_order()):
|
||||
n_action = action.replace("_action_", "")
|
||||
n_action = action['action'].replace("_action_", "")
|
||||
# Generate human readable method name, if was method docstring not
|
||||
# described, use generated name. Used when method failed
|
||||
step_method_name = "{}.Step{:03d}_{}".format(class_name,
|
||||
step,
|
||||
n_action)
|
||||
method = utils.copy_func(actions_method[action], step_method_name)
|
||||
_step_name = getattr(actions_method[action],
|
||||
|
||||
method = utils.copy_func(action['method'], step_method_name)
|
||||
_step_name = getattr(action['method'],
|
||||
"__doc__").splitlines()[0]
|
||||
setattr(method, "_step_name", "Step {:03d}. {}".format(step,
|
||||
_step_name))
|
||||
|
@ -78,7 +92,8 @@ class BaseActionsFactory(base_test_case.TestBasic):
|
|||
prev_step_name = "{}.Step{:03d}_{}".format(
|
||||
class_name,
|
||||
step - 1,
|
||||
cls.get_actions_order()[step - 1].replace("_action_", ""))
|
||||
cls.get_actions_order()[step - 1]['action'].replace(
|
||||
"_action_", ""))
|
||||
depends = [test_steps[prev_step_name]]
|
||||
else:
|
||||
depends = None
|
||||
|
|
|
@ -31,10 +31,7 @@ class CreateDeployOstf(actions_base.ActionsBase):
|
|||
|
||||
base_group = ['system_test', 'system_test.create_deploy_ostf']
|
||||
actions_order = [
|
||||
'setup_master',
|
||||
'config_release',
|
||||
'make_slaves',
|
||||
'revert_slaves',
|
||||
'prepare_admin_node_with_slaves',
|
||||
'create_env',
|
||||
'add_nodes',
|
||||
'network_check',
|
||||
|
|
Loading…
Reference in New Issue