class Task(base.ResourceBase): identity = base.Field('Id', required=True) """The Task identity""" name = base.Field('Name', required=True) """The Task name""" description = base.Field('Description') """The Task description""" task_monitor = base.Field('TaskMonitor') """An opaque URL that the client can use to monitor an asynchronous operation""" start_time = base.Field('StartTime') """Start time of the Task""" end_time = base.Field('EndTime') """End time of the Task""" percent_complete = base.Field('PercentComplete', adapter=utils.int_or_none) """Percentage complete of the Task""" task_state = base.MappedField('TaskState', task_maps.TASK_STATE_VALUE_MAP) """The Task state""" task_status = base.MappedField('TaskStatus', res_maps.HEALTH_VALUE_MAP) """The Task status""" messages = base.MessageListField("Messages") """List of :class:`.MessageListField` with messages from the Task""" def __init__(self, connector, identity, redfish_version=None, registries=None, json_doc=None): """A class representing a Task :param connector: A Connector instance :param identity: The identity of the task :param redfish_version: The version of RedFish. Used to construct the object according to schema of the given version. :param registries: Dict of Redfish Message Registry objects to be used in any resource that needs registries to parse messages :param field_data: the data to use populating the fields """ super(Task, self).__init__( connector, identity, redfish_version, registries, json_doc=json_doc) @property def is_processing(self): """Indicates if the Task is processing""" return self.status_code == http_client.ACCEPTED def parse_messages(self): """Parses the messages""" for m in self.messages: message_registry.parse_message(self._registries, m)
def test_parse_message_bad_registry(self): conn = mock.Mock() with open('sushy/tests/unit/json_samples/message_registry.json') as f: conn.get.return_value.json.return_value = json.load(f) registry = message_registry.MessageRegistry( conn, '/redfish/v1/Registries/Test', redfish_version='1.0.2') registries = {'Test.1.0.0': registry} message_field = sushy_base.MessageListField('Foo') message_field.message_id = 'BadRegistry.TooBig' parsed_msg = message_registry.parse_message(registries, message_field) self.assertEqual(message_field, parsed_msg)
def test_parse_message_fallback_to_basemessages(self): conn = mock.Mock() with open('sushy/tests/unit/json_samples/message_registry.json') as f: conn.get.return_value.json.return_value = json.load(f) registry = message_registry.MessageRegistry( conn, '/redfish/v1/Registries/Test', redfish_version='1.0.2') registries = {'BaseMessages': registry} message_field = sushy_base.MessageListField('Foo') message_field.message_id = 'Success' message_field.severity = res_cons.SEVERITY_OK message_field.resolution = 'Do nothing' parsed_msg = message_registry.parse_message(registries, message_field) self.assertEqual('Do nothing', parsed_msg.resolution) self.assertEqual(res_cons.SEVERITY_OK, parsed_msg.severity) self.assertEqual('Everything done successfully.', parsed_msg.message)
def test_parse_message(self): conn = mock.Mock() with open('sushy/tests/unit/json_samples/message_registry.json') as f: conn.get.return_value.json.return_value = json.load(f) registry = message_registry.MessageRegistry( conn, '/redfish/v1/Registries/Test', redfish_version='1.0.2') registries = {'Test.1.0.0': registry} message_field = sushy_base.MessageListField('Foo') message_field.message_id = 'Test.1.0.0.TooBig' message_field.message_args = ['arg1', 10] message_field.severity = None message_field.resolution = None parsed_msg = message_registry.parse_message(registries, message_field) self.assertEqual('Try again', parsed_msg.resolution) self.assertEqual(res_cons.SEVERITY_WARNING, parsed_msg.severity) self.assertEqual('Property\'s arg1 value cannot be greater than 10.', parsed_msg.message)
class SettingsField(base.CompositeField): """The settings of a resource Represents the future state and configuration of the resource. The field is added to resources that support future state and configuration. This field includes several properties to help clients monitor when the resource is consumed by the service and determine the results of applying the values, which may or may not have been successful. """ def __init__(self): super(SettingsField, self).__init__(path="@Redfish.Settings") time = base.Field('Time') """Indicates the time the settings were applied to the server""" _etag = base.Field('ETag') """The ETag of the resource to which the settings were applied, after the application """ _settings_object_idref = common.IdRefField("SettingsObject") """Reference to the resource the client may PUT/PATCH in order to change this resource """ _supported_apply_times = base.MappedListField( 'SupportedApplyTimes', res_maps.APPLY_TIME_VALUE_MAP) """List of supported apply times""" @property def maintenance_window(self): """MaintenanceWindow field Indicates if a given resource has a maintenance window assignment for applying settings or operations """ LOG.warning('The @Redfish.MaintenanceWindow annotation does not ' 'appear within @Redfish.Settings. Instead use the ' 'maintenance_window property in the target resource ' '(e.g. System resource)') return None messages = base.MessageListField("Messages") """Represents the results of the last time the values of the Settings resource were applied to the server""" @property def operation_apply_time_support(self): """OperationApplyTimeSupport field Indicates if a client is allowed to request for a specific apply time of a create, delete, or action operation of a given resource """ LOG.warning('Redfish ApplyTime annotations do not appear within ' '@Redfish.Settings. Instead use the apply_time_settings ' 'property in the target resource (e.g. Bios resource)') return None def commit(self, connector, value): """Commits new settings values The new values will be applied when the system or a service restarts. :param connector: A Connector instance :param value: Value representing JSON whose structure is specific to each resource and the caller must format it correctly """ connector.patch(self.resource_uri, data=value) @property def resource_uri(self): return self._settings_object_idref.resource_uri def get_status(self, registries): """Determines the status of last update based Uses message id-s and severity to determine the status. :param registries: registries to use to parse message :returns: :class:`.SettingsUpdate` object containing status and any messages """ if not self.time: return SettingsUpdate(NO_UPDATES, None) parsed_msgs = [] for m in self.messages: parsed_msgs.append(message_registry.parse_message(registries, m)) any_errors = any(m for m in parsed_msgs if not m.severity == res_cons.SEVERITY_OK) if any_errors: status = UPDATE_FAILURE else: status = UPDATE_SUCCESS return SettingsUpdate(status, parsed_msgs)