Merge "Add registries resource for RSD2.1"

This commit is contained in:
Zuul 2019-02-01 18:45:47 +00:00 committed by Gerrit Code Review
commit 65c5e8affa
15 changed files with 310 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
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
from rsd_lib.resources.v2_1.registries import registries
from rsd_lib.resources.v2_1.storage_service import storage_service
from rsd_lib.resources.v2_1.system import system
from rsd_lib.resources.v2_1.task import task_service
@ -52,6 +53,9 @@ class RSDLibV2_1(base.ResourceBase):
_task_service_path = base.Field(['Tasks', '@odata.id'], required=True)
"""Task Service path"""
_registries_path = base.Field(['Registries', '@odata.id'], required=True)
"""RegistriesCollection path"""
_redfish_version = base.Field(['RedfishVersion'], required=True)
"""Redfish version"""
@ -224,3 +228,27 @@ class RSDLibV2_1(base.ResourceBase):
return task_service.TaskService(self._conn,
self._task_service_path,
redfish_version=self.redfish_version)
def get_registries_collection(self):
"""Get the RegistriesCollection object
:raises: MissingAttributeError, if the collection attribute is
not found
:returns: a RegistriesCollection object
"""
return registries.RegistriesCollection(
self._conn,
self._registries_path,
redfish_version=self.redfish_version
)
def get_registries(self, identity):
"""Given the identity return a Registries object
:param identity: The identity of the registries resource
:returns: The Registries object
"""
return registries.Registries(
self._conn,
identity,
redfish_version=self.redfish_version)

View File

@ -0,0 +1,75 @@
# 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
class LocationField(base.ListField):
language = base.Field("Language")
"""The location language"""
publication_uri = base.Field("PublicationUri")
"""The location publication uri"""
class Registries(base.ResourceBase):
identity = base.Field("Id")
"""The registries identity"""
name = base.Field("Name")
"""The registries name"""
description = base.Field("Description")
"""The registries description"""
languages = base.Field("Languages")
"""The registries languages"""
registry = base.Field("Registry")
"""The registry"""
location = LocationField("Location")
"""The registries location"""
oem = base.Field("Oem")
"""The registries oem"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a Registries
:param connector: A Connector instance
:param identity: The identity of the registries resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(Registries, self).__init__(connector, identity, redfish_version)
class RegistriesCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return Registries
def __init__(self, connector, path, redfish_version=None):
"""A class representing a RegistriesCollection
:param connector: A Connector instance
:param path: The canonical path to the registries collection
resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(RegistriesCollection, self).__init__(connector, path,
redfish_version)

View File

@ -0,0 +1,21 @@
{
"@odata.context":"/redfish/v1/$metadata#Registries/Members/$entity",
"@odata.id":"/redfish/v1/Registries/Base",
"@odata.type":"#MessageRegistryFile.v1_0_0.MessageRegistryFile",
"Id":"Base",
"Name":"Base Message Registry File",
"Description":"Base Message Registry File locations",
"Languages":[
"en"
],
"Registry":"Base.1.0",
"Location":[
{
"Language":"en",
"PublicationUri":"https://www.dmtf.org/sites/default/files/standards/documents/DSP8011_1.0.0a.json"
}
],
"Oem":{
}
}

View File

@ -0,0 +1,13 @@
{
"@odata.context":"/redfish/v1/$metadata#MessageRegistryFileCollection.MessageRegistryFileCollection",
"@odata.id":"/redfish/v1/Registries",
"@odata.type":"#MessageRegistryFileCollection.MessageRegistryFileCollection",
"Name":"Registry File Collection",
"Description":"Registry Repository",
"Members@odata.count":1,
"Members":[
{
"@odata.id":"/redfish/v1/Registries/Base"
}
]
}

View File

@ -37,6 +37,9 @@
"EthernetSwitches": {
"@odata.id": "/redfish/v1/EthernetSwitches"
},
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"Links": {
"Sessions": {
"@odata.id": "/redfish/v1/SessionService/Sessions"

View File

@ -28,6 +28,9 @@
"TelemetryService": {
"@odata.id": "/redfish/v1/TelemetryService"
},
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ServiceRoot",

View File

@ -28,6 +28,9 @@
"StorageServices": {
"@odata.id": "/redfish/v1/StorageServices"
},
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ServiceRoot",

View File

@ -28,6 +28,9 @@
"StorageServices": {
"@odata.id": "/redfish/v1/StorageServices"
},
"Registries": {
"@odata.id": "/redfish/v1/Registries"
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ServiceRoot",

View File

@ -0,0 +1,89 @@
# 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 rsd_lib.resources.v2_1.registries import registries
class RegistriesTestCase(testtools.TestCase):
def setUp(self):
super(RegistriesTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/registries.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.registries_inst = registries.Registries(
self.conn, '/redfish/v1/Registries/Base',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.registries_inst._parse_attributes()
self.assertEqual("Base", self.registries_inst.identity)
self.assertEqual("Base Message Registry File",
self.registries_inst.name)
self.assertEqual("Base Message Registry File locations",
self.registries_inst.description)
self.assertEqual(['en'], self.registries_inst.languages)
self.assertEqual("Base.1.0", self.registries_inst.registry)
self.assertEqual("en", self.registries_inst.location[0].language)
self.assertEqual(
"https://www.dmtf.org/sites/default/files/standards"
"/documents/DSP8011_1.0.0a.json",
self.registries_inst.location[0].publication_uri)
self.assertEqual({}, self.registries_inst.oem)
class RegistriesCollectionTestCase(testtools.TestCase):
def setUp(self):
super(RegistriesCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'registries_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.registries_col = registries.RegistriesCollection(
self.conn,
'/redfish/v1/Registries',
redfish_version='1.0.2')
def test_parse_attributes(self):
self.registries_col._parse_attributes()
self.assertEqual("Registry File Collection", self.registries_col.name)
self.assertEqual(('/redfish/v1/Registries/Base',),
self.registries_col.members_identities)
@mock.patch.object(registries, 'Registries', autospec=True)
def test_get_member(self, mock_registries):
self.registries_col.get_member('/redfish/v1/Registries/Base')
mock_registries.assert_called_once_with(
self.registries_col._conn,
'/redfish/v1/Registries/Base',
redfish_version=self.registries_col.redfish_version
)
@mock.patch.object(registries, 'Registries', autospec=True)
def test_get_members(self, mock_registries):
members = self.registries_col.get_members()
self.assertEqual(mock_registries.call_count, 1)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))

View File

@ -23,6 +23,7 @@ from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch
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
from rsd_lib.resources.v2_1.registries import registries
from rsd_lib.resources.v2_1.storage_service import storage_service
from rsd_lib.resources.v2_1.system import system
from rsd_lib.resources.v2_1.task import task_service
@ -52,6 +53,8 @@ class RSDLibV2_1TestCase(testtools.TestCase):
self.rsd._ethernet_switches_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
@mock.patch.object(system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
@ -166,3 +169,18 @@ class RSDLibV2_1TestCase(testtools.TestCase):
mock_task_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(registries, 'RegistriesCollection', autospec=True)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(registries, 'Registries', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
redfish_version=self.rsd.redfish_version
)

View File

@ -20,6 +20,7 @@ import testtools
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
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
from rsd_lib.resources.v2_1.storage_service import storage_service \
as v2_1_storage_service
from rsd_lib.resources.v2_1.task import task_service as v2_1_task_service
@ -55,6 +56,8 @@ class RSDLibV2_2TestCase(testtools.TestCase):
self.rsd._telemetry_service_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
@mock.patch.object(v2_2_system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
@ -175,3 +178,18 @@ class RSDLibV2_2TestCase(testtools.TestCase):
mock_task_service.assert_called_once_with(
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'RegistriesCollection', autospec=True)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'Registries', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
redfish_version=self.rsd.redfish_version
)

View File

@ -18,6 +18,7 @@ import mock
import testtools
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
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.manager import manager as v2_2_manager
from rsd_lib.resources.v2_2.system import system as v2_2_system
@ -52,6 +53,8 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.assertEqual(None, self.rsd._telemetry_service_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
@mock.patch.object(v2_2_system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
@ -166,6 +169,21 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'RegistriesCollection', autospec=True)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'Registries', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
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()

View File

@ -18,6 +18,7 @@ import mock
import testtools
from rsd_lib.resources.v2_1.chassis import chassis as v2_1_chassis
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.manager import manager as v2_2_manager
from rsd_lib.resources.v2_2.system import system as v2_2_system
@ -52,6 +53,8 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.assertEqual(None, self.rsd._telemetry_service_path)
self.assertEqual("/redfish/v1/TaskService",
self.rsd._task_service_path)
self.assertEqual("/redfish/v1/Registries",
self.rsd._registries_path)
@mock.patch.object(v2_2_system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
@ -166,6 +169,21 @@ class RSDLibV2_3TestCase(testtools.TestCase):
self.rsd._conn, '/redfish/v1/TaskService',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'RegistriesCollection', autospec=True)
def test_get_registries_collection(self, mock_registries_collection):
self.rsd.get_registries_collection()
mock_registries_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Registries',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_registries, 'Registries', autospec=True)
def test_get_registries(self, mock_registries_service):
self.rsd.get_registries('fake-registries-id')
mock_registries_service.assert_called_once_with(
self.rsd._conn, 'fake-registries-id',
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()