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 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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def test_missing_parameter(self, *args):
        with patch.dict('sys.modules', **{
            'vdirect_client': self.module_mock,
            'vdirect_client.rest_client.RestClient': self.module_mock,
        }):
            from ansible_collections.notmintest.not_a_real_collection.plugins.modules import vdirect_commit

            try:
                params = BASE_PARAMS.copy()
                vdirect_commit.VdirectCommit(params)
                self.fail("KeyError was not thrown for missing parameter")
            except KeyError:
                assert True
Ejemplo n.º 5
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
Ejemplo n.º 6
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.notmintest.not_a_real_collection.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
Ejemplo n.º 7
0
    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
Ejemplo n.º 8
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.notmintest.not_a_real_collection.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.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()
        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
Ejemplo n.º 11
0
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible_collections.notmintest.not_a_real_collection.tests.unit.compat.mock import patch, MagicMock
from ansible_collections.notmintest.not_a_real_collection.tests.unit.modules.utils import set_module_args
from ..junos_module import TestJunosModule

jnpr_mock = MagicMock()
modules = {
    'jnpr': jnpr_mock,
    'jnpr.junos': jnpr_mock.junos,
    'jnpr.junos.utils': jnpr_mock.junos.utils,
    'jnpr.junos.utils.scp': jnpr_mock.junos.utils.scp,
}
module_patcher = patch.dict('sys.modules', modules)
module_patcher.start()

from ansible_collections.notmintest.not_a_real_collection.plugins.modules import junos_scp


class TestJunosScpModule(TestJunosModule):

    module = junos_scp

    def setUp(self):
        super(TestJunosScpModule, self).setUp()
        self.mock_get_device = patch('ansible_collections.notmintest.not_a_real_collection.plugins.modules.junos_scp.get_device')
        self.get_device = self.mock_get_device.start()

        self.mock_scp = patch('ansible_collections.notmintest.not_a_real_collection.plugins.modules.junos_scp.SCP')
Ejemplo n.º 12
0
    'nssrc': base_modules_mock,
    'nssrc.com': base_modules_mock,
    'nssrc.com.citrix': base_modules_mock,
    'nssrc.com.citrix.netscaler': base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro': base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.resource': base_modules_mock,
    'nssrc.com.citrix.netscaler.nitro.resource.config': 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()