We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
case_submit.py has an inaccurate test for continuing a run
The test for making sure continue_run makes sense in case_submit.py is not really valid. There's a line that uses successful completion of a previous run as the test instead of checking for valid pointer files. That section of the script looks like:

    # Check if CONTINUE_RUN value makes sense
    if job != "case.test" and case.get_value("CONTINUE_RUN"):
        rundir = case.get_value("RUNDIR")
        caseroot = case.get_value("CASEROOT")
        expect(os.path.isdir(rundir),
               "CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
        expect(len(glob.glob(os.path.join(rundir, "*.nc"))) > 0,
               "CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)")
        expect(does_file_have_string(os.path.join(caseroot, "CaseStatus"), "case.run {}".format(CASE_SUCCESS)),
               "CONTINUE_RUN is true but this case does not appear to have ever run successfully")
The last line either should be modified to really check for the requirements of a continued run or removed.

Note that we often start production runs to go many years and drop sets of restart files along the way. If they ever time out, this test fails and makes it difficult to restart, even thought there are valid sets of restart files.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `scripts/lib/CIME/case/case_submit.py`
Content:
```
1 #!/usr/bin/env python
2 
3 """
4 case.submit - Submit a cesm workflow to the queueing system or run it
5 if there is no queueing system.  A cesm workflow may include multiple
6 jobs.
7 submit, check_case and check_da_settings are members of class Case in file case.py
8 """
9 from six.moves                      import configparser
10 from CIME.XML.standard_module_setup import *
11 from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CASE_SUCCESS, does_file_have_string, CIMEError
12 from CIME.locked_files              import unlock_file, lock_file
13 from CIME.test_status               import *
14 
15 import socket, glob
16 
17 logger = logging.getLogger(__name__)
18 
19 def _build_prereq_str(case, prev_job_ids):
20     delimiter = case.get_value("depend_separator")
21     prereq_str = ""
22     for job_id in prev_job_ids.values():
23         prereq_str += str(job_id) + delimiter
24     return prereq_str[:-1]
25 
26 def _submit(case, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,
27             resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,
28             batch_args=None):
29     if job is None:
30         job = case.get_primary_job()
31 
32     # Check if CONTINUE_RUN value makes sense
33     if job != "case.test" and case.get_value("CONTINUE_RUN"):
34         rundir = case.get_value("RUNDIR")
35         caseroot = case.get_value("CASEROOT")
36         expect(os.path.isdir(rundir),
37                "CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
38         expect(len(glob.glob(os.path.join(rundir, "*.nc"))) > 0,
39                "CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)")
40         expect(does_file_have_string(os.path.join(caseroot, "CaseStatus"), "case.run {}".format(CASE_SUCCESS)),
41                "CONTINUE_RUN is true but this case does not appear to have ever run successfully")
42 
43     # if case.submit is called with the no_batch flag then we assume that this
44     # flag will stay in effect for the duration of the RESUBMITs
45     env_batch = case.get_env("batch")
46     if resubmit:
47         if env_batch.get_batch_system_type() == "none":
48             no_batch = True
49 
50         # This is a resubmission, do not reinitialize test values
51         if job == "case.test":
52             case.set_value("IS_FIRST_RUN", False)
53 
54         resub = case.get_value("RESUBMIT")
55         logger.info("Submitting job '{}', resubmit={:d}".format(job, resub))
56         case.set_value("RESUBMIT", resub-1)
57         if case.get_value("RESUBMIT_SETS_CONTINUE_RUN"):
58             case.set_value("CONTINUE_RUN", True)
59 
60     else:
61         if job == "case.test":
62             case.set_value("IS_FIRST_RUN", True)
63 
64         if no_batch:
65             batch_system = "none"
66         else:
67             batch_system = env_batch.get_batch_system_type()
68 
69         case.set_value("BATCH_SYSTEM", batch_system)
70 
71         env_batch_has_changed = False
72         try:
73             case.check_lockedfile(os.path.basename(env_batch.filename))
74         except CIMEError:
75             env_batch_has_changed = True
76 
77         if env_batch.get_batch_system_type() != "none" and env_batch_has_changed:
78             # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)
79             logger.warning(\
80 """
81 env_batch.xml appears to have changed, regenerating batch scripts
82 manual edits to these file will be lost!
83 """)
84             env_batch.make_all_batch_files(case)
85 
86         unlock_file(os.path.basename(env_batch.filename))
87         lock_file(os.path.basename(env_batch.filename))
88 
89         if job == case.get_primary_job():
90             case.check_case()
91             case.check_DA_settings()
92             if case.get_value("MACH") == "mira":
93                 with open(".original_host", "w") as fd:
94                     fd.write( socket.gethostname())
95 
96     #Load Modules
97     case.load_env()
98 
99     case.flush()
100 
101     logger.warning("submit_jobs {}".format(job))
102     job_ids = case.submit_jobs(no_batch=no_batch, job=job, prereq=prereq,
103                                skip_pnl=skip_pnl, resubmit_immediate=resubmit_immediate,
104                                allow_fail=allow_fail, mail_user=mail_user,
105                                mail_type=mail_type, batch_args=batch_args)
106 
107     xml_jobids = []
108     for jobname, jobid in job_ids.items():
109         logger.info("Submitted job {} with id {}".format(jobname, jobid))
110         if jobid:
111             xml_jobids.append("{}:{}".format(jobname, jobid))
112 
113     xml_jobid_text = ", ".join(xml_jobids)
114     if xml_jobid_text:
115         case.set_value("JOB_IDS", xml_jobid_text)
116 
117     return xml_jobid_text
118 
119 def submit(self, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,
120            resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,
121            batch_args=None):
122     if resubmit_immediate and self.get_value("MACH") in ['mira', 'cetus']:
123         logger.warning("resubmit_immediate does not work on Mira/Cetus, submitting normally")
124         resubmit_immediate = False
125 
126     caseroot = self.get_value("CASEROOT")
127     if self.get_value("TEST"):
128         casebaseid = self.get_value("CASEBASEID")
129         # This should take care of the race condition where the submitted job
130         # begins immediately and tries to set RUN phase. We proactively assume
131         # a passed SUBMIT phase. If this state is already PASS, don't set it again
132         # because then we'll lose RUN phase info if it's there. This info is important
133         # for system_tests_common to know if it needs to reinitialize the test or not.
134         with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
135             phase_status = ts.get_status(SUBMIT_PHASE)
136             if phase_status != TEST_PASS_STATUS:
137                 ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)
138 
139     # If this is a resubmit check the hidden file .submit_options for
140     # any submit options used on the original submit and use them again
141     submit_options = os.path.join(caseroot, ".submit_options")
142     if resubmit and os.path.exists(submit_options):
143         config = configparser.SafeConfigParser()
144         config.read(submit_options)
145         if not skip_pnl and config.has_option('SubmitOptions','skip_pnl'):
146             skip_pnl = config.getboolean('SubmitOptions', 'skip_pnl')
147         if mail_user is None and config.has_option('SubmitOptions', 'mail_user'):
148             mail_user = config.get('SubmitOptions', 'mail_user')
149         if mail_type is None and config.has_option('SubmitOptions', 'mail_type'):
150             mail_type = str(config.get('SubmitOptions', 'mail_type')).split(',')
151         if batch_args is None and config.has_option('SubmitOptions', 'batch_args'):
152             batch_args = config.get('SubmitOptions', 'batch_args')
153 
154     try:
155         functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,
156                                   allow_fail=allow_fail, resubmit=resubmit,
157                                   resubmit_immediate=resubmit_immediate, skip_pnl=skip_pnl,
158                                   mail_user=mail_user, mail_type=mail_type,
159                                   batch_args=batch_args)
160         run_and_log_case_status(functor, "case.submit", caseroot=caseroot,
161                                 custom_success_msg_functor=verbatim_success_msg)
162     except BaseException: # Want to catch KeyboardInterrupt too
163         # If something failed in the batch system, make sure to mark
164         # the test as failed if we are running a test.
165         if self.get_value("TEST"):
166             with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
167                 ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)
168 
169         raise
170 
171 def check_case(self):
172     self.check_lockedfiles()
173     self.create_namelists() # Must be called before check_all_input_data
174     logger.info("Checking that inputdata is available as part of case submission")
175     self.check_all_input_data()
176 
177     if self.get_value('COMP_WAV') == 'ww':
178         # the ww3 buildnml has dependancies on inputdata so we must run it again
179         self.create_namelists(component='WAV')
180 
181 
182     expect(self.get_value("BUILD_COMPLETE"), "Build complete is "
183            "not True please rebuild the model by calling case.build")
184     logger.info("Check case OK")
185 
186 def check_DA_settings(self):
187     script = self.get_value("DATA_ASSIMILATION_SCRIPT")
188     cycles = self.get_value("DATA_ASSIMILATION_CYCLES")
189     if len(script) > 0 and os.path.isfile(script) and cycles > 0:
190         logger.info("Data Assimilation enabled using script {} with {:d} cycles".format(script,
191                                                                                         cycles))
192
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/scripts/lib/CIME/case/case_submit.py b/scripts/lib/CIME/case/case_submit.py
--- a/scripts/lib/CIME/case/case_submit.py
+++ b/scripts/lib/CIME/case/case_submit.py
@@ -8,11 +8,11 @@
 """
 from six.moves                      import configparser
 from CIME.XML.standard_module_setup import *
-from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CASE_SUCCESS, does_file_have_string, CIMEError
+from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CIMEError
 from CIME.locked_files              import unlock_file, lock_file
 from CIME.test_status               import *
 
-import socket, glob
+import socket
 
 logger = logging.getLogger(__name__)
 
@@ -32,13 +32,18 @@
     # Check if CONTINUE_RUN value makes sense
     if job != "case.test" and case.get_value("CONTINUE_RUN"):
         rundir = case.get_value("RUNDIR")
-        caseroot = case.get_value("CASEROOT")
         expect(os.path.isdir(rundir),
                "CONTINUE_RUN is true but RUNDIR {} does not exist".format(rundir))
-        expect(len(glob.glob(os.path.join(rundir, "*.nc"))) > 0,
-               "CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)")
-        expect(does_file_have_string(os.path.join(caseroot, "CaseStatus"), "case.run {}".format(CASE_SUCCESS)),
-               "CONTINUE_RUN is true but this case does not appear to have ever run successfully")
+        expect(os.path.exists(os.path.join(rundir,"rpointer.drv")),
+               "CONTINUE_RUN is true but this case does not appear to have restart files staged in {}".format(rundir))
+        # Finally we open the rpointer.drv file and check that it's correct
+        casename = case.get_value("CASE")
+        with open(os.path.join(rundir,"rpointer.drv"), "r") as fd:
+            ncfile = fd.readline().strip()
+            expect(ncfile.startswith(casename) and
+                   os.path.exists(os.path.join(rundir,ncfile)),
+                   "File {ncfile} not present or does not match case {casename}".
+                   format(ncfile=os.path.join(rundir,ncfile),casename=casename))
 
     # if case.submit is called with the no_batch flag then we assume that this
     # flag will stay in effect for the duration of the RESUBMITs

{"golden_diff": "diff --git a/scripts/lib/CIME/case/case_submit.py b/scripts/lib/CIME/case/case_submit.py\n--- a/scripts/lib/CIME/case/case_submit.py\n+++ b/scripts/lib/CIME/case/case_submit.py\n@@ -8,11 +8,11 @@\n \"\"\"\n from six.moves                      import configparser\n from CIME.XML.standard_module_setup import *\n-from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CASE_SUCCESS, does_file_have_string, CIMEError\n+from CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CIMEError\n from CIME.locked_files              import unlock_file, lock_file\n from CIME.test_status               import *\n \n-import socket, glob\n+import socket\n \n logger = logging.getLogger(__name__)\n \n@@ -32,13 +32,18 @@\n     # Check if CONTINUE_RUN value makes sense\n     if job != \"case.test\" and case.get_value(\"CONTINUE_RUN\"):\n         rundir = case.get_value(\"RUNDIR\")\n-        caseroot = case.get_value(\"CASEROOT\")\n         expect(os.path.isdir(rundir),\n                \"CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n-        expect(len(glob.glob(os.path.join(rundir, \"*.nc\"))) > 0,\n-               \"CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)\")\n-        expect(does_file_have_string(os.path.join(caseroot, \"CaseStatus\"), \"case.run {}\".format(CASE_SUCCESS)),\n-               \"CONTINUE_RUN is true but this case does not appear to have ever run successfully\")\n+        expect(os.path.exists(os.path.join(rundir,\"rpointer.drv\")),\n+               \"CONTINUE_RUN is true but this case does not appear to have restart files staged in {}\".format(rundir))\n+        # Finally we open the rpointer.drv file and check that it's correct\n+        casename = case.get_value(\"CASE\")\n+        with open(os.path.join(rundir,\"rpointer.drv\"), \"r\") as fd:\n+            ncfile = fd.readline().strip()\n+            expect(ncfile.startswith(casename) and\n+                   os.path.exists(os.path.join(rundir,ncfile)),\n+                   \"File {ncfile} not present or does not match case {casename}\".\n+                   format(ncfile=os.path.join(rundir,ncfile),casename=casename))\n \n     # if case.submit is called with the no_batch flag then we assume that this\n     # flag will stay in effect for the duration of the RESUBMITs\n", "issue": "case_submit.py has an inaccurate test for continuing a run\nThe test for making sure continue_run makes sense in case_submit.py is not really valid. There's a line that uses successful completion of a previous run as the test instead of checking for valid pointer files. That section of the script looks like:\r\n\r\n    # Check if CONTINUE_RUN value makes sense\r\n    if job != \"case.test\" and case.get_value(\"CONTINUE_RUN\"):\r\n        rundir = case.get_value(\"RUNDIR\")\r\n        caseroot = case.get_value(\"CASEROOT\")\r\n        expect(os.path.isdir(rundir),\r\n               \"CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\r\n        expect(len(glob.glob(os.path.join(rundir, \"*.nc\"))) > 0,\r\n               \"CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)\")\r\n        expect(does_file_have_string(os.path.join(caseroot, \"CaseStatus\"), \"case.run {}\".format(CASE_SUCCESS)),\r\n               \"CONTINUE_RUN is true but this case does not appear to have ever run successfully\")\r\nThe last line either should be modified to really check for the requirements of a continued run or removed.\r\n\r\nNote that we often start production runs to go many years and drop sets of restart files along the way. If they ever time out, this test fails and makes it difficult to restart, even thought there are valid sets of restart files.\n", "before_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\ncase.submit - Submit a cesm workflow to the queueing system or run it\nif there is no queueing system.  A cesm workflow may include multiple\njobs.\nsubmit, check_case and check_da_settings are members of class Case in file case.py\n\"\"\"\nfrom six.moves                      import configparser\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CASE_SUCCESS, does_file_have_string, CIMEError\nfrom CIME.locked_files              import unlock_file, lock_file\nfrom CIME.test_status               import *\n\nimport socket, glob\n\nlogger = logging.getLogger(__name__)\n\ndef _build_prereq_str(case, prev_job_ids):\n    delimiter = case.get_value(\"depend_separator\")\n    prereq_str = \"\"\n    for job_id in prev_job_ids.values():\n        prereq_str += str(job_id) + delimiter\n    return prereq_str[:-1]\n\ndef _submit(case, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,\n            resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,\n            batch_args=None):\n    if job is None:\n        job = case.get_primary_job()\n\n    # Check if CONTINUE_RUN value makes sense\n    if job != \"case.test\" and case.get_value(\"CONTINUE_RUN\"):\n        rundir = case.get_value(\"RUNDIR\")\n        caseroot = case.get_value(\"CASEROOT\")\n        expect(os.path.isdir(rundir),\n               \"CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n        expect(len(glob.glob(os.path.join(rundir, \"*.nc\"))) > 0,\n               \"CONTINUE_RUN is true but this case does not appear to have been run before (no .nc files in RUNDIR)\")\n        expect(does_file_have_string(os.path.join(caseroot, \"CaseStatus\"), \"case.run {}\".format(CASE_SUCCESS)),\n               \"CONTINUE_RUN is true but this case does not appear to have ever run successfully\")\n\n    # if case.submit is called with the no_batch flag then we assume that this\n    # flag will stay in effect for the duration of the RESUBMITs\n    env_batch = case.get_env(\"batch\")\n    if resubmit:\n        if env_batch.get_batch_system_type() == \"none\":\n            no_batch = True\n\n        # This is a resubmission, do not reinitialize test values\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", False)\n\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '{}', resubmit={:d}\".format(job, resub))\n        case.set_value(\"RESUBMIT\", resub-1)\n        if case.get_value(\"RESUBMIT_SETS_CONTINUE_RUN\"):\n            case.set_value(\"CONTINUE_RUN\", True)\n\n    else:\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", True)\n\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n\n        env_batch_has_changed = False\n        try:\n            case.check_lockedfile(os.path.basename(env_batch.filename))\n        except CIMEError:\n            env_batch_has_changed = True\n\n        if env_batch.get_batch_system_type() != \"none\" and env_batch_has_changed:\n            # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)\n            logger.warning(\\\n\"\"\"\nenv_batch.xml appears to have changed, regenerating batch scripts\nmanual edits to these file will be lost!\n\"\"\")\n            env_batch.make_all_batch_files(case)\n\n        unlock_file(os.path.basename(env_batch.filename))\n        lock_file(os.path.basename(env_batch.filename))\n\n        if job == case.get_primary_job():\n            case.check_case()\n            case.check_DA_settings()\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\", \"w\") as fd:\n                    fd.write( socket.gethostname())\n\n    #Load Modules\n    case.load_env()\n\n    case.flush()\n\n    logger.warning(\"submit_jobs {}\".format(job))\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, prereq=prereq,\n                               skip_pnl=skip_pnl, resubmit_immediate=resubmit_immediate,\n                               allow_fail=allow_fail, mail_user=mail_user,\n                               mail_type=mail_type, batch_args=batch_args)\n\n    xml_jobids = []\n    for jobname, jobid in job_ids.items():\n        logger.info(\"Submitted job {} with id {}\".format(jobname, jobid))\n        if jobid:\n            xml_jobids.append(\"{}:{}\".format(jobname, jobid))\n\n    xml_jobid_text = \", \".join(xml_jobids)\n    if xml_jobid_text:\n        case.set_value(\"JOB_IDS\", xml_jobid_text)\n\n    return xml_jobid_text\n\ndef submit(self, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,\n           resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,\n           batch_args=None):\n    if resubmit_immediate and self.get_value(\"MACH\") in ['mira', 'cetus']:\n        logger.warning(\"resubmit_immediate does not work on Mira/Cetus, submitting normally\")\n        resubmit_immediate = False\n\n    caseroot = self.get_value(\"CASEROOT\")\n    if self.get_value(\"TEST\"):\n        casebaseid = self.get_value(\"CASEBASEID\")\n        # This should take care of the race condition where the submitted job\n        # begins immediately and tries to set RUN phase. We proactively assume\n        # a passed SUBMIT phase. If this state is already PASS, don't set it again\n        # because then we'll lose RUN phase info if it's there. This info is important\n        # for system_tests_common to know if it needs to reinitialize the test or not.\n        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n            phase_status = ts.get_status(SUBMIT_PHASE)\n            if phase_status != TEST_PASS_STATUS:\n                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\n\n    # If this is a resubmit check the hidden file .submit_options for\n    # any submit options used on the original submit and use them again\n    submit_options = os.path.join(caseroot, \".submit_options\")\n    if resubmit and os.path.exists(submit_options):\n        config = configparser.SafeConfigParser()\n        config.read(submit_options)\n        if not skip_pnl and config.has_option('SubmitOptions','skip_pnl'):\n            skip_pnl = config.getboolean('SubmitOptions', 'skip_pnl')\n        if mail_user is None and config.has_option('SubmitOptions', 'mail_user'):\n            mail_user = config.get('SubmitOptions', 'mail_user')\n        if mail_type is None and config.has_option('SubmitOptions', 'mail_type'):\n            mail_type = str(config.get('SubmitOptions', 'mail_type')).split(',')\n        if batch_args is None and config.has_option('SubmitOptions', 'batch_args'):\n            batch_args = config.get('SubmitOptions', 'batch_args')\n\n    try:\n        functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,\n                                  allow_fail=allow_fail, resubmit=resubmit,\n                                  resubmit_immediate=resubmit_immediate, skip_pnl=skip_pnl,\n                                  mail_user=mail_user, mail_type=mail_type,\n                                  batch_args=batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=caseroot,\n                                custom_success_msg_functor=verbatim_success_msg)\n    except BaseException: # Want to catch KeyboardInterrupt too\n        # If something failed in the batch system, make sure to mark\n        # the test as failed if we are running a test.\n        if self.get_value(\"TEST\"):\n            with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n                ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)\n\n        raise\n\ndef check_case(self):\n    self.check_lockedfiles()\n    self.create_namelists() # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    self.check_all_input_data()\n\n    if self.get_value('COMP_WAV') == 'ww':\n        # the ww3 buildnml has dependancies on inputdata so we must run it again\n        self.create_namelists(component='WAV')\n\n\n    expect(self.get_value(\"BUILD_COMPLETE\"), \"Build complete is \"\n           \"not True please rebuild the model by calling case.build\")\n    logger.info(\"Check case OK\")\n\ndef check_DA_settings(self):\n    script = self.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n    cycles = self.get_value(\"DATA_ASSIMILATION_CYCLES\")\n    if len(script) > 0 and os.path.isfile(script) and cycles > 0:\n        logger.info(\"Data Assimilation enabled using script {} with {:d} cycles\".format(script,\n                                                                                        cycles))\n", "path": "scripts/lib/CIME/case/case_submit.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n\"\"\"\ncase.submit - Submit a cesm workflow to the queueing system or run it\nif there is no queueing system.  A cesm workflow may include multiple\njobs.\nsubmit, check_case and check_da_settings are members of class Case in file case.py\n\"\"\"\nfrom six.moves                      import configparser\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status, verbatim_success_msg, CIMEError\nfrom CIME.locked_files              import unlock_file, lock_file\nfrom CIME.test_status               import *\n\nimport socket\n\nlogger = logging.getLogger(__name__)\n\ndef _build_prereq_str(case, prev_job_ids):\n    delimiter = case.get_value(\"depend_separator\")\n    prereq_str = \"\"\n    for job_id in prev_job_ids.values():\n        prereq_str += str(job_id) + delimiter\n    return prereq_str[:-1]\n\ndef _submit(case, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,\n            resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,\n            batch_args=None):\n    if job is None:\n        job = case.get_primary_job()\n\n    # Check if CONTINUE_RUN value makes sense\n    if job != \"case.test\" and case.get_value(\"CONTINUE_RUN\"):\n        rundir = case.get_value(\"RUNDIR\")\n        expect(os.path.isdir(rundir),\n               \"CONTINUE_RUN is true but RUNDIR {} does not exist\".format(rundir))\n        expect(os.path.exists(os.path.join(rundir,\"rpointer.drv\")),\n               \"CONTINUE_RUN is true but this case does not appear to have restart files staged in {}\".format(rundir))\n        # Finally we open the rpointer.drv file and check that it's correct\n        casename = case.get_value(\"CASE\")\n        with open(os.path.join(rundir,\"rpointer.drv\"), \"r\") as fd:\n            ncfile = fd.readline().strip()\n            expect(ncfile.startswith(casename) and\n                   os.path.exists(os.path.join(rundir,ncfile)),\n                   \"File {ncfile} not present or does not match case {casename}\".\n                   format(ncfile=os.path.join(rundir,ncfile),casename=casename))\n\n    # if case.submit is called with the no_batch flag then we assume that this\n    # flag will stay in effect for the duration of the RESUBMITs\n    env_batch = case.get_env(\"batch\")\n    if resubmit:\n        if env_batch.get_batch_system_type() == \"none\":\n            no_batch = True\n\n        # This is a resubmission, do not reinitialize test values\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", False)\n\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '{}', resubmit={:d}\".format(job, resub))\n        case.set_value(\"RESUBMIT\", resub-1)\n        if case.get_value(\"RESUBMIT_SETS_CONTINUE_RUN\"):\n            case.set_value(\"CONTINUE_RUN\", True)\n\n    else:\n        if job == \"case.test\":\n            case.set_value(\"IS_FIRST_RUN\", True)\n\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n\n        env_batch_has_changed = False\n        try:\n            case.check_lockedfile(os.path.basename(env_batch.filename))\n        except CIMEError:\n            env_batch_has_changed = True\n\n        if env_batch.get_batch_system_type() != \"none\" and env_batch_has_changed:\n            # May need to regen batch files if user made batch setting changes (e.g. walltime, queue, etc)\n            logger.warning(\\\n\"\"\"\nenv_batch.xml appears to have changed, regenerating batch scripts\nmanual edits to these file will be lost!\n\"\"\")\n            env_batch.make_all_batch_files(case)\n\n        unlock_file(os.path.basename(env_batch.filename))\n        lock_file(os.path.basename(env_batch.filename))\n\n        if job == case.get_primary_job():\n            case.check_case()\n            case.check_DA_settings()\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\", \"w\") as fd:\n                    fd.write( socket.gethostname())\n\n    #Load Modules\n    case.load_env()\n\n    case.flush()\n\n    logger.warning(\"submit_jobs {}\".format(job))\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, prereq=prereq,\n                               skip_pnl=skip_pnl, resubmit_immediate=resubmit_immediate,\n                               allow_fail=allow_fail, mail_user=mail_user,\n                               mail_type=mail_type, batch_args=batch_args)\n\n    xml_jobids = []\n    for jobname, jobid in job_ids.items():\n        logger.info(\"Submitted job {} with id {}\".format(jobname, jobid))\n        if jobid:\n            xml_jobids.append(\"{}:{}\".format(jobname, jobid))\n\n    xml_jobid_text = \", \".join(xml_jobids)\n    if xml_jobid_text:\n        case.set_value(\"JOB_IDS\", xml_jobid_text)\n\n    return xml_jobid_text\n\ndef submit(self, job=None, no_batch=False, prereq=None, allow_fail=False, resubmit=False,\n           resubmit_immediate=False, skip_pnl=False, mail_user=None, mail_type=None,\n           batch_args=None):\n    if resubmit_immediate and self.get_value(\"MACH\") in ['mira', 'cetus']:\n        logger.warning(\"resubmit_immediate does not work on Mira/Cetus, submitting normally\")\n        resubmit_immediate = False\n\n    caseroot = self.get_value(\"CASEROOT\")\n    if self.get_value(\"TEST\"):\n        casebaseid = self.get_value(\"CASEBASEID\")\n        # This should take care of the race condition where the submitted job\n        # begins immediately and tries to set RUN phase. We proactively assume\n        # a passed SUBMIT phase. If this state is already PASS, don't set it again\n        # because then we'll lose RUN phase info if it's there. This info is important\n        # for system_tests_common to know if it needs to reinitialize the test or not.\n        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n            phase_status = ts.get_status(SUBMIT_PHASE)\n            if phase_status != TEST_PASS_STATUS:\n                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\n\n    # If this is a resubmit check the hidden file .submit_options for\n    # any submit options used on the original submit and use them again\n    submit_options = os.path.join(caseroot, \".submit_options\")\n    if resubmit and os.path.exists(submit_options):\n        config = configparser.SafeConfigParser()\n        config.read(submit_options)\n        if not skip_pnl and config.has_option('SubmitOptions','skip_pnl'):\n            skip_pnl = config.getboolean('SubmitOptions', 'skip_pnl')\n        if mail_user is None and config.has_option('SubmitOptions', 'mail_user'):\n            mail_user = config.get('SubmitOptions', 'mail_user')\n        if mail_type is None and config.has_option('SubmitOptions', 'mail_type'):\n            mail_type = str(config.get('SubmitOptions', 'mail_type')).split(',')\n        if batch_args is None and config.has_option('SubmitOptions', 'batch_args'):\n            batch_args = config.get('SubmitOptions', 'batch_args')\n\n    try:\n        functor = lambda: _submit(self, job=job, no_batch=no_batch, prereq=prereq,\n                                  allow_fail=allow_fail, resubmit=resubmit,\n                                  resubmit_immediate=resubmit_immediate, skip_pnl=skip_pnl,\n                                  mail_user=mail_user, mail_type=mail_type,\n                                  batch_args=batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=caseroot,\n                                custom_success_msg_functor=verbatim_success_msg)\n    except BaseException: # Want to catch KeyboardInterrupt too\n        # If something failed in the batch system, make sure to mark\n        # the test as failed if we are running a test.\n        if self.get_value(\"TEST\"):\n            with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n                ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)\n\n        raise\n\ndef check_case(self):\n    self.check_lockedfiles()\n    self.create_namelists() # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    self.check_all_input_data()\n\n    if self.get_value('COMP_WAV') == 'ww':\n        # the ww3 buildnml has dependancies on inputdata so we must run it again\n        self.create_namelists(component='WAV')\n\n\n    expect(self.get_value(\"BUILD_COMPLETE\"), \"Build complete is \"\n           \"not True please rebuild the model by calling case.build\")\n    logger.info(\"Check case OK\")\n\ndef check_DA_settings(self):\n    script = self.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n    cycles = self.get_value(\"DATA_ASSIMILATION_CYCLES\")\n    if len(script) > 0 and os.path.isfile(script) and cycles > 0:\n        logger.info(\"Data Assimilation enabled using script {} with {:d} cycles\".format(script,\n                                                                                        cycles))\n", "path": "scripts/lib/CIME/case/case_submit.py"}]}