Add event service resource for RSD2.1
Change-Id: I5177236a4aaa3f3395a4064b32017b9935703af5
This commit is contained in:
parent
e662db24ae
commit
34d46bbead
@ -17,6 +17,7 @@ from sushy.resources import base
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
|
||||
from rsd_lib.resources.v2_1.event_service import event_service
|
||||
from rsd_lib.resources.v2_1.fabric import fabric
|
||||
from rsd_lib.resources.v2_1.manager import manager
|
||||
from rsd_lib.resources.v2_1.node import node
|
||||
@ -54,6 +55,9 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
_registries_path = base.Field(['Registries', '@odata.id'])
|
||||
"""RegistriesCollection path"""
|
||||
|
||||
_event_service_path = base.Field(['EventService', '@odata.id'])
|
||||
"""Event Service path"""
|
||||
|
||||
_redfish_version = base.Field(['RedfishVersion'])
|
||||
"""Redfish version"""
|
||||
|
||||
@ -249,3 +253,12 @@ class RSDLibV2_1(base.ResourceBase):
|
||||
self._conn,
|
||||
identity,
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def get_event_service(self):
|
||||
"""Return a EventService object
|
||||
|
||||
:returns: The EventService object
|
||||
"""
|
||||
return event_service.EventService(self._conn,
|
||||
self._event_service_path,
|
||||
redfish_version=self.redfish_version)
|
||||
|
0
rsd_lib/resources/v2_1/event_service/__init__.py
Normal file
0
rsd_lib/resources/v2_1/event_service/__init__.py
Normal file
97
rsd_lib/resources/v2_1/event_service/event_service.py
Normal file
97
rsd_lib/resources/v2_1/event_service/event_service.py
Normal file
@ -0,0 +1,97 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib.resources.v2_1.event_service import event_subscription
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class StatusField(base.CompositeField):
|
||||
state = base.Field("State")
|
||||
"""The state of Status"""
|
||||
|
||||
health = base.Field("Health")
|
||||
"""The Status health"""
|
||||
|
||||
health_rollup = base.Field('HealthRollup')
|
||||
"""The Status health_rollup field"""
|
||||
|
||||
|
||||
class EventService(base.ResourceBase):
|
||||
identity = base.Field("Id", required=True)
|
||||
"""The event service identity"""
|
||||
|
||||
name = base.Field("Name")
|
||||
"""The event service name"""
|
||||
|
||||
description = base.Field("Description")
|
||||
"""The description of event service"""
|
||||
|
||||
status = StatusField("Status")
|
||||
"""The event service status"""
|
||||
|
||||
service_enabled = base.Field("ServiceEnabled", adapter=bool)
|
||||
"""Whether the event service is enabled"""
|
||||
|
||||
delivery_retry_attempts = base.Field("DeliveryRetryAttempts",
|
||||
adapter=rsd_lib_utils.num_or_none)
|
||||
"""This is the number of attempts an event posting is retried before the
|
||||
subscription is terminated
|
||||
"""
|
||||
|
||||
delivery_retry_interval_seconds = base.Field(
|
||||
"DeliveryRetryIntervalSeconds", adapter=rsd_lib_utils.num_or_none)
|
||||
"""This represents the number of seconds between retry attempts for
|
||||
sending any given Event
|
||||
"""
|
||||
|
||||
event_types_for_subscription = base.Field("EventTypesForSubscription")
|
||||
"""These are the types of Events that can be subscribed to. Available
|
||||
event types:
|
||||
- StatusChange - The status of this resource has changed
|
||||
- ResourceUpdated - The value of this resource has been updated
|
||||
- ResourceAdded - A resource has been added
|
||||
- ResourceRemoved - A resource has been removed
|
||||
- Alert - A condition exists which requires attention
|
||||
"""
|
||||
|
||||
def __init__(self, connector, identity, redfish_version=None):
|
||||
"""A class representing a EventService
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param identity: The identity of the EventService resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(EventService, self).__init__(connector, identity,
|
||||
redfish_version)
|
||||
|
||||
def _get_subscriptions_collection_path(self):
|
||||
"""Helper function to find the EventSubscriptionCollection path"""
|
||||
return utils.get_sub_resource_path_by(self, 'Subscriptions')
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def subscriptions(self):
|
||||
"""Property to provide reference to `EventSubscriptionCollection`
|
||||
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
return event_subscription.EventSubscriptionCollection(
|
||||
self._conn, self._get_subscriptions_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
121
rsd_lib/resources/v2_1/event_service/event_subscription.py
Normal file
121
rsd_lib/resources/v2_1/event_service/event_subscription.py
Normal file
@ -0,0 +1,121 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from jsonschema import validate
|
||||
import logging
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib.resources.v2_1.event_service import schemas as \
|
||||
event_service_schemas
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class OemField(base.CompositeField):
|
||||
pass
|
||||
|
||||
|
||||
class EventSubscription(base.ResourceBase):
|
||||
identity = base.Field("Id")
|
||||
"""The Event Subscription id"""
|
||||
|
||||
name = base.Field("Name")
|
||||
"""The Event Subscription name"""
|
||||
|
||||
description = base.Field("Description")
|
||||
"""The Event Subscription description"""
|
||||
|
||||
oem = OemField("Oem")
|
||||
"""The Event Subscription oem"""
|
||||
|
||||
destination = base.Field("Destination")
|
||||
"""The URI of the destination Event Service"""
|
||||
|
||||
event_types = base.Field("EventTypes")
|
||||
"""These are the types of Events that can be subscribed to. Available
|
||||
event types:
|
||||
- StatusChange - The status of this resource has changed
|
||||
- ResourceUpdated - The value of this resource has been updated.
|
||||
- ResourceAdded - A resource has been added
|
||||
- ResourceRemoved - A resource has been removed
|
||||
- Alert - A condition exists which requires attention
|
||||
"""
|
||||
|
||||
context = base.Field("Context")
|
||||
"""A client-supplied string that is stored with the event destination
|
||||
subscription
|
||||
"""
|
||||
|
||||
protocol = base.Field("Protocol")
|
||||
"""The protocol type of the event connection. Available protocols:
|
||||
- "Redfish" - event type shall adhere to that defined in the
|
||||
Redfish specification.
|
||||
"""
|
||||
|
||||
http_headers = base.Field("HttpHeaders")
|
||||
"""This property shall contain an object consisting of the names and values
|
||||
of of HTTP header to be included with every event POST to the Event
|
||||
Destination
|
||||
"""
|
||||
|
||||
origin_resources = base.Field("OriginResources")
|
||||
"""A list of resources for which the service will send events specified in
|
||||
EventTypes array. Empty array or NULL is interpreted as subscription for
|
||||
all resources and assets in subsystem.
|
||||
"""
|
||||
|
||||
message_ids = base.Field("MessageIds")
|
||||
"""A list of MessageIds that the service will send"""
|
||||
|
||||
def delete(self):
|
||||
"""Delete this event subscription"""
|
||||
self._conn.delete(self._path)
|
||||
|
||||
|
||||
class EventSubscriptionCollection(base.ResourceCollectionBase):
|
||||
@property
|
||||
def _resource_type(self):
|
||||
return EventSubscription
|
||||
|
||||
def __init__(self, connector, path, redfish_version=None):
|
||||
"""A class representing a Event Subscription Collection
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param path: The canonical path to the Event Subscription collection
|
||||
resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(EventSubscriptionCollection, self).__init__(connector, path,
|
||||
redfish_version)
|
||||
|
||||
def create_event_subscription(self, event_subscription_req):
|
||||
"""Create a new event subscription
|
||||
|
||||
:param event_subscription_req: JSON for event subscription
|
||||
:returns: The uri of the new event subscription
|
||||
"""
|
||||
target_uri = self._path
|
||||
|
||||
validate(event_subscription_req,
|
||||
event_service_schemas.event_subscription_req_schema)
|
||||
|
||||
resp = self._conn.post(target_uri, data=event_subscription_req)
|
||||
event_subscription_url = resp.headers['Location']
|
||||
LOG.info("event subscription created at %s", event_subscription_url)
|
||||
|
||||
return event_subscription_url[event_subscription_url.find(self._path):]
|
45
rsd_lib/resources/v2_1/event_service/schemas.py
Normal file
45
rsd_lib/resources/v2_1/event_service/schemas.py
Normal file
@ -0,0 +1,45 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
event_subscription_req_schema = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'Name': {'type': 'string'},
|
||||
'Destination': {'type': 'string'},
|
||||
'EventTypes': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'string',
|
||||
'enum': ['ResourceAdded', 'ResourceRemoved', 'StatusChange',
|
||||
'ResourceUpdated', 'Alert']
|
||||
}
|
||||
},
|
||||
'Context': {'type': 'string'},
|
||||
'Protocol': {
|
||||
'type': 'string',
|
||||
'enum': ['Redfish']
|
||||
},
|
||||
'OriginResources': {
|
||||
'type': 'array',
|
||||
'items': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'@odata.id': {'type': 'string'}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
'additionalProperties': False
|
||||
}
|
29
rsd_lib/tests/unit/json_samples/v2_1/event_service.json
Normal file
29
rsd_lib/tests/unit/json_samples/v2_1/event_service.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#EventService",
|
||||
"@odata.id": "/redfish/v1/EventService",
|
||||
"@odata.type": "#EventService.v1_0_0.EventService",
|
||||
"Id": "EventService",
|
||||
"Name": "Event Service",
|
||||
"Description": "Event Service",
|
||||
"Status": {
|
||||
"State": "Enabled",
|
||||
"Health": "OK"
|
||||
},
|
||||
"ServiceEnabled": true,
|
||||
"DeliveryRetryAttempts": 3,
|
||||
"DeliveryRetryIntervalSeconds": 60,
|
||||
"EventTypesForSubscription": [
|
||||
"StatusChange",
|
||||
"ResourceUpdated",
|
||||
"ResourceAdded",
|
||||
"ResourceRemoved",
|
||||
"Alert"
|
||||
],
|
||||
"Subscriptions": {
|
||||
"@odata.id":"/redfish/v1/EventService/Subscriptions"
|
||||
},
|
||||
"Actions": {
|
||||
"Oem":{}
|
||||
},
|
||||
"Oem": {}
|
||||
}
|
15
rsd_lib/tests/unit/json_samples/v2_1/event_subscription.json
Normal file
15
rsd_lib/tests/unit/json_samples/v2_1/event_subscription.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"@odata.context":"/redfish/v1/$metadata#EventService/Members/Subscriptions/Members/$entity",
|
||||
"@odata.id":"/redfish/v1/EventService/Subscriptions/1",
|
||||
"@odata.type":"#EventService.v1_1_0.EventDestination",
|
||||
"Id":"1",
|
||||
"Name":"EventSubscription 1",
|
||||
"Description":"EventSubscription",
|
||||
"Destination":"http://192.168.1.1/Destination1",
|
||||
"EventTypes":[
|
||||
"ResourceAdded",
|
||||
"ResourceRemoved"
|
||||
],
|
||||
"Context":"My Event",
|
||||
"Protocol":"Redfish"
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"@odata.context":"/redfish/v1/$metadata#EventService/Members/Events/$entity",
|
||||
"@odata.type":"#EventDestinationCollection.EventDestinationCollection",
|
||||
"Name":"Event Subscriptions Collection",
|
||||
"Members@odata.count":1,
|
||||
"Members":[
|
||||
{
|
||||
"@odata.id":"/redfish/v1/EventService/Subscriptions/1"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from sushy import exceptions
|
||||
|
||||
from rsd_lib.resources.v2_1.event_service import event_service
|
||||
from rsd_lib.resources.v2_1.event_service import event_subscription
|
||||
|
||||
|
||||
class EventServiceTestCase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(EventServiceTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/event_service.json',
|
||||
'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.event_service_inst = event_service.EventService(
|
||||
self.conn, '/redfish/v1/EventService',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.event_service_inst._parse_attributes()
|
||||
self.assertEqual('EventService', self.event_service_inst.identity)
|
||||
self.assertEqual('Event Service', self.event_service_inst.name)
|
||||
self.assertEqual('Event Service', self.event_service_inst.description)
|
||||
self.assertEqual('Enabled', self.event_service_inst.status.state)
|
||||
self.assertEqual('OK', self.event_service_inst.status.health)
|
||||
self.assertEqual(None, self.event_service_inst.status.health_rollup)
|
||||
self.assertEqual(True, self.event_service_inst.service_enabled)
|
||||
self.assertEqual(3, self.event_service_inst.delivery_retry_attempts)
|
||||
self.assertEqual(
|
||||
60, self.event_service_inst.delivery_retry_interval_seconds)
|
||||
self.assertEqual(
|
||||
["StatusChange", "ResourceUpdated", "ResourceAdded",
|
||||
"ResourceRemoved", "Alert"],
|
||||
self.event_service_inst.event_types_for_subscription)
|
||||
|
||||
def test__get_subscriptions_collection_path(self):
|
||||
expected = '/redfish/v1/EventService/Subscriptions'
|
||||
result = self.event_service_inst._get_subscriptions_collection_path()
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test__get_subscriptions_collection_path_missing_attr(self):
|
||||
self.event_service_inst._json.pop('Subscriptions')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute Subscriptions'):
|
||||
self.event_service_inst._get_subscriptions_collection_path()
|
||||
|
||||
def test_subscriptions(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'event_subscription_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_subscriptions = self.event_service_inst.subscriptions
|
||||
# | THEN |
|
||||
self.assertIsInstance(actual_subscriptions,
|
||||
event_subscription.EventSubscriptionCollection)
|
||||
self.conn.get.return_value.json.assert_called_once_with()
|
||||
|
||||
# reset mock
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
# | WHEN & THEN |
|
||||
# tests for same object on invoking subsequently
|
||||
self.assertIs(actual_subscriptions,
|
||||
self.event_service_inst.subscriptions)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_event_subscriptions_on_refresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'event_subscription_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.event_service_inst.subscriptions,
|
||||
event_subscription.EventSubscriptionCollection)
|
||||
|
||||
# On refreshing the event_service instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'event_service.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.event_service_inst.invalidate()
|
||||
self.event_service_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'event_subscription_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.event_service_inst.subscriptions,
|
||||
event_subscription.EventSubscriptionCollection)
|
@ -0,0 +1,154 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import jsonschema
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_1.event_service import event_subscription
|
||||
from rsd_lib.tests.unit.fakes import request_fakes
|
||||
|
||||
|
||||
class EventSubscriptionTestCase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(EventSubscriptionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open(
|
||||
'rsd_lib/tests/unit/json_samples/v2_1/event_subscription.json',
|
||||
'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.event_subscription_inst = event_subscription.EventSubscription(
|
||||
self.conn, '/redfish/v1/EventService/Subscriptions/1',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.event_subscription_inst._parse_attributes()
|
||||
self.assertEqual('1', self.event_subscription_inst.identity)
|
||||
self.assertEqual('EventSubscription 1',
|
||||
self.event_subscription_inst.name)
|
||||
self.assertEqual('EventSubscription',
|
||||
self.event_subscription_inst.description)
|
||||
self.assertEqual('http://192.168.1.1/Destination1',
|
||||
self.event_subscription_inst.destination)
|
||||
self.assertEqual(['ResourceAdded', 'ResourceRemoved'],
|
||||
self.event_subscription_inst.event_types)
|
||||
self.assertEqual("My Event", self.event_subscription_inst.context)
|
||||
self.assertEqual("Redfish", self.event_subscription_inst.protocol)
|
||||
|
||||
def test_delete(self):
|
||||
self.event_subscription_inst.delete()
|
||||
self.event_subscription_inst._conn.delete.assert_called_once()
|
||||
|
||||
|
||||
class EventSubscriptionCollectionTestCase(testtools.TestCase):
|
||||
def setUp(self):
|
||||
super(EventSubscriptionCollectionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open(
|
||||
'rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'event_subscription_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.conn.post.return_value = request_fakes.fake_request_post(
|
||||
None, headers={"Location": "https://localhost:8443/redfish/v1/"
|
||||
"EventService/Subscriptions/2"})
|
||||
|
||||
self.event_subscription_col = event_subscription. \
|
||||
EventSubscriptionCollection(self.conn,
|
||||
'/redfish/v1/EventService/'
|
||||
'Subscriptions',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.event_subscription_col._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.event_subscription_col.redfish_version)
|
||||
self.assertEqual('Event Subscriptions Collection',
|
||||
self.event_subscription_col.name)
|
||||
self.assertEqual(('/redfish/v1/EventService/Subscriptions/1',),
|
||||
self.event_subscription_col.members_identities)
|
||||
|
||||
@mock.patch.object(event_subscription, 'EventSubscription', autospec=True)
|
||||
def test_get_member(self, mock_event_subscription):
|
||||
self.event_subscription_col.get_member(
|
||||
'/redfish/v1/EventService/Subscriptions/1')
|
||||
mock_event_subscription.assert_called_once_with(
|
||||
self.event_subscription_col._conn,
|
||||
'/redfish/v1/EventService/Subscriptions/1',
|
||||
redfish_version=self.event_subscription_col.redfish_version)
|
||||
|
||||
@mock.patch.object(event_subscription, 'EventSubscription', autospec=True)
|
||||
def test_get_members(self, mock_event_subscription):
|
||||
members = self.event_subscription_col.get_members()
|
||||
mock_event_subscription.assert_called_once_with(
|
||||
self.event_subscription_col._conn,
|
||||
'/redfish/v1/EventService/Subscriptions/1',
|
||||
redfish_version=self.event_subscription_col.redfish_version)
|
||||
self.assertIsInstance(members, list)
|
||||
self.assertEqual(1, len(members))
|
||||
|
||||
def test_create_subscription_reqs(self):
|
||||
reqs = {
|
||||
'Name': 'EventSubscription 1',
|
||||
'Destination': 'EventSubscription',
|
||||
'EventTypes': [
|
||||
'ResourceAdded',
|
||||
'ResourceRemoved'
|
||||
],
|
||||
'Context': 'My Event',
|
||||
'Protocol': 'Redfish',
|
||||
'OriginResources': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1'
|
||||
}]
|
||||
}
|
||||
|
||||
result = self.event_subscription_col.create_event_subscription(reqs)
|
||||
self.event_subscription_col._conn.post.assert_called_once_with(
|
||||
'/redfish/v1/EventService/Subscriptions',
|
||||
data=reqs)
|
||||
self.assertEqual(result,
|
||||
'/redfish/v1/EventService/Subscriptions/2')
|
||||
|
||||
def test_create_subscription_invalid_reqs(self):
|
||||
reqs = {
|
||||
'Name': 'EventSubscription 1',
|
||||
'Destination': 'EventSubscription',
|
||||
'EventTypes': [
|
||||
'ResourceAdded',
|
||||
'ResourceRemoved'
|
||||
],
|
||||
'Context': 'My Event',
|
||||
'Protocol': 'Redfish',
|
||||
'OriginResources': [{
|
||||
'@odata.id': '/redfish/v1/Systems/1'
|
||||
}]
|
||||
}
|
||||
|
||||
# Wrong format
|
||||
event_subscription_req = reqs.copy()
|
||||
event_subscription_req.update({'Context': True})
|
||||
self.assertRaises(
|
||||
jsonschema.exceptions.ValidationError,
|
||||
self.event_subscription_col.create_event_subscription,
|
||||
event_subscription_req)
|
||||
|
||||
# Wrong additional fields
|
||||
event_subscription_req = reqs.copy()
|
||||
event_subscription_req['Additional'] = 'AdditionalField'
|
||||
self.assertRaises(
|
||||
jsonschema.exceptions.ValidationError,
|
||||
self.event_subscription_col.create_event_subscription,
|
||||
event_subscription_req)
|
@ -20,6 +20,7 @@ import testtools
|
||||
from rsd_lib.resources import v2_1
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
|
||||
from rsd_lib.resources.v2_1.event_service import event_service
|
||||
from rsd_lib.resources.v2_1.fabric import fabric
|
||||
from rsd_lib.resources.v2_1.manager import manager
|
||||
from rsd_lib.resources.v2_1.node import node
|
||||
@ -55,6 +56,8 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
self.rsd._task_service_path)
|
||||
self.assertEqual("/redfish/v1/Registries",
|
||||
self.rsd._registries_path)
|
||||
self.assertEqual("/redfish/v1/EventService",
|
||||
self.rsd._event_service_path)
|
||||
|
||||
@mock.patch.object(system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
@ -163,8 +166,7 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
)
|
||||
|
||||
@mock.patch.object(task_service, 'TaskService', autospec=True)
|
||||
def test_get_task_service(
|
||||
self, mock_task_service):
|
||||
def test_get_task_service(self, mock_task_service):
|
||||
self.rsd.get_task_service()
|
||||
mock_task_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/TaskService',
|
||||
@ -184,3 +186,10 @@ class RSDLibV2_1TestCase(testtools.TestCase):
|
||||
self.rsd._conn, 'fake-registries-id',
|
||||
redfish_version=self.rsd.redfish_version
|
||||
)
|
||||
|
||||
@mock.patch.object(event_service, 'EventService', autospec=True)
|
||||
def test_get_event_service(self, mock_event_service):
|
||||
self.rsd.get_event_service()
|
||||
mock_event_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/EventService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
@ -18,6 +18,8 @@ import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
|
||||
from rsd_lib.resources.v2_1.event_service import event_service \
|
||||
as v2_1_event_service
|
||||
from rsd_lib.resources.v2_1.fabric import fabric as v2_1_fabric
|
||||
from rsd_lib.resources.v2_1.node import node as v2_1_node
|
||||
from rsd_lib.resources.v2_1.registries import registries as v2_1_registries
|
||||
@ -62,6 +64,8 @@ class RSDLibV2_2TestCase(testtools.TestCase):
|
||||
self.rsd._registries_path)
|
||||
self.assertEqual("/redfish/v1/UpdateService",
|
||||
self.rsd._update_service_path)
|
||||
self.assertEqual("/redfish/v1/EventService",
|
||||
self.rsd._event_service_path)
|
||||
|
||||
@mock.patch.object(v2_2_system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
@ -205,3 +209,10 @@ class RSDLibV2_2TestCase(testtools.TestCase):
|
||||
mock_update_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/UpdateService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
||||
@mock.patch.object(v2_1_event_service, 'EventService', autospec=True)
|
||||
def test_get_event_service(self, mock_event_service):
|
||||
self.rsd.get_event_service()
|
||||
mock_event_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/EventService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
@ -18,6 +18,8 @@ import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
|
||||
from rsd_lib.resources.v2_1.event_service import event_service \
|
||||
as v2_1_event_service
|
||||
from rsd_lib.resources.v2_1.registries import registries as v2_1_registries
|
||||
from rsd_lib.resources.v2_1.task import task_service as v2_1_task_service
|
||||
from rsd_lib.resources.v2_2.update_service import update_service \
|
||||
@ -59,6 +61,8 @@ class RSDLibV2_3TestCase(testtools.TestCase):
|
||||
self.rsd._registries_path)
|
||||
self.assertEqual("/redfish/v1/UpdateService",
|
||||
self.rsd._update_service_path)
|
||||
self.assertEqual("/redfish/v1/EventService",
|
||||
self.rsd._event_service_path)
|
||||
|
||||
@mock.patch.object(v2_3_system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
@ -196,6 +200,13 @@ class RSDLibV2_3TestCase(testtools.TestCase):
|
||||
self.rsd._conn, '/redfish/v1/UpdateService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
||||
@mock.patch.object(v2_1_event_service, 'EventService', autospec=True)
|
||||
def test_get_event_service(self, mock_event_service):
|
||||
self.rsd.get_event_service()
|
||||
mock_event_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/EventService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
||||
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
|
||||
# def test_get_telemetry_service(self, mock_telemetry_service):
|
||||
# self.rsd.get_telemetry_service()
|
||||
|
@ -18,6 +18,8 @@ import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
|
||||
from rsd_lib.resources.v2_1.event_service import event_service \
|
||||
as v2_1_event_service
|
||||
from rsd_lib.resources.v2_1.registries import registries as v2_1_registries
|
||||
from rsd_lib.resources.v2_1.task import task_service as v2_1_task_service
|
||||
from rsd_lib.resources.v2_2.update_service import update_service \
|
||||
@ -59,6 +61,8 @@ class RSDLibV2_3TestCase(testtools.TestCase):
|
||||
self.rsd._registries_path)
|
||||
self.assertEqual("/redfish/v1/UpdateService",
|
||||
self.rsd._update_service_path)
|
||||
self.assertEqual("/redfish/v1/EventService",
|
||||
self.rsd._event_service_path)
|
||||
|
||||
@mock.patch.object(v2_3_system, 'SystemCollection', autospec=True)
|
||||
def test_get_system_collection(self, mock_system_collection):
|
||||
@ -196,6 +200,13 @@ class RSDLibV2_3TestCase(testtools.TestCase):
|
||||
self.rsd._conn, '/redfish/v1/UpdateService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
||||
@mock.patch.object(v2_1_event_service, 'EventService', autospec=True)
|
||||
def test_get_event_service(self, mock_event_service):
|
||||
self.rsd.get_event_service()
|
||||
mock_event_service.assert_called_once_with(
|
||||
self.rsd._conn, '/redfish/v1/EventService',
|
||||
redfish_version=self.rsd.redfish_version)
|
||||
|
||||
# @mock.patch.object(v2_2_telemetry, 'Telemetry', autospec=True)
|
||||
# def test_get_telemetry_service(self, mock_telemetry_service):
|
||||
# self.rsd.get_telemetry_service()
|
||||
|
Loading…
x
Reference in New Issue
Block a user