Introduce `dateutil`
These changes introduce `dateutil.parser.parse()` to the sushy which converts ASCII text time into the Python's `datetime` object which is way more handy to work with rather than String. A follow up patch to Change-Id I479bc18f79c6c51644115671ef68a879a94d102e Change-Id: I1b8efd0387e489e98c7a79e8612a6ad0cbcaf30e
This commit is contained in:
parent
30d07ce541
commit
69f5e98504
|
@ -24,6 +24,7 @@ pbr==2.0.0
|
|||
pep8==1.5.7
|
||||
pyflakes==0.8.1
|
||||
Pygments==2.2.0
|
||||
python-dateutil==2.7.0
|
||||
python-mimeparse==1.6.0
|
||||
python-subunit==1.0.0
|
||||
pytz==2013.6
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
requests>=2.14.2 # Apache-2.0
|
||||
six>=1.10.0 # MIT
|
||||
python-dateutil>=2.7.0 # BSD
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# This is referred from Redfish standard schema.
|
||||
# https://redfish.dmtf.org/schemas/Settings.v1_2_0.json
|
||||
|
||||
from dateutil import parser
|
||||
|
||||
from sushy.resources import base
|
||||
from sushy.resources import common
|
||||
|
@ -57,7 +58,8 @@ class MaintenanceWindowField(base.CompositeField):
|
|||
|
||||
maintenance_window_start_time = base.Field(
|
||||
'MaintenanceWindowStartTime',
|
||||
required=True)
|
||||
required=True,
|
||||
adapter=parser.parse)
|
||||
"""The start time of a maintenance window"""
|
||||
|
||||
|
||||
|
@ -72,7 +74,8 @@ class OperationApplyTimeSupportField(base.CompositeField):
|
|||
"""The location of the maintenance window settings"""
|
||||
|
||||
maintenance_window_start_time = base.Field(
|
||||
'MaintenanceWindowStartTime')
|
||||
'MaintenanceWindowStartTime',
|
||||
adapter=parser.parse)
|
||||
"""The start time of a maintenance window"""
|
||||
|
||||
supported_values = base.Field('SupportedValues', required=True)
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
"ETag": "9234ac83b9700123cc32",
|
||||
"MaintenanceWindow": {
|
||||
"MaintenanceWindowDurationInSeconds": 1,
|
||||
"MaintenanceWindowStartTime": "2016-03-07T14:44.30-05:05"
|
||||
"MaintenanceWindowStartTime": "2016-03-07T14:44:30-05:05"
|
||||
},
|
||||
"OperationApplyTimeSupport": {
|
||||
"MaintenanceWindowDurationInSeconds": 1,
|
||||
"MaintenanceWindowResource": "",
|
||||
"MaintenanceWindowStartTime": "2016-03-07T14:44.30-05:10",
|
||||
"MaintenanceWindowStartTime": "2016-03-07T14:44:30-05:10",
|
||||
"SupportedValues": [
|
||||
"Immediate",
|
||||
"OnReset",
|
||||
|
@ -32,6 +32,6 @@
|
|||
"SettingsObject": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS/Settings"
|
||||
},
|
||||
"Time": "2016-03-07T14:44.30-05:00"
|
||||
"Time": "2016-03-07T14:44:30-05:00"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
import json
|
||||
import mock
|
||||
|
||||
from dateutil import parser
|
||||
|
||||
from sushy import exceptions
|
||||
from sushy.resources import constants as res_cons
|
||||
from sushy.resources import settings
|
||||
from sushy.tests.unit import base
|
||||
|
@ -35,7 +38,7 @@ class SettingsFieldTestCase(base.TestCase):
|
|||
|
||||
self.assertEqual('9234ac83b9700123cc32',
|
||||
instance._etag)
|
||||
self.assertEqual('2016-03-07T14:44.30-05:00',
|
||||
self.assertEqual('2016-03-07T14:44:30-05:00',
|
||||
instance.time)
|
||||
self.assertEqual('/redfish/v1/Systems/437XR1138R2/BIOS/Settings',
|
||||
instance._settings_object_idref.resource_uri)
|
||||
|
@ -58,20 +61,29 @@ class SettingsFieldTestCase(base.TestCase):
|
|||
instance.
|
||||
maintenance_window.maintenance_window_duration_in_seconds)
|
||||
self.assertEqual(
|
||||
'2016-03-07T14:44.30-05:05',
|
||||
parser.parse('2016-03-07T14:44:30-05:05'),
|
||||
instance.maintenance_window.maintenance_window_start_time)
|
||||
self.assertEqual(
|
||||
1,
|
||||
instance.operation_apply_time_support.
|
||||
maintenance_window_duration_in_seconds)
|
||||
self.assertEqual(
|
||||
'2016-03-07T14:44.30-05:10',
|
||||
parser.parse('2016-03-07T14:44:30-05:10'),
|
||||
instance.operation_apply_time_support.
|
||||
maintenance_window_start_time)
|
||||
self.assertIn(
|
||||
'Immediate',
|
||||
instance.operation_apply_time_support.supported_values)
|
||||
|
||||
def test__load_failure(self):
|
||||
self.json[
|
||||
'@Redfish.Settings']['MaintenanceWindow'][
|
||||
'MaintenanceWindowStartTime'] = 'bad date'
|
||||
self.assertRaisesRegex(
|
||||
exceptions.MalformedAttributeError,
|
||||
'@Redfish.Settings/MaintenanceWindow/MaintenanceWindowStartTime',
|
||||
self.settings._load, self.json, mock.Mock())
|
||||
|
||||
def test_commit(self):
|
||||
conn = mock.Mock()
|
||||
instance = self.settings._load(self.json, conn)
|
||||
|
|
Loading…
Reference in New Issue