Repository: ESMCI/cime

Issue:
Add --cime-output-root option to create_clone and mention it's use if can't write to it
Add the option "--cime-output-root" as an optional argument to create_clone. This will do xmlchange CIME_OUTPUT_ROOT=<input value> for the cloned case. If the create_clone can NOT create the $CIME_OUTPUT_ROOT because of a permission problem have it die with a warning that --cime-output-root needs to be set. This same thing may also need to be in create_newcase, especially if create_newcase is called from create_clone.

We'd also like to have this capability tested. This is an important feature that scientists rely on. We thought that this could be tested, by having CIME_OUTPUT_ROOT point to a directory that can't be written to (say unix root /).

@mvertens @jedwards4b please assign this as appropriate.


Discussion:

Resolving patch:
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
@@ -927,7 +927,12 @@ def apply_user_mods(self, user_mods_dir=None):
             self.set_value("USER_MODS_FULLPATH",user_mods_path)
             apply_user_mods(self._caseroot, user_mods_path)
 
-    def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None):
+    def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None, cime_output_root=None):
+        if cime_output_root is None:
+            cime_output_root = self.get_value("CIME_OUTPUT_ROOT")
+        expect(os.access(cime_output_root, os.W_OK), "Directory %s is not writable"
+               "by this user.  Use the --cime-output-root flag to provide a writable "
+               "scratch directory"%cime_output_root)
 
         newcaseroot = os.path.abspath(newcase)
         expect(not os.path.isdir(newcaseroot),
@@ -947,6 +952,7 @@ def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None):
         srcroot = os.path.join(newcase_cimeroot,"..")
         newcase = self.copy(newcasename, newcaseroot, newsrcroot=srcroot)
         newcase.set_value("CIMEROOT", newcase_cimeroot)
+        newcase.set_value("CIME_OUTPUT_ROOT", cime_output_root)
 
         # if we are cloning to a different user modify the output directory
         olduser = self.get_value("USER")


Test patch:
diff --git a/utils/python/tests/scripts_regression_tests.py b/utils/python/tests/scripts_regression_tests.py
--- a/utils/python/tests/scripts_regression_tests.py
+++ b/utils/python/tests/scripts_regression_tests.py
@@ -242,9 +242,12 @@ def test_d_create_clone_new_user(self):
         fakeoutputroot = string.replace(cls._testroot, os.environ.get("USER"), "this_is_not_a_user")
         run_cmd_assert_result(self, "./xmlchange CIME_OUTPUT_ROOT=%s"%fakeoutputroot,
                               from_dir=prevtestdir)
-
-        run_cmd_assert_result(self, "%s/create_clone --clone %s --case %s" %
-                              (SCRIPT_DIR, prevtestdir, testdir),from_dir=SCRIPT_DIR)
+        # this test should fail
+        run_cmd_assert_result(self, "%s/create_clone --clone %s --case %s " %
+                              (SCRIPT_DIR, prevtestdir, testdir),from_dir=SCRIPT_DIR, expected_stat=1)
+        #this test should pass
+        run_cmd_assert_result(self, "%s/create_clone --clone %s --case %s --cime-output-root %s" %
+                              (SCRIPT_DIR, prevtestdir, testdir, cls._testroot),from_dir=SCRIPT_DIR)
 
         cls._do_teardown.append(testdir)