Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lmc-base-classes
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
LOFAR2.0
lmc-base-classes
Commits
684a0eea
Commit
684a0eea
authored
Oct 13, 2020
by
Drew Devereux
Browse files
Options
Downloads
Patches
Plain Diff
[
MCCS-198
] Fix bug in Reset() command
parent
d78de86d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ska/base/base_device.py
+25
-0
25 additions, 0 deletions
src/ska/base/base_device.py
tests/test_base_device.py
+49
-4
49 additions, 4 deletions
tests/test_base_device.py
with
74 additions
and
4 deletions
src/ska/base/base_device.py
+
25
−
0
View file @
684a0eea
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
tests/test_base_device.py
+
49
−
4
View file @
684a0eea
...
@@ -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
"
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment