From 6a1c7563452e96f7fd67ffb6584df8f418f740fd Mon Sep 17 00:00:00 2001
From: Fabrice Le Goff <fabrice.le.goff@cern.ch>
Date: Thu, 14 Sep 2017 15:50:12 +0200
Subject: [PATCH] add script_setup.sh, set LC_ALL when invoking klist, make DDM
 proxy and endpoints config params

---
 Script/CastorScript.py        | 10 +++++++---
 Script/Conf.py                | 10 ++++++++++
 Script/DdmMonitoringThread.py | 10 +++++++++-
 Test/readme                   |  3 ++-
 script_setup.sh               |  6 ++++++
 5 files changed, 34 insertions(+), 5 deletions(-)
 create mode 100644 script_setup.sh

diff --git a/Script/CastorScript.py b/Script/CastorScript.py
index b36904b..733d406 100644
--- a/Script/CastorScript.py
+++ b/Script/CastorScript.py
@@ -391,9 +391,13 @@ def krb_updatetoken(keytab, user, logger):
 
 
 def krb_tokenexpiration(logger):
-
-    klist = Popen(['klist',],
-                  stdout = PIPE, stderr = STDOUT)
+    # on SLC6 klist (v1.10.3) does not take LC_ALL into account
+    # on CentOS 9 klist (v1.14.1) DOES take it into account
+    # This resulted in discrepancies in their output especially for timestamps
+    # So it's safer to always set LC_ALL to a 'default' constant
+    envm = os.environ.copy()
+    envm['LC_ALL'] = 'C'
+    klist = Popen(['klist',], env = envm, stdout=PIPE, stderr=STDOUT)
     ret = klist.wait()
 
     out = klist.stdout.read()
diff --git a/Script/Conf.py b/Script/Conf.py
index bc6a6ae..d25227d 100644
--- a/Script/Conf.py
+++ b/Script/Conf.py
@@ -369,3 +369,13 @@ class Conf:
             self.DdmMonitoringTimeout = cfg.DdmMonitoringTimeout
         except AttributeError:
             self.DdmMonitoringTimeout = 2
+
+        try:
+            self.DdmMonitoringProxy = cfg.DdmMonitoringProxy
+        except AttributeError:
+            self.DdmMonitoringProxy = 'atlasgw-exp:3128'
+
+        try:
+            self.DdmMonitoringEndpoint = cfg.DdmMonitoringEndpoint
+        except AttributeError:
+            self.DdmMonitoringEndpoint = 'https://rucio-lb-prod.cern.ch/traces/'
diff --git a/Script/DdmMonitoringThread.py b/Script/DdmMonitoringThread.py
index 8ebb2ba..babfa7b 100644
--- a/Script/DdmMonitoringThread.py
+++ b/Script/DdmMonitoringThread.py
@@ -41,6 +41,14 @@ class DdmMonitoringThread(threading.Thread):
     def run(self):
         self.logger.info(thread_id_string())
 
+        if self.conf.DdmMonitoringProxy:
+            self.logger.info('enabling proxy for DdmMonitoring publication: {}'.format(self.conf.DdmMonitoringProxy))
+            proxy = urllib2.ProxyHandler({'https': self.conf.DdmMonitoringProxy})
+            opener = urllib2.build_opener(proxy)
+            urllib2.install_opener(opener)
+
+        self.logger.info('DDMMonitoring publication endpoint: {}'.format(self.conf.DdmMonitoringEndpoint))
+
         while True:
             if self.exitFlag and self.DdmMonitoringQueue.empty():
                 break
@@ -53,7 +61,7 @@ class DdmMonitoringThread(threading.Thread):
                     break
 
                 try:
-                    req = urllib2.Request('https://rucio-lb-prod.cern.ch:443/traces/')
+                    req = urllib2.Request(self.conf.DdmMonitoringEndpoint)
                     req.add_header('Content-Type', 'application/json')
                     urllib2.urlopen(req, json.dumps(data))
                     self.logger.debug('published entry for {}: {}'.format(
diff --git a/Test/readme b/Test/readme
index 3c552d9..984bf20 100644
--- a/Test/readme
+++ b/Test/readme
@@ -17,7 +17,8 @@ cp test_config.cfg xxx.cfg
 Modify xxx.cfg appropriately
 To check files on EOS: xrd eosatlas dirlist /eos/atlas/atlastier0/rucio/data_test
 
-/sw/castor/script_setup.sh
+source /sw/castor/script_setup.sh
+# If you need to have an modified authorization file:
 export CORAL_AUTH_PATH="$CORAL_AUTH_PATH:/path/to/CastorScript/coral/"
 python -u ../Script/CastorScript.py xxx.cfg
 
diff --git a/script_setup.sh b/script_setup.sh
new file mode 100644
index 0000000..02b7f33
--- /dev/null
+++ b/script_setup.sh
@@ -0,0 +1,6 @@
+TDAQ_RELEASE=tdaq-07-01-00
+CMTCONFIG=x86_64-slc6-gcc62-opt
+source /sw/tdaq/setup/setup_$TDAQ_RELEASE.sh
+# Add path for xrdcp binary matching this release
+# Neither LCG_VERSION nor a (xrootd version or install path) are available at the moment
+export PATH="$LCG_INST_PATH/LCG_87/xrootd/4.4.1/$LCGPLAT/bin/:$PATH"
-- 
GitLab