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

TMSS-1806: added cmdline options to use the script in a more interactive way...

TMSS-1806: added cmdline options to use the script in a more interactive way against an existing TMSS(TestEnvironment) instance
parent 185d1e5b
No related branches found
No related tags found
1 merge request!933TMSS-1806
...@@ -29,49 +29,48 @@ from lofar.sas.tmss.test.test_environment import TMSSTestEnvironment ...@@ -29,49 +29,48 @@ from lofar.sas.tmss.test.test_environment import TMSSTestEnvironment
tmss_test_env = None tmss_test_env = None
if __name__ == "__main__": os.environ['TZ'] = 'UTC'
os.environ['TZ'] = 'UTC' logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
# logging.getLogger('lofar.sas.tmss.services.scheduling.constraints').level = logging.DEBUG # Check the invocation arguments
from optparse import OptionParser, OptionGroup
# Check the invocation arguments parser = OptionParser('%prog [options]',
from optparse import OptionParser, OptionGroup description='run the tmss_slack_webhook_service which listens for TMSS event messages on the messagebus, and posts the updates on the slack webhook api.')
parser = OptionParser('%prog [options]',
description='run the tmss_slack_webhook_service which listens for TMSS event messages on the messagebus, and posts the updates on the slack webhook api.') parser.add_option('-n', '--num_targets', dest='num_targets', type='int', default=-1, help='read at most this many targets (or all if -1), default: %default')
parser.add_option('-s', '--simulate', dest='simulate', action='store_true', help='simulate a run for each unit, allowing the scheduler to schedule the next unit when one finishes')
group = OptionGroup(parser, 'TMSS Test Environment options', description='Run this acceptance test against a fresh TMSSTestEnvironment a running one (specfied by -C).')
parser.add_option_group(group) group = OptionGroup(parser, 'TMSS Test Environment options', description='Run this acceptance test against a fresh TMSSTestEnvironment a running one (specfied by -C).')
group.add_option('-C', '--credentials', dest='dbcredentials', type='string', parser.add_option_group(group)
default=os.environ.get('TMSS_DBCREDENTIALS', 'TMSS'), group.add_option('-C', '--credentials', dest='dbcredentials', type='string',
help='django dbcredentials name, default: %default') default=os.environ.get('TMSS_DBCREDENTIALS', 'TMSS'),
group.add_option('--wipe', dest='wipe', action='store_true', help='wipe all scheduling units in the fresh/existing TMSS instance. Only available when developing.') help='django dbcredentials name, default: %default')
group.add_option('--wipe', dest='wipe', action='store_true', help='wipe all scheduling units in the fresh/existing TMSS instance. Only available when developing.')
(options, args) = parser.parse_args()
(options, args) = parser.parse_args()
if options.dbcredentials is not None:
# try to connect to existing TMSS if options.dbcredentials is not None:
from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error # try to connect to existing TMSS
setup_and_check_tmss_django_database_connection_and_exit_on_error(options.dbcredentials) from lofar.sas.tmss.tmss import setup_and_check_tmss_django_database_connection_and_exit_on_error
setup_and_check_tmss_django_database_connection_and_exit_on_error(options.dbcredentials)
# wipe scheduling units only in Development
from lofar.common import isDevelopmentEnvironment # wipe scheduling units only in Development
if options.wipe and isDevelopmentEnvironment(): from lofar.common import isDevelopmentEnvironment
from lofar.common.postgres import PostgresDatabaseConnection if options.wipe and isDevelopmentEnvironment():
from lofar.common import dbcredentials from lofar.common.postgres import PostgresDatabaseConnection
dbcreds = dbcredentials.DBCredentials().get(options.dbcredentials) from lofar.common import dbcredentials
with PostgresDatabaseConnection(dbcreds) as db: dbcreds = dbcredentials.DBCredentials().get(options.dbcredentials)
db.executeQuery('TRUNCATE tmssapp_schedulingunitdraft CASCADE;') with PostgresDatabaseConnection(dbcreds) as db:
db.commit() db.executeQuery('TRUNCATE tmssapp_schedulingunitdraft CASCADE;')
db.commit()
else:
# create fresh TMSSTestEnvironment else:
tmss_test_env = TMSSTestEnvironment(start_dynamic_scheduler=True, start_websocket=True, # create fresh TMSSTestEnvironment
start_subtask_scheduler=False, start_workflow_service=True) tmss_test_env = TMSSTestEnvironment(start_dynamic_scheduler=True, start_websocket=True,
tmss_test_env.start() start_subtask_scheduler=False, start_workflow_service=True)
tmss_test_env.populate_schemas_and_connectors() tmss_test_env.start()
tmss_test_env.populate_schemas_and_connectors()
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
...@@ -81,7 +80,8 @@ from lofar.sas.tmss.tmss.tmssapp.tasks import create_scheduling_unit_draft_from_ ...@@ -81,7 +80,8 @@ from lofar.sas.tmss.tmss.tmssapp.tasks import create_scheduling_unit_draft_from_
from lofar.sas.tmss.test.test_utils import assert_SUB_statuses, enable_dynamic_scheduling, disable_scheduling, wait_for_units_to_get_scheduled_and_simulate_run, print_scheduling_results, TestStats from lofar.sas.tmss.test.test_utils import assert_SUB_statuses, enable_dynamic_scheduling, disable_scheduling, wait_for_units_to_get_scheduled_and_simulate_run, print_scheduling_results, TestStats
from dateutil import parser from dateutil import parser
def populate_pulsar_timing_test_campaign(project: models.Project, between=None):
def populate_pulsar_timing_test_campaign(project: models.Project, between=None, max_num_targets: int=-1):
scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=project, scheduling_set = models.SchedulingSet.objects.create(**SchedulingSet_test_data(project=project,
name="pulsar timing run %s" % (min([parser.parse(x["from"], ignoretz=True) for x in between]).date() if between else datetime.today()),)) name="pulsar timing run %s" % (min([parser.parse(x["from"], ignoretz=True) for x in between]).date() if between else datetime.today()),))
with open(os.path.abspath(os.path.dirname(__file__)) + '/pulsar_targets.txt', 'r') as file: with open(os.path.abspath(os.path.dirname(__file__)) + '/pulsar_targets.txt', 'r') as file:
...@@ -132,8 +132,7 @@ def populate_pulsar_timing_test_campaign(project: models.Project, between=None): ...@@ -132,8 +132,7 @@ def populate_pulsar_timing_test_campaign(project: models.Project, between=None):
scheduling_unit_blueprint = create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft) scheduling_unit_blueprint = create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft(scheduling_unit_draft)
# uncomment for faster debugging if max_num_targets > -1 and scheduling_set.scheduling_unit_drafts.count() >= max_num_targets:
if scheduling_set.scheduling_unit_drafts.count() >= 5:
return return
assert_SUB_statuses(models.SchedulingUnitStatus.Choices.SCHEDULABLE.value) assert_SUB_statuses(models.SchedulingUnitStatus.Choices.SCHEDULABLE.value)
...@@ -156,10 +155,11 @@ def run_acceptance_test(): ...@@ -156,10 +155,11 @@ def run_acceptance_test():
stats.start_populate = datetime.utcnow() stats.start_populate = datetime.utcnow()
# populate one campaign constraint to start pretty much right away, at next midnight. # populate one campaign constraint to start pretty much right away, at next midnight.
# They have to fit in a 48 hour window # They have to fit in a 48 hour window
start_time = datetime.utcnow() #.replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(hours=48) start_time = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(hours=24)
populate_pulsar_timing_test_campaign(project=project, populate_pulsar_timing_test_campaign(project=project,
between=[{"from": start_time.isoformat(), between=[{"from": start_time.isoformat(),
"to": (start_time+timedelta(hours=48)).isoformat()}]) "to": (start_time+timedelta(hours=48)).isoformat()}],
max_num_targets=options.num_targets)
# populate another campaign constraint to start a month later # populate another campaign constraint to start a month later
start_time = start_time + timedelta(days=3) start_time = start_time + timedelta(days=3)
...@@ -172,13 +172,13 @@ def run_acceptance_test(): ...@@ -172,13 +172,13 @@ def run_acceptance_test():
# start scheduling and wait for it to finish # start scheduling and wait for it to finish
enable_dynamic_scheduling() enable_dynamic_scheduling()
wait_for_units_to_get_scheduled_and_simulate_run(tmss_test_env) if options.simulate:
stats.stop_scheduling = datetime.utcnow() wait_for_units_to_get_scheduled_and_simulate_run(tmss_test_env)
# assert success stats.stop_scheduling = datetime.utcnow()
assert_SUB_statuses(models.SchedulingUnitStatus.Choices.FINISHED.value) # assert success
assert_SUB_statuses(models.SchedulingUnitStatus.Choices.FINISHED.value)
stats.stop_test = datetime.utcnow() stats.stop_test = datetime.utcnow()
return stats return stats
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment