def test_update_servicegroup_when_servicegroup_differs(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.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.misc.not_a_real_collection.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')
Beispiel #2
0
    def test_absent_cs_vserver_noop_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.misc.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.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver',
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                cs_vserver_exists=Mock(side_effect=[False, False]),
                cs_vserver_identical=Mock(side_effect=[False, False]),
                ensure_feature_is_enabled=Mock(return_value=True),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            cs_vserver_proxy_mock.assert_not_called()
Beispiel #3
0
    def test_disabled_state_change_called(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))

        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_cs_vserver

        cs_vserver_proxy_mock = Mock()

        do_state_change_mock = Mock(return_value=Mock(errorcode=0))
        client_mock = Mock()
        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver',
                get_nitro_client=Mock(return_value=client_mock),
                ConfigProxy=Mock(return_value=cs_vserver_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                cs_vserver_exists=Mock(side_effect=[True, True]),
                cs_vserver_identical=Mock(side_effect=[True, True]),
                nitro_exception=self.MockException,
                do_state_change=do_state_change_mock,
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            self.assertTrue(len(do_state_change_mock.mock_calls) > 0,
                            msg='Did not call state change')
 def setUp(self):
     self.mock_module_helper = patch.multiple(basic.AnsibleModule,
                                              exit_json=exit_json,
                                              fail_json=fail_json)
     self.mock_module_helper.start()
     self.addCleanup(self.mock_module_helper.stop)
     self.server = MockONTAPConnection(kind='present_realm')
Beispiel #5
0
    def test_save_config_not_called_on_state_absent(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
                save_config=False,
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_cs_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        cs_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver',
                get_nitro_client=m,
                cs_vserver_exists=Mock(side_effect=[True, False]),
                ensure_feature_is_enabled=Mock(return_value=True),
                ConfigProxy=Mock(return_value=cs_vserver_proxy_mock),
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
    def test_present_gslb_service_identical_flow(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.misc.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.misc.not_a_real_collection.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=[True, 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_not_called()
    def test_no_change_to_module_when_all_identical(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.plugins.modules 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, True])
        service_identical_mock = Mock(side_effect=[True, True])
        monitor_bindings_identical_mock = Mock(side_effect=[True, True])

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_service',
                ConfigProxy=m,
                service_exists=service_exists_mock,
                service_identical=service_identical_mock,
                monitor_bindings_identical=monitor_bindings_identical_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_service
            result = self.exited()
            self.assertFalse(result['changed'],
                             msg='Erroneous changed status update')
Beispiel #8
0
    def test_absent_gslb_site_failed_delete(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='absent',
        ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_gslb_site

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_site_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_site_proxy_mock = Mock()
        gslb_site_proxy_mock.configure_mock(**glsb_site_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_site_proxy_mock)

        with patch.multiple(
            'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_gslb_site',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            gslb_site_exists=Mock(side_effect=[True, True]),
            gslb_site_identical=Mock(side_effect=[False, False]),
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_site
            result = self.failed()
            self.assertEqual(result['msg'], 'GSLB site still exists')
            self.assertTrue(result['failed'])
    def test_save_config_called_on_state_present(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_monitor

        client_mock = Mock()

        m = Mock(return_value=client_mock)

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

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=m,
                lbmonitor_exists=Mock(side_effect=[False, True]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
        ):
            self.module = netscaler_lb_monitor
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
Beispiel #10
0
    def test_present_server_failed_create(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.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.misc.not_a_real_collection.plugins.modules.netscaler_ssl_certkey',
                nitro_exception=self.MockException,
                get_nitro_client=m,
                diff_list=Mock(return_value={}),
                get_immutables_intersection=Mock(return_value=[]),
                key_exists=Mock(side_effect=[False, False]),
                key_identical=Mock(side_effect=[False, False]),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            result = self.failed()
            self.assertEqual(result['msg'], 'SSL certkey does not exist')
            self.assertTrue(result['failed'])
Beispiel #11
0
 def setUp(self):
     self.mock_module_helper = patch.multiple(basic.AnsibleModule,
                                              exit_json=exit_json,
                                              fail_json=fail_json)
     self.mock_module_helper.start()
     self.addCleanup(self.mock_module_helper.stop)
     self.mock_job = {'name': 'test_job', 'minutes': '25'}
Beispiel #12
0
    def test_present_key_identical_flow(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.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.misc.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=[True, True]),
                ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            ssl_certkey_proxy_mock.assert_not_called()
Beispiel #13
0
    def test_save_config_called_on_state_absent(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_ssl_certkey',
                get_nitro_client=m,
                key_exists=Mock(side_effect=[True, False]),
                ConfigProxy=Mock(return_value=ssl_certkey_proxy_mock),
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
    def test_servicegroup_monitor_bindings_sanity(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.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)
        sync_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_servicegroup',
                ConfigProxy=m,
                servicegroup_exists=Mock(side_effect=[True, True]),
                servicegroup_identical=Mock(side_effect=[True, True]),
                monitor_bindings_identical=Mock(side_effect=[False, False]),
                sync_monitor_bindings=Mock(),
                servicemembers_identical=Mock(side_effect=[True, True]),
                nitro_exception=self.MockException,
                sync_service_members=sync_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_servicegroup
            result = self.failed()
            self.assertEqual(result['msg'],
                             'Monitor bindings are not identical')
Beispiel #15
0
    def test_ensure_feature_is_enabled_called(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_gslb_vserver

        gslb_service_proxy_mock = Mock()
        ensure_feature_is_enabled_mock = Mock()
        client_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_gslb_vserver',
                get_nitro_client=Mock(return_value=client_mock),
                gslb_vserver_exists=Mock(side_effect=[False, True]),
                gslb_vserver_identical=Mock(side_effect=[True]),
                nitro_exception=self.MockException,
                ensure_feature_is_enabled=ensure_feature_is_enabled_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                ConfigProxy=Mock(return_value=gslb_service_proxy_mock),
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            ensure_feature_is_enabled_mock.assert_called_with(
                client_mock, 'GSLB')
    def test_ensure_feature_is_enabled_called(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
                save_config=False,
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_monitor

        client_mock = Mock()

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

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=Mock(return_value=client_mock),
                lbmonitor_exists=Mock(side_effect=[True, True]),
                lbmonitor_identical=Mock(side_effect=[True, True]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=feature_mock,
        ):
            self.module = netscaler_lb_monitor
            self.exited()
            feature_mock.assert_called_with(client_mock, 'LB')
    def test_save_config_not_called_on_state_present(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
            save_config=False,
        ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_gslb_service

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_service_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.misc.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=Mock(return_value=gslb_service_proxy_mock),
        ):
            self.module = netscaler_gslb_service
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
    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_collections.misc.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.misc.not_a_real_collection.plugins.modules.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_update_service_when_monitor_bindings_differ(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.plugins.modules 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, True])
        service_identical_mock = Mock(side_effect=[True, True])
        monitor_bindings_identical_mock = Mock(side_effect=[False, True])
        all_identical_mock = Mock(side_effect=[False])
        sync_monitor_bindings_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_service',
                ConfigProxy=m,
                service_exists=service_exists_mock,
                service_identical=service_identical_mock,
                monitor_bindings_identical=monitor_bindings_identical_mock,
                all_identical=all_identical_mock,
                sync_monitor_bindings=sync_monitor_bindings_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_service
            result = self.exited()
        # poor man's assert_called_once since python3.5 does not implement that mock method
        self.assertEqual(len(sync_monitor_bindings_mock.mock_calls),
                         1,
                         msg='sync monitor bindings not called once')
        self.assertTrue(result['changed'], msg='Change not recorded')
    def test_lb_monitor_identical_sanity_check(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.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.misc.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=Mock(return_value=client_mock),
                lbmonitor_exists=Mock(side_effect=[True, True]),
                lbmonitor_identical=Mock(side_effect=[False, False]),
                ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
                ensure_feature_is_enabled=Mock(return_value=True),
                get_immutables_intersection=(Mock(return_value=[])),
                nitro_exception=self.MockException,
                diff_list=Mock(return_value={}),
        ):
            self.module = netscaler_lb_monitor
            result = self.failed()
            self.assertEqual(result['msg'],
                             'lb monitor is not configured correctly')
 def setUp(self):
     self.mock_module_helper = patch.multiple(basic.AnsibleModule,
                                              exit_json=exit_json,
                                              fail_json=fail_json,
                                              get_bin_path=get_bin_path)
     self.mock_module_helper.start()
     self.addCleanup(self.mock_module_helper.stop)
    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.misc.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.misc.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')
Beispiel #23
0
    def test_save_config_called_on_state_present(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_cs_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        cs_vserver_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.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),
                diff_list=Mock(return_value={}),
                nitro_exception=self.MockException,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                ConfigProxy=Mock(return_value=cs_vserver_proxy_mock),
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            self.assertIn(call.save_config(), client_mock.mock_calls)
    def test_get_immutables_failure(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))

        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_monitor

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

        client_mock = Mock()
        m = Mock(return_value=['some'])
        with patch.multiple(
                'ansible_collections.misc.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(),
                lbmonitor_exists=Mock(side_effect=[True, True]),
                lbmonitor_identical=Mock(side_effect=[False, True]),
                get_immutables_intersection=m,
                diff_list=Mock(return_value={}),
                nitro_exception=self.MockException,
        ):
            self.module = netscaler_lb_monitor
            result = self.failed()
            self.assertTrue(
                result['msg'].startswith('Cannot update immutable attributes'),
                msg='Did not handle immutables error correctly',
            )
Beispiel #25
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_collections.misc.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.misc.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()])
    def test_graceful_nitro_error_on_login(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='present',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_monitor

        class MockException(Exception):
            def __init__(self, *args, **kwargs):
                self.errorcode = 0
                self.message = ''

        client_mock = Mock()
        client_mock.login = Mock(side_effect=MockException)
        m = Mock(return_value=client_mock)
        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_lb_monitor',
                get_nitro_client=m,
                nitro_exception=MockException,
        ):
            self.module = netscaler_lb_monitor
            result = self.failed()
            self.assertTrue(
                result['msg'].startswith('nitro exception'),
                msg='nitro exception during login not handled properly')
Beispiel #27
0
    def test_graceful_nitro_exception_state_absent(self):
        set_module_args(
            dict(
                nitro_user='******',
                nitro_pass='******',
                nsip='192.0.2.1',
                state='absent',
            ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_cs_vserver

        class MockException(Exception):
            def __init__(self, *args, **kwargs):
                self.errorcode = 0
                self.message = ''

        m = Mock(side_effect=MockException)
        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver',
                cs_vserver_exists=m,
                ensure_feature_is_enabled=Mock(return_value=True),
                nitro_exception=MockException):
            self.module = netscaler_cs_vserver
            result = self.failed()
            self.assertTrue(
                result['msg'].startswith('nitro exception'),
                msg='Nitro exception not caught on operation absent')
    def test_update_cs_policy_when_cs_policy_differs(self):
        self.set_module_state('present')
        from ansible_collections.misc.not_a_real_collection.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.misc.not_a_real_collection.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_graceful_no_connection_error(self):

        if sys.version_info[:2] == (2, 6):
            self.skipTest('requests library not available under python2.6')
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
        ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_save_config

        class MockException(Exception):
            pass
        client_mock = Mock()
        attrs = {'login.side_effect': requests.exceptions.ConnectionError}
        client_mock.configure_mock(**attrs)
        m = Mock(return_value=client_mock)
        with patch.multiple(
            'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_save_config',
            get_nitro_client=m,
            nitro_exception=MockException,
        ):
            self.module = netscaler_save_config
            result = self.failed()
            self.assertTrue(result['msg'].startswith('Connection error'), msg='Connection error was not handled gracefully')
Beispiel #30
0
    def test_server_servicegroup_bindings_sanity_check(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        client_mock = Mock()

        with patch.multiple(
            'ansible_collections.misc.not_a_real_collection.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, False]),
            service_bindings_identical=Mock(side_effect=[True, True]),
            ssl_certkey_bindings_identical=Mock(side_effect=[False, False]),
            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=[])),
            nitro_exception=self.MockException,
        ):
            self.module = netscaler_lb_vserver
            result = self.failed()
            self.assertEqual(result['msg'], 'servicegroup bindings are not identical')