def test_absent_server_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible.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.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()])
    def test_new_ssl_certkey_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible.modules.network.netscaler import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_attrs = {
            'diff_object.return_value': {},
        }
        ssl_certkey_proxy_mock = Mock()
        ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
        config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)

        with patch.multiple(
                'ansible.modules.network.netscaler.netscaler_ssl_certkey',
                get_nitro_client=m,
                key_exists=Mock(side_effect=[False, True]),
                key_identical=Mock(side_effect=[True]),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            ssl_certkey_proxy_mock.assert_has_calls([call.add()])
    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.modules.network.netscaler import netscaler_lb_monitor

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

        with patch.multiple(
            'ansible.modules.network.netscaler.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'])
    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.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.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()])
Beispiel #5
0
    def test_new_cs_vserver_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible.modules.network.netscaler import netscaler_cs_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

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

        with patch.multiple(
                'ansible.modules.network.netscaler.netscaler_cs_vserver',
                get_nitro_client=m,
                cs_vserver_exists=Mock(side_effect=[False, True]),
                cs_vserver_identical=Mock(side_effect=[True]),
                ensure_feature_is_enabled=Mock(return_value=True),
                ConfigProxy=config_proxy_mock,
                nitro_exception=self.MockException,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            cs_vserver_proxy_mock.assert_has_calls([call.add()])
    def test_absent_state_sanity_check(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible.modules.network.netscaler import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        client_mock = Mock()
        with patch.multiple(
                'ansible.modules.network.netscaler.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, True]),
                nitro_exception=self.MockException,
        ):
            self.module = netscaler_lb_vserver
            result = self.failed()
            lb_vserver_proxy_mock.assert_has_calls([call.delete()])
            self.assertEqual(result['msg'], 'lb vserver still exists')
    def test_create_new_lb_vserver_workflow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
                save_config=False,
            ))
        from ansible.modules.network.netscaler import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible.modules.network.netscaler.netscaler_lb_vserver',
                get_nitro_client=Mock(return_value=Mock()),
                lb_vserver_exists=Mock(side_effect=[False, True]),
                lb_vserver_identical=Mock(side_effect=[True]),
                servicegroup_bindings_identical=Mock(side_effect=[True, True]),
                service_bindings_identical=Mock(side_effect=[True, True]),
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                ConfigProxy=Mock(return_value=lb_vserver_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
        ):
            self.module = netscaler_lb_vserver
            result = self.exited()
            lb_vserver_proxy_mock.assert_has_calls([call.add()])
            self.assertTrue(result['changed'])
    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.modules.network.netscaler 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.modules.network.netscaler.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()])
    def test_ensure_feature_is_enabled_called(self):
        self.set_module_state('present')
        from ansible.modules.network.netscaler import netscaler_cs_policy

        client_mock = Mock()
        ensure_feature_is_enabled_mock = Mock()
        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_cs_policy',
            get_nitro_client=Mock(return_value=client_mock),
            policy_exists=Mock(side_effect=[True, True]),
            nitro_exception=self.MockException,
            ensure_feature_is_enabled=ensure_feature_is_enabled_mock,
        ):
            self.module = netscaler_cs_policy
            result = self.exited()
            ensure_feature_is_enabled_mock.assert_has_calls([call(client_mock, 'CS')])
Beispiel #10
0
    def test_modified_gslb_vserver_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible.modules.network.netscaler import netscaler_gslb_vserver

        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.modules.network.netscaler.netscaler_gslb_vserver',
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                gslb_vserver_exists=Mock(side_effect=[True, True]),
                gslb_vserver_identical=Mock(side_effect=[False, False, True]),
                ensure_feature_is_enabled=Mock(),
                domain_bindings_identical=Mock(side_effect=[True, True, True]),
                service_bindings_identical=Mock(
                    side_effect=[True, True, True]),
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                nitro_exception=self.MockException,
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            gslb_service_proxy_mock.assert_has_calls([call.update()])
    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.modules.network.netscaler import netscaler_save_config
        client_mock = Mock()

        with patch.multiple(
            'ansible.modules.network.netscaler.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)
 def test_fail_on_conflicting_authentication_methods(self):
     args = copy.deepcopy(module_arguments)
     args.update(
         dict(
             nitro_user='******',
             nitro_pass='******',
             nitro_auth_token='##DDASKLFDJ',
         ))
     mock_module_instance = Mock(params=args)
     expected_calls = [
         call.fail_json(
             changed=False,
             failed=True,
             msg=
             'Cannot define both authentication token and username/password'
         )
     ]
     module_mock = Mock(return_value=mock_module_instance)
     with patch(
             'ansible.modules.network.netscaler.netscaler_nitro_request.AnsibleModule',
             module_mock):
         netscaler_nitro_request.NitroAPICaller()
         mock_module_instance.assert_has_calls(expected_calls)
    def test_absent_state_workflow(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='absent',
        ))
        from ansible.modules.network.netscaler import netscaler_lb_monitor

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

        client_mock = Mock()
        with patch.multiple(
            'ansible.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, False]),
        ):
            self.module = netscaler_lb_monitor
            result = self.exited()
            lb_monitor_proxy_mock.assert_has_calls([call.delete()])
            self.assertTrue(result['changed'])