diff --git a/scripts/lib/CIME/SystemTests/err.py b/scripts/lib/CIME/SystemTests/err.py index 793cd69e279..0da24c00310 100644 --- a/scripts/lib/CIME/SystemTests/err.py +++ b/scripts/lib/CIME/SystemTests/err.py @@ -3,39 +3,29 @@ ERR tests short term archiving and restart capabilities """ from CIME.XML.standard_module_setup import * -from CIME.SystemTests.ers import ERS - -import shutil, glob +from CIME.SystemTests.restart_tests import RestartTest +from CIME.case_st_archive import restore_from_archive +from CIME.utils import ls_sorted_by_mtime logger = logging.getLogger(__name__) -class ERR(ERS): +class ERR(RestartTest): - def __init__(self, case): + def __init__(self, case): # pylint: disable=super-init-not-called """ initialize an object interface to the ERR system test """ - ERS.__init__(self, case) - - def run_phase(self): - first_phase = self._case.get_value("RESUBMIT") == 1 - - if first_phase: - self._case.set_value("DOUT_S", True) - self._case.flush() - self._ers_first_phase() - else: - dout_s_root = self._case.get_value("DOUT_S_ROOT") - rundir = self._case.get_value("RUNDIR") - case = self._case.get_value("CASE") - # First remove restart, history and rpointer files from the run directory - for item in glob.iglob(os.path.join(rundir, "{}.*".format(case))): - if not item.endswith("base"): - os.remove(item) - for item in glob.iglob(os.path.join(rundir, "rpointer.*")): - os.remove(item) - # Then replace them from the restart directory - for item in glob.iglob(os.path.join(dout_s_root,"rest","*","*")): - shutil.copy(item, rundir) + RestartTest.__init__(self, case, # pylint: disable=non-parent-init-called + separate_builds = False, + run_two_suffix = 'rest', + run_one_description = 'initial', + run_two_description = 'restart', + multisubmit = True) - self._ers_second_phase() + def _case_two_custom_prerun_action(self): + dout_s_root = self._case1.get_value("DOUT_S_ROOT") + rest_root = os.path.abspath(os.path.join(dout_s_root,"rest")) + restart_list = ls_sorted_by_mtime(rest_root) + expect(len(restart_list) >= 1, "No restart files found in {}".format(rest_root)) + restore_from_archive(self._case, rest_dir= + os.path.join(rest_root, restart_list[0])) diff --git a/scripts/lib/CIME/SystemTests/erri.py b/scripts/lib/CIME/SystemTests/erri.py index cf76c8d4b92..6fd79b3e1fa 100644 --- a/scripts/lib/CIME/SystemTests/erri.py +++ b/scripts/lib/CIME/SystemTests/erri.py @@ -18,17 +18,12 @@ def __init__(self, case): """ ERR.__init__(self, case) - def run_phase(self): - first_phase = self._case.get_value("RESUBMIT") == 1 - - ERR.run_phase(self) - - if not first_phase: - rundir = self._case.get_value("RUNDIR") - for logname_gz in glob.glob(os.path.join(rundir, '*.log*.gz')): - # gzipped logfile names are of the form $LOGNAME.gz - # Removing the last three characters restores the original name - logname = logname_gz[:-3] - with gzip.open(logname_gz, 'rb') as f_in, open(logname, 'w') as f_out: - shutil.copyfileobj(f_in, f_out) - os.remove(logname_gz) + def _case_two_custom_postrun_action(self): + rundir = self._case.get_value("RUNDIR") + for logname_gz in glob.glob(os.path.join(rundir, '*.log*.gz')): + # gzipped logfile names are of the form $LOGNAME.gz + # Removing the last three characters restores the original name + logname = logname_gz[:-3] + with gzip.open(logname_gz, 'rb') as f_in, open(logname, 'w') as f_out: + shutil.copyfileobj(f_in, f_out) + os.remove(logname_gz) diff --git a/scripts/lib/CIME/SystemTests/irt.py b/scripts/lib/CIME/SystemTests/irt.py index 879781a57de..fb853cc4755 100644 --- a/scripts/lib/CIME/SystemTests/irt.py +++ b/scripts/lib/CIME/SystemTests/irt.py @@ -10,37 +10,22 @@ """ -from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo +from CIME.SystemTests.restart_tests import RestartTest from CIME.XML.standard_module_setup import * from CIME.case_st_archive import case_st_archive, restore_from_archive from CIME.utils import ls_sorted_by_mtime logger = logging.getLogger(__name__) -class IRT(SystemTestsCompareTwo): +class IRT(RestartTest): def __init__(self, case): - SystemTestsCompareTwo.__init__(self, case, - separate_builds=False, - run_two_suffix = 'restart', - run_one_description = 'initial', - run_two_description = 'restart', - multisubmit = False) - - def _case_one_setup(self): - stop_n = self._case1.get_value("STOP_N") - expect(stop_n >= 3,"STOP_N must be at least 3, STOP_N = {}".format(stop_n)) - - def _case_two_setup(self): - rest_n = self._case1.get_value("REST_N") - stop_n = self._case1.get_value("STOP_N") - stop_new = stop_n - rest_n - expect(stop_new > 0, "ERROR: stop_n value {:d} too short {:d} {:d}".format(stop_new,stop_n,rest_n)) - # hist_n is set to the stop_n value of case1 - self._case.set_value("HIST_N", stop_n) - self._case.set_value("STOP_N", stop_new) - self._case.set_value("CONTINUE_RUN",True) - self._case.set_value("REST_OPTION", "never") + RestartTest.__init__(self, case, + separate_builds=False, + run_two_suffix = 'restart', + run_one_description = 'initial', + run_two_description = 'restart', + multisubmit = False) def _case_one_custom_postrun_action(self): case_st_archive(self._case) diff --git a/scripts/lib/CIME/SystemTests/restart_tests.py b/scripts/lib/CIME/SystemTests/restart_tests.py new file mode 100644 index 00000000000..cce4ca79241 --- /dev/null +++ b/scripts/lib/CIME/SystemTests/restart_tests.py @@ -0,0 +1,40 @@ +""" +Abstract class for restart tests + +""" + +from CIME.SystemTests.system_tests_compare_two import SystemTestsCompareTwo +from CIME.XML.standard_module_setup import * + +logger = logging.getLogger(__name__) + +class RestartTest(SystemTestsCompareTwo): + + def __init__(self, case, + separate_builds, + run_two_suffix = 'restart', + run_one_description = 'initial', + run_two_description = 'restart', + multisubmit = False): + SystemTestsCompareTwo.__init__(self, case, + separate_builds, + run_two_suffix = run_two_suffix, + run_one_description = run_one_description, + run_two_description = run_two_description, + multisubmit = multisubmit) + + + def _case_one_setup(self): + stop_n = self._case1.get_value("STOP_N") + expect(stop_n >= 3,"STOP_N must be at least 3, STOP_N = {}".format(stop_n)) + + def _case_two_setup(self): + rest_n = self._case1.get_value("REST_N") + stop_n = self._case1.get_value("STOP_N") + stop_new = stop_n - rest_n + expect(stop_new > 0, "ERROR: stop_n value {:d} too short {:d} {:d}".format(stop_new,stop_n,rest_n)) + # hist_n is set to the stop_n value of case1 + self._case.set_value("HIST_N", stop_n) + self._case.set_value("STOP_N", stop_new) + self._case.set_value("CONTINUE_RUN",True) + self._case.set_value("REST_OPTION", "never")