Several enhancements for Radware modules and their unit testing (#61467)

* Adding support for Plugin runnable type
Adding support for device arrays in vdirect_runnable module.
Adding "output" dictionary to the vdirect_runnable module result dictionary.

* Adding support for Plugin runnable type
Adding support for device arrays in vdirect_runnable module.
Adding "output" dictionary to the vdirect_runnable module result dictionary.
pull/62143/head
minievg 5 years ago committed by ansibot
parent fa03f438e7
commit a9d4415657

@ -111,7 +111,7 @@ options:
default: 'yes' default: 'yes'
requirements: requirements:
- "vdirect-client >= 4.1.1" - "vdirect-client >= 4.9.0-post4"
''' '''
EXAMPLES = ''' EXAMPLES = '''

@ -91,7 +91,7 @@ options:
required: true required: true
requirements: requirements:
- "vdirect-client >= 4.1.1" - "vdirect-client >= 4.9.0-post4"
''' '''
EXAMPLES = ''' EXAMPLES = '''

@ -88,7 +88,7 @@ options:
description: description:
- vDirect runnable type. - vDirect runnable type.
required: true required: true
choices: ['ConfigurationTemplate', 'Workflow', 'WorkflowTemplate'] choices: ['ConfigurationTemplate', 'Workflow', 'WorkflowTemplate', 'Plugin']
runnable_name: runnable_name:
description: description:
- vDirect runnable name to run. - vDirect runnable name to run.
@ -104,7 +104,7 @@ options:
- the device connection details should always be passed as a parameter. - the device connection details should always be passed as a parameter.
requirements: requirements:
- "vdirect-client >= 4.1.1" - "vdirect-client >= 4.9.0-post4"
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -138,10 +138,12 @@ except ImportError:
CONFIGURATION_TEMPLATE_RUNNABLE_TYPE = 'ConfigurationTemplate' CONFIGURATION_TEMPLATE_RUNNABLE_TYPE = 'ConfigurationTemplate'
WORKFLOW_TEMPLATE_RUNNABLE_TYPE = 'WorkflowTemplate' WORKFLOW_TEMPLATE_RUNNABLE_TYPE = 'WorkflowTemplate'
WORKFLOW_RUNNABLE_TYPE = 'Workflow' WORKFLOW_RUNNABLE_TYPE = 'Workflow'
PLUGIN_RUNNABLE_TYPE = 'Plugin'
TEMPLATE_SUCCESS = 'Configuration template run completed.' TEMPLATE_SUCCESS = 'Configuration template run completed.'
WORKFLOW_CREATION_SUCCESS = 'Workflow created.' WORKFLOW_CREATION_SUCCESS = 'Workflow created.'
WORKFLOW_ACTION_SUCCESS = 'Workflow action run completed.' WORKFLOW_ACTION_SUCCESS = 'Workflow action run completed.'
PLUGIN_ACTION_SUCCESS = 'Plugin action run completed.'
meta_args = dict( meta_args = dict(
vdirect_ip=dict(required=True, fallback=(env_fallback, ['VDIRECT_IP'])), vdirect_ip=dict(required=True, fallback=(env_fallback, ['VDIRECT_IP'])),
@ -172,7 +174,7 @@ meta_args = dict(
default=2188, type='int'), default=2188, type='int'),
runnable_type=dict( runnable_type=dict(
required=True, required=True,
choices=[CONFIGURATION_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_RUNNABLE_TYPE]), choices=[CONFIGURATION_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_TEMPLATE_RUNNABLE_TYPE, WORKFLOW_RUNNABLE_TYPE, PLUGIN_RUNNABLE_TYPE]),
runnable_name=dict(required=True), runnable_name=dict(required=True),
action_name=dict(required=False, default=None), action_name=dict(required=False, default=None),
parameters=dict(required=False, type='dict', default={}) parameters=dict(required=False, type='dict', default={})
@ -222,29 +224,39 @@ class VdirectRunnable(object):
https_port=params['vdirect_https_port'], https_port=params['vdirect_https_port'],
http_port=params['vdirect_http_port'], http_port=params['vdirect_http_port'],
timeout=params['vdirect_timeout'], timeout=params['vdirect_timeout'],
strict_http_results=True,
https=params['vdirect_use_ssl'], https=params['vdirect_use_ssl'],
verify=params['validate_certs']) verify=params['validate_certs'])
self.params = params self.params = params
self.type = self.params['runnable_type'] self.type = self.params['runnable_type']
self.name = self.params['runnable_name'] self.name = self.params['runnable_name']
if 'parameters' in self.params:
if self.type == WORKFLOW_TEMPLATE_RUNNABLE_TYPE:
self.action_name = VdirectRunnable.CREATE_WORKFLOW_ACTION
elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE:
self.action_name = VdirectRunnable.RUN_ACTION
else:
self.action_name = self.params['action_name']
if 'parameters' in self.params and self.params['parameters']:
self.action_params = self.params['parameters'] self.action_params = self.params['parameters']
else: else:
self.action_params = [] self.action_params = {}
def _validate_runnable_exists(self): def _validate_runnable_exists(self):
if self.type == WORKFLOW_RUNNABLE_TYPE:
res = self.client.runnable.get_runnable_objects(self.type) res = self.client.runnable.get_runnable_objects(self.type)
runnable_names = res[rest_client.RESP_DATA]['names'] runnable_names = res[rest_client.RESP_DATA]['names']
if self.name not in runnable_names: if self.name not in runnable_names:
raise MissingRunnableException(self.name) raise MissingRunnableException(self.name)
else:
try:
self.client.catalog.get_catalog_item(self.type, self.name)
except rest_client.RestClientException:
raise MissingRunnableException(self.name)
def _validate_action_name(self): def _validate_action_name(self):
if self.type == WORKFLOW_TEMPLATE_RUNNABLE_TYPE: if self.type in [WORKFLOW_RUNNABLE_TYPE, PLUGIN_RUNNABLE_TYPE]:
self.action_name = VdirectRunnable.CREATE_WORKFLOW_ACTION
elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE:
self.action_name = VdirectRunnable.RUN_ACTION
else:
self.action_name = self.params['action_name']
res = self.client.runnable.get_available_actions(self.type, self.name) res = self.client.runnable.get_available_actions(self.type, self.name)
available_actions = res[rest_client.RESP_DATA]['names'] available_actions = res[rest_client.RESP_DATA]['names']
if self.action_name not in available_actions: if self.action_name not in available_actions:
@ -263,6 +275,9 @@ class VdirectRunnable(object):
if p['type'] == 'alteon' or if p['type'] == 'alteon' or
p['type'] == 'defensePro' or p['type'] == 'defensePro' or
p['type'] == 'appWall' or p['type'] == 'appWall' or
p['type'] == 'alteon[]' or
p['type'] == 'defensePro[]' or
p['type'] == 'appWall[]' or
p['direction'] != 'out'] p['direction'] != 'out']
required_action_params_names = [n['name'] for n in required_action_params_dict] required_action_params_names = [n['name'] for n in required_action_params_dict]
@ -284,11 +299,11 @@ class VdirectRunnable(object):
result_to_return['msg'] = WORKFLOW_CREATION_SUCCESS result_to_return['msg'] = WORKFLOW_CREATION_SUCCESS
elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE: elif self.type == CONFIGURATION_TEMPLATE_RUNNABLE_TYPE:
result_to_return['msg'] = TEMPLATE_SUCCESS result_to_return['msg'] = TEMPLATE_SUCCESS
elif self.type == PLUGIN_RUNNABLE_TYPE:
result_to_return['msg'] = PLUGIN_ACTION_SUCCESS
else: else:
result_to_return['msg'] = WORKFLOW_ACTION_SUCCESS result_to_return['msg'] = WORKFLOW_ACTION_SUCCESS
result_to_return['output'] = result[rest_client.RESP_DATA]
if 'parameters' in result[rest_client.RESP_DATA]:
result_to_return['parameters'] = result[rest_client.RESP_DATA]['parameters']
else: else:
if 'exception' in result[rest_client.RESP_DATA]: if 'exception' in result[rest_client.RESP_DATA]:
@ -307,7 +322,8 @@ class VdirectRunnable(object):
def main(): def main():
module = AnsibleModule(argument_spec=meta_args, module = AnsibleModule(argument_spec=meta_args,
required_if=[['runnable_type', WORKFLOW_RUNNABLE_TYPE, ['action_name']]]) required_if=[['runnable_type', WORKFLOW_RUNNABLE_TYPE, ['action_name']],
['runnable_type', PLUGIN_RUNNABLE_TYPE, ['action_name']]])
if not HAS_REST_CLIENT: if not HAS_REST_CLIENT:
module.fail_json(msg="The python vdirect-client module is required") module.fail_json(msg="The python vdirect-client module is required")

@ -27,14 +27,44 @@ BASE_PARAMS = {'vdirect_ip': None, 'vdirect_user': None, 'vdirect_password': Non
'vdirect_https_port': None, 'vdirect_http_port': None, 'vdirect_https_port': None, 'vdirect_http_port': None,
'vdirect_timeout': None, 'vdirect_use_ssl': None, 'validate_certs': None} 'vdirect_timeout': None, 'vdirect_use_ssl': None, 'validate_certs': None}
RUNNABLE_PARAMS = {'runnable_type': 'ConfigurationTemplate', 'runnable_name': 'runnable', CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS = {
'runnable_type': 'ConfigurationTemplate', 'runnable_name': 'runnable',
'action_name': None, 'parameters': None} 'action_name': None, 'parameters': None}
RUNNABLE_OBJECTS_RESULT = [200, '', '', {'names': ['runnable']}] WORKFLOW_TEMPLATE_RUNNABLE_PARAMS = {
AVAILABLE_ACTIONS_RESULT = [200, '', '', {'names': ['a', 'b']}] 'runnable_type': 'WorkflowTemplate', 'runnable_name': 'runnable',
ACTIONS_PARAMS_RESULT = [200, '', '', {'parameters': [{'name': 'pin', 'type': 'in', 'direction': 'in'}, 'action_name': None, 'parameters': None}
WORKFLOW_RUNNABLE_PARAMS = {
'runnable_type': 'Workflow', 'runnable_name': 'runnable',
'action_name': 'one', 'parameters': None}
PLUGIN_RUNNABLE_PARAMS = {
'runnable_type': 'Plugin', 'runnable_name': 'runnable',
'action_name': 'two', 'parameters': None}
WORKFLOW_RUNNABLE_OBJECT_RESULT = [200, '', '', {'names': ['runnable']}]
ACTIONS_RESULT = [200, '', '', {'names': ['one', 'two']}]
ACTIONS_PARAMS_RESULT_BASIC = [200, '', '',
{'parameters': [
{'name': 'pin', 'type': 'in', 'direction': 'in'},
{'name': 'pout', 'type': 'out', 'direction': 'out'}, {'name': 'pout', 'type': 'out', 'direction': 'out'},
{'name': 'alteon', 'type': 'alteon'}]}] {'name': 'alteon', 'type': 'alteon'}
]}]
ACTIONS_PARAMS_RESULT_FULL = [200, '', '',
{'parameters': [
{'name': 'pin', 'type': 'in', 'direction': 'in'},
{'name': 'pout', 'type': 'out', 'direction': 'out'},
{'name': 'alteon', 'type': 'alteon'},
{'name': 'alteon_array', 'type': 'alteon[]'},
{'name': 'dp', 'type': 'defensePro'},
{'name': 'dp_array', 'type': 'defensePro[]'},
{'name': 'appWall', 'type': 'appWall'},
{'name': 'appWall_array', 'type': 'appWall[]'}
]}]
RUN_RESULT = [200, '', '', { RUN_RESULT = [200, '', '', {
"uri": "https://10.11.12.13:2189/api/status?token=Workflow%5Ca%5Capply%5Cc4b533a8-8764-4cbf-a19c-63b11b9ccc09", "uri": "https://10.11.12.13:2189/api/status?token=Workflow%5Ca%5Capply%5Cc4b533a8-8764-4cbf-a19c-63b11b9ccc09",
@ -42,7 +72,7 @@ RUN_RESULT = [200, '', '', {
"complete": True, "status": 200, "success": True, "messages": [], "action": "apply", "parameters": {}, "complete": True, "status": 200, "success": True, "messages": [], "action": "apply", "parameters": {},
}] }]
MODULE_RESULT = {"msg": "Configuration template run completed.", "parameters": {}} MODULE_RESULT = {"msg": "Configuration template run completed."}
@patch('vdirect_client.rest_client.RestClient') @patch('vdirect_client.rest_client.RestClient')
@ -56,29 +86,32 @@ class RestClient:
@patch('vdirect_client.rest_client.Runnable') @patch('vdirect_client.rest_client.Runnable')
class Runnable: class Runnable:
runnable_objects_result = None
available_actions_result = None available_actions_result = None
action_info_result = None action_info_result = None
runnable_objects_result = None
run_result = None run_result = None
def __init__(self, client): def __init__(self, client):
self.client = client self.client = client
@classmethod @classmethod
def set_action_info_result(cls, result): def set_runnable_objects_result(cls, result):
Runnable.action_info_result = result Runnable.runnable_objects_result = result
@classmethod @classmethod
def set_available_actions_result(cls, result): def set_available_actions_result(cls, result):
Runnable.available_actions_result = result Runnable.available_actions_result = result
@classmethod
def set_action_info_result(cls, result):
Runnable.action_info_result = result
@classmethod @classmethod
def set_run_result(cls, result): def set_run_result(cls, result):
Runnable.run_result = result Runnable.run_result = result
@classmethod def get_runnable_objects(self, type):
def set_runnable_objects_result(cls, result): return Runnable.runnable_objects_result
Runnable.runnable_objects_result = result
def get_available_actions(self, type=None, name=None): def get_available_actions(self, type=None, name=None):
return Runnable.available_actions_result return Runnable.available_actions_result
@ -89,8 +122,27 @@ class Runnable:
def run(self, data, type, name, action_name): def run(self, data, type, name, action_name):
return Runnable.run_result return Runnable.run_result
def get_runnable_objects(self, type):
return Runnable.runnable_objects_result @patch('vdirect_client.rest_client.Catalog')
class Catalog:
_404 = False
def __init__(self, client):
self.client = client
@classmethod
def set_catalog_item_200(cls):
Catalog._404 = False
@classmethod
def set_catalog_item_404(cls):
Catalog._404 = True
@classmethod
def get_catalog_item(cls, type=None, name=None):
if Catalog._404:
from ansible.modules.network.radware import vdirect_runnable
raise vdirect_runnable.MissingRunnableException(name)
class TestManager(unittest.TestCase): class TestManager(unittest.TestCase):
@ -116,85 +168,184 @@ class TestManager(unittest.TestCase):
except KeyError: except KeyError:
assert True assert True
def test_validate_runnable_exists(self, *args): def test_validate_configuration_template_exists(self, *args):
with patch.dict('sys.modules', **{ with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock, 'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock,
}): }):
from ansible.modules.network.radware import vdirect_runnable from ansible.modules.network.radware import vdirect_runnable
Runnable.set_runnable_objects_result(RUNNABLE_OBJECTS_RESULT) Catalog.set_catalog_item_200()
BASE_PARAMS.update(RUNNABLE_PARAMS) BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
vdirectRunnable._validate_runnable_exists()
assert True
def test_validate_workflow_template_exists(self, *args):
with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Catalog.set_catalog_item_200()
BASE_PARAMS.update(WORKFLOW_TEMPLATE_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
vdirectRunnable._validate_runnable_exists()
assert True
def test_validate_workflow_exists(self, *args):
with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Catalog.set_catalog_item_200()
BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
Runnable.set_runnable_objects_result(WORKFLOW_RUNNABLE_OBJECT_RESULT)
BASE_PARAMS.update(WORKFLOW_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
vdirectRunnable._validate_runnable_exists()
assert True
def test_validate_plugin_exists(self, *args):
with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Runnable.set_runnable_objects_result(WORKFLOW_RUNNABLE_OBJECT_RESULT)
BASE_PARAMS.update(WORKFLOW_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
vdirectRunnable._validate_runnable_exists()
assert True
BASE_PARAMS['runnable_name'] = 'missing'
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
try:
vdirectRunnable._validate_runnable_exists() vdirectRunnable._validate_runnable_exists()
self.fail("MissingRunnableException was not thrown for missing runnable name")
except vdirect_runnable.MissingRunnableException:
assert True assert True
BASE_PARAMS.update(RUNNABLE_PARAMS) def test_validate_configuration_template_action_name(self, *args):
BASE_PARAMS['runnable_name'] = "missing" with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Catalog.set_catalog_item_200()
BASE_PARAMS.update(PLUGIN_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client)
vdirectRunnable._validate_runnable_exists()
assert True
Catalog.set_catalog_item_404()
try: try:
vdirectRunnable._validate_runnable_exists() vdirectRunnable._validate_runnable_exists()
self.fail("MissingRunnableException was not thrown for missing runnable name") self.fail("MissingRunnableException was not thrown for missing runnable name")
except vdirect_runnable.MissingRunnableException: except vdirect_runnable.MissingRunnableException:
assert True assert True
def test_validate_action_name(self, *args): def test_validate_configuration_template_action_name(self, *args):
with patch.dict('sys.modules', **{ with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock, 'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock,
}): }):
from ansible.modules.network.radware import vdirect_runnable from ansible.modules.network.radware import vdirect_runnable
Runnable.set_runnable_objects_result(RUNNABLE_OBJECTS_RESULT) Runnable.set_available_actions_result(ACTIONS_RESULT)
BASE_PARAMS.update(RUNNABLE_PARAMS) BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.RUN_ACTION assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.RUN_ACTION
BASE_PARAMS['runnable_type'] = vdirect_runnable.WORKFLOW_TEMPLATE_RUNNABLE_TYPE def test_validate_workflow_template_action_name(self, *args):
with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Runnable.set_available_actions_result(ACTIONS_RESULT)
BASE_PARAMS.update(WORKFLOW_TEMPLATE_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.CREATE_WORKFLOW_ACTION assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.CREATE_WORKFLOW_ACTION
BASE_PARAMS['runnable_type'] = vdirect_runnable.WORKFLOW_RUNNABLE_TYPE def test_validate_workflow_action_name(self, *args):
BASE_PARAMS['action_name'] = 'a' with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Runnable.set_available_actions_result(ACTIONS_RESULT)
BASE_PARAMS.update(WORKFLOW_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
Runnable.set_available_actions_result(AVAILABLE_ACTIONS_RESULT)
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
assert vdirectRunnable.action_name == 'a' assert vdirectRunnable.action_name == 'one'
BASE_PARAMS['action_name'] = 'c' BASE_PARAMS['action_name'] = 'three'
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
Runnable.set_available_actions_result(AVAILABLE_ACTIONS_RESULT)
try: try:
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
self.fail("WrongActionNameException was not thrown for wrong action name") self.fail("WrongActionNameException was not thrown for wrong action name")
except vdirect_runnable.WrongActionNameException: except vdirect_runnable.WrongActionNameException:
assert True assert True
def test_validate_required_action_params(self, *args): def test_validate_plugin_action_name(self, *args):
with patch.dict('sys.modules', **{ with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock, 'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock,
}): }):
from ansible.modules.network.radware import vdirect_runnable from ansible.modules.network.radware import vdirect_runnable
Runnable.set_runnable_objects_result(RUNNABLE_OBJECTS_RESULT) Runnable.set_available_actions_result(ACTIONS_RESULT)
BASE_PARAMS.update(RUNNABLE_PARAMS) BASE_PARAMS.update(PLUGIN_RUNNABLE_PARAMS)
BASE_PARAMS['runnable_type'] = vdirect_runnable.WORKFLOW_RUNNABLE_TYPE
BASE_PARAMS['action_name'] = 'a'
BASE_PARAMS['parameters'] = {"alteon": "x"}
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
Runnable.set_available_actions_result(AVAILABLE_ACTIONS_RESULT) vdirectRunnable._validate_action_name()
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT) assert vdirectRunnable.action_name == 'two'
BASE_PARAMS['action_name'] = 'three'
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
try:
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
self.fail("WrongActionNameException was not thrown for wrong action name")
except vdirect_runnable.WrongActionNameException:
assert True
def test_validate_required_action_params(self, *args):
with patch.dict('sys.modules', **{
'vdirect_client': self.module_mock,
'vdirect_client.rest_client': self.module_mock,
}):
from ansible.modules.network.radware import vdirect_runnable
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT_BASIC)
BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
try: try:
vdirectRunnable._validate_required_action_params() vdirectRunnable._validate_required_action_params()
self.fail("MissingActionParametersException was not thrown for missing parameters") self.fail("MissingActionParametersException was not thrown for missing parameters")
@ -203,6 +354,19 @@ class TestManager(unittest.TestCase):
BASE_PARAMS['parameters'] = {"alteon": "x"} BASE_PARAMS['parameters'] = {"alteon": "x"}
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
try:
vdirectRunnable._validate_required_action_params()
self.fail("MissingActionParametersException was not thrown for missing parameters")
except vdirect_runnable.MissingActionParametersException:
assert True
BASE_PARAMS['parameters'] = {"pin": "x", "alteon": "a1"}
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable._validate_action_name()
vdirectRunnable._validate_required_action_params()
assert True
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT_FULL)
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
try: try:
vdirectRunnable._validate_required_action_params() vdirectRunnable._validate_required_action_params()
@ -210,7 +374,12 @@ class TestManager(unittest.TestCase):
except vdirect_runnable.MissingActionParametersException: except vdirect_runnable.MissingActionParametersException:
assert True assert True
BASE_PARAMS['parameters'] = {"pin": "x", "alteon": "x"} BASE_PARAMS['parameters'].update(
{"alteon_array": "[a1, a2]",
"dp": "dp1", "dp_array": "[dp1, dp2]",
"appWall": "appWall1",
"appWall_array": "[appWall1, appWall2]"
})
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable._validate_action_name() vdirectRunnable._validate_action_name()
vdirectRunnable._validate_required_action_params() vdirectRunnable._validate_required_action_params()
@ -223,46 +392,28 @@ class TestManager(unittest.TestCase):
}): }):
from ansible.modules.network.radware import vdirect_runnable from ansible.modules.network.radware import vdirect_runnable
Runnable.set_runnable_objects_result(RUNNABLE_OBJECTS_RESULT) Catalog.set_catalog_item_200()
BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
BASE_PARAMS.update(RUNNABLE_PARAMS) Runnable.set_available_actions_result(ACTIONS_RESULT)
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT_BASIC)
BASE_PARAMS['runnable_type'] = vdirect_runnable.CONFIGURATION_TEMPLATE_RUNNABLE_TYPE
BASE_PARAMS['parameters'] = {"pin": "x", "alteon": "x"} BASE_PARAMS['parameters'] = {"pin": "x", "alteon": "x"}
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
Runnable.set_available_actions_result(AVAILABLE_ACTIONS_RESULT)
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT)
Runnable.set_run_result(RUN_RESULT)
res = vdirectRunnable.run()
assert res == MODULE_RESULT
BASE_PARAMS['runnable_type'] = vdirect_runnable.WORKFLOW_TEMPLATE_RUNNABLE_TYPE
MODULE_RESULT['msg'] = "Workflow created."
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
res = vdirectRunnable.run()
assert res == MODULE_RESULT
BASE_PARAMS['runnable_type'] = vdirect_runnable.WORKFLOW_RUNNABLE_TYPE
BASE_PARAMS['action_name'] = 'a'
MODULE_RESULT['msg'] = "Workflow action run completed."
vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client)
Runnable.set_available_actions_result(AVAILABLE_ACTIONS_RESULT) Runnable.set_run_result(RUN_RESULT)
Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT)
res = vdirectRunnable.run() res = vdirectRunnable.run()
assert res == MODULE_RESULT assert res['msg'] == MODULE_RESULT['msg']
result_parameters = {"param1": "value1", "param2": "value2"} result_parameters = {"param1": "value1", "param2": "value2"}
RUN_RESULT[self.module_mock.rest_client.RESP_DATA]['parameters'] = result_parameters RUN_RESULT[self.module_mock.rest_client.RESP_DATA]['parameters'] = result_parameters
MODULE_RESULT['parameters'] = result_parameters MODULE_RESULT['parameters'] = result_parameters
res = vdirectRunnable.run() res = vdirectRunnable.run()
assert res == MODULE_RESULT assert res['msg'] == MODULE_RESULT['msg']
assert res['output']['parameters'] == result_parameters
RUN_RESULT[self.module_mock.rest_client.RESP_DATA]['status'] = 404 RUN_RESULT[self.module_mock.rest_client.RESP_DATA]['status'] = 404
vdirectRunnable.run() vdirectRunnable.run()
assert res == MODULE_RESULT assert res['msg'] == MODULE_RESULT['msg']
RUN_RESULT[self.module_mock.rest_client.RESP_STATUS] = 400 RUN_RESULT[self.module_mock.rest_client.RESP_STATUS] = 400
RUN_RESULT[self.module_mock.rest_client.RESP_REASON] = "Reason" RUN_RESULT[self.module_mock.rest_client.RESP_REASON] = "Reason"

Loading…
Cancel
Save