From 211a738aeb1ce751edf60fbeede9a7f17eb8743e Mon Sep 17 00:00:00 2001
From: Ross Hunter <ross.john.hunter@cern.ch>
Date: Wed, 15 Nov 2023 14:25:45 +0000
Subject: [PATCH 1/3] Add block of code to copy over the hlt2 full stream
 output to eos

---
 handlers/BandwidthTestHandler.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/handlers/BandwidthTestHandler.py b/handlers/BandwidthTestHandler.py
index 3713ca0a..388e6a03 100644
--- a/handlers/BandwidthTestHandler.py
+++ b/handlers/BandwidthTestHandler.py
@@ -397,6 +397,27 @@ class BandwidthTestHandler(BaseHandler):
             ]:
                 upload_file(dirname, mon_file)
 
+        # Temporary test of the system: copy the full stream MDF to eos
+        if options == "Moore_hlt2_bandwidth" and slot == "lhcb-master":
+            from datetime import datetime
+            before_copy = datetime.now()
+            full_stream_mdf = os.path.join(directory, 'tmp', 'MDF', "hlt2_bw_testing__production__full.mdf")
+            log.info(f"Trying to copy {full_stream_mdf} to eos. File size: {os.stat(full_stream_mdf).st_size / 1e6} MB.")
+            publish.upload_eos_www(
+                full_stream_mdf,
+                os.path.basename(full_stream_mdf),
+                baseurl=os.path.join(os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest")
+            )
+            log.info(f"Copied {full_stream_mdf} to eos. This took " + str(datetime.now() - before_copy)) 
+            log.info("Trying to copy to new directory...")
+            before_second_copy = datetime.now()
+            publish.upload_eos_www(
+                full_stream_mdf,
+                os.path.join("current_hlt2_output", os.path.basename(full_stream_mdf)),
+                baseurl=os.path.join(os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest")
+            )
+            log.info(f"Copied {full_stream_mdf} to eos new directory. This took " + str(datetime.now() - before_second_copy)) 
+
         # Read message to post 
         with open(full_output_path('message.txt'), 'r') as message_file:
             message = message_file.read()
-- 
GitLab


From 4966dc42c300e3c240be232306a2b8fcdd182967 Mon Sep 17 00:00:00 2001
From: Ross Hunter <ross.john.hunter@cern.ch>
Date: Wed, 15 Nov 2023 14:27:43 +0000
Subject: [PATCH 2/3] Only do it if all subjobs successful

---
 handlers/BandwidthTestHandler.py | 41 ++++++++++++++++----------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/handlers/BandwidthTestHandler.py b/handlers/BandwidthTestHandler.py
index 388e6a03..0e553c00 100644
--- a/handlers/BandwidthTestHandler.py
+++ b/handlers/BandwidthTestHandler.py
@@ -397,8 +397,28 @@ class BandwidthTestHandler(BaseHandler):
             ]:
                 upload_file(dirname, mon_file)
 
+        # Read message to post 
+        with open(full_output_path('message.txt'), 'r') as message_file:
+            message = message_file.read()
+            tot_rate = float(get_from_message(message, r"total_rate = ([\d.]+) kHz"))
+            tot_bandwidth = float(get_from_message(message, r"total_bandwidth = ([\d.]+) GB/s"))
+            n_low_rate = int(get_from_message(message, r"n_low_rate = ([\d.]+)"))
+            n_high_rate = int(get_from_message(message, r"n_high_rate = ([\d.]+)"))
+            status = bool(int(get_from_message(message, r"all_jobs_successful_bool = ([\d.]+)"))) # get_from_message will return a string '0' or '1', and bool(string) is always True, so cast to int first.
+        for metric_name, metric_val in {'rate': tot_rate, 'bandwidth': tot_bandwidth}.items():
+            self.saveFloat(
+                f'total_{metric_name}',
+                metric_val,
+                description=f'total {metric_name} of {process} lines',
+                group=metric_name
+            )
+        status_sentence = ":bluetick: All sub-jobs in this test exited successfully.\n" if status else ":alarm: **There were errors in some of the sub-jobs of this test; please see the logs.** :alarm:\n"
+
+        send_mattermost_feedback(n_low_rate, n_high_rate, tot_rate, tot_bandwidth, options, version, targetRootWebDir, status_sentence, process)
+
         # Temporary test of the system: copy the full stream MDF to eos
-        if options == "Moore_hlt2_bandwidth" and slot == "lhcb-master":
+        # Only do so if test was completely successful.
+        if options == "Moore_hlt2_bandwidth" and slot == "lhcb-master" and status:
             from datetime import datetime
             before_copy = datetime.now()
             full_stream_mdf = os.path.join(directory, 'tmp', 'MDF', "hlt2_bw_testing__production__full.mdf")
@@ -418,25 +438,6 @@ class BandwidthTestHandler(BaseHandler):
             )
             log.info(f"Copied {full_stream_mdf} to eos new directory. This took " + str(datetime.now() - before_second_copy)) 
 
-        # Read message to post 
-        with open(full_output_path('message.txt'), 'r') as message_file:
-            message = message_file.read()
-            tot_rate = float(get_from_message(message, r"total_rate = ([\d.]+) kHz"))
-            tot_bandwidth = float(get_from_message(message, r"total_bandwidth = ([\d.]+) GB/s"))
-            n_low_rate = int(get_from_message(message, r"n_low_rate = ([\d.]+)"))
-            n_high_rate = int(get_from_message(message, r"n_high_rate = ([\d.]+)"))
-            status = bool(int(get_from_message(message, r"all_jobs_successful_bool = ([\d.]+)"))) # get_from_message will return a string '0' or '1', and bool(string) is always True, so cast to int first.
-        for metric_name, metric_val in {'rate': tot_rate, 'bandwidth': tot_bandwidth}.items():
-            self.saveFloat(
-                f'total_{metric_name}',
-                metric_val,
-                description=f'total {metric_name} of {process} lines',
-                group=metric_name
-            )
-        status_sentence = ":bluetick: All sub-jobs in this test exited successfully.\n" if status else ":alarm: **There were errors in some of the sub-jobs of this test; please see the logs.** :alarm:\n"
-
-        send_mattermost_feedback(n_low_rate, n_high_rate, tot_rate, tot_bandwidth, options, version, targetRootWebDir, status_sentence, process)
-
         # Post GitLab MR feedback; a bit more complex bcuz might be comparing to a reference build.
         if (slot in ["lhcb-master-mr", "lhcb-master-ref", "lhcb-master"]) and (
             options
-- 
GitLab


From 05f726f9ce75835d12383d851ee72d7820f9cab7 Mon Sep 17 00:00:00 2001
From: Ross Hunter <ross.john.hunter@cern.ch>
Date: Wed, 15 Nov 2023 16:07:23 +0000
Subject: [PATCH 3/3] lb-format

---
 handlers/BandwidthTestHandler.py | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/handlers/BandwidthTestHandler.py b/handlers/BandwidthTestHandler.py
index 2e9660b7..16f1b2eb 100644
--- a/handlers/BandwidthTestHandler.py
+++ b/handlers/BandwidthTestHandler.py
@@ -517,22 +517,30 @@ class BandwidthTestHandler(BaseHandler):
         if options == "Moore_hlt2_bandwidth" and slot == "lhcb-master" and status:
             from datetime import datetime
             before_copy = datetime.now()
-            full_stream_mdf = os.path.join(directory, 'tmp', 'MDF', "hlt2_bw_testing__production__full.mdf")
-            log.info(f"Trying to copy {full_stream_mdf} to eos. File size: {os.stat(full_stream_mdf).st_size / 1e6} MB.")
+            full_stream_mdf = os.path.join(
+                directory, 'tmp', 'MDF',
+                "hlt2_bw_testing__production__full.mdf")
+            log.info(
+                f"Trying to copy {full_stream_mdf} to eos. File size: {os.stat(full_stream_mdf).st_size / 1e6} MB."
+            )
             publish.upload_eos_www(
                 full_stream_mdf,
                 os.path.basename(full_stream_mdf),
-                baseurl=os.path.join(os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest")
-            )
-            log.info(f"Copied {full_stream_mdf} to eos. This took " + str(datetime.now() - before_copy)) 
+                baseurl=os.path.join(
+                    os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest"))
+            log.info(f"Copied {full_stream_mdf} to eos. This took " +
+                     str(datetime.now() - before_copy))
             log.info("Trying to copy to new directory...")
             before_second_copy = datetime.now()
             publish.upload_eos_www(
                 full_stream_mdf,
-                os.path.join("current_hlt2_output", os.path.basename(full_stream_mdf)),
-                baseurl=os.path.join(os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest")
-            )
-            log.info(f"Copied {full_stream_mdf} to eos new directory. This took " + str(datetime.now() - before_second_copy)) 
+                os.path.join("current_hlt2_output",
+                             os.path.basename(full_stream_mdf)),
+                baseurl=os.path.join(
+                    os.getenv("LHCBPR_WWW_EOS"), "UpgradeRateTest"))
+            log.info(
+                f"Copied {full_stream_mdf} to eos new directory. This took " +
+                str(datetime.now() - before_second_copy))
 
         # Post GitLab MR feedback; a bit more complex as comparing to a reference build.
         if (slot in [
-- 
GitLab