From 84c1e8a8042af2f1e098188581dccd82b6f0b289 Mon Sep 17 00:00:00 2001 From: Mahnoor Asghar Date: Thu, 17 Oct 2024 11:02:27 -0400 Subject: [PATCH] Reject node power off requests to align with ironic supporting NCSI Change-Id: I99b0c934ab97b01672d304900a54631db6401a87 --- doc/source/admin/emulator.conf | 3 +++ sushy_tools/emulator/main.py | 6 ++++++ sushy_tools/tests/unit/emulator/test_main.py | 19 ++++++++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/doc/source/admin/emulator.conf b/doc/source/admin/emulator.conf index 74a668a5..e72d7614 100644 --- a/doc/source/admin/emulator.conf +++ b/doc/source/admin/emulator.conf @@ -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 \ No newline at end of file diff --git a/sushy_tools/emulator/main.py b/sushy_tools/emulator/main.py index 03c202bb..0236bbdb 100755 --- a/sushy_tools/emulator/main.py +++ b/sushy_tools/emulator/main.py @@ -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) diff --git a/sushy_tools/tests/unit/emulator/test_main.py b/sushy_tools/tests/unit/emulator/test_main.py index 83d1876b..8ef671a7 100644 --- a/sushy_tools/tests/unit/emulator/test_main.py +++ b/sushy_tools/tests/unit/emulator/test_main.py @@ -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):