コード例 #1
0
    def test_graceful_nitro_error_on_login(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.ansible.misc.plugins.modules import netscaler_gslb_service

        class MockException(Exception):
            def __init__(self, *args, **kwargs):
                self.errorcode = 0
                self.message = ''

        client_mock = Mock()
        client_mock.login = Mock(side_effect=MockException)
        m = Mock(return_value=client_mock)
        with patch(
                'ansible_collections.ansible.misc.plugins.modules.netscaler_gslb_service.get_nitro_client',
                m):
            with patch(
                    'ansible_collections.ansible.misc.plugins.modules.netscaler_gslb_service.nitro_exception',
                    MockException):
                self.module = netscaler_gslb_service
                result = self.failed()
                self.assertTrue(
                    result['msg'].startswith('nitro exception'),
                    msg='nitro exception during login not handled properly')
コード例 #2
0
    def test_graceful_nitro_error_on_login(self):
        self.set_module_state('present')
        from ansible_collections.ansible.misc.plugins.modules import netscaler_cs_policy

        class MockException(Exception):
            def __init__(self, *args, **kwargs):
                self.errorcode = 0
                self.message = ''

        client_mock = Mock()
        client_mock.login = Mock(side_effect=MockException)
        m = Mock(return_value=client_mock)
        with patch(
                'ansible_collections.ansible.misc.plugins.modules.netscaler_cs_policy.get_nitro_client',
                m):
            with patch(
                    'ansible_collections.ansible.misc.plugins.modules.netscaler_cs_policy.nitro_exception',
                    MockException):
                self.module = netscaler_cs_policy
                result = self.failed()
                self.assertTrue(
                    result['msg'].startswith('nitro exception'),
                    msg='nitro exception during login not handled properly')