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.notstdlib.moveitallout.plugins.modules import netscaler_lb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        lb_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_lb_vserver',
                get_nitro_client=m,
                lb_vserver_exists=Mock(side_effect=[True, False]),
                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_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.notstdlib.moveitallout.plugins.modules import netscaler_cs_action

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        cs_action_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.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)
Exemplo n.º 3
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.notstdlib.moveitallout.plugins.modules import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_ssl_certkey',
                get_nitro_client=m,
                key_exists=Mock(side_effect=[True, False]),
                ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
        ):
            self.module = netscaler_ssl_certkey
            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.notstdlib.moveitallout.plugins.modules import netscaler_gslb_service

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_service_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.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)
    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.notstdlib.moveitallout.plugins.modules import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_server',
                get_nitro_client=m,
                server_exists=Mock(side_effect=[False, True]),
                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)
    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.notstdlib.moveitallout.plugins.modules import netscaler_save_config
        client_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.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)