From cbfdea651bc6391aad9f2a5eda00385b9b68d98b Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 10 Jul 2020 13:10:59 +0200
Subject: [PATCH] TMSS-152: retreive stations from lcuhead for stationgroup

---
 LCS/PyCommon/lcu_utils.py             | 7 ++++++-
 SAS/TMSS/src/tmss/tmssapp/subtasks.py | 8 ++++----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/LCS/PyCommon/lcu_utils.py b/LCS/PyCommon/lcu_utils.py
index 1377d1004ef..c0a17b1e811 100755
--- a/LCS/PyCommon/lcu_utils.py
+++ b/LCS/PyCommon/lcu_utils.py
@@ -126,6 +126,11 @@ def get_current_stations(station_group='today', as_host_names=True):
     :param as_host_names - bool: return the station names as ssh-able hostnames if True (like cs001c, cs002c). return the station names as parset-like VirtualInstrument.stationList names if False (like CS001, CS002).
     :return: the station names for the given station_group as ssh-able hostnames if as_host_names=True (like cs001c, cs002c) or as parset-like VirtualInstrument.stationList names if as_host_names=False (like CS001, CS002).
     '''
+    # sanitize
+    station_group = station_group.lower().strip()
+    if station_group == 'all':
+        station_group = 'today'
+
     cmd = ['cat', '/opt/operations/bin/stations.txt']
     cmd = wrap_command_in_lcu_head_node_ssh_call(cmd)
     logger.debug('executing cmd: %s', ' '.join(cmd))
@@ -136,7 +141,7 @@ def get_current_stations(station_group='today', as_host_names=True):
         raise LCURuntimeError("Could not fetch stations.txt file. sdterr=%s" % (err, ))
 
     station_file_lines = out.splitlines(False)
-    station_group_filter = station_group.strip()+' '
+    station_group_filter = station_group +' '
     station_group_line = next(l for l in station_file_lines if l.startswith(station_group_filter))
     station_aliases = station_group_line.split(' ')[-1].split(',')
     station_hostnames = []
diff --git a/SAS/TMSS/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
index 36fa8cbeb04..3f93d4329b5 100644
--- a/SAS/TMSS/src/tmss/tmssapp/subtasks.py
+++ b/SAS/TMSS/src/tmss/tmssapp/subtasks.py
@@ -7,6 +7,7 @@ from collections.abc import Iterable
 from lofar.common.datetimeutils import formatDatetime
 from lofar.common import isProductionEnvironment
 from lofar.common.json_utils import add_defaults_to_json_object_for_schema, get_default_json_object_for_schema
+from lofar.common.lcu_utils import get_current_stations
 
 from lofar.sas.tmss.tmss.exceptions import SubtaskCreationException, SubtaskSchedulingException
 
@@ -63,11 +64,10 @@ def get_station_specifications_from_observation_blueprint(task_spec):
                  })
 
     if "stations" in task_spec:
-        # TODO: Retrieve stations list in case of a dynamic list : ALL, SUPERTERP, CORE, REMOTE, DUTCH, INTERNATIONAL
-        #       for now just hack one station....so also ignore the minimum for now
-        #       could be that this is already some ticket?
         if "group" in task_spec["stations"][0]:
-            station_list = ["CS001"]
+            # retreive current available stations in group from lcuhead
+            station_group = task_spec["stations"][0]["group"]
+            station_list = get_current_stations(station_group, as_host_names=False)
         else:
             station_list = task_spec["stations"]
 
-- 
GitLab