def test_graceful_login_error(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.notstdlib.moveitallout.plugins.modules import netscaler_cs_vserver

        if sys.version_info[:2] == (2, 6):
            self.skipTest('requests library not available under python2.6')

        class MockException(Exception):
            pass
        client_mock = Mock()
        attrs = {'login.side_effect': requests.exceptions.SSLError}
        client_mock.configure_mock(**attrs)
        m = Mock(return_value=client_mock)
        with patch.multiple(
            'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_cs_vserver',
            get_nitro_client=m,
            nitro_exception=MockException,
        ):
            self.module = netscaler_cs_vserver
            result = self.failed()
            self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
 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')
Exemplo n.º 3
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
Exemplo n.º 4
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
    def test_no_change_to_module_when_all_identical(self):
        self.set_module_state('present')
        from ansible_collections.notstdlib.moveitallout.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.notstdlib.moveitallout.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_udevadm_uuid(self):
        module = Mock()
        module.run_command = Mock(return_value=(0, UDEVADM_OUTPUT,
                                                ''))  # (rc, out, err)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        udevadm_uuid = lh._udevadm_uuid('mock_device')

        self.assertEqual(udevadm_uuid, '57b1a3e7-9019-4747-9809-7ec52bba9179')
    def test_lsblk_uuid_no_lsblk(self):
        module = Mock()
        module.get_bin_path = Mock(return_value=None)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        lsblk_uuids = lh._lsblk_uuid()

        self.assertIsInstance(lsblk_uuids, dict)
        self.assertEqual(len(lsblk_uuids), 0)
    def test_find_bind_mounts_no_findmnts(self):
        module = Mock()
        module.get_bin_path = Mock(return_value=None)
        lh = linux.LinuxHardware(module=module, load_on_init=False)
        bind_mounts = lh._find_bind_mounts()

        self.assertIsInstance(bind_mounts, set)
        self.assertEqual(len(bind_mounts), 0)
 def _mock_module(self):
     mock_module = Mock()
     mock_module.params = {
         'gather_subset': self.gather_subset,
         'gather_timeout': 5,
         'filter': '*'
     }
     mock_module.get_bin_path = Mock(return_value=None)
     return mock_module
Exemplo n.º 10
0
def mock_module():
    mock_module = Mock()
    mock_module.params = {
        'gather_subset': ['all'],
        'gather_timeout': 5,
        'filter': '*'
    }
    mock_module.get_bin_path = Mock(return_value=None)
    return mock_module
    def get_port_mock_object(self):
        """
        Helper method to return an na_ontap_port object
        """
        port_obj = port_module()
        port_obj.asup_log_for_cserver = Mock(return_value=None)
        port_obj.server = Mock()
        port_obj.server.invoke_successfully = Mock()

        return port_obj
    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.notstdlib.moveitallout.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.notstdlib.moveitallout.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'
            )
Exemplo n.º 13
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.notstdlib.moveitallout.plugins.modules import netscaler_lb_vserver

        lb_vserver_proxy_mock = Mock()

        client_mock = Mock()
        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.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, 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_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.notstdlib.moveitallout.plugins.modules import netscaler_gslb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        gslb_service_proxy_mock = Mock()

        with patch.multiple(
            'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_gslb_vserver',
            get_nitro_client=m,
            gslb_vserver_exists=Mock(side_effect=[False, True]),
            gslb_vserver_identical=Mock(side_effect=[True]),
            nitro_exception=self.MockException,
            do_state_change=Mock(return_value=Mock(errorcode=0)),
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=Mock(return_value=gslb_service_proxy_mock),
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            self.assertNotIn(call.save_config(), client_mock.mock_calls)
    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.notstdlib.moveitallout.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.notstdlib.moveitallout.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 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')
 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)
Exemplo n.º 18
0
def mock_module(gather_subset=None, filter=None):
    if gather_subset is None:
        gather_subset = ['all', '!facter', '!ohai']
    if filter is None:
        filter = '*'
    mock_module = Mock()
    mock_module.params = {
        'gather_subset': gather_subset,
        'gather_timeout': 5,
        'filter': filter
    }
    mock_module.get_bin_path = Mock(return_value=None)
    return mock_module
    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.notstdlib.moveitallout.plugins.modules import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.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_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')
Exemplo n.º 21
0
    def test_lb_monitor_exists_sanity_check(self):
        set_module_args(dict(
            nitro_user='******',
            nitro_pass='******',
            nsip='192.0.2.1',
            state='present',
        ))
        from ansible_collections.notstdlib.moveitallout.plugins.modules import netscaler_lb_monitor

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

        client_mock = Mock()

        with patch.multiple(
            'ansible_collections.notstdlib.moveitallout.plugins.modules.netscaler_lb_monitor',
            get_nitro_client=Mock(return_value=client_mock),
            lbmonitor_exists=Mock(side_effect=[False, False]),
            lbmonitor_identical=Mock(side_effect=[False, True]),
            ConfigProxy=Mock(return_value=lb_monitor_proxy_mock),
            ensure_feature_is_enabled=Mock(return_value=True),
            nitro_exception=self.MockException,
        ):
            self.module = netscaler_lb_monitor
            result = self.failed()
            self.assertEqual(result['msg'], 'lb monitor does not exist')
    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.notstdlib.moveitallout.plugins.modules import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_mock = Mock()

        with patch.multiple(
                'ansible_collections.notstdlib.moveitallout.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_update_servicegroup_when_service_members_differ(self):
        self.set_module_state('present')
        from ansible_collections.notstdlib.moveitallout.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.notstdlib.moveitallout.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')
    def test_servicegroup_monitor_bindings_sanity(self):
        self.set_module_state('present')
        from ansible_collections.notstdlib.moveitallout.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.notstdlib.moveitallout.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 get_nfs_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_volume object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_volume object
     """
     nfsy_obj = nfs_module()
     nfsy_obj.asup_log_for_cserver = Mock(return_value=None)
     nfsy_obj.cluster = Mock()
     nfsy_obj.cluster.invoke_successfully = Mock()
     if kind is None:
         nfsy_obj.server = MockONTAPConnection()
     else:
         nfsy_obj.server = MockONTAPConnection(kind=kind, data=self.mock_nfs_group)
     return nfsy_obj
Exemplo n.º 26
0
 def test_elementsw_svip_exists(self):
     ''' svip_exists '''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.asup_log_for_cserver = Mock(return_value=None)
     mock_helper = Mock()
     mock_helper.get_cluster_info.return_value.cluster_info.svip = '10.10.10.10'
     if not self.onbox:
         my_obj.server = MockONTAPConnection('snapmirror',
                                             status='idle',
                                             parm='snapmirrored')
     res = my_obj.validate_elementsw_svip('10.10.10.10:/lun/1000',
                                          mock_helper)
     assert res is None
 def get_key_manager_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_security_key_manager object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_security_key_manager object
     """
     obj = key_manager_module()
     obj.asup_log_for_cserver = Mock(return_value=None)
     obj.cluster = Mock()
     obj.cluster.invoke_successfully = Mock()
     if kind is None:
         obj.cluster = MockONTAPConnection()
     else:
         obj.cluster = MockONTAPConnection(kind=kind, data=self.mock_key_manager)
     return obj
 def get_role_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_user_role object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_user_role object
     """
     role_obj = role_module()
     role_obj.asup_log_for_cserver = Mock(return_value=None)
     role_obj.cluster = Mock()
     role_obj.cluster.invoke_successfully = Mock()
     if kind is None:
         role_obj.server = MockONTAPConnection()
     else:
         role_obj.server = MockONTAPConnection(kind=kind, data=self.mock_role)
     return role_obj
Exemplo n.º 29
0
 def get_kerberos_realm_mock_object(kind=None):
     """
     Helper method to return an na_ontap_volume object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_volume object
     """
     krbrealm_obj = my_module()
     krbrealm_obj.asup_log_for_cserver = Mock(return_value=None)
     krbrealm_obj.cluster = Mock()
     krbrealm_obj.cluster.invoke_successfully = Mock()
     if kind is None:
         krbrealm_obj.server = MockONTAPConnection()
     else:
         krbrealm_obj.server = MockONTAPConnection(kind=kind)
     return krbrealm_obj
Exemplo n.º 30
0
 def get_policy_group_mock_object(self, kind=None):
     """
     Helper method to return an na_ontap_volume object
     :param kind: passes this param to MockONTAPConnection()
     :return: na_ontap_volume object
     """
     policy_obj = qos_policy_group_module()
     policy_obj.autosupport_log = Mock(return_value=None)
     policy_obj.cluster = Mock()
     policy_obj.cluster.invoke_successfully = Mock()
     if kind is None:
         policy_obj.server = MockONTAPConnection()
     else:
         policy_obj.server = MockONTAPConnection(kind=kind, data=self.mock_policy_group)
     return policy_obj