Ejemplo n.º 1
0
 def _get_wapi(self, test_object):
     wapi = api.WapiModule(self.module)
     wapi.get_object = Mock(name='get_object', return_value=test_object)
     wapi.create_object = Mock(name='create_object')
     wapi.update_object = Mock(name='update_object')
     wapi.delete_object = Mock(name='delete_object')
     return wapi
Ejemplo n.º 2
0
 def test_ensure_feature_is_enabled(self):
     client = Mock()
     attrs = {'get_enabled_features.return_value': ['GSLB']}
     client.configure_mock(**attrs)
     ensure_feature_is_enabled(client, 'GSLB')
     ensure_feature_is_enabled(client, 'LB')
     client.enable_features.assert_called_once_with('LB')
    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')
Ejemplo n.º 4
0
 def test_successful_modify_schedules_add(self, modify_snapshot):
     ''' adding snapshot policy schedules and testing idempotency '''
     data = self.set_default_args()
     data['schedule'] = ['hourly', 'daily', 'weekly']
     data['count'] = [100, 5, 10]
     data['snapmirror_label'] = ['', 'daily', '']
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('policy')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     current = self.set_default_current()
     modify_snapshot.assert_called_with(current)
     # to reset na_helper from remembering the previous 'changed' value
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection(
             'snapshot_policy_info_schedules_added')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
    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',
            )
Ejemplo n.º 6
0
 def get_volume_mock_object(self, kind=None, job_error=None):
     """
     Helper method to return an na_ontap_volume object
     :param kind: passes this param to MockONTAPConnection().
     :param job_error: error message when getting job status.
     :return: na_ontap_volume object
     """
     vol_obj = vol_module()
     vol_obj.ems_log_event = Mock(return_value=None)
     vol_obj.cluster = Mock()
     vol_obj.cluster.invoke_successfully = Mock()
     vol_obj.volume_style = None
     if kind is None:
         vol_obj.server = MockONTAPConnection()
     elif kind == 'volume':
         vol_obj.server = MockONTAPConnection(kind='volume',
                                              data=self.mock_vol)
     elif kind == 'job_info':
         vol_obj.server = MockONTAPConnection(kind='job_info',
                                              data=self.mock_vol,
                                              job_error=job_error)
     elif kind == 'error_modify':
         vol_obj.server = MockONTAPConnection(kind='error_modify',
                                              data=self.mock_vol)
     elif kind == 'failure_modify_async':
         vol_obj.server = MockONTAPConnection(kind='failure_modify_async',
                                              data=self.mock_vol)
     elif kind == 'success_modify_async':
         vol_obj.server = MockONTAPConnection(kind='success_modify_async',
                                              data=self.mock_vol)
     elif kind == 'zapi_error':
         vol_obj.server = MockONTAPConnection(kind='zapi_error',
                                              data=self.mock_vol)
     return vol_obj
Ejemplo n.º 7
0
    def test_create(self, *args):
        set_module_args(dict(
            name='foo',
            description='this is a description',
            ports=[1, 2, 3, 4],
            port_ranges=['10-20', '30-40', '50-60'],
            port_lists=['/Common/foo', 'foo'],
            password='******',
            server='localhost',
            user='******'
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )
        mm = ModuleManager(module=module)

        # Override methods to force specific logic in the module to happen
        mm.exists = Mock(side_effect=[False, True])
        mm.create_on_device = Mock(return_value=True)

        results = mm.exec_module()

        assert results['changed'] is True
        assert 'ports' in results
        assert 'port_lists' in results
        assert 'port_ranges' in results
        assert len(results['ports']) == 4
        assert len(results['port_ranges']) == 3
        assert len(results['port_lists']) == 2
        assert results['description'] == 'this is a description'
 def test_successful_initialize(self, snapmirror_initialize):
     ''' initialize snapmirror and testing idempotency '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='transferring')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_initialize.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
    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')
 def test_successful_create(self, snapmirror_create):
     ''' creating snapmirror and testing idempotency '''
     data = self.set_default_args()
     data['schedule'] = 'abc'
     data['identity_preserve'] = True
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_create.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             'snapmirrored',
                                             status='idle')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
 def test_successful_modify(self, snapmirror_modify):
     ''' modifying snapmirror and testing idempotency '''
     data = self.set_default_args()
     data['policy'] = 'ansible2'
     data['schedule'] = 'abc2'
     data['max_transfer_rate'] = 2000
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror', status='idle')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     snapmirror_modify.assert_called_with({
         'policy': 'ansible2',
         'schedule': 'abc2',
         'max_transfer_rate': 2000
     })
     # to reset na_helper from remembering the previous 'changed' value
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
Ejemplo n.º 12
0
    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_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]),
                diff_list=Mock(return_value={}),
                ensure_feature_is_enabled=Mock(return_value=True),
                do_state_change=Mock(return_value=Mock(errorcode=0)),
                nitro_exception=self.MockException,
                ConfigProxy=Mock(return_value=cs_vserver_proxy_mock),
        ):
            self.module = netscaler_cs_vserver
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
Ejemplo n.º 13
0
    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_cs_vserver

        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(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver.get_nitro_client',
                m):
            with patch(
                    'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_cs_vserver.nitro_exception',
                    MockException):
                self.module = netscaler_cs_vserver
                result = self.failed()
                self.assertTrue(
                    result['msg'].startswith('nitro exception'),
                    msg='nitro exception during login not handled properly')
    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')
    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 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')
Ejemplo n.º 17
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_site

        gslb_site_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_site',
            get_nitro_client=Mock(return_value=client_mock),
            gslb_site_exists=Mock(side_effect=[False, True]),
            gslb_site_identical=Mock(side_effect=[True]),
            nitro_exception=self.MockException,
            ensure_feature_is_enabled=ensure_feature_is_enabled_mock,
            ConfigProxy=Mock(return_value=gslb_site_proxy_mock),
        ):
            self.module = netscaler_gslb_site
            self.exited()
            ensure_feature_is_enabled_mock.assert_called_with(client_mock, 'GSLB')
Ejemplo n.º 18
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_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.assertNotIn(call.save_config(), client_mock.mock_calls)
Ejemplo n.º 19
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')
Ejemplo n.º 20
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')
Ejemplo n.º 21
0
    def test_disable_server_graceful(self):
        set_module_args(
            dict(nitro_user='******',
                 nitro_pass='******',
                 nsip='192.0.2.1',
                 state='present',
                 disabled=True,
                 graceful=True))
        from ansible_collections.misc.not_a_real_collection.plugins.modules import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        d = {
            'graceful': True,
            'delay': 20,
        }
        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_server',
                nitro_exception=self.MockException,
                get_nitro_client=m,
                diff_list=Mock(return_value=d),
                get_immutables_intersection=Mock(return_value=[]),
                server_exists=Mock(side_effect=[True, True]),
                ConfigProxy=Mock(return_value=server_proxy_mock),
                do_state_change=Mock(return_value=Mock(errorcode=0))):
            self.module = netscaler_server
            result = self.exited()
            self.assertEqual(
                d, {},
                'Graceful disable options were not discarded from the diff_list with the actual object'
            )
Ejemplo n.º 22
0
 def test_missing_from_values_dict_not_copied_to_actual(self):
     actual = Mock()
     client = Mock()
     values = {
         'irrelevant_key': 'irrelevant_value',
     }
     print('value %s' % actual.key_for_none)
     ConfigProxy(actual=actual,
                 client=client,
                 attribute_values_dict=values,
                 readwrite_attrs=['key_for_none'])
     print('none %s' % getattr(actual, 'key_for_none'))
     self.assertIsInstance(actual.key_for_none, Mock)
Ejemplo n.º 23
0
 def test_values_copied_to_actual(self):
     actual = Mock()
     client = Mock()
     values = {
         'some_key': 'some_value',
     }
     ConfigProxy(actual=actual,
                 client=client,
                 attribute_values_dict=values,
                 readwrite_attrs=['some_key'])
     self.assertEqual(actual.some_key,
                      values['some_key'],
                      msg='Failed to pass correct value from values dict')
Ejemplo n.º 24
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_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_server',
                get_nitro_client=m,
                server_exists=Mock(side_effect=[True, False]),
                ConfigProxy=Mock(return_value=server_proxy_mock),
                diff_list=Mock(return_value={}),
                do_state_change=Mock(return_value=Mock(errorcode=0))):
            self.module = netscaler_server
            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')
    def test_update_servicegroup_when_service_members_differ(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=[True, True]),
                sync_monitor_bindings=Mock(),
                servicemembers_identical=Mock(side_effect=[False, True]),
                sync_service_members=sync_mock,
                do_state_change=Mock(return_value=Mock(errorcode=0)),
        ):
            self.module = netscaler_servicegroup
            result = self.exited()
        # poor man's assert_called_once since python3.5 does not implement that mock method
        self.assertEqual(len(sync_mock.mock_calls),
                         1,
                         msg='sync monitor bindings not called once')
        self.assertTrue(result['changed'], msg='Change not recorded')
Ejemplo n.º 27
0
    def test_do_state_change_fail(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_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.misc.not_a_real_collection.plugins.modules.netscaler_server',
                nitro_exception=self.MockException,
                get_nitro_client=m,
                server_exists=Mock(side_effect=[True, False]),
                ConfigProxy=Mock(return_value=server_proxy_mock),
                diff_list=Mock(return_value={}),
                do_state_change=Mock(return_value=Mock(
                    errorcode=1, message='Failed on purpose'))):
            self.module = netscaler_server
            result = self.failed()
            self.assertEqual(
                result['msg'],
                'Error when setting disabled state. errorcode: 1 message: Failed on purpose'
            )
    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)
Ejemplo n.º 29
0
 def test_none_values_not_copied_to_actual(self):
     actual = Mock()
     client = Mock()
     actual.key_for_none = 'initial'
     print('actual %s' % actual.key_for_none)
     values = {
         'key_for_none': None,
     }
     print('value %s' % actual.key_for_none)
     ConfigProxy(actual=actual,
                 client=client,
                 attribute_values_dict=values,
                 readwrite_attrs=['key_for_none'])
     self.assertEqual(actual.key_for_none, 'initial')
Ejemplo n.º 30
0
 def get_ndmp_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_ndmp object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_ndmp object
     """
     obj = ndmp_module()
     obj.asup_log_for_cserver = Mock(return_value=None)
     obj.server = Mock()
     obj.server.invoke_successfully = Mock()
     if kind is None:
         obj.server = MockONTAPConnection()
     else:
         obj.server = MockONTAPConnection(kind=kind, data=self.mock_ndmp)
     return obj