Exemple #1
0
def execute_test_event_action():
    """Executes the SubmitTestEvent Action

        Return a JSON containing the EventType received.
        Logs exception of any error and return abort.

        Returns:
            JSON: JSON containing the EventType.

        Exceptions:
            OneViewRedfishError: When an invalid JSON is received.
            return abort(400)

            Exception: Unexpected error.
            return abort(500)
    """

    try:
        try:
            event_type = request.get_json()['EventType']
        except Exception:
            raise OneViewRedfishError(
                {'message': 'Invalid JSON data. Missing EventType property.'})

        if (event_type not in util.subscriptions_by_type.keys()):
            raise OneViewRedfishError(
                {'message': 'Invalid EventType value: %s' % event_type})

        # Creates a sample OneView SCMB message according to
        # the value of 'event_type'
        if (event_type == "Alert"):
            message = deepcopy(ONEVIEW_TEST_ALERT)
        else:
            message = deepcopy(ONEVIEW_TEST_TASK)
            message['changeType'] = REDFISH_TO_ONEVIEW_EVENTS[event_type]

        event = Event(message)

        util.dispatch_event(event)

        json_str = event.serialize()

        return Response(response=json_str,
                        status=status.HTTP_202_ACCEPTED,
                        mimetype='application/json')
    except OneViewRedfishError as e:
        logging.exception('Mapping error: {}'.format(e))
        abort(status.HTTP_400_BAD_REQUEST, e.msg['message'])
    except Exception as e:
        logging.exception('Unexpected error: {}'.format(e))
        abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #2
0
    def test_build_event_from_task(self):

        task = self.alert
        task["resource"]["category"] = "task"
        task["resourceUri"] = \
            "/rest/server-hardware/30373737-3237-4D32-3230-313530314752"
        task["resource"]["name"] = "0000A66101, bay 3"
        event = Event(self.alert)

        result = json.loads(event.serialize())

        event_mockup = self.event_mockup
        event_mockup["Events"][0]["EventType"] = "ResourceAdded"
        self.assertEqualMockup(self.event_mockup, result)
    def test_serialize(self):
        # Tests the serialize function result against known result

        try:
            event = Event(self.alert)
        except Exception as e:
            self.fail("Failed to instantiate Event class."
                      " Error: {}".format(e))

        try:
            result = json.loads(event.serialize())
        except Exception as e:
            self.fail("Failed to serialize. Error: {}".format(e))

        self.assertEqualMockup(self.event_mockup, result)