Skip to content
GitLab
Explore
Sign in
Register
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
bd8382da
Unverified
Commit
bd8382da
authored
Oct 8, 2021
by
SKAJohanVenter
Browse files
Options
Downloads
Patches
Plain Diff
SAR-276
Converted On, Off, Standby, Reset to async
parent
6dc85804
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ska_tango_base/base/base_device.py
+43
-17
43 additions, 17 deletions
src/ska_tango_base/base/base_device.py
tests/reference_base_device.py
+10
-6
10 additions, 6 deletions
tests/reference_base_device.py
tests/test_reference_base_device.py
+10
-5
10 additions, 5 deletions
tests/test_reference_base_device.py
with
63 additions
and
28 deletions
src/ska_tango_base/base/base_device.py
+
43
−
17
View file @
bd8382da
...
...
@@ -36,7 +36,7 @@ import debugpy
import
ska_ser_logging
from
ska_tango_base
import
release
from
ska_tango_base.base
import
AdminModeModel
,
OpStateModel
,
BaseComponentManager
from
ska_tango_base.base.task_queue_manager
import
QueueManager
from
ska_tango_base.base.task_queue_manager
import
QueueManager
,
QueueTask
from
ska_tango_base.commands
import
(
BaseCommand
,
CompletionCommand
,
...
...
@@ -1230,11 +1230,17 @@ class SKABaseDevice(Device):
information purpose only.
:rtype: (ResultCode, str)
"""
self
.
target
.
reset
()
class
ResetTask
(
QueueTask
):
def
do
(
self
):
self
.
args
[
0
].
reset
()
message
=
"
Reset command completed OK
"
self
.
logger
.
info
(
message
)
return
(
ResultCode
.
OK
,
message
)
unique_id
=
self
.
target
.
enqueue
(
ResetTask
(
self
.
target
,
logger
=
self
.
logger
))
return
ResultCode
.
OK
,
unique_id
def
is_Reset_allowed
(
self
):
"""
Whether the ``Reset()`` command is allowed to be run in the current state.
...
...
@@ -1297,11 +1303,19 @@ class SKABaseDevice(Device):
information purpose only.
:rtype: (ResultCode, str)
"""
self
.
target
.
standby
()
class
StandByTask
(
QueueTask
):
def
do
(
self
):
self
.
args
[
0
].
standby
()
message
=
"
Standby command completed OK
"
self
.
logger
.
info
(
message
)
return
(
ResultCode
.
OK
,
message
)
unique_id
=
self
.
target
.
enqueue
(
StandByTask
(
self
.
target
,
logger
=
self
.
logger
)
)
return
ResultCode
.
OK
,
unique_id
def
is_Standby_allowed
(
self
):
"""
Check if command Standby is allowed in the current device state.
...
...
@@ -1365,11 +1379,17 @@ class SKABaseDevice(Device):
information purpose only.
:rtype: (ResultCode, str)
"""
self
.
target
.
off
()
class
OffTask
(
QueueTask
):
def
do
(
self
):
self
.
args
[
0
].
off
()
message
=
"
Off command completed OK
"
self
.
logger
.
info
(
message
)
return
(
ResultCode
.
OK
,
message
)
unique_id
=
self
.
target
.
enqueue
(
OffTask
(
self
.
target
,
logger
=
self
.
logger
))
return
ResultCode
.
OK
,
unique_id
def
is_Off_allowed
(
self
):
"""
Check if command `Off` is allowed in the current device state.
...
...
@@ -1433,11 +1453,17 @@ class SKABaseDevice(Device):
information purpose only.
:rtype: (ResultCode, str)
"""
self
.
target
.
on
()
class
OnTask
(
QueueTask
):
def
do
(
self
):
self
.
args
[
0
].
on
()
message
=
"
On command completed OK
"
self
.
logger
.
info
(
message
)
return
(
ResultCode
.
OK
,
message
)
unique_id
=
self
.
target
.
enqueue
(
OnTask
(
self
.
target
,
logger
=
self
.
logger
))
return
ResultCode
.
OK
,
unique_id
def
is_On_allowed
(
self
):
"""
Check if command `On` is allowed in the current device state.
...
...
This diff is collapsed.
Click to expand it.
src/ska_tango_base/base
/reference_base_device.py
→
tests
/reference_base_device.py
+
10
−
6
View file @
bd8382da
...
...
@@ -7,8 +7,7 @@ There are two versions used for testing long running commands.
- AsyncBaseDevice - Uses the custom QueueManager. Multiple threads,
async commands/responses.
It is provided for explanatory purposes, and to support testing of this
package.
It is provided to support testing of the BaseDevice.
"""
import
time
from
tango.server
import
command
...
...
@@ -19,8 +18,10 @@ from ska_tango_base.base.base_device import SKABaseDevice
from
ska_tango_base.base.task_queue_manager
import
QueueManager
,
ResultCode
,
QueueTask
from
ska_tango_base.commands
import
ResponseCommand
from
ska_tango_base.subarray
import
SubarrayObsStateModel
class
BaseTestDevice
(
SKABaseDevice
):
class
LongRunningCommandBaseTestDevice
(
SKABaseDevice
):
"""
Implement commands to test queued work.
"""
def
init_command_objects
(
self
):
...
...
@@ -224,13 +225,13 @@ class BaseTestDevice(SKABaseDevice):
return
f
"
{
return_code
}
"
,
f
"
{
message
}
"
class
BlockingBaseDevice
(
BaseTestDevice
):
class
BlockingBaseDevice
(
LongRunningCommand
BaseTestDevice
):
"""
Test device that has a component manager with the default queue manager that has no workers.
"""
pass
class
AsyncBaseDevice
(
BaseTestDevice
):
class
AsyncBaseDevice
(
LongRunningCommand
BaseTestDevice
):
"""
Test device that has a component manager with workers.
"""
def
create_component_manager
(
self
:
SKABaseDevice
):
...
...
@@ -241,4 +242,7 @@ class AsyncBaseDevice(BaseTestDevice):
logger
=
self
.
logger
,
push_change_event
=
self
.
push_change_event
,
)
return
BaseComponentManager
(
op_state_model
=
None
,
queue_manager
=
queue_manager
)
return
BaseComponentManager
(
op_state_model
=
SubarrayObsStateModel
(
self
.
logger
),
queue_manager
=
queue_manager
,
)
This diff is collapsed.
Click to expand it.
tests/test_reference_base_device.py
+
10
−
5
View file @
bd8382da
...
...
@@ -9,15 +9,16 @@ from unittest import mock
from
tango
import
EventType
from
tango.test_context
import
DeviceTestContext
from
tango.utils
import
EventCallback
from
ska_tango_base.base
.reference_base_device
import
(
from
.reference_base_device
import
(
BlockingBaseDevice
,
AsyncBaseDevice
,
)
from
ska_tango_base.base.task_queue_manager
import
TaskResult
from
ska_tango_base.commands
import
ResultCode
from
ska_tango_base.control_model
import
AdminMode
@pytest.mark.
skip
(
"
Works as expected when run alone. Segfaults in suite.
"
)
@pytest.mark.
forked
class
TestCommands
:
"""
Check that blocking and async commands behave the same way.
...
...
@@ -29,7 +30,11 @@ class TestCommands:
def
test_short_command
(
self
):
"""
Test a simple command.
"""
for
class_name
in
[
BlockingBaseDevice
,
AsyncBaseDevice
]:
with
DeviceTestContext
(
class_name
,
process
=
True
)
as
proxy
:
with
DeviceTestContext
(
class_name
,
process
=
True
,
memorized
=
{
"
adminMode
"
:
str
(
AdminMode
.
ONLINE
.
value
)},
)
as
proxy
:
proxy
.
Short
(
1
)
# Wait for a result, if the task does not abort, we'll time out here
while
not
proxy
.
longRunningCommandResult
:
...
...
@@ -91,7 +96,7 @@ class TestCommands:
)
@pytest.mark.
skip
(
"
Works as expected when run alone. Segfaults in suite.
"
)
@pytest.mark.
forked
def
test_callbacks
():
"""
Check that the callback is firing that sends the push change event.
"""
with
mock
.
patch
.
object
(
AsyncBaseDevice
,
"
push_change_event
"
)
as
my_cb
:
...
...
@@ -155,7 +160,7 @@ def test_callbacks():
tr
.
task_result
==
"
None
"
@pytest.mark.
skip
(
"
Works as expected when run alone. Segfaults in suite.
"
)
@pytest.mark.
forked
def
test_events
():
"""
Testing the events.
...
...
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