Repository: ESMCI/cime

Issue:
bless_test_results isn't copying cpl.log to the baseline 
When invoking bless_test_results to store the baselines, cpl.log is being missed.    This is causing
through put tests to be skipped.

@cacraigucar 


Discussion:
@jgfouca - thanks for taking this on.

Resolving patch:
diff --git a/scripts/lib/CIME/case.py b/scripts/lib/CIME/case.py
--- a/scripts/lib/CIME/case.py
+++ b/scripts/lib/CIME/case.py
@@ -1353,3 +1353,16 @@ def update_env(self, new_object, env_file):
         self._files.remove(old_object)
         self._files.append(new_object)
         self.schedule_rewrite(new_object)
+
+    def get_latest_cpl_log(self):
+        """
+        find and return the latest cpl log file in the run directory
+        """
+        coupler_log_path = self.get_value("RUNDIR")
+        cpllog = None
+        cpllogs = glob.glob(os.path.join(coupler_log_path, 'cpl.log.*'))
+        if cpllogs:
+            cpllog = max(cpllogs, key=os.path.getctime)
+            return cpllog
+        else:
+            return None
diff --git a/scripts/lib/CIME/hist_utils.py b/scripts/lib/CIME/hist_utils.py
--- a/scripts/lib/CIME/hist_utils.py
+++ b/scripts/lib/CIME/hist_utils.py
@@ -396,6 +396,13 @@ def generate_baseline(case, baseline_dir=None, allow_baseline_overwrite=False):
             shutil.copy(hist, baseline)
             comments += "    generating baseline '{}' from file {}\n".format(baseline, hist)
 
+    # copy latest cpl log to baseline
+    # drop the date so that the name is generic
+    newestcpllogfile = case.get_latest_cpl_log()
+    if newestcpllogfile:
+        shutil.copyfile(newestcpllogfile,
+                        os.path.join(basegen_dir, "cpl.log.gz"))
+
     expect(num_gen > 0, "Could not generate any hist files for case '{}', something is seriously wrong".format(testcase))
     #make sure permissions are open in baseline directory
     for root, _, files in os.walk(basegen_dir):


Test patch:
diff --git a/scripts/lib/CIME/SystemTests/system_tests_common.py b/scripts/lib/CIME/SystemTests/system_tests_common.py
--- a/scripts/lib/CIME/SystemTests/system_tests_common.py
+++ b/scripts/lib/CIME/SystemTests/system_tests_common.py
@@ -232,7 +232,7 @@ def run_indv(self, suffix="base", st_archive=False):
             case_st_archive(self._case)
 
     def _coupler_log_indicates_run_complete(self):
-        newestcpllogfile = self._get_latest_cpl_log()
+        newestcpllogfile = self._case.get_latest_cpl_log()
         logger.debug("Latest Coupler log file is {}".format(newestcpllogfile))
         # Exception is raised if the file is not compressed
         try:
@@ -294,7 +294,7 @@ def _check_for_memleak(self):
         Examine memory usage as recorded in the cpl log file and look for unexpected
         increases.
         """
-        cpllog = self._get_latest_cpl_log()
+        cpllog = self._case.get_latest_cpl_log()
 
         memlist = self._get_mem_usage(cpllog)
 
@@ -339,18 +339,6 @@ def compare_env_run(self, expected=None):
                 return False
         return True
 
-    def _get_latest_cpl_log(self):
-        """
-        find and return the latest cpl log file in the run directory
-        """
-        coupler_log_path = self._case.get_value("RUNDIR")
-        cpllog = None
-        cpllogs = glob.glob(os.path.join(coupler_log_path, 'cpl.log.*'))
-        if cpllogs:
-            cpllog = max(cpllogs, key=os.path.getctime)
-
-        return cpllog
-
     def _compare_baseline(self):
         """
         compare the current test output to a baseline result
@@ -366,7 +354,7 @@ def _compare_baseline(self):
             basecmp_dir = os.path.join(self._case.get_value("BASELINE_ROOT"), baseline_name)
 
             # compare memory usage to baseline
-            newestcpllogfile = self._get_latest_cpl_log()
+            newestcpllogfile = self._case.get_latest_cpl_log()
             memlist = self._get_mem_usage(newestcpllogfile)
             baselog = os.path.join(basecmp_dir, "cpl.log.gz")
             if not os.path.isfile(baselog):
@@ -407,13 +395,6 @@ def _generate_baseline(self):
             status = TEST_PASS_STATUS if success else TEST_FAIL_STATUS
             baseline_name = self._case.get_value("BASEGEN_CASE")
             self._test_status.set_status("{}".format(GENERATE_PHASE), status, comments=os.path.dirname(baseline_name))
-            basegen_dir = os.path.join(self._case.get_value("BASELINE_ROOT"), baseline_name)
-
-            # copy latest cpl log to baseline
-            # drop the date so that the name is generic
-            newestcpllogfile = self._get_latest_cpl_log()
-            shutil.copyfile(newestcpllogfile,
-                            os.path.join(basegen_dir,"cpl.log.gz"))
 
 class FakeTest(SystemTestsCommon):
     """