def test_save_config_not_called_on_state_present(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
            save_config=False,
        ))
        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_cs_action

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        cs_action_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_cs_action',
            get_nitro_client=m,
            action_exists=Mock(side_effect=[False, True]),
            diff_list=Mock(return_value={}),
            ensure_feature_is_enabled=Mock(return_value=True),
            ConfigProxy=Mock(return_value=cs_action_proxy_mock),
        ):
            self.module = netscaler_cs_action
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
    def test_save_config_not_called_on_state_absent(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
                save_config=False,
            ))
        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_gslb_service

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_service_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_gslb_service',
                get_nitro_client=m,
                gslb_service_exists=Mock(side_effect=[True, False]),
                nitro_exception=self.MockException,
                ensure_feature_is_enabled=Mock(),
                monkey_patch_nitro_api=Mock(),
                ConfigProxy=Mock(return_value=gslb_service_proxy_mock),
        ):
            self.module = netscaler_gslb_service
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
Example #3
0
    def test_save_config_called_on_state_absent(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_lb_monitor

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        lb_monitor_proxy_mock = Mock(diff_object=Mock(return_value={}))

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_lb_monitor',
                get_nitro_client=m,
                lbmonitor_exists=Mock(side_effect=[True, False]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
        ):
            self.module = netscaler_lb_monitor
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
    def test_save_config_not_called_on_state_absent(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='absent',
            save_config=False,
        ))
        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_server',
            get_nitro_client=m,
            server_exists=Mock(side_effect=[True, False]),
            ConfigProxy=Mock(return_value=server_proxy_mock),
            do_state_change=Mock(return_value=Mock(errorcode=0))
        ):
            self.module = netscaler_server
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
Example #5
0
    def test_save_config_called_on_state_present(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.community.general.plugins.modules import netscaler_gslb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_service_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.community.general.plugins.modules.netscaler_gslb_vserver',
            get_nitro_client=m,
            gslb_vserver_exists=Mock(side_effect=[False, True]),
            gslb_vserver_identical=Mock(side_effect=[True]),
            do_state_change=Mock(return_value=Mock(errorcode=0)),
            nitro_exception=self.MockException,
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=Mock(return_value=gslb_service_proxy_mock),
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
    def test_save_config_not_called_on_state_present(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
                save_config=False,
            ))
        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_ssl_certkey',
                get_nitro_client=m,
                key_exists=Mock(side_effect=[False, True]),
                key_identical=Mock(side_effect=[True]),
                ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
                nitro_exception=self.MockException,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
Example #7
0
    def test_save_config_called(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
        ))

        class MockException(Exception):
            pass

        from ansible_collections.community.general.plugins.modules.network.netscaler import netscaler_save_config
        client_mock = Mock()

        with patch.multiple(
            'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_save_config',
            get_nitro_client=Mock(return_value=client_mock),
            nitro_exception=MockException,
        ):
            self.module = netscaler_save_config
            self.exited()
            call_sequence = [call.login(), call.save_config(), call.logout()]
            client_mock.assert_has_calls(call_sequence)