prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  PR #1230 appears to break batch systems 
  After merging #1230 I get an error from Z_FullSystemTest:
  
  Traceback (most recent call last):
    File "./scripts_regression_tests.py", line 1175, in test_full_system
      self.assertTrue(test_time > 0, msg="test time was zero for %s" % test_status)
  AssertionError: test time was zero for /scratch/cluster/jedwards/scripts_regression_test.20170313_145646/ERR.f45_g37_rx1.A.hobart_intel.fake_testing_only_20170313_151740/TestStatus
  
  
  All of the tests actually passed.  
  
  --- 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_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 """
  8 import socket
  9 from CIME.XML.standard_module_setup import *
  10 from CIME.utils                     import expect, run_and_log_case_status
  11 from CIME.preview_namelists         import create_namelists
  12 from CIME.check_lockedfiles         import check_lockedfiles
  13 from CIME.check_input_data          import check_all_input_data
  14 from CIME.test_status               import *
  15 
  16 logger = logging.getLogger(__name__)
  17 
  18 def _submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):
  19     caseroot = case.get_value("CASEROOT")
  20 
  21     if job is None:
  22         if case.get_value("TEST"):
  23             job = "case.test"
  24         else:
  25             job = "case.run"
  26 
  27     if resubmit:
  28         resub = case.get_value("RESUBMIT")
  29         logger.info("Submitting job '%s', resubmit=%d" % (job, resub))
  30         case.set_value("RESUBMIT",resub-1)
  31         if case.get_value("RESUBMIT_SETS_CONTINUE_RUN"):
  32             case.set_value("CONTINUE_RUN", True)
  33     else:
  34         if job in ("case.test","case.run"):
  35             check_case(case, caseroot)
  36             check_DA_settings(case)
  37             if case.get_value("MACH") == "mira":
  38                 with open(".original_host","w") as fd:
  39                     fd.write( socket.gethostname())
  40 
  41     # if case.submit is called with the no_batch flag then we assume that this
  42     # flag will stay in effect for the duration of the RESUBMITs
  43     env_batch = case.get_env("batch")
  44     if not resubmit:
  45         case.set_value("IS_FIRST_RUN", True)
  46         if no_batch:
  47             batch_system = "none"
  48         else:
  49             batch_system = env_batch.get_batch_system_type()
  50         case.set_value("BATCH_SYSTEM", batch_system)
  51     else:
  52         if env_batch.get_batch_system_type() == "none":
  53             no_batch = True
  54 
  55         # This is a resubmission, do not reinitialize test values
  56         case.set_value("IS_FIRST_RUN", False)
  57 
  58     #Load Modules
  59     case.load_env()
  60 
  61     case.set_value("RUN_WITH_SUBMIT",True)
  62     case.flush()
  63 
  64     logger.warn("submit_jobs %s" % job)
  65     job_ids = case.submit_jobs(no_batch=no_batch, job=job, batch_args=batch_args)
  66     logger.info("Submitted job ids %s" % job_ids)
  67 
  68 def submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):
  69     if case.get_value("TEST"):
  70         caseroot = case.get_value("CASEROOT")
  71         casebaseid = case.get_value("CASEBASEID")
  72         # This should take care of the race condition where the submitted job
  73         # begins immediately and tries to set RUN phase. We proactively assume
  74         # a passed SUBMIT phase.
  75         with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
  76             ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)
  77 
  78     try:
  79         functor = lambda: _submit(case, job, resubmit, no_batch, batch_args)
  80         run_and_log_case_status(functor, "case.submit", caseroot=case.get_value("CASEROOT"))
  81     except:
  82         # If something failed in the batch system, make sure to mark
  83         # the test as failed if we are running a test.
  84         if case.get_value("TEST"):
  85             with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
  86                 ts.set_status(SUBMIT_PHASE, TEST_FAIL_STATUS)
  87 
  88         raise
  89 
  90 def check_case(case, caseroot):
  91     check_lockedfiles(caseroot)
  92     create_namelists(case) # Must be called before check_all_input_data
  93     logger.info("Checking that inputdata is available as part of case submission")
  94     check_all_input_data(case)
  95 
  96     expect(case.get_value("BUILD_COMPLETE"), "Build complete is "
  97            "not True please rebuild the model by calling case.build")
  98     logger.info("Check case OK")
  99 
  100 def check_DA_settings(case):
  101     if case.get_value("DATA_ASSIMILATION"):
  102         script = case.get_value("DATA_ASSIMILATION_SCRIPT")
  103         cycles = case.get_value("DATA_ASSIMILATION_CYCLES")
  104         logger.info("Data Assimilation enabled using script %s with %d cycles"%(script,cycles))
  105 
  106
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/scripts/lib/CIME/case_submit.py b/scripts/lib/CIME/case_submit.py
  --- a/scripts/lib/CIME/case_submit.py
  +++ b/scripts/lib/CIME/case_submit.py
  @@ -71,9 +71,13 @@
           casebaseid = case.get_value("CASEBASEID")
           # This should take care of the race condition where the submitted job
           # begins immediately and tries to set RUN phase. We proactively assume
  -        # a passed SUBMIT phase.
  +        # a passed SUBMIT phase. If this state is already PASS, don't set it again
  +        # because then we'll lose RUN phase info if it's there. This info is important
  +        # for system_tests_common to know if it needs to reinitialize the test or not.
           with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:
  -            ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)
  +            phase_status = ts.get_status(SUBMIT_PHASE)
  +            if phase_status != TEST_PASS_STATUS:
  +                ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)
   
       try:
           functor = lambda: _submit(case, job, resubmit, no_batch, batch_args)
  
verification_info: {"golden_diff": "diff --git a/scripts/lib/CIME/case_submit.py b/scripts/lib/CIME/case_submit.py\n--- a/scripts/lib/CIME/case_submit.py\n+++ b/scripts/lib/CIME/case_submit.py\n@@ -71,9 +71,13 @@\n         casebaseid = case.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.\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-            ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\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     try:\n         functor = lambda: _submit(case, job, resubmit, no_batch, batch_args)\n", "issue": "PR #1230 appears to break batch systems \nAfter merging #1230 I get an error from Z_FullSystemTest:\r\n\r\nTraceback (most recent call last):\r\n  File \"./scripts_regression_tests.py\", line 1175, in test_full_system\r\n    self.assertTrue(test_time > 0, msg=\"test time was zero for %s\" % test_status)\r\nAssertionError: test time was zero for /scratch/cluster/jedwards/scripts_regression_test.20170313_145646/ERR.f45_g37_rx1.A.hobart_intel.fake_testing_only_20170313_151740/TestStatus\r\n\r\n\r\nAll of the tests actually passed.  \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.\n\"\"\"\nimport socket\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status\nfrom CIME.preview_namelists         import create_namelists\nfrom CIME.check_lockedfiles         import check_lockedfiles\nfrom CIME.check_input_data          import check_all_input_data\nfrom CIME.test_status               import *\n\nlogger = logging.getLogger(__name__)\n\ndef _submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):\n    caseroot = case.get_value(\"CASEROOT\")\n\n    if job is None:\n        if case.get_value(\"TEST\"):\n            job = \"case.test\"\n        else:\n            job = \"case.run\"\n\n    if resubmit:\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '%s', resubmit=%d\" % (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    else:\n        if job in (\"case.test\",\"case.run\"):\n            check_case(case, caseroot)\n            check_DA_settings(case)\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\",\"w\") as fd:\n                    fd.write( socket.gethostname())\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 not resubmit:\n        case.set_value(\"IS_FIRST_RUN\", True)\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n    else:\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        case.set_value(\"IS_FIRST_RUN\", False)\n\n    #Load Modules\n    case.load_env()\n\n    case.set_value(\"RUN_WITH_SUBMIT\",True)\n    case.flush()\n\n    logger.warn(\"submit_jobs %s\" % job)\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, batch_args=batch_args)\n    logger.info(\"Submitted job ids %s\" % job_ids)\n\ndef submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):\n    if case.get_value(\"TEST\"):\n        caseroot = case.get_value(\"CASEROOT\")\n        casebaseid = case.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.\n        with TestStatus(test_dir=caseroot, test_name=casebaseid) as ts:\n            ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)\n\n    try:\n        functor = lambda: _submit(case, job, resubmit, no_batch, batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=case.get_value(\"CASEROOT\"))\n    except:\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 case.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(case, caseroot):\n    check_lockedfiles(caseroot)\n    create_namelists(case) # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    check_all_input_data(case)\n\n    expect(case.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(case):\n    if case.get_value(\"DATA_ASSIMILATION\"):\n        script = case.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n        cycles = case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        logger.info(\"Data Assimilation enabled using script %s with %d cycles\"%(script,cycles))\n\n", "path": "scripts/lib/CIME/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.\n\"\"\"\nimport socket\nfrom CIME.XML.standard_module_setup import *\nfrom CIME.utils                     import expect, run_and_log_case_status\nfrom CIME.preview_namelists         import create_namelists\nfrom CIME.check_lockedfiles         import check_lockedfiles\nfrom CIME.check_input_data          import check_all_input_data\nfrom CIME.test_status               import *\n\nlogger = logging.getLogger(__name__)\n\ndef _submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):\n    caseroot = case.get_value(\"CASEROOT\")\n\n    if job is None:\n        if case.get_value(\"TEST\"):\n            job = \"case.test\"\n        else:\n            job = \"case.run\"\n\n    if resubmit:\n        resub = case.get_value(\"RESUBMIT\")\n        logger.info(\"Submitting job '%s', resubmit=%d\" % (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    else:\n        if job in (\"case.test\",\"case.run\"):\n            check_case(case, caseroot)\n            check_DA_settings(case)\n            if case.get_value(\"MACH\") == \"mira\":\n                with open(\".original_host\",\"w\") as fd:\n                    fd.write( socket.gethostname())\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 not resubmit:\n        case.set_value(\"IS_FIRST_RUN\", True)\n        if no_batch:\n            batch_system = \"none\"\n        else:\n            batch_system = env_batch.get_batch_system_type()\n        case.set_value(\"BATCH_SYSTEM\", batch_system)\n    else:\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        case.set_value(\"IS_FIRST_RUN\", False)\n\n    #Load Modules\n    case.load_env()\n\n    case.set_value(\"RUN_WITH_SUBMIT\",True)\n    case.flush()\n\n    logger.warn(\"submit_jobs %s\" % job)\n    job_ids = case.submit_jobs(no_batch=no_batch, job=job, batch_args=batch_args)\n    logger.info(\"Submitted job ids %s\" % job_ids)\n\ndef submit(case, job=None, resubmit=False, no_batch=False, batch_args=None):\n    if case.get_value(\"TEST\"):\n        caseroot = case.get_value(\"CASEROOT\")\n        casebaseid = case.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    try:\n        functor = lambda: _submit(case, job, resubmit, no_batch, batch_args)\n        run_and_log_case_status(functor, \"case.submit\", caseroot=case.get_value(\"CASEROOT\"))\n    except:\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 case.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(case, caseroot):\n    check_lockedfiles(caseroot)\n    create_namelists(case) # Must be called before check_all_input_data\n    logger.info(\"Checking that inputdata is available as part of case submission\")\n    check_all_input_data(case)\n\n    expect(case.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(case):\n    if case.get_value(\"DATA_ASSIMILATION\"):\n        script = case.get_value(\"DATA_ASSIMILATION_SCRIPT\")\n        cycles = case.get_value(\"DATA_ASSIMILATION_CYCLES\")\n        logger.info(\"Data Assimilation enabled using script %s with %d cycles\"%(script,cycles))\n\n", "path": "scripts/lib/CIME/case_submit.py"}]}