Repository: ESMCI/cime

Issue:
Set the queue from command line when running create_test
Prior to cime5, you could run

`$ ./create_test [options specifying testlist] -queue $QUEUE`

And it would submit all the tests to `$QUEUE` instead of the default queue. It appears that this particular option did not survive the conversion to python.



Discussion:

Resolving patch:
diff --git a/utils/python/CIME/XML/env_batch.py b/utils/python/CIME/XML/env_batch.py
--- a/utils/python/CIME/XML/env_batch.py
+++ b/utils/python/CIME/XML/env_batch.py
@@ -262,23 +262,28 @@ def make_batch_script(self, input_template, job, case):
             fd.write(output_text)
         os.chmod(job, os.stat(job).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
 
-    def set_job_defaults(self, bjobs, pesize=None, walltime=None):
+    def set_job_defaults(self, bjobs, pesize=None, walltime=None, force_queue=None):
         if self.batchtype is None:
             self.batchtype = self.get_batch_system_type()
+
         if self.batchtype == 'none':
             return
+
         for job, jsect in bjobs:
             task_count = jsect["task_count"]
             if task_count is None or task_count == "default":
                 task_count = pesize
             else:
                 task_count = int(task_count)
-            queue = self.select_best_queue(task_count)
+
+            queue = force_queue if force_queue is not None else self.select_best_queue(task_count)
             self.set_value("JOB_QUEUE", queue, subgroup=job)
+
             walltime = self.get_max_walltime(queue) if walltime is None else walltime
             if walltime is None:
                 logger.warn("Could not find a queue matching task count %d, falling back to depreciated default walltime parameter"%task_count)
                 walltime = self.get_default_walltime()
+
             self.set_value( "JOB_WALLCLOCK_TIME", walltime , subgroup=job)
             logger.info("Job %s queue %s walltime %s"%(job, queue, walltime))
 
diff --git a/utils/python/CIME/case.py b/utils/python/CIME/case.py
--- a/utils/python/CIME/case.py
+++ b/utils/python/CIME/case.py
@@ -443,7 +443,7 @@ def configure(self, compset_name, grid_name, machine_name=None,
                   project=None, pecount=None, compiler=None, mpilib=None,
                   user_compset=False, pesfile=None,
                   user_grid=False, gridfile=None, ninst=1, test=False,
-                  walltime=None):
+                  walltime=None, queue=None):
 
         #--------------------------------------------
         # compset, pesfile, and compset components
@@ -614,7 +614,7 @@ def configure(self, compset_name, grid_name, machine_name=None,
         env_batch = self.get_env("batch")
         env_batch.set_batch_system(batch, batch_system_type=batch_system_type)
         env_batch.create_job_groups(bjobs)
-        env_batch.set_job_defaults(bjobs, pesize=maxval, walltime=walltime)
+        env_batch.set_job_defaults(bjobs, pesize=maxval, walltime=walltime, force_queue=queue)
         self.schedule_rewrite(env_batch)
 
         self.set_value("COMPSET",self._compsetname)


Test patch:
diff --git a/scripts/create_test b/scripts/create_test
--- a/scripts/create_test
+++ b/scripts/create_test
@@ -156,6 +156,9 @@ OR
                         help="Set the wallclock limit for all tests in the suite. "
                         "Can use env var CIME_GLOBAL_WALLTIME to set this for all test.")
 
+    parser.add_argument("-q", "--queue", default=None,
+                        help="Force batch system to use a certain queue")
+
     parser.add_argument("--xml-machine",
                         help="Use this machine key in the lookup in testlist.xml")
     parser.add_argument("--xml-compiler",
@@ -225,7 +228,7 @@ OR
         args.test_root, args.baseline_root, args.clean, args.compare, args.generate, \
         args.baseline_name, args.namelists_only, args.project, args.test_id, args.parallel_jobs, \
         args.xml_machine, args.xml_compiler, args.xml_category, args.xml_testlist, args.walltime, \
-        args.single_submit, args.proc_pool, args.use_existing, args.save_timing
+        args.single_submit, args.proc_pool, args.use_existing, args.save_timing, args.queue
 
 ###############################################################################
 def single_submit_impl(machine_name, test_id, proc_pool, project, args, job_cost_map, wall_time, test_root):
@@ -331,7 +334,7 @@ def create_test(testargs, compiler, machine_name, no_run, no_build, no_setup, no
                 baseline_root, clean, compare, generate,
                 baseline_name, namelists_only, project, test_id, parallel_jobs,
                 xml_machine, xml_compiler, xml_category, xml_testlist, walltime,
-                single_submit, proc_pool, use_existing, save_timing):
+                single_submit, proc_pool, use_existing, save_timing, queue):
 ###############################################################################
     if testargs and machine_name is None and compiler is None:
         for test in testargs:
@@ -352,7 +355,8 @@ def create_test(testargs, compiler, machine_name, no_run, no_build, no_setup, no
                       project=project, parallel_jobs=parallel_jobs,
                       xml_machine=xml_machine, xml_compiler=xml_compiler,
                       xml_category=xml_category, xml_testlist=xml_testlist, walltime=walltime,
-                      proc_pool=proc_pool, use_existing=use_existing, save_timing=save_timing)
+                      proc_pool=proc_pool, use_existing=use_existing, save_timing=save_timing,
+                      queue=queue)
 
     success = impl.run_tests()
 
@@ -391,13 +395,13 @@ def _main_func(description):
     testargs, compiler, machine_name, no_run, no_build, no_setup, no_batch, test_root, baseline_root, clean, \
         compare, generate, baseline_name, namelists_only, project, test_id, parallel_jobs, \
         xml_machine, xml_compiler, xml_category, xml_testlist, walltime, single_submit, proc_pool, \
-        use_existing, save_timing \
+        use_existing, save_timing, queue \
         = parse_command_line(sys.argv, description)
 
     sys.exit(create_test(testargs, compiler, machine_name, no_run, no_build, no_setup, no_batch, test_root,
                          baseline_root, clean, compare, generate, baseline_name, namelists_only,
                          project, test_id, parallel_jobs, xml_machine, xml_compiler, xml_category,
-                         xml_testlist, walltime, single_submit, proc_pool, use_existing, save_timing))
+                         xml_testlist, walltime, single_submit, proc_pool, use_existing, save_timing, queue))
 
 ###############################################################################
 
diff --git a/utils/python/CIME/test_scheduler.py b/utils/python/CIME/test_scheduler.py
--- a/utils/python/CIME/test_scheduler.py
+++ b/utils/python/CIME/test_scheduler.py
@@ -46,12 +46,13 @@ def __init__(self, test_names,
                  project=None, parallel_jobs=None,
                  xml_machine=None, xml_compiler=None, xml_category=None,
                  xml_testlist=None, walltime=None, proc_pool=None,
-                 use_existing=False, save_timing=False):
+                 use_existing=False, save_timing=False, queue=None):
     ###########################################################################
         self._cime_root  = CIME.utils.get_cime_root()
         self._cime_model = CIME.utils.get_model()
 
         self._save_timing = save_timing
+        self._queue       = queue
 
         # needed for perl interface
         os.environ["CIMEROOT"] = self._cime_root
@@ -79,6 +80,8 @@ def __init__(self, test_names,
         # We will not use batch system if user asked for no_batch or if current
         # machine is not a batch machine
         self._no_batch = no_batch or not self._machobj.has_batch_system()
+        expect(not (self._no_batch and self._queue is not None),
+               "Does not make sense to request a queue without batch system")
 
         self._test_root = test_root if test_root is not None \
             else self._machobj.get_value("CESMSCRATCHROOT")
@@ -394,6 +397,9 @@ def _create_newcase_phase(self, test):
                     pesize = case_opt[1:]
                     create_newcase_cmd += " --pecount %s"%pesize
 
+        if self._queue is not None:
+            create_newcase_cmd += " --queue=%s" % self._queue
+
         if self._walltime is not None:
             create_newcase_cmd += " --walltime %s" % self._walltime
         elif test in self._test_xml and "wallclock" in self._test_xml[test]: