Repository: ESMCI/cime

Issue:
system_tests.py is not fully parsing test
The system_tests.py is not fully parsing the test name to pass to create_newcase, for example
SMS_Mmpi-serial.f19_g16.X  does not pass the mpi option to create_newcase.   



Discussion:

Resolving patch:
diff --git a/utils/python/CIME/utils.py b/utils/python/CIME/utils.py
--- a/utils/python/CIME/utils.py
+++ b/utils/python/CIME/utils.py
@@ -233,6 +233,8 @@ def parse_test_name(test_name):
     ['ERS', ['D'], 'fe12_123', 'JGF', None, None, None]
     >>> parse_test_name('ERS_D_P1.fe12_123.JGF')
     ['ERS', ['D', 'P1'], 'fe12_123', 'JGF', None, None, None]
+    >>> parse_test_name('SMS_D_Ln9_Mmpi-serial.f19_g16_rx1.A')
+    ['SMS', ['D', 'Ln9', 'Mmpi-serial'], 'f19_g16_rx1', 'A', None, None, None]
     >>> parse_test_name('ERS.fe12_123.JGF.machine_compiler')
     ['ERS', None, 'fe12_123', 'JGF', 'machine', 'compiler', None]
     >>> parse_test_name('ERS.fe12_123.JGF.machine_compiler.test-mods')


Test patch:
diff --git a/cime_config/acme/machines/template.case.test b/cime_config/acme/machines/template.case.test
--- a/cime_config/acme/machines/template.case.test
+++ b/cime_config/acme/machines/template.case.test
@@ -12,7 +12,7 @@ if workdir is not None:
 
 _CIMEROOT = os.environ.get("CIMEROOT")
 if _CIMEROOT is None:
-    raise exc_type("ERROR: must set CIMEROOT environment variable")
+    raise SystemExit("ERROR: must set CIMEROOT environment variable")
 
 _LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
 sys.path.append(_LIBDIR)
diff --git a/cime_config/cesm/machines/template.case.test b/cime_config/cesm/machines/template.case.test
--- a/cime_config/cesm/machines/template.case.test
+++ b/cime_config/cesm/machines/template.case.test
@@ -12,7 +12,7 @@ if workdir is not None:
 
 _CIMEROOT = os.environ.get("CIMEROOT")
 if _CIMEROOT is None:
-    raise exc_type("ERROR: must set CIMEROOT environment variable")
+    raise SystemExit("ERROR: must set CIMEROOT environment variable")
 
 _LIBDIR = os.path.join(_CIMEROOT, "scripts", "Tools")
 sys.path.append(_LIBDIR)
diff --git a/utils/python/CIME/SystemTests/system_tests_common.py b/utils/python/CIME/SystemTests/system_tests_common.py
--- a/utils/python/CIME/SystemTests/system_tests_common.py
+++ b/utils/python/CIME/SystemTests/system_tests_common.py
@@ -93,11 +93,12 @@ def _getmemusage(self, cpllog):
         """
         memlist = list()
         meminfo = re.compile(".*model date =\s+(\w+).*memory =\s+(\d+\.?\d+).*highwater")
-        with gzip.open(cpllog, "rb") as f:
-            for line in f:
-                m = meminfo.match(line)
-                if m:
-                    memlist.append((m.group(1), m.group(2)))
+        if cpllog is not None:
+            with gzip.open(cpllog, "rb") as f:
+                for line in f:
+                    m = meminfo.match(line)
+                    if m:
+                        memlist.append((m.group(1), m.group(2)))
         return memlist
 
     def _checkformemleak(self, cpllog):
@@ -145,10 +146,11 @@ def _getlatestcpllog(self):
         find and return the latest cpl log file in the run directory
         """
         cpllog = None
-        cpllogs = glob.iglob(os.path.join(
+        cpllogs = glob.glob(os.path.join(
                     self._case.get_value('RUNDIR'),'cpl.log.*'))
         if cpllogs:
             cpllog = min(cpllogs, key=os.path.getctime)
+
         return cpllog
 
 
diff --git a/utils/python/CIME/system_test.py b/utils/python/CIME/system_test.py
--- a/utils/python/CIME/system_test.py
+++ b/utils/python/CIME/system_test.py
@@ -358,7 +358,15 @@ def _create_newcase_phase(self, test):
                 return False
             create_newcase_cmd += " -user_mods_dir %s" % test_mod_file
 
-        logger.debug("Calling create_newcase: "+create_newcase_cmd)
+        if case_opts is not None:
+            for case_opt in case_opts:
+                if case_opt.startswith('M'):
+                    match =  re.match('M(.+)', case_opt)
+                    mpilib = case_opt[1:]
+                    create_newcase_cmd += " --mpilib %s" % mpilib
+                    logger.debug (" MPILIB set to %s" % mpilib)
+
+        logger.debug("Calling create_newcase: " + create_newcase_cmd)
         return self._shell_cmd_for_phase(test, create_newcase_cmd, CREATE_NEWCASE_PHASE)
 
     ###########################################################################
@@ -442,10 +450,8 @@ def _xml_phase(self, test):
                     logger.debug (" STOP_N      set to %s" %opti)
 
                 elif opt.startswith('M'):
-                    match =  re.match('M(.+)', opt)
-                    mpilib = opt[1:]
-                    envtest.set_test_parameter("MPILIB", opt)
-                    logger.debug (" MPILIB set to %s" %opt)
+                    # M option handled by create newcase
+                    continue
 
                 elif opt.startswith('P'):
                     match =  re.match('P([0-9]+)', opt)