Files
sushy-tools/sushy_tools/tests/unit/emulator/resources/test_managers.py
Queensly Acheampongmaa 81352b1d34 Add PATCH support for Redfish DateTime fields in Manager resource
This patch enables PATCH support for the DateTime and DateTimeLocalOffset
fields of the Redfish Manager resource in sushy-tools, allowing clients like
sushy to update the BMC clock through the Redfish interface.

Key changes:
- In managers.py, added set_datetime() and get_datetime() methods in the
  FakeDriver class. These store and retrieve datetime values as instance
  attributes (not indexed by UUID), since each instance represents a single
  manager.
- In main.py, added PATCH support in the Manager resource handler.
  Removed reset_cache() hook to preserve instance state across
  requests, enabling PATCH updates to persist.
- In test_main.py, mocked get_datetime() return values to support unit
  tests for the datetime PATCH logic.
- In test_managers.py, added a unit test for the set_datetime() and
  get_datetime() methods.

Also includes a release note describing the new functionality.

Change-Id: I91c671316d8c646fa6cd80c926a2c8b872a7a1fa
2025-06-11 15:04:26 +00:00

79 lines
3.0 KiB
Python

# Copyright 2019 Red Hat, 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 unittest import mock
from oslotest import base
from sushy_tools.emulator.resources import managers
from sushy_tools import error
class FakeDriverTestCase(base.BaseTestCase):
def setUp(self):
super(FakeDriverTestCase, self).setUp()
self.identity = 'xxx'
self.systems = mock.Mock(systems=[self.identity])
self.systems.uuid.return_value = 'xxx'
self.systems.name.return_value = 'name'
self.manager = {'UUID': self.identity,
'Id': self.identity,
'Name': 'name-Manager'}
self.chassis = mock.Mock(chassis=[])
self.test_driver = managers.FakeDriver({}, mock.Mock(),
self.systems, self.chassis)
self.datetime_value = "2025-06-11T12:00:00+00:00"
self.datetimelocaloffset_value = "+00:00"
def test_get_manager_not_found(self):
self.systems.uuid.side_effect = error.FishyError('boom')
self.assertRaises(
error.FishyError, self.test_driver.get_manager, 'foo')
def test_get_manager_by_uuid(self):
manager = self.test_driver.get_manager('xxx')
self.assertEqual(self.manager, manager)
def test_managers(self):
result = self.test_driver.managers
self.assertEqual([self.identity], result)
def test_managed_systems(self):
self.assertEqual(
['xxx'], self.test_driver.get_managed_systems(self.manager))
def test_set_datetime(self):
self.test_driver.set_datetime(self.datetime_value,
self.datetimelocaloffset_value)
self.assertEqual(self.test_driver._datetime, self.datetime_value)
self.assertEqual(self.test_driver._datetimelocaloffset,
self.datetimelocaloffset_value)
def test_get_datetime_returns_expected_dict(self):
self.test_driver.set_datetime(self.datetime_value,
self.datetimelocaloffset_value)
result = self.test_driver.get_datetime()
expected = {
"DateTime": self.datetime_value,
"DateTimeLocalOffset": self.datetimelocaloffset_value
}
self.assertEqual(result, expected)
def test_get_datetime_returns_empty_dict_when_not_set(self):
result = self.test_driver.get_datetime()
self.assertEqual(result, {})