Esempio n. 1
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.notmintest.not_a_real_collection.plugins.modules import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.notmintest.not_a_real_collection.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'])
Esempio n. 2
0
    def test_create_new_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.notmintest.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.notmintest.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=Mock(return_value=Mock()),
                lbmonitor_exists=Mock(side_effect=[False, True]),
                lbmonitor_identical=Mock(side_effect=[True]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
        ):
            self.module = netscaler_lb_monitor
            result = self.exited()
            lb_monitor_proxy_mock.assert_has_calls([call.add()])
            self.assertTrue(result['changed'])
Esempio 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.notmintest.not_a_real_collection.plugins.modules import netscaler_lb_monitor

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

        client_mock = Mock()
        with patch.multiple(
                'ansible_collections.notmintest.not_a_real_collection.plugins.modules.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')
Esempio n. 4
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.notmintest.not_a_real_collection.plugins.modules 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_collections.notmintest.not_a_real_collection.plugins.modules.netscaler_ssl_certkey',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            key_exists=Mock(side_effect=[True, True]),
            key_identical=Mock(side_effect=[False, True]),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            ssl_certkey_proxy_mock.assert_has_calls([call.update()])
Esempio n. 5
0
    def test_absent_gslb_vserver_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.notmintest.not_a_real_collection.plugins.modules 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_collections.notmintest.not_a_real_collection.plugins.modules.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, False]),
                gslb_vserver_identical=Mock(side_effect=[False, True]),
                ensure_feature_is_enabled=Mock(),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            gslb_service_proxy_mock.assert_has_calls([call.delete()])
    def test_new_gslb_site_execution_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.notmintest.not_a_real_collection.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.notmintest.not_a_real_collection.plugins.modules.netscaler_gslb_service',
                get_nitro_client=m,
                gslb_service_exists=Mock(side_effect=[False, True]),
                gslb_service_identical=Mock(side_effect=[True]),
                nitro_exception=self.MockException,
                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.add()])
    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_collections.notmintest.not_a_real_collection.plugins.modules 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_collections.notmintest.not_a_real_collection.plugins.modules.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()])
Esempio n. 8
0
    def test_ensure_feature_is_enabled_called(self):
        self.set_module_state('present')
        from ansible_collections.notmintest.not_a_real_collection.plugins.modules import netscaler_cs_policy

        client_mock = Mock()
        ensure_feature_is_enabled_mock = Mock()
        with patch.multiple(
                'ansible_collections.notmintest.not_a_real_collection.plugins.modules.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')])
Esempio n. 9
0
    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_collections.notmintest.not_a_real_collection.plugins.modules import netscaler_save_config
        client_mock = Mock()

        with patch.multiple(
            'ansible_collections.notmintest.not_a_real_collection.plugins.modules.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)
Esempio n. 10
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.notmintest.not_a_real_collection.plugins.modules import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        client_mock = Mock()
        with patch.multiple(
            'ansible_collections.notmintest.not_a_real_collection.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'])
Esempio n. 11
0
 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_collections.notmintest.not_a_real_collection.plugins.modules.netscaler_nitro_request.AnsibleModule',
             module_mock):
         netscaler_nitro_request.NitroAPICaller()
         mock_module_instance.assert_has_calls(expected_calls)