예제 #1
0
 def not_found(error):
     """Creates a Not Found Error response"""
     redfish_error = RedfishError("GeneralError", error.description)
     error_str = redfish_error.serialize()
     return Response(response=error_str,
                     status=status.HTTP_404_NOT_FOUND,
                     mimetype='application/json')
    def error_501(error):
        redfish_error = RedfishError("ActionNotSupported", error.description)
        redfish_error.add_extended_info(message_id="ActionNotSupported",
                                        message_args=["action"])

        return ResponseBuilder.response(redfish_error,
                                        status.HTTP_501_NOT_IMPLEMENTED)
예제 #3
0
        def unauthorized_error(error):
            """Creates a Unauthorized Error response"""
            redfish_error = RedfishError("GeneralError", error.description)

            error_str = redfish_error.serialize()
            return Response(response=error_str,
                            status=status.HTTP_401_UNAUTHORIZED,
                            mimetype='application/json')
 def error_500(error):
     redfish_error = RedfishError(
         "InternalError",
         "The request failed due to an internal service error.  "
         "The service is still operational.")
     redfish_error.add_extended_info("InternalError")
     return ResponseBuilder.response(redfish_error,
                                     status.HTTP_500_INTERNAL_SERVER_ERROR)
예제 #5
0
    def test_add_extended_info_invalid_error_code(self):
        """Tests the add_extended_info invalid error code"""

        redfish_error = RedfishError("GeneralError", "General Error")

        try:
            redfish_error.add_extended_info("InvalidCode", "General Message")
        except errors.OneViewRedfishResourceNotFoundError as e:
            self.assertEqual(e.msg, "message_id InvalidCode not found")
예제 #6
0
    def not_implemented(error):
        """Creates a Not Implemented Error response"""
        redfish_error = RedfishError("ActionNotSupported", error.description)
        redfish_error.add_extended_info(message_id="ActionNotSupported",
                                        message_args=["action"])

        error_str = redfish_error.serialize()
        return Response(response=error_str,
                        status=status.HTTP_501_NOT_IMPLEMENTED,
                        mimetype='application/json')
예제 #7
0
    def test_serialize(self):
        """Tests the serialize function result against known result"""

        redfish_error = RedfishError("GeneralError", "General Error")
        result = json.loads(redfish_error.serialize())

        with open('oneview_redfish_toolkit/mockups/errors/'
                  'RedfishErrorNoExtendedInfo.json') as f:
            redfish_error_mockup = json.load(f)
        self.assertEqual(redfish_error_mockup, result)
    def test_add_extended_info_invalid_error_code(self):
        """Tests the add_extended_info invalid error code"""

        redfish_error = RedfishError("GeneralError", "General Error")

        try:
            redfish_error.add_extended_info("InvalidCode", "General Message")
        except OneViewRedfishResourceNotFoundException as e:
            self.assertEqual(e.msg, "Message id InvalidCode not found.")
            self.assertEqual(e.status_code_error, status.HTTP_404_NOT_FOUND)
    def error_500(error):
        if hasattr(error, "description"):
            msg = error.description
        else:
            msg = str(error)

        redfish_error = RedfishError("InternalError", msg)
        redfish_error.add_extended_info("InternalError")
        return ResponseBuilder.response(redfish_error,
                                        status.HTTP_500_INTERNAL_SERVER_ERROR)
예제 #10
0
        def internal_server_error(error):
            """General InternalServerError handler for the app"""

            redfish_error = RedfishError(
                "InternalError",
                "The request failed due to an internal service error.  "
                "The service is still operational.")
            redfish_error.add_extended_info("InternalError")
            error_str = redfish_error.serialize()
            return Response(response=error_str,
                            status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                            mimetype="application/json")
예제 #11
0
    def bad_request(error):
        """Creates a Bad Request Error response"""
        redfish_error = RedfishError("PropertyValueNotInList",
                                     error.description)

        redfish_error.add_extended_info(message_id="PropertyValueNotInList",
                                        message_args=["VALUE", "PROPERTY"],
                                        related_properties=["PROPERTY"])

        error_str = redfish_error.serialize()
        return Response(response=error_str,
                        status=status.HTTP_400_BAD_REQUEST,
                        mimetype='application/json')
예제 #12
0
    def test_add_extended_info_invalid_message_args(self):
        """Tests the add_extended_info invalid message_args"""

        redfish_error = RedfishError("GeneralError", "General Error")

        try:
            redfish_error.add_extended_info(
                message_id="PropertyValueNotInList",
                message_args=["Only 1, need 2"])
        except errors.OneViewRedfishError as e:
            self.assertEqual(
                e.msg,
                'Message has 2 replacements to be made but 1 args where sent')
예제 #13
0
        def bad_request(error):
            """Creates a Bad Request Error response"""
            redfish_error = RedfishError("PropertyValueNotInList",
                                         error.description)

            return ResponseBuilder.response(redfish_error,
                                            status.HTTP_400_BAD_REQUEST)
예제 #14
0
    def test_class_instantiation(self):
        """Tests class instantiation"""

        try:
            redfish_error = RedfishError("GeneralError", "General Error")
        except Exception as e:
            self.fail("Failed to instantiate RedfishError. Error: ".format(e))
        self.assertIsInstance(redfish_error, RedfishError)
예제 #15
0
    def test_redfish_error_with_extended_info(self):
        """Tests the add_extended_info with two additional info"""

        with open('oneview_redfish_toolkit/mockups/errors/'
                  'RedfishErrorExtendedInfo.json') as f:
            redfish_error_mockup = json.load(f)

        try:
            redfish_error = RedfishError(
                "GeneralError",
                "A general error has occurred. See ExtendedInfo "
                "for more information.")
            redfish_error.add_extended_info(
                message_id="PropertyValueNotInList",
                message_args=["RED", "IndicatorLED"],
                related_properties=["#/IndicatorLED"])
            redfish_error.add_extended_info(message_id="PropertyNotWritable",
                                            message_args=["SKU"],
                                            related_properties=["#/SKU"])
        except errors.OneViewRedfishError as e:
            self.fail("Failled to add Extened info".format(e))

        result = json.loads(redfish_error.serialize())
        self.assertEqual(redfish_error_mockup, result)
 def error_400(error):
     redfish_error = RedfishError("PropertyValueNotInList",
                                  error.description)
     return ResponseBuilder.response(redfish_error,
                                     status.HTTP_400_BAD_REQUEST)
 def error_404(error):
     redfish_error = RedfishError("GeneralError", error.description)
     return ResponseBuilder.response(redfish_error,
                                     status.HTTP_404_NOT_FOUND)
 def error_403(error):
     redfish_error = RedfishError("GeneralError", error.description)
     return ResponseBuilder.response(redfish_error,
                                     status.HTTP_403_FORBIDDEN)
 def error_401(error):
     redfish_error = RedfishError("GeneralError", error.description)
     return ResponseBuilder.response(redfish_error,
                                     status.HTTP_401_UNAUTHORIZED)