def test_validate_plugin_action_name(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock, }): from ansible_collections.ansible.misc.plugins.modules import vdirect_runnable Runnable.set_available_actions_result(ACTIONS_RESULT) BASE_PARAMS.update(PLUGIN_RUNNABLE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable._validate_action_name() 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() self.fail( "WrongActionNameException was not thrown for wrong action name" ) except vdirect_runnable.WrongActionNameException: 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_collections.ansible.misc.plugins.modules 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.client.runnable = Runnable(vdirectRunnable.client) vdirectRunnable.client.catalog = Catalog(vdirectRunnable.client) try: vdirectRunnable._validate_runnable_exists() self.fail( "MissingRunnableException was not thrown for missing runnable name" ) except vdirect_runnable.MissingRunnableException: assert True
def test_run(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock, }): from ansible_collections.ansible.misc.plugins.modules import vdirect_runnable Catalog.set_catalog_item_200() BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS) Runnable.set_available_actions_result(ACTIONS_RESULT) Runnable.set_action_info_result(ACTIONS_PARAMS_RESULT_BASIC) BASE_PARAMS['parameters'] = {"pin": "x", "alteon": "x"} vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable.client.runnable = Runnable(vdirectRunnable.client) Runnable.set_run_result(RUN_RESULT) res = vdirectRunnable.run() assert res['msg'] == MODULE_RESULT['msg'] result_parameters = {"param1": "value1", "param2": "value2"} RUN_RESULT[self.module_mock.rest_client. RESP_DATA]['parameters'] = result_parameters MODULE_RESULT['parameters'] = result_parameters res = vdirectRunnable.run() assert res['msg'] == MODULE_RESULT['msg'] assert res['output']['parameters'] == result_parameters RUN_RESULT[self.module_mock.rest_client.RESP_DATA]['status'] = 404 vdirectRunnable.run() assert res['msg'] == MODULE_RESULT['msg'] 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_STR] = "Details" try: vdirectRunnable.run() self.fail("RunnableException was not thrown for failed run.") except vdirect_runnable.RunnableException as e: assert str(e) == "Reason: Reason. Details:Details." RUN_RESULT[self.module_mock.rest_client.RESP_STATUS] = 200 RUN_RESULT[self.module_mock.rest_client.RESP_DATA]["status"] = 400 RUN_RESULT[ self.module_mock.rest_client.RESP_DATA]["success"] = False RUN_RESULT[self.module_mock.rest_client.RESP_DATA]["exception"] = { "message": "exception message" } try: vdirectRunnable.run() self.fail("RunnableException was not thrown for failed run.") except vdirect_runnable.RunnableException as e: assert str(e) == "Reason: exception message. Details:Details."
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_collections.ansible.misc.plugins.modules import vdirect_runnable Runnable.set_available_actions_result(ACTIONS_RESULT) BASE_PARAMS.update(WORKFLOW_TEMPLATE_RUNNABLE_PARAMS) vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS) vdirectRunnable._validate_action_name() assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.CREATE_WORKFLOW_ACTION
def test_missing_parameter(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock, }): from ansible_collections.ansible.misc.plugins.modules import vdirect_runnable try: params = BASE_PARAMS.copy() vdirect_runnable.VdirectRunnable(params) self.fail("KeyError was not thrown for missing parameter") except KeyError: 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_collections.ansible.misc.plugins.modules 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_configuration_template_action_name(self, *args): with patch.dict( 'sys.modules', **{ 'vdirect_client': self.module_mock, 'vdirect_client.rest_client': self.module_mock, }): from ansible_collections.ansible.misc.plugins.modules import vdirect_runnable Catalog.set_catalog_item_200() BASE_PARAMS.update(PLUGIN_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 Catalog.set_catalog_item_404() try: vdirectRunnable._validate_runnable_exists() self.fail( "MissingRunnableException was not thrown for missing runnable name" ) except vdirect_runnable.MissingRunnableException: 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_collections.ansible.misc.plugins.modules 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: vdirectRunnable._validate_required_action_params() self.fail( "MissingActionParametersException was not thrown for missing parameters" ) except vdirect_runnable.MissingActionParametersException: assert True BASE_PARAMS['parameters'] = {"alteon": "x"} 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() try: vdirectRunnable._validate_required_action_params() self.fail( "MissingActionParametersException was not thrown for missing parameters" ) except vdirect_runnable.MissingActionParametersException: assert True 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._validate_action_name() vdirectRunnable._validate_required_action_params() assert True