def test_servicegroup_bindings_handling(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='1.1.1.1',
                state='present',
                save_config=False,
            ))
        from ansible.modules.network.netscaler 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.modules.network.netscaler.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'])
예제 #2
0
    def test_servicegroup_bindings_handling(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='1.1.1.1',
            state='present',
            save_config=False,
        ))
        from ansible.modules.network.netscaler 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.modules.network.netscaler.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'])