Repository: ESMCI/cime

Issue:
Can change batch submission options before submit but not before build
@jgfouca 's changes in #2320 allow users to change batch submission options (such as JOB_WALLCLOCK_TIME) after building but before submitting. However, I noticed an asymmetry: If you try to change these options between case.setup and case.build, you get an error:

```
File /glade/scratch/sacks/cesm_tests/x_0430a/LockedFiles/env_batch.xml has been modified
  found difference in JOB_WALLCLOCK_TIME : case '5:00:00' locked '4:00:00'
  found difference in USER_REQUESTED_WALLTIME : case '5:00' locked '4:00'
ERROR: Batch configuration has changed, please run case.setup --reset
```

This isn't a big deal, but I do find the asymmetry a bit troubling: Normally, if you can safely change a variable at a given stage of the setup-build-submit process, then you can also safely change that variable at any earlier stage. But this is not the case here.

@jedwards4b and @mvertens I'm going to add this to the cesm2 milestone because I think it would be nice to have this resolved by then. But I'd view it as non-essential for cesm2 (lower priority than some other things for the release).


Discussion:
@jedwards4b , is there a reason env_batch.xml is locked for case.build?

Resolving patch:
diff --git a/scripts/lib/CIME/build.py b/scripts/lib/CIME/build.py
--- a/scripts/lib/CIME/build.py
+++ b/scripts/lib/CIME/build.py
@@ -385,7 +385,7 @@ def _case_build_impl(caseroot, case, sharedlib_only, model_only, buildlist):
 
     comp_classes = case.get_values("COMP_CLASSES")
 
-    case.check_lockedfiles()
+    case.check_lockedfiles(skip="env_batch")
 
     # Retrieve relevant case data
     # This environment variable gets set for cesm Make and
diff --git a/scripts/lib/CIME/case/check_lockedfiles.py b/scripts/lib/CIME/case/check_lockedfiles.py
--- a/scripts/lib/CIME/case/check_lockedfiles.py
+++ b/scripts/lib/CIME/case/check_lockedfiles.py
@@ -13,7 +13,7 @@
 from CIME.locked_files import unlock_file, LOCKED_DIR
 logger = logging.getLogger(__name__)
 
-import glob
+import glob, six
 
 def check_pelayouts_require_rebuild(self, models):
     """
@@ -98,7 +98,7 @@ def check_lockedfile(self, filebase):
             else:
                 expect(False, "'{}' diff was not handled".format(objname))
 
-def check_lockedfiles(self):
+def check_lockedfiles(self, skip=None):
     """
     Check that all lockedfiles match what's in case
 
@@ -106,10 +106,19 @@ def check_lockedfiles(self):
     """
     caseroot = self.get_value("CASEROOT")
     lockedfiles = glob.glob(os.path.join(caseroot, "LockedFiles", "*.xml"))
+    skip = [] if skip is None else skip
+    skip = [skip] if isinstance(skip, six.string_types) else skip
     for lfile in lockedfiles:
         fpart = os.path.basename(lfile)
         # ignore files used for tests such as env_mach_pes.ERP1.xml by looking for extra dots in the name
         if fpart.count('.') > 1:
             continue
 
-        self.check_lockedfile(fpart)
+        do_skip = False
+        for item in skip:
+            if fpart.startswith(item):
+                do_skip = True
+                break
+
+        if not do_skip:
+            self.check_lockedfile(fpart)


Test patch: