def setUpClass(cls):
        class MockException(Exception):
            pass

        cls.MockException = MockException
        m = MagicMock()
        cls.servicegroup_mock = MagicMock()
        cls.servicegroup_mock.__class__ = MagicMock()
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup.servicegroup':
            cls.servicegroup_mock,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_servicegroupmember_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_servicegroupmember_binding.servicegroup_servicegroupmember_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.servicegroup_lbmonitor_binding.servicegroup_lbmonitor_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_servicegroup_binding.lbmonitor_servicegroup_binding':
            m
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules,
                                                nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    def setUpClass(cls):
        class MockException(Exception):
            pass

        cls.MockException = MockException

        m = MagicMock()
        cls.cs_vserver_mock = MagicMock()
        cls.cs_vserver_mock.__class__ = MagicMock(add=Mock())
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver.csvserver':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver_cspolicy_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver_cspolicy_binding.csvserver_cspolicy_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver_lbvserver_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.csvserver_lbvserver_binding.csvserver_lbvserver_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.ssl':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslvserver_sslcertkey_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.ssl.sslvserver_sslcertkey_binding.sslvserver_sslcertkey_binding':
            m,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules,
                                                nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    def setUpClass(cls):
        class MockException(Exception):
            pass

        cls.MockException = MockException

        m = MagicMock()
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver.gslbvserver':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_gslbservice_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_gslbservice_binding.gslbvserver_gslbservice_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_domain_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbvserver_domain_binding.gslbvserver_domain_binding':
            m,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules,
                                                nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    def setUpClass(cls):
        class MockException(Exception):
            pass

        cls.MockException = MockException

        m = MagicMock()
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbservice': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbservice.gslbservice': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.gslb.gslbservice_lbmonitor_binding.gslbservice_lbmonitor_binding': m,

            # The following are needed because of monkey_patch_nitro_api()
            'nssrc.com.citrix.netscaler.nitro.resource.base': m,
            'nssrc.com.citrix.netscaler.nitro.resource.base.Json': m,
            'nssrc.com.citrix.netscaler.nitro.resource.base.Json.Json': m,
            'nssrc.com.citrix.netscaler.nitro.util': m,
            'nssrc.com.citrix.netscaler.nitro.util.nitro_util': m,
            'nssrc.com.citrix.netscaler.nitro.util.nitro_util.nitro_util': m,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
Example #5
0
    def setUpClass(cls):
        m = MagicMock()
        cls.service_mock = MagicMock()
        cls.service_mock.__class__ = MagicMock()
        cls.service_lbmonitor_binding_mock = MagicMock()
        cls.lbmonitor_service_binding_mock = MagicMock()
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.service':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.service.service':
            cls.service_mock,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding':
            cls.service_lbmonitor_binding_mock,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.service_lbmonitor_binding.service_lbmonitor_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_service_binding':
            m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.lb.lbmonitor_service_binding.lbmonitor_service_binding':
            cls.lbmonitor_service_binding_mock,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules,
                                                nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    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.community.general.plugins.modules.network.radware 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.community.general.plugins.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.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
Example #8
0
    def test_from_params(self):
        with patch(make_absolute('HAS_TSS_AUTHORIZER'), False):
            self.assert_client_version('v0')

            with patch.dict(self.server_params, {'domain': 'foo'}):
                with self.assertRaises(tss.AnsibleError):
                    self._get_client()

        with patch.multiple(TSS_IMPORT_PATH,
                            HAS_TSS_AUTHORIZER=True,
                            PasswordGrantAuthorizer=DEFAULT,
                            DomainPasswordGrantAuthorizer=DEFAULT):

            self.assert_client_version('v1')

            with patch.dict(self.server_params, {'domain': 'foo'}):
                self.assert_client_version('v1')
    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.community.general.plugins.modules.network.radware 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."
Example #10
0
    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.community.general.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
Example #11
0
    def setUpClass(cls):
        class MockException(Exception):
            pass
        cls.MockException = MockException
        m = MagicMock()
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.cs.cspolicy': m,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    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.community.general.plugins.modules.network.radware import vdirect_runnable

            Runnable.set_available_actions_result(ACTIONS_RESULT)
            BASE_PARAMS.update(CONFIGURATION_TEMPLATE_RUNNABLE_PARAMS)
            vdirectRunnable = vdirect_runnable.VdirectRunnable(BASE_PARAMS)
            vdirectRunnable._validate_action_name()
            assert vdirectRunnable.action_name == vdirect_runnable.VdirectRunnable.RUN_ACTION
Example #13
0
    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.community.general.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
Example #14
0
    def test_commit(self, *args):
        with patch.dict(
                'sys.modules', **{
                    'vdirect_client': self.module_mock,
                    'vdirect_client.rest_client.RestClient': self.module_mock,
                }):
            from ansible_collections.community.general.plugins.modules import vdirect_commit

            BASE_PARAMS.update(COMMIT_PARAMS)
            vdirectcommit = vdirect_commit.VdirectCommit(BASE_PARAMS)
            vdirectcommit.client.adc = DeviceMock('adc', vdirectcommit.client)
            vdirectcommit.client.container = DeviceMock(
                'vx', vdirectcommit.client)
            vdirectcommit.client.appWall = DeviceMock('appwall',
                                                      vdirectcommit.client)
            vdirectcommit.client.defensePro = DeviceMock(
                'defensepro', vdirectcommit.client)

            res = vdirectcommit.commit()
            assert res == MODULE_RESULT

            vdirectcommit.sync = False
            for detail in MODULE_RESULT['details']:
                if 'sync' in detail:
                    detail['sync'] = vdirect_commit.NOT_PERFORMED
            res = vdirectcommit.commit()
            assert res == MODULE_RESULT

            vdirectcommit.client.adc.control_result = COMMIT_RESULT_204
            vdirectcommit.client.adc.control_result[
                self.module_mock.rest_client.RESP_STATUS] = 500
            vdirectcommit.client.adc.control_result[
                self.module_mock.rest_client.RESP_STR] = 'Some Failure'
            MODULE_RESULT[
                'msg'] = 'Failure occurred while performing requested actions on devices. See details'
            for detail in MODULE_RESULT['details']:
                if detail['device_name'] == 'adc':
                    detail['apply'] = vdirect_commit.FAILED
                    detail['failure_description'] = 'Some Failure'
                    detail['save'] = vdirect_commit.NOT_PERFORMED
                    detail['sync'] = vdirect_commit.NOT_PERFORMED
            res = vdirectcommit.commit()
            assert res == MODULE_RESULT

            vdirectcommit.client.adc.throw_exception(control_throw=True)
            for detail in MODULE_RESULT['details']:
                if detail['device_name'] == 'adc':
                    detail['failure_description'] = 'Exception occurred while performing apply action. ' \
                                                    'Exception: exception message'
            res = vdirectcommit.commit()
            assert res == MODULE_RESULT
Example #15
0
    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.community.general.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
Example #16
0
    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.community.general.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
Example #17
0
    def test_validate_devices(self, *args):
        with patch.dict(
                'sys.modules', **{
                    'vdirect_client': self.module_mock,
                    'vdirect_client.rest_client.RestClient': self.module_mock,
                }):
            from ansible_collections.community.general.plugins.modules import vdirect_commit

            BASE_PARAMS.update(COMMIT_PARAMS)
            vdirectcommit = vdirect_commit.VdirectCommit(BASE_PARAMS)
            vdirectcommit.client.adc = DeviceMock('adc', vdirectcommit.client)
            vdirectcommit.client.container = DeviceMock(
                'vx', vdirectcommit.client)
            vdirectcommit.client.appWall = DeviceMock('appwall',
                                                      vdirectcommit.client)
            vdirectcommit.client.defensePro = DeviceMock(
                'defensepro', vdirectcommit.client)

            vdirectcommit._validate_devices()
            assert True

            vdirectcommit.client.adc.throw_exception(True)
            try:
                vdirectcommit._validate_devices()
                self.fail(
                    "CommitException was not thrown for device communication failure"
                )
            except vdirect_commit.CommitException:
                assert True

            vdirectcommit.client.adc.throw_exception(False)
            vdirectcommit.client.defensePro.throw_exception(True)
            try:
                vdirectcommit._validate_devices()
                self.fail(
                    "CommitException was not thrown for device communication failure"
                )
            except vdirect_commit.CommitException:
                assert True

            vdirectcommit.client.defensePro.throw_exception(False)

            vdirectcommit.client.adc.name = 'wrong'
            try:
                vdirectcommit._validate_devices()
                self.fail(
                    "MissingDeviceException was not thrown for missing device")
            except vdirect_commit.MissingDeviceException:
                assert True
    def setUpClass(cls):
        class MockException(Exception):
            pass

        cls.MockException = MockException

        m = MagicMock()
        cls.server_mock = MagicMock()
        cls.server_mock.__class__ = MagicMock(add=Mock())
        nssrc_modules_mock = {
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.server': m,
            'nssrc.com.citrix.netscaler.nitro.resource.config.basic.server.server': cls.server_mock,
        }

        cls.nitro_specific_patcher = patch.dict(sys.modules, nssrc_modules_mock)
        cls.nitro_base_patcher = nitro_base_patcher
    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_collections.community.general.plugins.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
Example #20
0
    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.community.general.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
Example #21
0
    base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.exception':
    base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.exception.nitro_exception':
    base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.exception.nitro_exception.nitro_exception':
    nitro_exception_mock,
    'nssrc.com.citrix.netscaler.nitro.service':
    base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.service.nitro_service':
    base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.service.nitro_service.nitro_service':
    nitro_service_mock,
}

nitro_base_patcher = patch.dict(sys.modules, base_modules_to_mock)


class TestModule(ModuleTestCase):
    def failed(self):
        with self.assertRaises(AnsibleFailJson) as exc:
            self.module.main()

        result = exc.exception.args[0]
        self.assertTrue(result['failed'], result)
        return result

    def exited(self, changed=False):
        with self.assertRaises(AnsibleExitJson) as exc:
            self.module.main()