Skip to content
Snippets Groups Projects
Commit 684a0eea authored by Drew Devereux's avatar Drew Devereux
Browse files

[MCCS-198] Fix bug in Reset() command

parent d78de86d
No related branches found
No related tags found
No related merge requests found
...@@ -1194,6 +1194,31 @@ class SKABaseDevice(Device): ...@@ -1194,6 +1194,31 @@ class SKABaseDevice(Device):
""" """
super().__init__(target, state_model, "reset", logger=logger) super().__init__(target, state_model, "reset", logger=logger)
def check_allowed(self):
"""
Checks whether the command is allowed to be run in the current
state of the state model.
:returns: True if the command is allowed to be run
"""
return self._try_action("reset_succeeded_off")
def is_allowed(self):
"""
Whether this command is allowed to run in the current state of
the state model.
:returns: whether this command is allowed to run
:rtype: boolean
"""
return self._is_action_allowed("reset_succeeded_off")
def succeeded(self):
"""
Action to take on successful completion of a reset
"""
self.state_model.perform_action("reset_succeeded_off")
def do(self): def do(self):
""" """
Stateless hook for device reset. Stateless hook for device reset.
......
...@@ -19,6 +19,8 @@ import tango ...@@ -19,6 +19,8 @@ import tango
from unittest import mock from unittest import mock
from tango import DevFailed, DevState from tango import DevFailed, DevState
from ska.base import SKABaseDevice
from ska.base.commands import ResultCode
from ska.base.control_model import ( from ska.base.control_model import (
AdminMode, ControlMode, HealthState, LoggingLevel, SimulationMode, TestMode AdminMode, ControlMode, HealthState, LoggingLevel, SimulationMode, TestMode
) )
...@@ -30,7 +32,7 @@ from ska.base.base_device import ( ...@@ -30,7 +32,7 @@ from ska.base.base_device import (
DeviceStateModel, DeviceStateModel,
TangoLoggingServiceHandler, TangoLoggingServiceHandler,
) )
from ska.base.faults import StateModelError from ska.base.faults import CommandError, StateModelError
from .conftest import load_state_machine_spec, StateMachineTester from .conftest import load_state_machine_spec, StateMachineTester
...@@ -479,9 +481,8 @@ class TestSKABaseDevice(object): ...@@ -479,9 +481,8 @@ class TestSKABaseDevice(object):
def test_Reset(self, tango_context): def test_Reset(self, tango_context):
"""Test for Reset""" """Test for Reset"""
# PROTECTED REGION ID(SKABaseDevice.test_Reset) ENABLED START # # PROTECTED REGION ID(SKABaseDevice.test_Reset) ENABLED START #
# This is a pretty weak test, but Reset() is only allowed from # The main test of this command is
# device state FAULT, and we have no way of putting into FAULT # TestSKABaseDevice_commands::test_ResetCommand
# state through its interface.
with pytest.raises(DevFailed): with pytest.raises(DevFailed):
tango_context.device.Reset() tango_context.device.Reset()
# PROTECTED REGION END # // SKABaseDevice.test_Reset # PROTECTED REGION END # // SKABaseDevice.test_Reset
...@@ -692,3 +693,47 @@ class TestSKABaseDevice(object): ...@@ -692,3 +693,47 @@ class TestSKABaseDevice(object):
# PROTECTED REGION ID(SKABaseDevice.test_testMode) ENABLED START # # PROTECTED REGION ID(SKABaseDevice.test_testMode) ENABLED START #
assert tango_context.device.testMode == TestMode.NONE assert tango_context.device.testMode == TestMode.NONE
# PROTECTED REGION END # // SKABaseDevice.test_testMode # PROTECTED REGION END # // SKABaseDevice.test_testMode
class TestSKABaseDevice_commands:
"""
This class contains tests of SKASubarray commands
"""
def test_ResetCommand(self, device_state_model):
"""
Test for SKBaseDevice.ResetCommand
"""
mock_device = mock.Mock()
reset_command = SKABaseDevice.ResetCommand(
mock_device,
device_state_model
)
machine_spec = load_state_machine_spec("device_state_machine")
states = machine_spec["states"]
transitions = {
"FAULT_MAINTENANCE": "OFF_MAINTENANCE",
"FAULT_ONLINE": "OFF_ONLINE",
}
for state in states:
device_state_model._straight_to_state(**states[state])
if state in transitions:
# the reset command is permitted, should succeed.
assert reset_command.is_allowed()
assert reset_command() == (
ResultCode.OK,
"Reset command completed OK",
)
expected = transitions[state]
else:
# the reset command is not permitted, should not be allowed,
# should fail, should have no side-effect
assert not reset_command.is_allowed()
with pytest.raises(CommandError):
reset_command()
expected = state
assert device_state_model.admin_mode == states[expected]["admin_mode"]
assert device_state_model.op_state == states[expected]["op_state"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment