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.ansible.misc.plugins.modules import netscaler_gslb_service

        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.ansible.misc.plugins.modules.netscaler_gslb_service.get_nitro_client',
                m):
            with patch(
                    'ansible_collections.ansible.misc.plugins.modules.netscaler_gslb_service.nitro_exception',
                    MockException):
                self.module = netscaler_gslb_service
                result = self.failed()
                self.assertTrue(
                    result['msg'].startswith('nitro exception'),
                    msg='nitro exception during login not handled properly')
    def setUp(self):
        super(TestSlxosVlanModule, self).setUp()
        self._patch_run_commands = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_vlan.run_commands'
        )
        self._patch_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_vlan.load_config'
        )

        self._run_commands = self._patch_run_commands.start()
        self._load_config = self._patch_load_config.start()
    def setUp(self):
        super(TestSlxosLldpModule, self).setUp()
        self._patch_get_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_lldp.get_config'
        )
        self._patch_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_lldp.load_config'
        )

        self._get_config = self._patch_get_config.start()
        self._load_config = self._patch_load_config.start()
Example #4
0
    def setUp(self):
        super(TestUnitInformationModule, self).setUp()

        self.mock_make_request = patch('ansible.modules.network.ingate.'
                                       'ig_unit_information.make_request')
        self.make_request = self.mock_make_request.start()

        self.mock_is_ingatesdk_installed = patch(
            'ansible.modules.network.ingate.'
            'ig_unit_information.is_ingatesdk_installed')
        self.is_ingatesdk_installed = self.mock_is_ingatesdk_installed.start()
Example #5
0
    def setUp(self):
        super(TestEdgeswitchVlanModule, self).setUp()

        self.mock_run_commands = patch(
            'ansible_collections.ansible.misc.plugins.modules.edgeswitch_vlan.run_commands'
        )
        self.run_commands = self.mock_run_commands.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.edgeswitch_vlan.load_config'
        )
        self.load_config = self.mock_load_config.start()
Example #6
0
    def setUp(self):
        super(TestOpxCpsModule, self).setUp()

        self.mock_cps_get = patch('ansible_collections.ansible.misc.plugins.modules.opx_cps.cps_get')
        self.cps_get = self.mock_cps_get.start()

        self.mock_cps_transaction = patch('ansible_collections.ansible.misc.plugins.modules.opx_cps.cps_transaction')
        self.cps_transaction = self.mock_cps_transaction.start()

        self.mock_parse_cps_parameters = patch('ansible_collections.ansible.misc.plugins.modules.opx_cps.parse_cps_parameters')
        self.parse_cps_parameters = self.mock_parse_cps_parameters.start()

        self.mock_get_config = patch('ansible_collections.ansible.misc.plugins.modules.opx_cps.cps_get.parse_cps_parameters')
        self.get_config = self.mock_get_config.start()
    def setUp(self):
        super(TestSlxosInterfaceModule, self).setUp()
        self._patch_get_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_interface.get_config'
        )
        self._patch_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_interface.load_config'
        )
        self._patch_exec_command = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_interface.exec_command'
        )

        self._get_config = self._patch_get_config.start()
        self._load_config = self._patch_load_config.start()
        self._exec_command = self._patch_exec_command.start()
Example #8
0
    def setUp(self):
        super(TestParted, self).setUp()

        self.module = parted_module
        self.mock_check_parted_label = (patch('ansible_collections.ansible.misc.plugins.modules.parted.check_parted_label', return_value=False))
        self.check_parted_label = self.mock_check_parted_label.start()

        self.mock_parted = (patch('ansible_collections.ansible.misc.plugins.modules.parted.parted'))
        self.parted = self.mock_parted.start()

        self.mock_run_command = (patch('ansible.module_utils.basic.AnsibleModule.run_command'))
        self.run_command = self.mock_run_command.start()

        self.mock_get_bin_path = (patch('ansible.module_utils.basic.AnsibleModule.get_bin_path'))
        self.get_bin_path = self.mock_get_bin_path.start()
    def setUp(self):
        super(TestRouterosCommandModule, self).setUp()

        self.mock_run_commands = patch(
            'ansible_collections.ansible.misc.plugins.modules.routeros_command.run_commands'
        )
        self.run_commands = self.mock_run_commands.start()
    def test_handle_get_return_object(self):
        resource = 'lbvserver'
        args = copy.deepcopy(module_arguments)
        args.update(dict(
            nitro_user='******',
            nitro_pass='******',
            resource=resource,
        ))
        resource_data = {
            'property1': 'value1',
            'property2': 'value2',
        }
        module_mock = Mock(params=args, from_json=json.loads)
        with patch('ansible_collections.ansible.misc.plugins.modules.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
            instance = netscaler_nitro_request.NitroAPICaller()

            data = {resource: resource_data}
            result = {
                'nitro_errorcode': 0,
                'http_response_body': json.dumps(data),
            }
            expected_result = {
                'nitro_object': resource_data
            }
            expected_result.update(result)
            instance.handle_get_return_object(result)
            self.assertDictEqual(result, expected_result)
    def test_edit_response_data_body_in_info(self):
        args = copy.deepcopy(module_arguments)
        args.update(dict(
            nitro_user='******',
            nitro_pass='******',
        ))
        module_mock = Mock(params=args, from_json=json.loads)
        with patch('ansible_collections.ansible.misc.plugins.modules.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
            body = {
                'errorcode': 258,
                'message': 'Numerical error 258',
                'severity': 'ERROR'
            }
            instance = netscaler_nitro_request.NitroAPICaller()
            r = None
            info = {
                'status': 200,
                'body': codecs.encode(json.dumps(body), 'utf-8'),
            }
            result = {}
            success_status = 200

            expected_result = {
                'http_response_body': json.dumps(body),
                'http_response_data': info,
            }

            nitro_data = {}
            for key, value in body.items():
                nitro_data['nitro_%s' % key] = value

            expected_result.update(nitro_data)
            instance.edit_response_data(r, info, result, success_status)
            self.assertDictEqual(result, expected_result)
    def test_edit_response_data_actual_body_data_irrelevant(self):
        args = copy.deepcopy(module_arguments)
        args.update(dict(
            nitro_user='******',
            nitro_pass='******',
            nitro_auth_token='##DDASKLFDJ',
        ))
        module_mock = Mock(params=args, from_json=json.loads)
        with patch('ansible_collections.ansible.misc.plugins.modules.netscaler_nitro_request.AnsibleModule', Mock(return_value=module_mock)):
            with tempfile.TemporaryFile() as r:
                actual_body = {}
                r.write(codecs.encode(json.dumps(actual_body), 'utf-8'))
                r.seek(0)

                instance = netscaler_nitro_request.NitroAPICaller()
                info = {
                    'status': 200,
                }
                result = {}
                success_status = 200

                expected_result = {
                    'http_response_body': json.dumps(actual_body),
                    'http_response_data': info,
                    'nitro_errorcode': 0,
                    'nitro_message': 'Success',
                    'nitro_severity': 'NONE',
                }

                instance.edit_response_data(r, info, result, success_status)
                self.assertDictEqual(result, expected_result)
    def setUp(self):
        super(TestSlxosL2InterfaceModule, self).setUp()
        self._patch_get_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_l2_interface.get_config'
        )
        self._patch_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_l2_interface.load_config'
        )
        self._patch_run_commands = patch(
            'ansible_collections.ansible.misc.plugins.modules.slxos_l2_interface.run_commands'
        )

        self._get_config = self._patch_get_config.start()
        self._load_config = self._patch_load_config.start()
        self._run_commands = self._patch_run_commands.start()
        self._run_commands.side_effect = self.run_commands_load_fixtures
Example #14
0
    def test_change_flag(self):
        # Flags are set in a second run of parted().
        # Between the two runs, the partition dict is updated.
        # use checkmode here allow us to continue even if the dictionary is
        # not updated.
        set_module_args({
            'device': '/dev/sdb',
            'number': 3,
            'state': 'present',
            'flags': ['lvm', 'boot'],
            '_ansible_check_mode': True,
        })

        with patch('ansible_collections.ansible.misc.plugins.modules.parted.get_device_info', return_value=parted_dict1):
            self.parted.reset_mock()
            self.execute_module(changed=True)
            # When using multiple flags:
            # order of execution is non deterministic, because set() operations are used in
            # the current implementation.
            expected_calls_order1 = [call('unit KiB set 3 lvm on set 3 boot on ',
                                          '/dev/sdb', 'optimal')]
            expected_calls_order2 = [call('unit KiB set 3 boot on set 3 lvm on ',
                                          '/dev/sdb', 'optimal')]
            self.assertTrue(self.parted.mock_calls == expected_calls_order1 or
                            self.parted.mock_calls == expected_calls_order2)
Example #15
0
    def setUp(self):
        super(TestConfigModule, self).setUp()

        self.mock_make_request = patch('ansible.modules.network.ingate.'
                                       'ig_config.make_request')
        self.make_request = self.mock_make_request.start()
        # ATM the Ingate Python SDK is not needed in this unit test.
        self.module.HAS_INGATESDK = True
Example #16
0
 def test_create_new_partition(self):
     set_module_args({
         'device': '/dev/sdb',
         'number': 4,
         'state': 'present',
     })
     with patch('ansible_collections.ansible.misc.plugins.modules.parted.get_device_info', return_value=parted_dict1):
         self.execute_module(changed=True, script='unit KiB mkpart primary 0% 100%')
Example #17
0
 def setUp(self):
     self.mock_module = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
     self.mock_module.start()
     self.mock_sleep = patch('time.sleep')
     self.mock_sleep.start()
     set_module_args({})
     self.addCleanup(self.mock_module.stop)
     self.addCleanup(self.mock_sleep.stop)
Example #18
0
    def setUp(self):
        super(TestNosConfigModule, self).setUp()

        self.mock_get_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.nos_config.get_config'
        )
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.modules.nos_config.load_config'
        )
        self.load_config = self.mock_load_config.start()

        self.mock_run_commands = patch(
            'ansible_collections.ansible.misc.plugins.modules.nos_config.run_commands'
        )
        self.run_commands = self.mock_run_commands.start()
Example #19
0
 def test_partition_already_exists(self):
     set_module_args({
         'device': '/dev/sdb',
         'number': 1,
         'state': 'present',
     })
     with patch('ansible_collections.ansible.misc.plugins.modules.parted.get_device_info', return_value=parted_dict1):
         self.execute_module(changed=False)
Example #20
0
 def test_remove_partition_number_1(self):
     set_module_args({
         'device': '/dev/sdb',
         'number': 1,
         'state': 'absent',
     })
     with patch('ansible_collections.ansible.misc.plugins.modules.parted.get_device_info', return_value=parted_dict1):
         self.execute_module(changed=True, script='rm 1')
Example #21
0
    def setUp(self):
        super(TestOnyxBgpModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_bgp.OnyxBgpModule, "_get_bgp_summary")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
Example #22
0
    def setUp(self):
        super(TestOnyxQosModule, self).setUp()
        self.mock_get_if_qos_config = patch.object(
            onyx_qos.OnyxQosModule, "_show_interface_qos")
        self.get_if_qos_config = self.mock_get_if_qos_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
Example #23
0
    def setUp(self):
        super(TestOnyxBufferPoolModule, self).setUp()
        self.mock_get_buffer_pool_config = patch.object(
            onyx_buffer_pool.OnyxBufferPoolModule, "_show_traffic_pool")
        self.get_buffer_pool_config = self.mock_get_buffer_pool_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
Example #24
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxSysLogRemoteModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_syslog_remote.OnyxSyslogRemoteModule, "show_logging")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
Example #25
0
    def setUp(self):
        super(TestOnyxInterfaceModule, self).setUp()
        self.mock_get_config = patch.object(onyx_lldp.OnyxLldpModule,
                                            "_get_lldp_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
Example #26
0
    def setUp(self):
        self.enabled = False
        super(TestOnyxBFDModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_bfd.OnyxBFDModule, "_show_bfd_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config')
        self.load_config = self.mock_load_config.start()
Example #27
0
    def setUp(self):
        super(TestOnyxMlagIplModule, self).setUp()
        self._mlag_enabled = True
        self.mock_get_config = patch.object(onyx_mlag_ipl.OnyxMlagIplModule,
                                            "_show_mlag_data")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
    def setUp(self):
        self.enabled = False
        super(TestOnyxNtpServersPeersModule, self).setUp()
        self.mock_get_config = patch.object(
            onyx_ntp_servers_peers.OnyxNTPServersPeersModule,
            "_show_peers_servers_config")
        self.get_config = self.mock_get_config.start()

        self.mock_load_config = patch(
            'ansible_collections.ansible.misc.plugins.module_utils.network.onyx.onyx.load_config'
        )
        self.load_config = self.mock_load_config.start()
Example #29
0
 def test_create_new_primary_lvm_partition(self):
     # use check_mode, see previous test comment
     set_module_args({
         'device': '/dev/sdb',
         'number': 4,
         'flags': ["boot"],
         'state': 'present',
         'part_start': '257GiB',
         '_ansible_check_mode': True,
     })
     with patch('ansible_collections.ansible.misc.plugins.modules.parted.get_device_info', return_value=parted_dict1):
         self.execute_module(changed=True, script='unit KiB mkpart primary 257GiB 100% unit KiB set 4 boot on')
Example #30
0
    def setUp(self):
        super(TestNuageModule, self).setUp()

        def session_start(self):
            self._root_object = vsdk.NUMe()
            self._root_object.enterprise_id = 'enterprise-id'
            nurest_session._NURESTSessionCurrentContext.session = self
            return self

        self.session_mock = patch('vspk.v5_0.NUVSDSession.start',
                                  new=session_start)
        self.session_mock.start()