def test_update_service_when_service_differs(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_service
        service_proxy_mock = MagicMock()
        attrs = {
            'diff_object.return_value': {},
        }
        service_proxy_mock.configure_mock(**attrs)

        m = MagicMock(return_value=service_proxy_mock)
        service_exists_mock = Mock(side_effect=[True, True])
        service_identical_mock = Mock(side_effect=[False, True])
        monitor_bindings_identical_mock = Mock(side_effect=[True, True])
        all_identical_mock = Mock(side_effect=[False])

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_service',
                ConfigProxy=m,
                service_exists=service_exists_mock,
                service_identical=service_identical_mock,
                monitor_bindings_identical=monitor_bindings_identical_mock,
                all_identical=all_identical_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_service
            result = self.exited()
            service_proxy_mock.assert_has_calls([call.update()])
            self.assertTrue(result['changed'], msg='Change not recorded')
    def test_update_cs_policy_when_cs_policy_differs(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_cs_policy
        cs_policy_mock = MagicMock()
        attrs = {
            'diff_object.return_value': {},
        }
        cs_policy_mock.configure_mock(**attrs)

        m = MagicMock(return_value=cs_policy_mock)
        policy_exists_mock = Mock(side_effect=[True, True])
        policy_identical_mock = Mock(side_effect=[False, True])

        with patch.multiple(
            'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_policy',
            ConfigProxy=m,
            policy_exists=policy_exists_mock,
            policy_identical=policy_identical_mock,
            ensure_feature_is_enabled=Mock(),
            nitro_exception=self.MockException,
        ):
            self.module = netscaler_cs_policy
            result = self.exited()
            cs_policy_mock.assert_has_calls([call.update()])
            self.assertTrue(result['changed'], msg='Change not recorded')
Esempio n. 3
0
    def test_modified_gslb_site_execution_flow(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_gslb_site

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_site_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_site_proxy_mock = Mock()
        gslb_site_proxy_mock.configure_mock(**glsb_site_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_site_proxy_mock)

        with patch.multiple(
            'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_gslb_site',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            gslb_site_exists=Mock(side_effect=[True, True]),
            gslb_site_identical=Mock(side_effect=[False, True]),
            ensure_feature_is_enabled=Mock(),
            nitro_exception=self.MockException,
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_site
            self.exited()
            gslb_site_proxy_mock.assert_has_calls([call.update()])
    def test_update_lb_monitor_workflow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
                save_config=False,
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_monitor

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

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=Mock(return_value=Mock()),
                lbmonitor_exists=Mock(side_effect=[True, True]),
                lbmonitor_identical=Mock(side_effect=[False, True]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                get_immutables_intersection=Mock(return_value=[]),
                diff_list=Mock(return_value={}),
        ):
            self.module = netscaler_lb_monitor
            result = self.exited()
            lb_monitor_proxy_mock.assert_has_calls([call.update()])
            self.assertTrue(result['changed'])
Esempio n. 5
0
    def test_modified_server_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        server_proxy_mock = Mock()
        server_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=server_proxy_mock)

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_server',
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                server_exists=Mock(side_effect=[True, True]),
                server_identical=Mock(side_effect=[False, True]),
                ConfigProxy=config_proxy_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0))):
            self.module = netscaler_server
            self.exited()
            server_proxy_mock.assert_has_calls([call.update()])