Exemplo n.º 1
0
    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.network.plugins.modules.network.netscaler import netscaler_gslb_site

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_site_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_gslb_site',
                get_nitro_client=m,
                gslb_site_exists=Mock(side_effect=[True, False]),
                nitro_exception=self.MockException,
                ensure_feature_is_enabled=Mock(),
                ConfigProxy=Mock(return_value=gslb_site_proxy_mock),
        ):
            self.module = netscaler_gslb_site
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
Exemplo n.º 2
0
    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.network.plugins.modules.network.netscaler import netscaler_lb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        lb_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_lb_vserver',
                get_nitro_client=m,
                lb_vserver_exists=Mock(side_effect=[False, True]),
                ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_lb_vserver
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
    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.network.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.network.plugins.modules.network.netscaler.netscaler_server',
            get_nitro_client=m,
            server_exists=Mock(side_effect=[True, False]),
            ConfigProxy=Mock(return_value=server_proxy_mock),
            diff_list=Mock(return_value={}),
            do_state_change=Mock(return_value=Mock(errorcode=0))
        ):
            self.module = netscaler_server
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
Exemplo n.º 4
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.network.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.network.plugins.modules.network.netscaler.netscaler_cs_action',
            get_nitro_client=m,
            action_exists=Mock(side_effect=[False, True]),
            ensure_feature_is_enabled=Mock(return_value=True),
            diff_list=Mock(return_value={}),
            ConfigProxy=Mock(return_value=cs_action_proxy_mock),
        ):
            self.module = netscaler_cs_action
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
Exemplo n.º 5
0
    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.network.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.network.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)
Exemplo n.º 6
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.network.plugins.modules.network.netscaler import netscaler_save_config
        client_mock = Mock()

        with patch.multiple(
            'ansible_collections.community.network.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)