Add all missing attributes of Task in RSD 2.1

Change-Id: If13810c0ce265e266fd4fc374a24f78fc6d81928
This commit is contained in:
Lin Yang 2019-03-26 11:58:34 -07:00
parent ea9bc9ec49
commit 9adb95c051
5 changed files with 149 additions and 138 deletions

View File

@ -0,0 +1,43 @@
# 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 MessageCollectionField(base.ListField):
message_id = base.Field("MessageId")
"""This is the key for this message which can be used to look up the
message in a message registry.
"""
message = base.Field("Message")
"""This is the human readable message, if provided."""
related_properties = base.Field("RelatedProperties")
"""This is an array of properties described by the message."""
message_args = base.Field("MessageArgs")
"""This array of message arguments are substituted for the arguments in
the message when looked up in the message registry.
"""
severity = base.Field("Severity")
"""This is the severity of the errors."""
resolution = base.Field("Resolution")
"""Used to provide suggestions on how to resolve the situation that caused
the error.
"""

View File

@ -15,67 +15,38 @@
from sushy.resources import base
class MessagesField(base.ListField):
message_id = base.Field("MessageId")
"""The message id"""
related_properties = base.Field("RelatedProperties")
"""The message related properties"""
message = base.Field("Message")
"""The message returned"""
message_args = base.Field("MessageArgs")
"""The message args"""
severity = base.Field("Severity")
"""The message severity"""
from rsd_lib import base as rsd_lib_base
from rsd_lib.resources.v2_1.common import message
class Task(base.ResourceBase):
identity = base.Field("Id")
"""The task identity"""
class Task(rsd_lib_base.ResourceBase):
"""Task resource class
name = base.Field("Name")
"""The task name"""
description = base.Field("Description")
"""The task description"""
This resource contains information about a specific Task scheduled by
or being executed by a Redfish service's Task Service.
"""
task_state = base.Field("TaskState")
"""The task state"""
"""The state of the task."""
start_time = base.Field("StartTime")
"""The task start time"""
"""The date-time stamp that the task was last started."""
end_time = base.Field("EndTime")
"""The task end time"""
"""The date-time stamp that the task was last completed."""
task_status = base.Field("TaskStatus")
""""The task status"""
"""This is the completion status of the task."""
messages = MessagesField("Messages")
"""The task message"""
messages = message.MessageCollectionField("Messages")
"""This is an array of messages associated with the task."""
def delete(self):
"""Delete this task"""
self._conn.delete(self.path)
class TaskCollection(base.ResourceCollectionBase):
class TaskCollection(rsd_lib_base.ResourceCollectionBase):
@property
def _resource_type(self):
return Task
def __init__(self, connector, path, redfish_version=None):
"""A class representing a Task Collection
:param connector: A Connector instance
:param path: The canonical path to the task collection resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(TaskCollection, self).__init__(connector,
path,
redfish_version)

View File

@ -16,59 +16,51 @@
from sushy.resources import base
from sushy import utils
from rsd_lib import common as rsd_lib_common
from rsd_lib import base as rsd_lib_base
from rsd_lib.resources.v2_1.task import task
class TaskService(base.ResourceBase):
identity = base.Field("Id")
"""The task service identity"""
class TaskService(rsd_lib_base.ResourceBase):
"""TaskService resource class
name = base.Field("Name")
"""The task service name"""
This is the schema definition for the Task Service. It represents the
properties for the service itself and has links to the actual list of
tasks.
"""
completed_task_over_write_policy = base.Field(
"CompletedTaskOverWritePolicy"
)
"""Overwrite policy of completed tasks"""
date_time = base.Field("DateTime")
"""The task service date time"""
completed_task_overwrite_policy = base.Field(
"CompletedTaskOverWritePolicy")
"""The task service date completed task overwrite policy"""
"""The current DateTime (with offset) setting that the task service is
using.
"""
life_cycle_event_on_task_state_change = base.Field(
"LifeCycleEventOnTaskStateChange", adapter=bool)
"""Whether the task service cycle event on task state change"""
status = rsd_lib_common.StatusField('Status')
"""The task service status"""
"LifeCycleEventOnTaskStateChange", adapter=bool
)
"""Send an Event upon Task State Change."""
service_enabled = base.Field("ServiceEnabled", adapter=bool)
"""Whether the task service is enabled"""
"""This indicates whether this service is enabled."""
oem = base.Field("Oem")
"""The task service oem"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a TaskService
:param connector: A Connector instance
:param identity: The identity of the TaskService resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(TaskService, self).__init__(connector, identity, redfish_version)
def _get_task_collection_path(self):
"""Helper function to find the TaskCollection path"""
return utils.get_sub_resource_path_by(self, 'Tasks')
status = rsd_lib_base.StatusField("Status")
"""This indicates the known state of the resource, such as if it is
enabled.
"""
@property
@utils.cache_it
def tasks(self):
"""Property to provide reference to `TaskCollection` instance
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
"""
return task.TaskCollection(
self._conn, self._get_task_collection_path(),
redfish_version=self.redfish_version)
self._conn,
utils.get_sub_resource_path_by(self, "Tasks"),
redfish_version=self.redfish_version,
)

View File

@ -22,17 +22,17 @@ from rsd_lib.resources.v2_1.task import task
class TaskTestCase(testtools.TestCase):
def setUp(self):
super(TaskTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/task.json',
'r') as f:
with open("rsd_lib/tests/unit/json_samples/v2_1/task.json", "r") as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.task_inst = task.Task(
self.conn, '/redfish/v1/TaskService/Tasks/1',
redfish_version='1.0.2')
self.conn,
"/redfish/v1/TaskService/Tasks/1",
redfish_version="1.0.2",
)
def test__parse_attributes(self):
self.task_inst._parse_attributes()
@ -43,51 +43,57 @@ class TaskTestCase(testtools.TestCase):
self.assertEqual("2016-08-18T12:00+01:00", self.task_inst.start_time)
self.assertEqual("2016-08-18T13:13+01:00", self.task_inst.end_time)
self.assertEqual("OK", self.task_inst.task_status)
self.assertEqual("Base.1.0.Created",
self.task_inst.messages[0].message_id)
self.assertEqual(
"Base.1.0.Created", self.task_inst.messages[0].message_id
)
self.assertEqual([], self.task_inst.messages[0].related_properties)
self.assertEqual("The resource has been created successfully",
self.task_inst.messages[0].message)
self.assertEqual(
"The resource has been created successfully",
self.task_inst.messages[0].message,
)
self.assertEqual([], self.task_inst.messages[0].message_args)
self.assertEqual("OK", self.task_inst.messages[0].severity)
def test_delete(self):
self.task_inst.delete()
self.task_inst._conn.delete.assert_called_once_with(
self.task_inst.path)
self.task_inst.path
)
class TaskCollectionTestCase(testtools.TestCase):
def setUp(self):
super(TaskCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'task_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/" "task_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.task_col = task.TaskCollection(self.conn,
'/redfish/v1/TaskService/Tasks',
redfish_version='1.0.2')
self.task_col = task.TaskCollection(
self.conn, "/redfish/v1/TaskService/Tasks", redfish_version="1.0.2"
)
def test_parse_attributes(self):
self.task_col._parse_attributes()
self.assertEqual("Task Collection", self.task_col.name)
self.assertEqual(('/redfish/v1/TaskService/Tasks/1',),
self.task_col.members_identities)
self.assertEqual(
("/redfish/v1/TaskService/Tasks/1",),
self.task_col.members_identities,
)
@mock.patch.object(task, 'Task', autospec=True)
@mock.patch.object(task, "Task", autospec=True)
def test_get_member(self, mock_task):
self.task_col.get_member('/redfish/v1/TaskService/Tasks/1')
self.task_col.get_member("/redfish/v1/TaskService/Tasks/1")
mock_task.assert_called_once_with(
self.task_col._conn,
'/redfish/v1/TaskService/Tasks/1',
redfish_version=self.task_col.redfish_version
"/redfish/v1/TaskService/Tasks/1",
redfish_version=self.task_col.redfish_version,
)
@mock.patch.object(task, 'Task', autospec=True)
@mock.patch.object(task, "Task", autospec=True)
def test_get_members(self, mock_task):
members = self.task_col.get_members()
self.assertEqual(mock_task.call_count, 1)

View File

@ -23,82 +23,81 @@ from rsd_lib.resources.v2_1.task import task_service
class TaskServiceTestCase(testtools.TestCase):
def setUp(self):
super(TaskServiceTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/task_service.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/task_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.task_service_inst = task_service.TaskService(
self.conn, '/redfish/v1/TaskService',
redfish_version='1.0.2')
self.conn, "/redfish/v1/TaskService", redfish_version="1.0.2"
)
def test__parse_attributes(self):
self.task_service_inst._parse_attributes()
self.assertEqual("TaskService", self.task_service_inst.identity)
self.assertEqual("Tasks Service", self.task_service_inst.name)
self.assertEqual("2015-03-13T04:14:33+06:00",
self.task_service_inst.date_time)
self.assertEqual("Manual",
self.task_service_inst.
completed_task_overwrite_policy)
self.assertEqual(True,
self.task_service_inst.
life_cycle_event_on_task_state_change)
self.assertEqual(
"2015-03-13T04:14:33+06:00", self.task_service_inst.date_time
)
self.assertEqual(
"Manual", self.task_service_inst.completed_task_over_write_policy
)
self.assertEqual(
True, self.task_service_inst.life_cycle_event_on_task_state_change
)
self.assertEqual("Enabled", self.task_service_inst.status.state)
self.assertEqual("OK", self.task_service_inst.status.health)
self.assertEqual(True, self.task_service_inst.service_enabled)
self.assertEqual({}, self.task_service_inst.oem)
def test__get_task_collection_path(self):
expected = '/redfish/v1/TaskService/Tasks'
result = self.task_service_inst._get_task_collection_path()
self.assertEqual(expected, result)
def test_tasks(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'task_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/task_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_tasks = self.task_service_inst.tasks
# | THEN |
self.assertIsInstance(actual_tasks,
task.TaskCollection)
self.assertIsInstance(actual_tasks, task.TaskCollection)
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_tasks,
self.task_service_inst.tasks)
self.assertIs(actual_tasks, self.task_service_inst.tasks)
self.conn.get.return_value.json.assert_not_called()
def test_tasks_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'task_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/task_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.task_service_inst.tasks,
task.TaskCollection)
self.assertIsInstance(
self.task_service_inst.tasks, task.TaskCollection
)
# On refreshing the event_service instance...
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'task_service.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/task_service.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.task_service_inst.invalidate()
self.task_service_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'task_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_1/task_collection.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.task_service_inst.tasks,
task.TaskCollection)
self.assertIsInstance(
self.task_service_inst.tasks, task.TaskCollection
)