Repository: ESMCI/cime

Issue:
PR #1450 breaks use of any machine queue 
Prior to #1450 a user could specifiy a machine queue that was not explicitly listed in config_batch.xml on the create_newcase command line.   After #1450 this results in 
ERROR: Queue 'verylong' is unknown to this system


Discussion:
As a workaround you can still
./xmlchange JOB_QUEUE=verylong
after you have created the case. 


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
@@ -199,6 +199,7 @@ def set_job_defaults(self, batch_jobs, pesize=None, walltime=None, force_queue=N
             if force_queue:
                 if not self.queue_meets_spec(force_queue, task_count, walltime=walltime, job=job):
                     logger.warning("WARNING: User-requested queue '%s' does not meet requirements for job '%s'" % (force_queue, job))
+                queue = force_queue
             else:
                 queue = self.select_best_queue(task_count, walltime=walltime, job=job)
                 if queue is None and walltime is not None:
@@ -221,8 +222,16 @@ def set_job_defaults(self, batch_jobs, pesize=None, walltime=None, force_queue=N
                     queue = default_queue_node.text
                     walltime = self.get_queue_specs(queue)[3]
 
-            walltime = self.get_queue_specs(queue)[3] if walltime is None else walltime
-            walltime = self._default_walltime if walltime is None else walltime # last-chance fallback
+            if walltime is None:
+                # Figure out walltime
+                specs = self.get_queue_specs(queue)
+                if specs is None:
+                    # Queue is unknown, use specs from default queue
+                    walltime = self.get_default_queue().get("walltimemax")
+                else:
+                    walltime = specs[3]
+
+                walltime = self._default_walltime if walltime is None else walltime # last-chance fallback
 
             self.set_value("JOB_QUEUE", queue, subgroup=job)
             self.set_value("JOB_WALLCLOCK_TIME", walltime, subgroup=job)
@@ -435,7 +444,12 @@ def get_job_id(self, output):
         return jobid
 
     def queue_meets_spec(self, queue, num_pes, walltime=None, job=None):
-        jobmin, jobmax, jobname, walltimemax, strict = self.get_queue_specs(queue)
+        specs = self.get_queue_specs(queue)
+        if specs is None:
+            logger.warning("WARNING: queue '%s' is unknown to this system" % queue)
+            return True
+
+        jobmin, jobmax, jobname, walltimemax, strict = specs
 
         # A job name match automatically meets spec
         if job is not None and jobname is not None:
@@ -484,7 +498,7 @@ def get_queue_specs(self, queue):
 
                 return jobmin, jobmax, jobname, walltimemax, strict
 
-        expect(False, "Queue '%s' is unknown to this system" % queue)
+        return None
 
     def get_default_queue(self):
         node = self.get_optional_node("queue", attributes={"default" : "true"})


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
@@ -1486,6 +1486,27 @@ def test_cime_case_test_walltime_mgmt_4(self):
         result = run_cmd_assert_result(self, "./xmlquery JOB_QUEUE --subgroup=case.test --value", from_dir=casedir)
         self.assertEqual(result, "shared")
 
+    ###########################################################################
+    def test_cime_case_test_walltime_mgmt_5(self):
+    ###########################################################################
+        if CIME.utils.get_model() != "acme":
+            self.skipTest("Skipping walltime test. Depends on ACME batch settings")
+
+        test_name = "ERS_P1.f19_g16_rx1.A"
+        machine, compiler = "blues", "gnu"
+        run_cmd_assert_result(self, "unset CIME_GLOBAL_WALLTIME && %s/create_test --no-setup --machine %s %s -t %s --test-root %s --output-root %s --queue slartibartfast" %
+                              (SCRIPT_DIR, machine, test_name, self._baseline_name, self._testroot, self._testroot))
+
+        casedir = os.path.join(self._testroot,
+                               "%s.%s" % (CIME.utils.get_full_test_name(test_name, machine=machine, compiler=compiler), self._baseline_name))
+        self.assertTrue(os.path.isdir(casedir), msg="Missing casedir '%s'" % casedir)
+
+        result = run_cmd_assert_result(self, "./xmlquery JOB_WALLCLOCK_TIME --subgroup=case.test --value", from_dir=casedir)
+        self.assertEqual(result, "03:00:00")
+
+        result = run_cmd_assert_result(self, "./xmlquery JOB_QUEUE --subgroup=case.test --value", from_dir=casedir)
+        self.assertEqual(result, "slartibartfast")
+
 ###############################################################################
 class X_TestSingleSubmit(TestCreateTestCommon):
 ###############################################################################