Reject node power off requests to align with ironic supporting NCSI
Change-Id: I99b0c934ab97b01672d304900a54631db6401a87
This commit is contained in:
parent
c5b64a27e1
commit
84c1e8a804
@ -193,3 +193,6 @@ SUSHY_EMULATOR_ALLOWED_INSTANCES = [
|
|||||||
"529QB9453R6"
|
"529QB9453R6"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Disable the ability to power off the node, in line with NCSI enablement in
|
||||||
|
# Ironic
|
||||||
|
SUSHY_EMULATOR_DISABLE_POWER_OFF = False
|
@ -614,6 +614,12 @@ def processor(identity, processor_id):
|
|||||||
@api_utils.returns_json
|
@api_utils.returns_json
|
||||||
def system_reset_action(identity):
|
def system_reset_action(identity):
|
||||||
reset_type = flask.request.json.get('ResetType')
|
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)
|
app.systems.set_power_state(identity, reset_type)
|
||||||
|
|
||||||
|
@ -424,10 +424,10 @@ class SystemsTestCase(EmulatorTestCase):
|
|||||||
set_http_boot_uri.assert_called_once_with('http://test.url/boot.iso')
|
set_http_boot_uri.assert_called_once_with('http://test.url/boot.iso')
|
||||||
|
|
||||||
@patch_resource('systems')
|
@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
|
set_power_state = systems_mock.return_value.set_power_state
|
||||||
for reset_type in ('On', 'ForceOn', 'ForceOff', 'GracefulShutdown',
|
for reset_type in ('On', 'ForceOn', 'GracefulRestart', 'ForceRestart',
|
||||||
'GracefulRestart', 'ForceRestart', 'Nmi'):
|
'Nmi'):
|
||||||
set_power_state.reset_mock()
|
set_power_state.reset_mock()
|
||||||
data = {'ResetType': reset_type}
|
data = {'ResetType': reset_type}
|
||||||
response = self.app.post(
|
response = self.app.post(
|
||||||
@ -438,6 +438,19 @@ class SystemsTestCase(EmulatorTestCase):
|
|||||||
set_power_state.assert_called_once_with('xxxx-yyyy-zzzz',
|
set_power_state.assert_called_once_with('xxxx-yyyy-zzzz',
|
||||||
reset_type)
|
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('indicators')
|
||||||
@patch_resource('systems')
|
@patch_resource('systems')
|
||||||
def test_system_indicator_set_ok(self, systems_mock, indicators_mock):
|
def test_system_indicator_set_ok(self, systems_mock, indicators_mock):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user