Пример #1
0
 def test_update_device_details_with_filtering_failure_case_01(self, ome_connection_mock, ome_response_mock):
     error_msg = '400: Bad Request'
     service_tag_dict = {}
     non_available_tags = [Constants.service_tag2]
     ome_connection_mock.invoke_request.side_effect = HTTPError('http://testhost.com', 400, error_msg, {}, None)
     with pytest.raises(HTTPError, match=error_msg) as ex:
         self.module.update_device_details_with_filtering(non_available_tags, service_tag_dict, ome_connection_mock)
Пример #2
0
 def test_modules_provisioned_raises(self):
     self.connection.send.side_effect = HTTPError(
         'https://bigip.local/mgmt/tm/sys/provision', 400, '', {}, StringIO('{"errorMessage": "ERROR"}')
     )
     with self.assertRaises(F5ModuleError) as res:
         modules_provisioned(self.client)
     assert "{'errorMessage': 'ERROR'}" in str(res.exception)
Пример #3
0
 def test_main_detailed_inventory_http_error_case(
         self, ome_default_args, module_mock, validate_device_inputs_mock,
         ome_connection_mock, get_device_resource_parameters_mock,
         ome_response_mock):
     ome_default_args.update({
         "fact_subset": "detailed_inventory",
         "system_query_options": {
             "device_id": [Constants.device_id1],
             "device_service_tag": [Constants.service_tag1]
         }
     })
     detailed_inventory = {
         "detailed_inventory:": {
             "device_id": {
                 Constants.device_id1:
                 "DeviceService/Devices(Constants.device_id1)/InventoryDetails"
             },
             "device_service_tag": {
                 Constants.service_tag1:
                 "DeviceService/Devices(4321)/InventoryDetails"
             }
         }
     }
     get_device_resource_parameters_mock.return_value = detailed_inventory
     ome_connection_mock.invoke_request.side_effect = HTTPError(
         'http://testhost.com', 400, '', {}, None)
     result = self._run_module_with_fail_json(ome_default_args)
     assert 'device_info' not in result
Пример #4
0
 def test_get_device_id_from_service_tags_error_case(
         self, ome_connection_mock, ome_response_mock):
     ome_connection_mock.get_all_report_details.side_effect = HTTPError(
         'http://testhost.com', 400, '', {}, None)
     with pytest.raises(HTTPError) as ex:
         self.module._get_device_id_from_service_tags(["INVALID"],
                                                      ome_connection_mock)
Пример #5
0
 def test_bigiq_version_raises_on_http_error(self):
     self.connection.send.side_effect = HTTPError(
         'https://bigiq.local/mgmt/shared/resolver/device-groups/cm-shared-all-big-iqs/devices',
         400, '', {}, StringIO('{"errorMessage": "ERROR"}'))
     with self.assertRaises(F5ModuleError) as res:
         bigiq_version(self.client)
     assert '{\'errorMessage\': \'ERROR\'}' in str(res.exception)
Пример #6
0
 def test_main_HTTPError_case(self, idrac_connection_firmware_mock,
                              idrac_default_args,
                              idrac_connection_firmware_redfish_mock,
                              mocker):
     idrac_default_args.update({
         "share_name": "sharename",
         "catalog_file_name": "Catalog.xml",
         "share_user": "******",
         "share_password": "******",
         "share_mnt": "sharmnt",
         "reboot": True,
         "job_wait": True
     })
     json_str = to_text(json.dumps({"data": "out"}))
     idrac_connection_firmware_redfish_mock.success = True
     idrac_connection_firmware_redfish_mock.json_data = {
         "FirmwareVersion": "2.70"
     }
     mocker.patch(MODULE_PATH + 'idrac_firmware.update_firmware_omsdk',
                  side_effect=HTTPError('http://testhost.com', 400,
                                        'http error message',
                                        {"accept-type": "application/json"},
                                        StringIO(json_str)))
     result = self._run_module_with_fail_json(idrac_default_args)
     assert 'msg' in result
     assert result['failed'] is True
Пример #7
0
    def test_send_request_should_return_error_info_when_http_error_raises(self):
        self.connection_mock.send.side_effect = HTTPError('http://testhost.com', 500, '', {},
                                                          StringIO('{"errorMessage": "ERROR"}'))

        resp = self.checkpoint_plugin.send_request('/test', None)

        assert resp == (500, {'errorMessage': 'ERROR'})
Пример #8
0
 def test_perform_storage_volume_action_exception_case(self, redfish_response_mock,
                                                       redfish_connection_mock_for_storage_volume):
     redfish_response_mock.headers.update({"Location": "JobService/Jobs/JID_123"})
     redfish_connection_mock_for_storage_volume.invoke_request.side_effect = HTTPError('http://testhost.com', 400,
                                                                                       '', {}, None)
     with pytest.raises(HTTPError) as ex:
         self.module.perform_storage_volume_action("POST", "uri", redfish_connection_mock_for_storage_volume,
                                                   "create", payload={"payload": "value"})
    def test_auth_error(self, mocker):
        request_mock = mocker.patch.object(client, "Request").return_value
        request_mock.open.side_effect = HTTPError("", 401, "Unauthorized", {},
                                                  None)

        c = client.Client("https://instance.com", "user", "pass")
        with pytest.raises(errors.AuthError):
            c.request("GET", "api/now/some/path")
    def test_login_raises_exception_when_http_error(self):
        self.connection_mock.send.side_effect = HTTPError('http://testhost.com', 400, '', {},
                                                          StringIO('{"message": "Failed to authenticate user"}'))

        with self.assertRaises(ConnectionError) as res:
            self.ftd_plugin.login('foo', 'bar')

        assert 'Failed to authenticate user' in str(res.exception)
    def test_send_request_should_return_error_info_when_http_error_raises(self):
        self.connection_mock.send.side_effect = HTTPError('http://testhost.com', 500, '', {},
                                                          StringIO('{"errorMessage": "ERROR"}'))

        resp = self.ftd_plugin.send_request('/test', HTTPMethod.GET)

        assert {ResponseParams.SUCCESS: False, ResponseParams.STATUS_CODE: 500,
                ResponseParams.RESPONSE: {'errorMessage': 'ERROR'}} == resp
Пример #12
0
 def test_fetch_storage_resource_error_case_04(self, redfish_connection_mock_for_storage_volume,
                                               redfish_response_mock):
     f_module = self.get_module_mock()
     msg = "http error"
     redfish_connection_mock_for_storage_volume.root_uri = "/redfish/v1/"
     redfish_connection_mock_for_storage_volume.invoke_request.side_effect = HTTPError('http://testhost.com', 400,
                                                                                       msg, {}, None)
     with pytest.raises(Exception, match=msg) as exc:
         self.module.fetch_storage_resource(f_module, redfish_connection_mock_for_storage_volume)
Пример #13
0
 def test_fetch_storage_resource_error_case_03(self, redfish_connection_mock_for_storage_volume,
                                               redfish_response_mock):
     f_module = self.get_module_mock()
     msg = "Target out-of-band controller does not support storage feature using Redfish API."
     redfish_connection_mock_for_storage_volume.root_uri = "/redfish/v1/"
     redfish_connection_mock_for_storage_volume.invoke_request.side_effect = HTTPError('http://testhost.com', 404,
                                                                                       json.dumps(msg), {}, None)
     with pytest.raises(Exception) as exc:
         self.module.fetch_storage_resource(f_module, redfish_connection_mock_for_storage_volume)
Пример #14
0
    def test_download_file_http_error(self):
        self.connection.send.side_effect = [
            HTTPError('http://bigip.local', 400, '', {}, StringIO('{"errorMessage": "ERROR"}'))
        ]

        with self.assertRaises(HTTPError) as res:
            self.connection.download_file('/fake/path/to/download/fakefile', '/tmp/fakefile')

        assert res.exception.code == 400
Пример #15
0
 def test_request_raises_on_status_500(self, open_url_mock):
     open_url_mock.side_effect = HTTPError('https://api.test.manifold.co/v1/endpoint',
                                           500, 'Server error', {}, six.StringIO('ERROR'))
     client = ManifoldApiClient('token-123')
     with self.assertRaises(ApiError) as context:
         client.request('test', 'endpoint')
     self.assertEqual('Server returned: HTTP Error 500: Server error while requesting '
                      'https://api.test.manifold.co/v1/endpoint:\nERROR',
                      str(context.exception))
Пример #16
0
 def test_get_device_id_from_service_tags_error_case(self, connection_mock, response_mock):
     connection_mock.__enter__.return_value = connection_mock
     connection_mock.invoke_request.side_effect = HTTPError('http://testhost.com',
                                                            400, '', {}, None)
     response_mock.json_data = {"value": [{"DeviceServiceTag": "MX1234", "Id": 1234}]}
     response_mock.status_code = 200
     response_mock.success = True
     with pytest.raises(HTTPError) as ex:
         self.module._get_device_id_from_service_tags(["INVALID"], connection_mock)
Пример #17
0
 def test_main_HTTPError_error_case(self, module_mock, validate_inputs_mock, connection_mock, get_resource_parameters_mock, response_mock):
     get_resource_parameters_mock.return_value = resource_basic_inventory
     connection_mock.__enter__.return_value = connection_mock
     connection_mock.invoke_request.side_effect = HTTPError('http://testhost.com', 400, '', {}, None)
     response_mock.json_data = {"value": [{"device_id1": "details", "device_id2": "details"}]}
     response_mock.status_code = 400
     result = self._run_module_with_fail_json(default_args)
     assert 'device_info' not in result
     assert result['failed'] is True
Пример #18
0
    def test_send_request_should_return_error_info_when_http_error_raises(self):
        self.connection.send.side_effect = HTTPError(
            'http://bigip.local', 400, '', {}, StringIO('{"errorMessage": "ERROR"}')
        )

        with self.assertRaises(AnsibleConnectionFailure) as res:
            self.connection.httpapi.login('foo', 'bar')

        assert "Authentication process failed, server returned: {'errorMessage': 'ERROR'}" in str(res.exception)
Пример #19
0
    def test_send_request_should_return_error_info_when_http_error_raises(
            self):
        self.connection_mock.send.side_effect = HTTPError(
            'http://f5cs.com', 500, '', {},
            StringIO('{"errorMessage": "ERROR"}'))

        resp = self.f5cs_plugin.send_request('/login', None)

        assert resp == dict(code=500, contents={'errorMessage': 'ERROR'})
Пример #20
0
    def test_http_error_handling(self, mocker):
        request = mocker.patch.object(client, "Request").return_value
        request.open.side_effect = HTTPError("url", 404, "missing", {}, None)
        c = client.Client("https://host", "u", "p", True, "ca")

        r = c.request("PUT", ("config", "a/b"))

        assert r.status == 404
        assert r.data == "missing"
 def test_idrac_redfish_main_HTTPError_case(self, param, idrac_connection_mock_for_redfish_storage_controller,
                                            redfish_default_args, mocker):
     redfish_default_args.update(param)
     json_str = to_text(json.dumps({"data": "out"}))
     mocker.patch('ansible.modules.remote_management.dellemc.idrac_redfish_storage_controller.check_raid_service',
                  side_effect=HTTPError('http://testhost.com', 400, 'http error message',
                                        {"accept-type": "application/json"}, StringIO(json_str)))
     result = self._run_module_with_fail_json(redfish_default_args)
     assert 'msg' in result
     assert result['failed'] is True
Пример #22
0
    def test_get_list_of_supported_api_versions_with_failed_http_request(self):
        error_msg = "Invalid Credentials"
        fp = mock.MagicMock()
        fp.read.return_value = '{{"error-msg": "{0}"}}'.format(error_msg)
        send_mock = mock.MagicMock(side_effect=HTTPError('url', 400, 'msg', 'hdrs', fp))
        with mock.patch.object(self.ftd_plugin.connection, 'send', send_mock):
            with self.assertRaises(ConnectionError) as res:
                self.ftd_plugin._get_supported_api_versions()

        assert error_msg in str(res.exception)
Пример #23
0
 def test_check_specified_identifier_exists_in_the_system_exception_case_02(
         self, redfish_connection_mock_for_storage_volume,
         redfish_response_mock):
     f_module = self.get_module_mock(params={"controller_id": "1234"})
     msg = "http error"
     redfish_connection_mock_for_storage_volume.invoke_request.side_effect = HTTPError(
         'http://testhost.com', 400, msg, {}, None)
     with pytest.raises(Exception, match=msg) as exc:
         self.module.check_specified_identifier_exists_in_the_system(
             f_module, redfish_connection_mock_for_storage_volume, "uri",
             "Specified Controller 123 does not exist in the System.")
    def test_handle_httperror_should_update_tokens_and_retry_on_auth_errors(self):
        self.ftd_plugin.refresh_token = 'REFRESH_TOKEN'
        self.connection_mock.send.return_value = self._connection_response(
            {'access_token': 'NEW_ACCESS_TOKEN', 'refresh_token': 'NEW_REFRESH_TOKEN'}
        )

        retry = self.ftd_plugin.handle_httperror(HTTPError('http://testhost.com', 401, '', {}, None))

        assert retry
        assert 'NEW_ACCESS_TOKEN' == self.ftd_plugin.access_token
        assert 'NEW_REFRESH_TOKEN' == self.ftd_plugin.refresh_token
 def test_check_domain_service_http(self, ome_conn_mock_network, ome_default_args, mocker):
     f_module = self.get_module_mock()
     err_message = {'error': {'@Message.ExtendedInfo': [{'MessageId': 'CGEN1006'}]}}
     ome_conn_mock_network.invoke_request.side_effect = HTTPError('http://testhost.com', 400,
                                                                  json.dumps(err_message),
                                                                  {"accept-type": "application/json"}, None)
     mocker.patch(MODULE_PATH + 'json.loads', return_value=err_message)
     with pytest.raises(Exception) as err:
         self.module.check_domain_service(f_module, ome_conn_mock_network)
     assert err.value.args[0] == "The device location settings operation is supported only on " \
                                 "OpenManage Enterprise Modular."
 def test_invoke_request_http_error_handling(self, mock_response, mocker):
     open_url_mock = mocker.patch('ansible.module_utils.remote_management.dellemc.ome.open_url',
                                  return_value=mock_response)
     open_url_mock.side_effect = HTTPError('http://testhost.com/', 400,
                                           'Bad Request Error', {}, None)
     module_params = {'hostname': '192.168.0.1', 'username': '******',
                      'password': '******', "port": 443}
     req_session = False
     with pytest.raises(HTTPError) as e:
         with RestOME(module_params, req_session) as obj:
             obj.invoke_request("/testpath", "GET")
    def test_http_error(self, mocker):
        request_mock = mocker.patch.object(client, "Request").return_value
        request_mock.open.side_effect = HTTPError(
            "", 404, "Not Found", {}, io.StringIO(to_text("My Error")))

        c = client.Client("https://instance.com", "user", "pass")
        resp = c.request("GET", "api/now/some/path")

        assert resp.status == 404
        assert resp.data == "My Error"
        assert resp.headers == {}
Пример #28
0
    def test_upload_file_total_failure(self):
        self.connection.send.side_effect = HTTPError(
            'http://bigip.local', 400, '', {}, StringIO('{"errorMessage": "ERROR"}')
        )
        binary_file = os.path.join(fixture_path, 'test_binary_file.mock')

        with self.assertRaises(AnsibleConnectionFailure) as res:
            self.connection.httpapi.upload_file('/fake/path/to/upload', binary_file)

        assert 'Failed to upload file too many times.' in str(res.exception)
        assert self.connection.send.call_count == 3
Пример #29
0
    def test_non_200(self, mocker):
        auth_resp = mocker.Mock()
        auth_resp.read.return_value = '{"access_token": "token"}'
        data_resp = HTTPError("url", 404, '{"msg": "missing item"}', {}, None)
        open_url = mocker.patch.object(client, "open_url")
        open_url.side_effect = auth_resp, data_resp

        resp = client.Client("http://ex.com/", "user", "pass").get("/path")

        assert 404 == resp.status
        assert '{"msg": "missing item"}' == resp.data
        assert {"msg": "missing item"} == resp.json
Пример #30
0
    def test_oauth_failure(self, mocker):
        request_mock = mocker.patch.object(client, "Request").return_value
        request_mock.open.side_effect = HTTPError(
            "", 403, "Forbidden", {}, io.StringIO(to_text("Error message")))

        c = client.Client("instance.com",
                          "user",
                          "pass",
                          client_id="id",
                          client_secret="secret")
        with pytest.raises(errors.UnexpectedAPIResponse,
                           match="Error message"):
            c.auth_header