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,16 +29,17 @@ from lofar.sas.tmss.test.test_environment import TMSSTestEnvironment ...@@ -29,16 +29,17 @@ 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 # Check the invocation arguments
from optparse import OptionParser, OptionGroup from optparse import OptionParser, OptionGroup
parser = OptionParser('%prog [options]', 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.') 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).') 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) parser.add_option_group(group)
group.add_option('-C', '--credentials', dest='dbcredentials', type='string', group.add_option('-C', '--credentials', dest='dbcredentials', type='string',
...@@ -72,8 +73,6 @@ if __name__ == "__main__": ...@@ -72,8 +73,6 @@ if __name__ == "__main__":
tmss_test_env.populate_schemas_and_connectors() tmss_test_env.populate_schemas_and_connectors()
from lofar.sas.tmss.tmss.tmssapp import models from lofar.sas.tmss.tmss.tmssapp import models
from lofar.sas.tmss.tmss.tmssapp.tasks import create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft from lofar.sas.tmss.tmss.tmssapp.tasks import create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft
from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, Project_test_data, Cycle_test_data from lofar.sas.tmss.test.tmss_test_data_django_models import SchedulingSet_test_data, Project_test_data, Cycle_test_data
...@@ -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()
if options.simulate:
wait_for_units_to_get_scheduled_and_simulate_run(tmss_test_env) wait_for_units_to_get_scheduled_and_simulate_run(tmss_test_env)
stats.stop_scheduling = datetime.utcnow() stats.stop_scheduling = datetime.utcnow()
# assert success # assert success
assert_SUB_statuses(models.SchedulingUnitStatus.Choices.FINISHED.value) 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