Reject node power off requests to align with ironic supporting NCSI

Change-Id: I99b0c934ab97b01672d304900a54631db6401a87
This commit is contained in:
Mahnoor Asghar 2024-10-17 11:02:27 -04:00
parent c5b64a27e1
commit 84c1e8a804
3 changed files with 25 additions and 3 deletions

View File

@ -193,3 +193,6 @@ SUSHY_EMULATOR_ALLOWED_INSTANCES = [
"529QB9453R6"
]
# Disable the ability to power off the node, in line with NCSI enablement in
# Ironic
SUSHY_EMULATOR_DISABLE_POWER_OFF = False

View File

@ -614,6 +614,12 @@ def processor(identity, processor_id):
@api_utils.returns_json
def system_reset_action(identity):
reset_type = flask.request.json.get('ResetType')
if app.config.get('SUSHY_EMULATOR_DISABLE_POWER_OFF') is True and \
reset_type in ('ForceOff', 'GracefulShutdown'):
raise error.BadRequest('Can not request power off transition. It is '
'disabled via the '
'SUSHY_EMULATOR_DISABLE_POWER_OFF configuration'
'option.')
app.systems.set_power_state(identity, reset_type)

View File

@ -424,10 +424,10 @@ class SystemsTestCase(EmulatorTestCase):
set_http_boot_uri.assert_called_once_with('http://test.url/boot.iso')
@patch_resource('systems')
def test_system_reset_action(self, systems_mock):
def test_system_reset_action_ok(self, systems_mock):
set_power_state = systems_mock.return_value.set_power_state
for reset_type in ('On', 'ForceOn', 'ForceOff', 'GracefulShutdown',
'GracefulRestart', 'ForceRestart', 'Nmi'):
for reset_type in ('On', 'ForceOn', 'GracefulRestart', 'ForceRestart',
'Nmi'):
set_power_state.reset_mock()
data = {'ResetType': reset_type}
response = self.app.post(
@ -438,6 +438,19 @@ class SystemsTestCase(EmulatorTestCase):
set_power_state.assert_called_once_with('xxxx-yyyy-zzzz',
reset_type)
@patch_resource('systems')
def test_system_reset_action_fail(self, systems_mock):
self.app.application.config['SUSHY_EMULATOR_DISABLE_POWER_OFF'] = True
print(self.app.application.config)
for reset_type in ('ForceOff', 'GracefulShutdown'):
data = {'ResetType': reset_type}
response = self.app.post(
'/redfish/v1/Systems/xxxx-yyyy-zzzz/Actions/'
'ComputerSystem.Reset',
json=data)
self.assertEqual(400, response.status_code)
@patch_resource('indicators')
@patch_resource('systems')
def test_system_indicator_set_ok(self, systems_mock, indicators_mock):