def test_update_cs_policy_when_cs_policy_differs(self):
        self.set_module_state('present')
        from ansible_collections.notstdlib.moveitallout.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.notstdlib.moveitallout.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')
    def test_update_servicegroup_when_servicegroup_differs(self):
        self.set_module_state('present')
        from ansible_collections.notstdlib.moveitallout.plugins.modules import netscaler_servicegroup
        servicegroup_proxy_mock = MagicMock()
        attrs = {
            'diff_object.return_value': {},
        }
        servicegroup_proxy_mock.configure_mock(**attrs)

        m = MagicMock(return_value=servicegroup_proxy_mock)
        servicegroup_exists_mock = Mock(side_effect=[True, True])
        servicegroup_identical_mock = Mock(side_effect=[False, True])
        monitor_bindings_identical_mock = Mock(side_effect=[True, True])

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_servicegroup',
                ConfigProxy=m,
                servicegroup_exists=servicegroup_exists_mock,
                servicegroup_identical=servicegroup_identical_mock,
                monitor_bindings_identical=monitor_bindings_identical_mock,
                servicemembers_identical=Mock(side_effect=[True, True]),
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                nitro_exception=self.MockException,
        ):
            self.module = netscaler_servicegroup
            result = self.exited()
            servicegroup_proxy_mock.assert_has_calls([call.update()])
            self.assertTrue(result['changed'], msg='Change not recorded')
    def test_modified_cs_action_execution_flow(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_cs_action

        client_mock = Mock()

        m = Mock(return_value=client_mock)

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

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_cs_action',
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                action_exists=Mock(side_effect=[True, True]),
                action_identical=Mock(side_effect=[False, True]),
                ensure_feature_is_enabled=Mock(return_value=True),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_cs_action
            self.exited()
            cs_action_proxy_mock.assert_has_calls([call.update()])
Beispiel #4
0
    def test_update_lb_vserver_workflow(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_lb_vserver

        lb_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_lb_vserver',
                get_nitro_client=Mock(return_value=Mock()),
                lb_vserver_exists=Mock(side_effect=[True, True]),
                lb_vserver_identical=Mock(side_effect=[False, True]),
                servicegroup_bindings_identical=Mock(side_effect=[True, True]),
                service_bindings_identical=Mock(side_effect=[True, 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)),
                get_immutables_intersection=Mock(return_value=[]),
        ):
            self.module = netscaler_lb_vserver
            result = self.exited()
            lb_vserver_proxy_mock.assert_has_calls([call.update()])
            self.assertTrue(result['changed'])
    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.notstdlib.moveitallout.plugins.modules import netscaler_gslb_service

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_service_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_service_proxy_mock = Mock()
        gslb_service_proxy_mock.configure_mock(**glsb_service_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_service_proxy_mock)

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_gslb_service',
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                gslb_service_exists=Mock(side_effect=[True, True]),
                gslb_service_identical=Mock(side_effect=[False, False, True]),
                monitor_bindings_identical=Mock(
                    side_effect=[True, True, True]),
                ensure_feature_is_enabled=Mock(),
                monkey_patch_nitro_api=Mock(),
                nitro_exception=self.MockException,
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_service
            self.exited()
            gslb_service_proxy_mock.assert_has_calls([call.update()])