Skip to content
Snippets Groups Projects
Commit df3c1d22 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-516: test now uses TemporaryQueue

parent 615838db
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ StatusUpdateCommand : finction to update the status of a tree. ...@@ -30,6 +30,7 @@ StatusUpdateCommand : finction to update the status of a tree.
import sys import sys
import logging import logging
from lofar.messaging.messagebus import *
from lofar.messaging.RPC import * from lofar.messaging.RPC import *
logging.basicConfig(stream=sys.stdout, level=logging.WARNING) logging.basicConfig(stream=sys.stdout, level=logging.WARNING)
...@@ -58,91 +59,92 @@ def do_rpc(rpc_instance, arg_dict): ...@@ -58,91 +59,92 @@ def do_rpc(rpc_instance, arg_dict):
return data return data
if __name__ == "__main__": if __name__ == "__main__":
busname = sys.argv[1] if len(sys.argv) > 1 else "simpletest" with TemporaryQueue(__name__) as tmp_queue:
busname = tmp_queue.address
with RPC("OTDBService.TaskGetIDs", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
# Existing: otdb_id:1099268, mom_id:353713 with RPC("OTDBService.TaskGetIDs", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': 353713 }) # Existing: otdb_id:1099268, mom_id:353713
do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': 5 }) do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': 353713 })
do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': None }) do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': 5 })
do_rpc (otdbRPC, {'OtdbID': 5, 'MomID': 353713 }) do_rpc (otdbRPC, {'OtdbID': 1099268, 'MomID': None })
do_rpc_catch_exception('', otdbRPC, {'OtdbID': 5, 'MomID': 5 }) do_rpc (otdbRPC, {'OtdbID': 5, 'MomID': 353713 })
do_rpc_catch_exception('', otdbRPC, {'OtdbID': 5, 'MomID': None }) do_rpc_catch_exception('', otdbRPC, {'OtdbID': 5, 'MomID': 5 })
do_rpc (otdbRPC, {'OtdbID': None, 'MomID': 353713 }) do_rpc_catch_exception('', otdbRPC, {'OtdbID': 5, 'MomID': None })
do_rpc_catch_exception('', otdbRPC, {'OtdbID': None, 'MomID': 5 }) do_rpc (otdbRPC, {'OtdbID': None, 'MomID': 353713 })
do_rpc_catch_exception('', otdbRPC, {'OtdbID': None, 'MomID': None }) do_rpc_catch_exception('', otdbRPC, {'OtdbID': None, 'MomID': 5 })
do_rpc_catch_exception('', otdbRPC, {'OtdbID': None, 'MomID': None })
with RPC("OTDBService.GetDefaultTemplates", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{}) with RPC("OTDBService.GetDefaultTemplates", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{})
with RPC("OTDBService.SetProject", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{'name':"Taka Tuka Land", "title":"Adventure movie", "pi":"Pippi", "co_i":"Mr.Nelson", "contact":"Witje"}) with RPC("OTDBService.SetProject", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{'name':"Taka Tuka Land", "title":"Adventure movie", "pi":"Pippi", "co_i":"Mr.Nelson", "contact":"Witje"})
with RPC("OTDBService.TaskCreate", ForwardExceptions=True, busname=busname, timeout=10) as task_create:
do_rpc(task_create, {'OtdbID':1099268, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}}) with RPC("OTDBService.TaskCreate", ForwardExceptions=True, busname=busname, timeout=10) as task_create:
do_rpc(task_create, {'MomID':353713, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}}) do_rpc(task_create, {'OtdbID':1099268, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}})
do_rpc_catch_exception('on non-exsisting campaign', task_create, do_rpc(task_create, {'MomID':353713, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}})
{'MomID':998877, 'TemplateName':'BeamObservation', do_rpc_catch_exception('on non-exsisting campaign', task_create,
'CampaignName':'No such campaign', 'Specification': {'state':'finished'}}) {'MomID':998877, 'TemplateName':'BeamObservation',
do_rpc(task_create, {'MomID':998877, 'TemplateName':'BeamObservation', 'CampaignName':'No such campaign', 'Specification': {'state':'finished'}})
'CampaignName':'Taka Tuka Land', 'Specification': {'state':'finished'}}) do_rpc(task_create, {'MomID':998877, 'TemplateName':'BeamObservation',
data = do_rpc(task_create, {'MomID':12345, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}}) 'CampaignName':'Taka Tuka Land', 'Specification': {'state':'finished'}})
new_tree1 = data['MomID'] data = do_rpc(task_create, {'MomID':12345, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}})
data = do_rpc(task_create, {'MomID':54321, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}}) new_tree1 = data['MomID']
new_tree2= data['MomID'] data = do_rpc(task_create, {'MomID':54321, 'TemplateName':'BeamObservation', 'Specification': {'state':'finished'}})
new_tree2= data['MomID']
with RPC("OTDBService.TaskPrepareForScheduling", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'MomID':new_tree1}) # template with RPC("OTDBService.TaskPrepareForScheduling", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'MomID':new_tree1}) # now a VIC tree do_rpc(otdbRPC, {'MomID':new_tree1}) # template
do_rpc(otdbRPC, {'MomID':new_tree1, 'StartTime':'2016-03-01 12:00:00', 'StopTime':'2016-03-01 12:34:56'}) do_rpc(otdbRPC, {'MomID':new_tree1}) # now a VIC tree
do_rpc_catch_exception("on invalid stoptime", otdbRPC, do_rpc(otdbRPC, {'MomID':new_tree1, 'StartTime':'2016-03-01 12:00:00', 'StopTime':'2016-03-01 12:34:56'})
{'MomID':new_tree1, 'StartTime':'2016-03-01 12:00:00', 'StopTime':'2016'}) do_rpc_catch_exception("on invalid stoptime", otdbRPC,
{'MomID':new_tree1, 'StartTime':'2016-03-01 12:00:00', 'StopTime':'2016'})
with RPC("OTDBService.TaskDelete", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'MomID':new_tree2}) with RPC("OTDBService.TaskDelete", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'MomID':new_tree2})
with RPC("OTDBService.TaskGetSpecification", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'OtdbID':1099269}) # PIC with RPC("OTDBService.TaskGetSpecification", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC, {'OtdbID':1099238}) # Template do_rpc(otdbRPC, {'OtdbID':1099269}) # PIC
do_rpc(otdbRPC, {'OtdbID':1099266}) # VIC do_rpc(otdbRPC, {'OtdbID':1099238}) # Template
do_rpc_catch_exception('on non-existing treeID', otdbRPC, {'OtdbID':5}) # Non existing do_rpc(otdbRPC, {'OtdbID':1099266}) # VIC
do_rpc_catch_exception('on non-existing treeID', otdbRPC, {'OtdbID':5}) # Non existing
with RPC("OTDBService.TaskSetStatus", ForwardExceptions=True, busname=busname, timeout=5) as status_update_command:
# PIC with RPC("OTDBService.TaskSetStatus", ForwardExceptions=True, busname=busname, timeout=5) as status_update_command:
do_rpc(status_update_command, {'OtdbID':1099269, 'NewStatus':'finished', 'UpdateTimestamps':True}) # PIC
# Template do_rpc(status_update_command, {'OtdbID':1099269, 'NewStatus':'finished', 'UpdateTimestamps':True})
do_rpc(status_update_command, {'OtdbID':1099238, 'NewStatus':'finished', 'UpdateTimestamps':True}) # Template
# VIC do_rpc(status_update_command, {'OtdbID':1099238, 'NewStatus':'finished', 'UpdateTimestamps':True})
do_rpc(status_update_command, {'OtdbID':1099266, 'NewStatus':'finished', 'UpdateTimestamps':True}) # VIC
do_rpc(status_update_command, {'OtdbID':1099266, 'NewStatus':'finished', 'UpdateTimestamps':True})
# Nonexisting tree
do_rpc_catch_exception('on invalid treeID', # Nonexisting tree
status_update_command, {'OtdbID':10, 'NewStatus':'finished', 'UpdateTimestamps':True}) do_rpc_catch_exception('on invalid treeID',
status_update_command, {'OtdbID':10, 'NewStatus':'finished', 'UpdateTimestamps':True})
# VIC tree: invalid status
do_rpc_catch_exception('on invalid status', # VIC tree: invalid status
status_update_command, {'OtdbID':1099266, 'NewStatus':'what_happend', 'UpdateTimestamps':True}) do_rpc_catch_exception('on invalid status',
# Set PIC back to active... status_update_command, {'OtdbID':1099266, 'NewStatus':'what_happend', 'UpdateTimestamps':True})
do_rpc(status_update_command, {'OtdbID':1099269, 'NewStatus':'active', 'UpdateTimestamps':True}) # Set PIC back to active...
do_rpc(status_update_command, {'OtdbID':1099269, 'NewStatus':'active', 'UpdateTimestamps':True})
with RPC("OTDBService.GetStations", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{}) with RPC("OTDBService.GetStations", ForwardExceptions=True, busname=busname, timeout=10) as otdbRPC:
do_rpc(otdbRPC,{})
with RPC("OTDBService.TaskSetSpecification", ForwardExceptions=True, busname=busname, timeout=5) as key_update:
# VIC tree: valid with RPC("OTDBService.TaskSetSpecification", ForwardExceptions=True, busname=busname, timeout=5) as key_update:
do_rpc(key_update, {'OtdbID':1099266, # VIC tree: valid
'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.pythonHost':'NameOfTestHost'}}) do_rpc(key_update, {'OtdbID':1099266,
# Template tree: not supported yet 'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.pythonHost':'NameOfTestHost'}})
do_rpc(key_update, {'OtdbID':1099238, # Template tree: not supported yet
'Specification':{'LOFAR.ObsSW.Observation.Scheduler.priority':'0.1'}}) do_rpc(key_update, {'OtdbID':1099238,
# PIC tree: not supported yet 'Specification':{'LOFAR.ObsSW.Observation.Scheduler.priority':'0.1'}})
do_rpc_catch_exception('on invalid treetype (PIC)', key_update, # PIC tree: not supported yet
{'OtdbID':1099269, 'Specification':{'LOFAR.PIC.Core.CS001.status_state':'50'}}) do_rpc_catch_exception('on invalid treetype (PIC)', key_update,
# Non exsisting tree {'OtdbID':1099269, 'Specification':{'LOFAR.PIC.Core.CS001.status_state':'50'}})
do_rpc_catch_exception('on invalid treeID', key_update, {'OtdbID':10, # Non exsisting tree
'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.pythonHost':'NameOfTestHost'}}) do_rpc_catch_exception('on invalid treeID', key_update, {'OtdbID':10,
# VIC tree: wrong key 'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.pythonHost':'NameOfTestHost'}})
do_rpc_catch_exception('on invalid key', key_update, {'OtdbID':1099266, # VIC tree: wrong key
'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.NoSuchKey':'NameOfTestHost'}}) do_rpc_catch_exception('on invalid key', key_update, {'OtdbID':1099266,
'Specification':{'LOFAR.ObsSW.Observation.ObservationControl.PythonControl.NoSuchKey':'NameOfTestHost'}})
...@@ -3,23 +3,19 @@ ...@@ -3,23 +3,19 @@
DBHOST=sasdbtest.control.lofar DBHOST=sasdbtest.control.lofar
#cleanup on normal exit and on SIGHUP, SIGINT, SIGQUIT, and SIGTERM #cleanup on normal exit and on SIGHUP, SIGINT, SIGQUIT, and SIGTERM
trap 'qpid-config del exchange --force $queue ; kill ${SERVICE_PID} ; dropdb -U postgres -h ${DBHOST} ${DBNAME}' 0 1 2 3 15 trap 'kill ${SERVICE_PID} ; dropdb -U postgres -h ${DBHOST} ${DBNAME}' 0 1 2 3 15
# Generate randome queue name # Generate randome queue name
queue=$(< /dev/urandom tr -dc [:alnum:] | head -c10)
DBNAME=unittest_$queue DBNAME=unittest_$queue
# Create the queue
qpid-config add exchange topic $queue
# Setup a clean database with predefined content # Setup a clean database with predefined content
createdb -U postgres -h ${DBHOST} ${DBNAME} createdb -U postgres -h ${DBHOST} ${DBNAME}
gzip -dc $srcdir/unittest_db.dump.gz | psql -U postgres -h ${DBHOST} ${DBNAME} -f - gzip -dc $srcdir/unittest_db.dump.gz | psql -U postgres -h ${DBHOST} ${DBNAME} -f -
TreeService.py -B $queue -D ${DBNAME} -H ${DBHOST} -U postgres & TreeService.py -D ${DBNAME} -H ${DBHOST} -U postgres &
SERVICE_PID=$! SERVICE_PID=$!
# Starting up takes a while # Starting up takes a while
sleep 3 sleep 3
# Run the unit test # Run the unit test
source python-coverage.sh source python-coverage.sh
python_coverage_test "Messaging/python" t_TreeService.py $queue python_coverage_test "Messaging/python" t_TreeService.py
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment