Repository: ESMCI/cime

Issue:
Error on non-batch systems 
PR #2511 seems to be causing the following error :
```
       Submit job case.st_archive
        Traceback (most recent call last):
          File "./case.submit", line 105, in <module>
            _main_func(__doc__)
          File "./case.submit", line 102, in _main_func
            mail_user=mail_user, mail_type=mail_type, batch_args=batch_args)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/case/case_submit.py", line 156, in submit
            custom_success_msg_functor=verbatim_success_msg)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/utils.py", line 1609, in run_and_log_case_status
            rv = func()
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/case/case_submit.py", line 154, in <lambda>
            batch_args=batch_args)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/case/case_submit.py", line 99, in _submit
            mail_type=mail_type, batch_args=batch_args)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/case/case.py", line 1207, in submit_jobs
            batch_args=batch_args, dry_run=dry_run)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/XML/env_batch.py", line 485, in submit_jobs
            dry_run=dry_run)
          File "/home/jedwards/cesm/scratch/cime-nightly-build/cime/scripts/Tools/../../scripts/lib/CIME/XML/env_batch.py", line 565, in _submit_single_job
            getattr(case, function_name)(**{k: v for k, (v, _) in args.items()})
        TypeError: case_st_archive() got an unexpected keyword argument 'submit_resubmits'
```


Discussion:
I think that the problem is not the py3 but rather that this machine does not have a batch system.

Resolving patch:
diff --git a/scripts/lib/CIME/XML/env_batch.py b/scripts/lib/CIME/XML/env_batch.py
--- a/scripts/lib/CIME/XML/env_batch.py
+++ b/scripts/lib/CIME/XML/env_batch.py
@@ -497,15 +497,17 @@ def submit_jobs(self, case, no_batch=False, job=None, user_prereq=None, skip_pnl
             return depid
 
     @staticmethod
-    def _get_supported_args(job):
+    def _get_supported_args(job, no_batch):
         """
         Returns a map of the supported parameters and their arguments to the given script
         TODO: Maybe let each script define this somewhere?
 
-        >>> EnvBatch._get_supported_args("")
+        >>> EnvBatch._get_supported_args("", False)
         {}
-        >>> EnvBatch._get_supported_args("case.test")
+        >>> EnvBatch._get_supported_args("case.test", False)
         {'skip_pnl': '--skip-preview-namelist'}
+        >>> EnvBatch._get_supported_args("case.st_archive", True)
+        {'resubmit': '--resubmit'}
         """
         supported = {}
         if job in ["case.run", "case.test"]:
@@ -513,33 +515,36 @@ def _get_supported_args(job):
         if job == "case.run":
             supported["set_continue_run"] = "--completion-sets-continue-run"
         if job in ["case.st_archive", "case.run"]:
-            supported["submit_resubmits"] = "--resubmit"
+            if job == "case.st_archive" and no_batch:
+                supported["resubmit"] = "--resubmit"
+            else:
+                supported["submit_resubmits"] = "--resubmit"
         return supported
 
     @staticmethod
-    def _build_run_args(job, **run_args):
+    def _build_run_args(job, no_batch, **run_args):
         """
         Returns a map of the filtered parameters for the given script,
         as well as the values passed and the equivalent arguments for calling the script
 
-        >>> EnvBatch._build_run_args("case.run", skip_pnl=True, cthulu="f'taghn")
+        >>> EnvBatch._build_run_args("case.run", False, skip_pnl=True, cthulu="f'taghn")
         {'skip_pnl': (True, '--skip-preview-namelist')}
-        >>> EnvBatch._build_run_args("case.run", skip_pnl=False, cthulu="f'taghn")
+        >>> EnvBatch._build_run_args("case.run", False, skip_pnl=False, cthulu="f'taghn")
         {}
         """
-        supported_args = EnvBatch._get_supported_args(job)
+        supported_args = EnvBatch._get_supported_args(job, no_batch)
         args = {}
         for arg_name, arg_value in run_args.items():
             if arg_value and (arg_name in supported_args.keys()):
                 args[arg_name] = (arg_value, supported_args[arg_name])
         return args
 
-    def _build_run_args_str(self, job, **run_args):
+    def _build_run_args_str(self, job, no_batch, **run_args):
         """
         Returns a string of the filtered arguments for the given script,
         based on the arguments passed
         """
-        args = self._build_run_args(job, **run_args)
+        args = self._build_run_args(job, no_batch, **run_args)
         run_args_str = " ".join(param for _, param in args.values())
         if run_args_str is None:
             return ""
@@ -560,9 +565,10 @@ def _submit_single_job(self, case, job, dep_jobs=None, allow_fail=False,
             logger.info("Starting job script {}".format(job))
             function_name = job.replace(".", "_")
             if not dry_run:
-                args = self._build_run_args(job, skip_pnl=skip_pnl, set_continue_run=resubmit_immediate,
+                args = self._build_run_args(job, True, skip_pnl=skip_pnl, set_continue_run=resubmit_immediate,
                                             submit_resubmits=not resubmit_immediate)
                 getattr(case, function_name)(**{k: v for k, (v, _) in args.items()})
+
             return
 
         submitargs = self.get_submit_args(case, job)
@@ -634,7 +640,7 @@ def _submit_single_job(self, case, job, dep_jobs=None, allow_fail=False,
                "Unable to determine the correct command for batch submission.")
         batchredirect = self.get_value("batch_redirect", subgroup=None)
         batch_env_flag = self.get_value("batch_env", subgroup=None)
-        run_args = self._build_run_args_str(job, skip_pnl=skip_pnl, set_continue_run=resubmit_immediate,
+        run_args = self._build_run_args_str(job, False, skip_pnl=skip_pnl, set_continue_run=resubmit_immediate,
                                             submit_resubmits=not resubmit_immediate)
         if batch_env_flag:
             sequence = (batchsubmit, submitargs, run_args, batchredirect, get_batch_script_for_job(job))
diff --git a/scripts/lib/CIME/case/case_run.py b/scripts/lib/CIME/case/case_run.py
--- a/scripts/lib/CIME/case/case_run.py
+++ b/scripts/lib/CIME/case/case_run.py
@@ -140,7 +140,7 @@ def _run_model_impl(case, lid, skip_pnl=False, da_cycle=0):
                 if loop:
                     # Archive the last consistent set of restart files and restore them
                     if case.get_value("DOUT_S"):
-                        case.case_st_archive(no_resubmit=True)
+                        case.case_st_archive(resubmit=False)
                         case.restore_from_archive()
 
                     lid = new_lid()
diff --git a/scripts/lib/CIME/case/case_st_archive.py b/scripts/lib/CIME/case/case_st_archive.py
--- a/scripts/lib/CIME/case/case_st_archive.py
+++ b/scripts/lib/CIME/case/case_st_archive.py
@@ -590,7 +590,7 @@ def archive_last_restarts(self, archive_restdir, rundir, last_date=None, link_to
                                link_to_last_restart_files=link_to_restart_files)
 
 ###############################################################################
-def case_st_archive(self, last_date_str=None, archive_incomplete_logs=True, copy_only=False, no_resubmit=False):
+def case_st_archive(self, last_date_str=None, archive_incomplete_logs=True, copy_only=False, resubmit=True):
 ###############################################################################
     """
     Create archive object and perform short term archiving
@@ -630,7 +630,7 @@ def case_st_archive(self, last_date_str=None, archive_incomplete_logs=True, copy
 
     # resubmit case if appropriate
     resubmit = self.get_value("RESUBMIT")
-    if resubmit > 0 and not no_resubmit:
+    if resubmit > 0 and resubmit:
         logger.info("resubmitting from st_archive, resubmit={:d}".format(resubmit))
         if self.get_value("MACH") == "mira":
             expect(os.path.isfile(".original_host"), "ERROR alcf host file not found")


Test patch:
diff --git a/scripts/tests/scripts_regression_tests.py b/scripts/tests/scripts_regression_tests.py
--- a/scripts/tests/scripts_regression_tests.py
+++ b/scripts/tests/scripts_regression_tests.py
@@ -1642,10 +1642,10 @@ def test_cime_case_st_archive_resubmit(self):
             case.case_setup(clean=False, test_mode=False, reset=True)
             orig_resubmit = 2
             case.set_value("RESUBMIT", orig_resubmit)
-            case.case_st_archive(no_resubmit=True)
+            case.case_st_archive(resubmit=False)
             new_resubmit = case.get_value("RESUBMIT")
             self.assertTrue(orig_resubmit == new_resubmit, "st_archive resubmitted when told not to")
-            case.case_st_archive(no_resubmit=False)
+            case.case_st_archive(resubmit=True)
             new_resubmit = case.get_value("RESUBMIT")
             self.assertTrue((orig_resubmit - 1) == new_resubmit, "st_archive did not resubmit when told to")