Exemplo n.º 1
0
    def test_servicegroup_bindings_handling(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 import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()
        configured_dict = {
            'first': Mock(),
            'second': Mock(has_equal_attributes=Mock(return_value=False)),
        }

        actual_dict = {
            'second': Mock(),
            'third': Mock(),
        }

        client_mock = Mock()

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.netscaler_lb_vserver',
                get_nitro_client=Mock(return_value=client_mock),
                lb_vserver_exists=Mock(side_effect=[True, True]),
                lb_vserver_identical=Mock(side_effect=[False, True]),
                servicegroup_bindings_identical=Mock(
                    side_effect=[False, True]),
                service_bindings_identical=Mock(side_effect=[True, True]),
                get_configured_servicegroup_bindings=Mock(
                    return_value=configured_dict),
                get_actual_servicegroup_bindings=Mock(
                    return_value=actual_dict),
                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()
            configured_dict['first'].assert_has_calls([call.add()])

            configured_dict['second'].assert_has_calls(
                [call.has_equal_attributes(actual_dict['second']),
                 call.add()])

            actual_dict['second'].assert_has_calls(
                [call.delete(client_mock, actual_dict['second'])])

            actual_dict['third'].assert_has_calls(
                [call.delete(client_mock, actual_dict['third'])])

            self.assertTrue(result['changed'])
    def test_absent_gslb_site_execution_flow(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_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.community.general.plugins.modules.network.netscaler.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, False]),
                gslb_service_identical=Mock(side_effect=[False, True]),
                ensure_feature_is_enabled=Mock(),
                monkey_patch_nitro_api=Mock(),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_service
            self.exited()
            gslb_service_proxy_mock.assert_has_calls([call.delete()])
Exemplo n.º 3
0
    def test_absent_state_sanity_check(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

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

        client_mock = Mock()
        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_lb_monitor',
                get_nitro_client=Mock(return_value=client_mock),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                lbmonitor_exists=Mock(side_effect=[True, True]),
                nitro_exception=self.MockException,
        ):
            self.module = netscaler_lb_monitor
            result = self.failed()
            lb_monitor_proxy_mock.assert_has_calls([call.delete()])
            self.assertEqual(result['msg'], 'lb monitor still exists')
    def test_absent_server_execution_flow(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_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.community.general.plugins.modules.network.netscaler.netscaler_server',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            server_exists=Mock(side_effect=[True, False]),
            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.delete()])
Exemplo n.º 5
0
    def test_absent_operation(self):
        self.set_module_state('absent')
        from ansible_collections.community.general.plugins.modules.network.netscaler 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, False])

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_service',
                ConfigProxy=m,
                service_exists=service_exists_mock,
        ):
            self.module = netscaler_service
            result = self.exited()
            service_proxy_mock.assert_has_calls([call.delete()])
            self.assertTrue(result['changed'],
                            msg='Changed status not set correctly')
Exemplo n.º 6
0
    def test_absent_operation(self):
        self.set_module_state('absent')
        from ansible_collections.community.general.plugins.modules.network.netscaler 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, False])

        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.network.netscaler.netscaler_cs_policy',
                ConfigProxy=m,
                policy_exists=policy_exists_mock,
                nitro_exception=self.MockException,
                ensure_feature_is_enabled=Mock(),
        ):
            self.module = netscaler_cs_policy
            result = self.exited()
            cs_policy_mock.assert_has_calls([call.delete()])
            self.assertTrue(result['changed'],
                            msg='Changed status not set correctly')
Exemplo n.º 7
0
    def test_absent_state_workflow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.community.general.plugins.modules import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        client_mock = Mock()
        with patch.multiple(
                'ansible_collections.community.general.plugins.modules.netscaler_lb_vserver',
                get_nitro_client=Mock(return_value=client_mock),
                ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                lb_vserver_exists=Mock(side_effect=[True, False]),
        ):
            self.module = netscaler_lb_vserver
            result = self.exited()
            lb_vserver_proxy_mock.assert_has_calls([call.delete()])
            self.assertTrue(result['changed'])