Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with clone to new user #1835

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions scripts/lib/CIME/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,12 +1138,6 @@ def _get_comp_user_mods(self, component):
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")
if os.path.isdir(cime_output_root):
expect(os.access(cime_output_root, os.W_OK), "Directory {} is not writable"
"by this user. Use the --cime-output-root flag to provide a writable "
"scratch directory".format(cime_output_root))
else:
os.makedirs(cime_output_root)

newcaseroot = os.path.abspath(newcase)
expect(not os.path.isdir(newcaseroot),
Expand All @@ -1158,28 +1152,32 @@ def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None, cime
logger.warning(" clone CIMEROOT is {} ".format(clone_cimeroot))
logger.warning(" It is NOT recommended to clone cases from different versions of CIME.")


# *** create case object as deepcopy of clone object ***
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")
newuser = os.environ.get("USER")
if olduser != newuser:
outputroot = self.get_value("CIME_OUTPUT_ROOT")
outputroot = string.replace(outputroot, olduser, newuser)
# try to make the new output directory and raise an exception
# on any error other than directory already exists.
cime_output_root = string.replace(cime_output_root, olduser, newuser)
newcase.set_value("USER", newuser)
newcase.set_value("CIME_OUTPUT_ROOT", cime_output_root)

# try to make the new output directory and raise an exception
# on any error other than directory already exists.
if os.path.isdir(cime_output_root):
expect(os.access(cime_output_root, os.W_OK), "Directory {} is not writable"
"by this user. Use the --cime-output-root flag to provide a writable "
"scratch directory".format(cime_output_root))
else:
try:
os.makedirs(outputroot)
except OSError:
if not os.path.isdir(outputroot):
os.makedirs(cime_output_root)
except:
if not os.path.isdir(cime_output_root):
raise
newcase.set_value("CIME_OUTPUT_ROOT", outputroot)
newcase.set_value("USER", newuser)

# determine if will use clone executable or not
if keepexe:
orig_exeroot = self.get_value("EXEROOT")
Expand Down
10 changes: 7 additions & 3 deletions scripts/tests/scripts_regression_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,17 @@ def test_d_create_clone_new_user(self):
# this is intended as a test of whether create_clone is independent of user
run_cmd_assert_result(self, "./xmlchange USER=this_is_not_a_user",
from_dir=prevtestdir)

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)
# this test should fail

# this test should pass (user name is replaced)
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
(SCRIPT_DIR, prevtestdir, testdir),from_dir=SCRIPT_DIR)

shutil.rmtree(testdir)
# 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)

Expand Down