From 3c677a15d92345e18b97d6ab5de8c977a990c65d Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 1 Feb 2024 07:30:42 +0100
Subject: [PATCH] TMSS-2829: fixed tests

---
 .../backend/services/copy_service/t_copy_service.py  | 12 +++++++++++-
 SAS/TMSS/backend/src/tmss/tmssapp/populate.py        |  3 +--
 SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py        |  2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/SAS/TMSS/backend/services/copy_service/t_copy_service.py b/SAS/TMSS/backend/services/copy_service/t_copy_service.py
index 932d3b6a6d3..45e82fd1535 100755
--- a/SAS/TMSS/backend/services/copy_service/t_copy_service.py
+++ b/SAS/TMSS/backend/services/copy_service/t_copy_service.py
@@ -20,6 +20,7 @@
 import unittest
 import uuid
 import os
+from unittest import mock
 
 import logging
 logger = logging.getLogger('lofar.'+__name__)
@@ -63,8 +64,17 @@ class TestCopyService(unittest.TestCase):
         cls.tmss_test_env.stop()
         cls.tmp_exchange.close()
 
+    def setUp(self):
+        def mocked_wrap_command_in_cep4_head_node_ssh_call(cmd, *args, **kwargs):
+            logger.info('mocked_wrap_command_in_cep4_head_node_ssh_call returning original command (without ssh): %s', ' '.join(cmd))
+            return cmd
 
-    def test_copy(self):
+        wrap_command_in_cep4_head_node_ssh_call_patcher = mock.patch('lofar.sas.tmss.services.copy_service.wrap_command_in_cep4_available_node_with_lowest_load_ssh_call')
+        self.addCleanup(wrap_command_in_cep4_head_node_ssh_call_patcher.stop)
+        self.wrap_command_in_cep4_head_node_ssh_call_mock = wrap_command_in_cep4_head_node_ssh_call_patcher.start()
+        self.wrap_command_in_cep4_head_node_ssh_call_mock.side_effect = mocked_wrap_command_in_cep4_head_node_ssh_call
+
+    def test_copy_managed_and_unmanaged(self):
         from lofar.sas.tmss.tmss.tmssapp.models import SchedulingUnitObservingStrategyTemplate, SchedulingSet, SubtaskType
         from lofar.sas.tmss.tmss.tmssapp.tasks import create_scheduling_unit_draft_from_observing_strategy_template, create_scheduling_unit_blueprint_and_tasks_and_subtasks_from_scheduling_unit_draft, create_cleanuptask_for_scheduling_unit_blueprint
         from lofar.sas.tmss.tmss.tmssapp.subtasks import schedule_subtask, wait_for_subtask_status
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
index ff09c76dfa8..915ce6b0588 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/populate.py
@@ -617,8 +617,7 @@ def populate_misc(apps, schema_editor):
     elif isTestEnvironment():
         Filesystem.objects.create(name="Test Storage (CIT)", cluster=cep4_cluster, capacity=3.6e15, directory="/data/test-projects")
     else:
-        localhost = Cluster.objects.create(name="localhost", location="local", archive_site=False)
-        Filesystem.objects.create(name="Development Test FS", cluster=localhost, capacity=1e9, directory="/tmp")
+        Filesystem.objects.create(name="Development Test FS", cluster=cep4_cluster, capacity=1e9, directory="/tmp")
 
     # LTA-site clusters
     sara_cluster = Cluster.objects.create(name="SARA", location="SARA", archive_site=True)
diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py
index db6f09db0d2..6c8e15bfe8d 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/subtasks.py
@@ -660,7 +660,7 @@ def create_observation_control_subtask_from_task_blueprint(task_blueprint: TaskB
         raise SubtaskCreationException("Total number of subbands %d exceeds the maximum of 488 for task_blueprint id=%s" % (len(all_subbands), task_blueprint.id))
 
     # step 1: create subtask in defining state
-    cluster_name = task_blueprint.specifications_doc.get("correlator", {}).get("storage_cluster", "CEP4") if isProductionEnvironment() else "localhost"
+    cluster_name = task_blueprint.specifications_doc.get("correlator", {}).get("storage_cluster", "CEP4")
     subtask_data = { "scheduled_start_time": None,
                      "scheduled_stop_time": None,
                      "state": SubtaskState.objects.get(value=SubtaskState.Choices.DEFINING.value),
-- 
GitLab