Merge "Add Message Registry File resource"
This commit is contained in:
commit
22299ccd27
|
@ -19,6 +19,7 @@ from sushy import connector as sushy_connector
|
|||
from sushy import exceptions
|
||||
from sushy.resources import base
|
||||
from sushy.resources.manager import manager
|
||||
from sushy.resources.registry import message_registry_file
|
||||
from sushy.resources.sessionservice import session
|
||||
from sushy.resources.sessionservice import sessionservice
|
||||
from sushy.resources.system import system
|
||||
|
@ -49,6 +50,9 @@ class Sushy(base.ResourceBase):
|
|||
_session_service_path = base.Field(['SessionService', '@odata.id'])
|
||||
"""SessionService path"""
|
||||
|
||||
_registries_path = base.Field(['Registries', '@odata.id'])
|
||||
"""Registries path"""
|
||||
|
||||
def __init__(self, base_url, username=None, password=None,
|
||||
root_prefix='/redfish/v1/', verify=True,
|
||||
auth=None, connector=None):
|
||||
|
@ -161,3 +165,18 @@ class Sushy(base.ResourceBase):
|
|||
"""
|
||||
return session.Session(self._conn, identity,
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def _get_registry_collection(self):
|
||||
"""Get MessageRegistryFileCollection object
|
||||
|
||||
This resource is optional and can be empty.
|
||||
|
||||
:returns: MessageRegistryFileCollection object
|
||||
or None if Registries not provided
|
||||
"""
|
||||
|
||||
if self._registries_path:
|
||||
return message_registry_file.MessageRegistryFileCollection(
|
||||
self._conn,
|
||||
self._registries_path,
|
||||
redfish_version=self.redfish_version)
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# 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.
|
||||
|
||||
# https://redfish.dmtf.org/schemas/v1/MessageRegistryFileCollection.json
|
||||
# https://redfish.dmtf.org/schemas/v1/MessageRegistryFile.v1_1_0.json
|
||||
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
|
||||
class LocationListField(base.ListField):
|
||||
"""Location for each registry file of languages supported
|
||||
|
||||
There are 3 options where the file can be hosted:
|
||||
|
||||
* locally as a single file,
|
||||
* locally as a part of archive (zip or other),
|
||||
* publicly on the Internet.
|
||||
"""
|
||||
|
||||
language = base.Field('Language')
|
||||
"""File's RFC5646 language code or the string 'default'"""
|
||||
|
||||
uri = base.Field('Uri')
|
||||
"""Location URI for co-located registry file with the Redfish service"""
|
||||
|
||||
archive_uri = base.Field('ArchiveUri')
|
||||
"""Location URI for archive file"""
|
||||
|
||||
archive_file = base.Field('ArchiveFile')
|
||||
"""File name for registry if using archive_uri"""
|
||||
|
||||
publication_uri = base.Field('PublicationUri')
|
||||
"""Location URI of publicly available schema"""
|
||||
|
||||
|
||||
class MessageRegistryFile(base.ResourceBase):
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""Identity of Message Registry file resource"""
|
||||
|
||||
description = base.Field('Description')
|
||||
"""Description of Message Registry file resource"""
|
||||
|
||||
name = base.Field('Name', required=True)
|
||||
"""Name of Message Registry file resource"""
|
||||
|
||||
languages = base.Field('Languages', required=True)
|
||||
"""List of RFC 5646 language codes supported by this resource"""
|
||||
|
||||
registry = base.Field('Registry', required=True)
|
||||
"""Prefix for MessageId used for messages from this resource
|
||||
|
||||
This attribute is in form Registry_name.Major_version.Minor_version
|
||||
"""
|
||||
|
||||
location = LocationListField('Location', required=True)
|
||||
"""List of locations of Registry files for each supported language"""
|
||||
|
||||
|
||||
class MessageRegistryFileCollection(base.ResourceCollectionBase):
|
||||
"""Collection of Message Registry Files"""
|
||||
|
||||
@property
|
||||
def _resource_type(self):
|
||||
return MessageRegistryFile
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"@odata.type": "#MessageRegistryFile.v1_1_0.MessageRegistryFile",
|
||||
"Id": "Test",
|
||||
"Name": "Test Message Registry File",
|
||||
"Description": "Message Registry file for testing",
|
||||
"Languages": ["en"],
|
||||
"Registry": "Test.1.0",
|
||||
"Location": [
|
||||
{"Language": "default",
|
||||
"Uri": "/redfish/v1/Registries/Test/Test.1.0.json",
|
||||
"ArchiveUri": "/redfish/v1/Registries/Archive.zip",
|
||||
"ArchiveFile": "Test.1.0.json",
|
||||
"PublicationUri": "https://example.com/Registries/Test.1.0.json"
|
||||
}
|
||||
],
|
||||
"@odata.context": "/redfish/v1/$metadata#MessageRegistryFile.MessageRegistryFile",
|
||||
"@odata.id": "/redfish/v1/Registries/Test"
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"@odata.type": "#MessageRegistryFileCollection.MessageRegistryFileCollection",
|
||||
"Name": "Message Registry Test Collection",
|
||||
"Members@odata.count": 1,
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Registries/Test"
|
||||
}
|
||||
],
|
||||
"@odata.context": "/redfish/v1/$metadata#MessageRegistryFileCollection.MessageRegistryFileCollection",
|
||||
"@odata.id": "/redfish/v1/Registries"
|
||||
}
|
|
@ -31,6 +31,9 @@
|
|||
"@odata.id": "/redfish/v1/SessionService/Sessions"
|
||||
}
|
||||
},
|
||||
"Registries": {
|
||||
"@odata.id": "/redfish/v1/Registries"
|
||||
},
|
||||
"Oem": {},
|
||||
"@odata.context": "/redfish/v1/$metadata#ServiceRoot",
|
||||
"@odata.id": "/redfish/v1/",
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# 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
|
||||
|
||||
from sushy.resources.registry import message_registry_file
|
||||
from sushy.tests.unit import base
|
||||
|
||||
|
||||
class MessageRegistryFileTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MessageRegistryFileTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('sushy/tests/unit/json_samples/'
|
||||
'message_registry_file.json') as f:
|
||||
self.conn.get.return_value.json.return_value = json.load(f)
|
||||
|
||||
self.reg_file = message_registry_file.MessageRegistryFile(
|
||||
self.conn, '/redfish/v1/Registries/Test',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.reg_file._parse_attributes()
|
||||
self.assertEqual('Test', self.reg_file.identity)
|
||||
self.assertEqual('Test Message Registry File', self.reg_file.name)
|
||||
self.assertEqual('Message Registry file for testing',
|
||||
self.reg_file.description)
|
||||
self.assertEqual('en', self.reg_file.languages[0])
|
||||
self.assertEqual('Test.1.0', self.reg_file.registry)
|
||||
self.assertEqual('default', self.reg_file.location[0].language)
|
||||
self.assertEqual('/redfish/v1/Registries/Test/Test.1.0.json',
|
||||
self.reg_file.location[0].uri)
|
||||
self.assertEqual('https://example.com/Registries/Test.1.0.json',
|
||||
self.reg_file.location[0].publication_uri)
|
||||
self.assertEqual('/redfish/v1/Registries/Archive.zip',
|
||||
self.reg_file.location[0].archive_uri)
|
||||
self.assertEqual('Test.1.0.json',
|
||||
self.reg_file.location[0].archive_file)
|
||||
|
||||
|
||||
class MessageRegistryFileCollectionTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MessageRegistryFileCollectionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('sushy/tests/unit/json_samples/'
|
||||
'message_registry_file_collection.json') as f:
|
||||
self.conn.get.return_value.json.return_value = json.load(f)
|
||||
self.reg_file_col =\
|
||||
message_registry_file.MessageRegistryFileCollection(
|
||||
self.conn, '/redfish/v1/Registries',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.reg_file_col._parse_attributes()
|
||||
self.assertEqual('1.0.2', self.reg_file_col.redfish_version)
|
||||
self.assertEqual('Message Registry Test Collection',
|
||||
self.reg_file_col.name)
|
||||
self.assertEqual(('/redfish/v1/Registries/Test',),
|
||||
self.reg_file_col.members_identities)
|
|
@ -22,6 +22,7 @@ from sushy import connector
|
|||
from sushy import exceptions
|
||||
from sushy import main
|
||||
from sushy.resources.manager import manager
|
||||
from sushy.resources.registry import message_registry_file
|
||||
from sushy.resources.sessionservice import session
|
||||
from sushy.resources.sessionservice import sessionservice
|
||||
from sushy.resources.system import system
|
||||
|
@ -120,6 +121,16 @@ class MainTestCase(base.TestCase):
|
|||
self.root._conn, 'asdf',
|
||||
redfish_version=self.root.redfish_version)
|
||||
|
||||
@mock.patch.object(message_registry_file,
|
||||
'MessageRegistryFileCollection',
|
||||
autospec=True)
|
||||
def test__get_registry_collection(
|
||||
self, MessageRegistryFileCollection_mock):
|
||||
self.root._get_registry_collection()
|
||||
MessageRegistryFileCollection_mock.assert_called_once_with(
|
||||
self.root._conn, '/redfish/v1/Registries',
|
||||
redfish_version=self.root.redfish_version)
|
||||
|
||||
|
||||
class BareMinimumMainTestCase(base.TestCase):
|
||||
|
||||
|
@ -146,3 +157,6 @@ class BareMinimumMainTestCase(base.TestCase):
|
|||
self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError,
|
||||
'SessionService/@odata.id', self.root.get_session_service)
|
||||
|
||||
def test__get_registry_collection_when_registries_attr_absent(self):
|
||||
self.assertIsNone(self.root._get_registry_collection())
|
||||
|
|
Loading…
Reference in New Issue