Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5392d36
Change "set -x" to "set -x" to reduce clutter in output.
gsketefian Nov 19, 2021
10b6e3a
Change printing of input arguments to a function or script only if th…
gsketefian Nov 19, 2021
666cdea
Change printing out of informational message only if the new experime…
gsketefian Nov 19, 2021
24b49bf
Add new experiment variable DEBUG to config_defaults.sh and use it in…
gsketefian Nov 19, 2021
b275988
Changes to allow use of "template" variables in config_defaults.sh an…
gsketefian Nov 19, 2021
fc59ea0
Modifications to when messages are printed to screen (VERBOSE, DEBUG).
gsketefian Nov 19, 2021
aa23ce3
Merge branch 'develop' into feature/debug_mode
gsketefian Nov 19, 2021
45c6ffb
Change "set -x" to "set +x" in j-jobs to make output less compact.
gsketefian Nov 19, 2021
b003c52
Merge branch 'feature/debug_mode' into feature/template_vars
gsketefian Nov 19, 2021
a966685
Fix typo.
gsketefian Nov 29, 2021
754e2da
Merge branch 'develop' into feature/template_vars
gsketefian Dec 6, 2021
d0eb0db
Merge branch 'develop' into feature/template_vars
gsketefian Dec 6, 2021
7424e13
Merge branch 'develop' into feature/template_vars
gsketefian Dec 7, 2021
52a1c9e
Set the variables BUILD_ENV_FN and WFLOW_ENV_FN in setup.sh (instead …
gsketefian Dec 9, 2021
4beda25
Rewrite the way the variable definitions file (var_defns.sh) is creat…
gsketefian Dec 9, 2021
6845ce3
Merge remote-tracking branch 'refs/remotes/origin/feature/template_va…
gsketefian Dec 9, 2021
880bebe
Minor edits.
gsketefian Dec 10, 2021
2ff052d
Minor edits.
gsketefian Dec 10, 2021
a525cb5
In constants.sh, add the variable VAR_REF_CHAR that contains the char…
gsketefian Dec 10, 2021
0c2e5c4
Minor changes.
gsketefian Dec 11, 2021
5365a1e
Introduce new utility function get_bash_file_contents(). Details:
gsketefian Dec 12, 2021
11fbbd4
Bug fix.
gsketefian Dec 13, 2021
06a3d2a
Fix typo in message.
gsketefian Dec 13, 2021
dc69b5f
Typo fixes to comments and output messages.
gsketefian Dec 13, 2021
0a6db56
Modify the WE2E test deactivate_tasks so that it can also be used to …
gsketefian Dec 13, 2021
40588ef
Add forgotten file.
gsketefian Dec 13, 2021
6d1ad63
Merge branch 'develop' into feature/template_vars
gsketefian Dec 13, 2021
f37de7e
For clarity, change variable name from VAR_REF_CHAR to VARVALUE_REF_C…
gsketefian Dec 13, 2021
03d0767
Fix up comments.
gsketefian Dec 16, 2021
bc2a78f
Enclose the template RUN_CMD_FCST in single quotes instead of double …
gsketefian Dec 16, 2021
3d5c2c3
Use VARVALUE_REF_CHAR when searching for template variables; clean up…
gsketefian Dec 16, 2021
dd5f764
Clean up comments regarding use of templates in the WE2E configuratio…
gsketefian Dec 16, 2021
efdd5e1
Indent comments and remove obvious comments.
gsketefian Dec 16, 2021
e885589
Indent comments; remove obvious comments.
gsketefian Dec 16, 2021
3f65bd2
Merge branch 'develop' into feature/template_vars
gsketefian Dec 17, 2021
fd288dd
Bug fix -- include variables in setup.sh left out from previous manua…
gsketefian Dec 17, 2021
d1bd7b5
Fixes to comments and output messages (avoid hyphenation).
gsketefian Dec 17, 2021
7f11b80
Change local variable name to lowercase and rename for clarity.
gsketefian Dec 29, 2021
f37bfb6
Remove variable VARVALUE_REF_CHAR.
gsketefian Dec 29, 2021
a41a5a3
Fix comments; remove duplicate recording of NCORES_PER_NODE.
gsketefian Jan 6, 2022
ebe408e
Modifications to simplify code under the assumption that all template…
gsketefian Jan 10, 2022
6cd1786
Bug fix.
gsketefian Jan 12, 2022
d6847dc
Simplify syntax of if-statement test for detecting a dollar sign (to …
gsketefian Jan 12, 2022
7481e6d
Merge branch 'develop' into feature/template_vars
gsketefian Jan 13, 2022
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
4 changes: 2 additions & 2 deletions tests/WE2E/get_WE2Etest_names_subdirs_descs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ This is probably because it is a directory. Please correct and rerun."
test_names=("${prim_test_names[@]}")
test_subdirs=("${prim_test_subdirs[@]}")
if [ "${num_alt_tests}" -gt "0" ]; then
test_names+=("${alt_test_subdirs[@]:-}")
test_names+=("${alt_test_names[@]:-}")
test_subdirs+=("${alt_test_subdirs[@]:-}")
fi
#
Expand Down Expand Up @@ -1025,7 +1025,7 @@ Please correct and rerun."
# listed first.
#
# Finally, we extract from test_ids_and_inds_sorted the second number
# in each element (the one afte the first number, which is the test ID,
# in each element (the one after the first number, which is the test ID,
# and the test type, which we no longer need), which is the original
# array index before sorting, and save the results in the array sort_inds.
# This array will contain the original indices in sorted order that we
Expand Down
4 changes: 2 additions & 2 deletions tests/WE2E/run_WE2E_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ accordingly and rerun."
if [ "${match_found}" = "FALSE" ]; then
avail_WE2E_test_names_str=$( printf " \"%s\"\n" "${avail_WE2E_test_names[@]}" )
print_err_msg_exit "\
The name current user-specified test to run (user_spec_test) does not
match any of the names (either primary or alternate) of the available
The name of the current user-specified test to run (user_spec_test) does
not match any of the names (either primary or alternate) of the available
WE2E tests:
user_spec_test = \"${user_spec_test}\"
Valid values for user_spec_test consist of the names (primary or alternate)
Expand Down
101 changes: 95 additions & 6 deletions tests/WE2E/test_configs/wflow_features/config.deactivate_tasks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@
# TEST PURPOSE/DESCRIPTION:
# ------------------------
#
# This test ensures that the various workflow tasks can be deactivated,
# i.e. removed from the Rocoto XML. Note that we leave the MAKE_GRID_TN,
# MAKE_OROG_TN, and MAKE_SFC_CLIMO_TN activated because there is a
# separate test for turning those off.
# This test has two purposes:
#
# 1) It checks that the various workflow tasks can be deactivated, i.e.
# removed from the Rocoto XML.
# 2) It checks the capability of the workflow to use "template" experiment
# variables, i.e. variables whose definitions include references to
# other variables, e.g.
#
# MY_VAR='\${ANOTHER_VAR}'
#
# Note that we do not deactivate all tasks in the workflow; we leave the
# MAKE_GRID_TN, MAKE_OROG_TN, and MAKE_SFC_CLIMO_TN activated because:
#
# 1) There is already a WE2E test that runs with these three tasks
# deactivated (that test is to ensure that pre-generated grid,
# orography, and surface climatology files can be used).
# 2) In checking the template variable capability, we want to make sure
# that the variable defintions file (GLOBAL_VAR_DEFNS_FN) generated
# does not have syntax or other errors in it by sourcing it in these
# three tasks.
#

RUN_ENVIR="community"
Expand All @@ -14,13 +30,86 @@ PREEXISTING_DIR_METHOD="rename"
PREDEF_GRID_NAME="RRFS_CONUS_25km"
CCPP_PHYS_SUITE="FV3_GFS_v15p2"

DATE_FIRST_CYCL="20190615"
DATE_LAST_CYCL="20190615"
EXTRN_MDL_NAME_ICS="FV3GFS"
EXTRN_MDL_NAME_LBCS="FV3GFS"
USE_USER_STAGED_EXTRN_FILES="TRUE"

DATE_FIRST_CYCL="20190701"
DATE_LAST_CYCL="20190701"
CYCL_HRS=( "00" )

FCST_LEN_HRS="6"
LBC_SPEC_INTVL_HRS="3"

RUN_TASK_GET_EXTRN_ICS="FALSE"
RUN_TASK_GET_EXTRN_LBCS="FALSE"
RUN_TASK_MAKE_ICS="FALSE"
RUN_TASK_MAKE_LBCS="FALSE"
RUN_TASK_RUN_FCST="FALSE"
RUN_TASK_RUN_POST="FALSE"
#
# The following shows examples of how to define template variables. Here,
# we define RUN_CMD_UTILS, RUN_CMD_FCST, and RUN_CMD_POST as template
# variables. Note that these variables aren't actually needed to run
# any commands but are simply included for demonstration purposes.
#
# If we want the contents in RUN_CMD_UTILS, RUN_CMD_FCST, and RUN_CMD_POST
# to be expanded and/or executed when the variable definitions file
# (GLOBAL_VAR_DEFNS_FN) is sourced in a script or function, then we must
# escape bash's variable reference character "$" using backslashes, as
# follows:
#
# RUN_CMD_UTILS="echo \$yyyymmdd"
# RUN_CMD_FCST="mpirun -np \${PE_MEMBER01}"
# RUN_CMD_POST="\$( echo hello \$yyymmdd )"
#
# With this method, when the variable defintions file is sourced, the
# variable references on the right-hand sides (here $yyyymmdd and
# ${PE_MEMBER01}) as well as the command substitution [i.e. $( echo ...)]
# will first be evaluated/expanded and the results then combined with
# the remainder of each string on the right-hand side (if any) to obtain
# literal strings to assign to RUN_CMD_UTILS, RUN_CMD_FCST, and RUN_CMD_POST.
# Thus, the values that these three variables are assigned in the variable
# definitions file will not contain any variable references; they will
# contain only literal strings.
#
# In general, this is not what we want because the variables on the right-
# hand sides may not yet be defined at the time the variable definitions
# file is sourced. Thus, what we usually want is for variable references
# and command substitutions appearing on the right-hand sides in that
# file to be escaped. To do this, we must escape the "$" character twice,
# as follows:
#
# RUN_CMD_UTILS="echo \\\$yyyymmdd"
# RUN_CMD_FCST="mpirun -np \\\${PE_MEMBER01}"
# RUN_CMD_POST="\\\$( echo hello \\\$yyyymmdd )"
#
# A more compact way to do this is to use single quotes on the outside
# and eliminate the escaped-\ within, i.e.
#
# RUN_CMD_UTILS='echo \$yyyymmdd'
# RUN_CMD_FCST='mpirun -np \${PE_MEMBER01}'
# RUN_CMD_POST='\$( echo hello \$yyyymmdd )'
#
# This will cause $yyyymmdd, ${PE_MEMBER01}, and $(...) to be expanded
# only at the time RUN_CMD_UTILS, RUN_CMD_FCST, and RUN_CMD_POST are
# referenced in a file or script (using the syntax ${RUN_CMD_UTILS}, ...)
# and not earlier when the variable definitions file is sourced. That
# is what we do in this WE2E test.
#
# With the last set of settings above, in a given script or function we
# can source the variable defintions file and then use the three variables
# as follows:
#
# . $exptdir/var_defns.sh
# yyyymmdd="goodbye"
# eval ${RUN_CMD_UTILS}
# eval ${RUN_CMD_FCST}
# eval myvar=${RUN_CMD_POST}
#
# (The mpirun command in RUN_CMD_FCST will generate an error, but that is
# ok since using mpirun is not the primary concern here.)
#
RUN_CMD_UTILS='echo \$yyyymmdd'
RUN_CMD_FCST='mpirun -np \${PE_MEMBER01}'
RUN_CMD_POST='\$( echo hello \$yyyymmdd )'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me how this test will pass/fail. It certainly wouldn't run for a WE2E test where commands are actually submitted. Is it a smoke test to make sure a var_defns.sh file comes out? Are the contents of that file checked for the right answer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a test to make sure the templated variables are placed towards the end of var_defns.sh. I actually wrote some other code to make sure that the commands in these variables can be evaluated and executed properly (in as much as it makes sense to evaluate them), and they do. I did not have a good case of how these would be used in an actual application, so I left it at that. If you have a use case we can include as a WE2E test, that would be great.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this test run?

27 changes: 19 additions & 8 deletions ush/bash_utils/check_var_valid_value.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,35 @@ The value specified in ${var_name} is not supported:
#
#-----------------------------------------------------------------------
#
# Check whether var_value is equal to one of the elements of the array
# valid_var_values. If not, print out an error message and exit the
# If var_value contains the character specified by VARVALUE_REF_CHAR, we
# assume the corresponding variable (var_name) is a template variable,
# i.e. one whose value contains a reference to another variable, e.g.
#
# MY_VAR='\${ANOTHER_VAR}'
#
# [In bash, VARVALUE_REF_CHAR is a (escaped) dollar sign.] In this case,
# it does not make sense to check whether var_value is a valid value since
# its contents have not yet been expanded. If var_value doesn't contain
# VARVALUE_REF_CHAR, it must contain a literal string. In this case, we
# check whether it is equal to one of the elements of the array
# valid_var_values. If not, we print out an error message and exit the
# calling script.
#
#-----------------------------------------------------------------------
#
is_element_of "valid_var_values" "${var_value}" || { \
valid_var_values_str=$(printf "\"%s\" " "${valid_var_values[@]}");
print_err_msg_exit "\
if [[ "${var_value}" != *"${VARVALUE_REF_CHAR}"* ]]; then
is_element_of "valid_var_values" "${var_value}" || { \
valid_var_values_str=$(printf "\"%s\" " "${valid_var_values[@]}");
print_err_msg_exit "\
${err_msg}
${var_name} must be set to one of the following:
${valid_var_values_str}"; \
}
}
fi
#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/func-
# tion.
# Restore the shell options saved at the beginning of this script/function.
#
#-----------------------------------------------------------------------
#
Expand Down
119 changes: 119 additions & 0 deletions ush/bash_utils/get_bash_file_contents.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using appropriate indentation level for all comments in the code. It's impossible to follow what the code is doing and the level of indentation when all comments start from the first column.

This request applies to all the new functions.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done. Also did check_expt_config_vars.sh. Feedback welcome!

#-----------------------------------------------------------------------
#
# This file defines a function that returns the contents of a bash script/
# function with all empty lines, comment lines, and leading and trailing
# whitespace removed. Arguments are as follows:
#
# fp:
# The relative or full path to the file containing the bash script or
# function.
#
# output_varname_contents:
# Name of the output variable that will contain the (processed) contents
# of the file. This is the output of the function.
#
#-----------------------------------------------------------------------
#
function get_bash_file_contents() {
#
#-----------------------------------------------------------------------
#
# Save current shell options (in a global array). Then set new options
# for this script/function.
#
#-----------------------------------------------------------------------
#
{ save_shell_opts; set -u +x; } > /dev/null 2>&1
#
#-----------------------------------------------------------------------
#
# Specify the set of valid argument names for this script/function. Then
# process the arguments provided to this script/function (which should
# consist of a set of name-value pairs of the form arg1="value1", etc).
#
#-----------------------------------------------------------------------
#
local valid_args=( \
"fp" \
"output_varname_contents" \
)
process_args valid_args "$@"
#
#-----------------------------------------------------------------------
#
# For debugging purposes, print out values of arguments passed to this
# script. Note that these will be printed out only if VERBOSE is set to
# TRUE.
#
#-----------------------------------------------------------------------
#
print_input_args "valid_args"
#
#-----------------------------------------------------------------------
#
# Verify that the required arguments to this function have been specified.
# If not, print out an error message and exit.
#
#-----------------------------------------------------------------------
#
if [ -z "$fp" ]; then
print_err_msg_exit "\
The argument \"fp\" specifying the relative or full path to the file to
read was not specified in the call to this function:
fp = \"$fp\""
fi
#
#-----------------------------------------------------------------------
#
# Declare local variables.
#
#-----------------------------------------------------------------------
#
local contents \
crnt_line
#
#-----------------------------------------------------------------------
#
# Read in all lines in the file. In doing so:
#
# 1) Concatenate any line ending with the bash line continuation character
# (a backslash) with the following line.
# 2) Remove any leading and trailing whitespace.
#
# Note that these two actions are automatically performed by the "read"
# utility in the while-loop below.
#
#-----------------------------------------------------------------------
#
contents=""
while read crnt_line; do
contents="${contents}${crnt_line}
"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems like it needs a line continuation, maybe?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually correct; I tested it. It is just adding a newline after appending ${crnt_line} to contents. Adding a line continuation will cause the newline to be skipped, and all newlines will be missing from contents (making it one super long line, which isn't what we want). An alternate and maybe clearer way to append a new line to contents is

printf -v "contents" "${contents}${crnt_line}\n"

This is a bit slower since it calls printf for every line that's read in. Either way is ok with me.

done < "$fp"
#
# Strip out any comment and empty lines from contents.
#
contents=$( printf "${contents}" | \
$SED -r -e "/^#.*/d" `# Remove comment lines.` \
-e "/^$/d" `# Remove empty lines.` \
)
#
#-----------------------------------------------------------------------
#
# Set output variables.
#
#-----------------------------------------------------------------------
#
printf -v ${output_varname_contents} "${contents}"
#
#-----------------------------------------------------------------------
#
# Restore the shell options saved at the beginning of this script/function.
#
#-----------------------------------------------------------------------
#
{ restore_shell_opts; } > /dev/null 2>&1

}

2 changes: 1 addition & 1 deletion ush/bash_utils/print_input_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ have been set as follows:
#-----------------------------------------------------------------------
#
# If a global variable named DEBUG is not defined, print out the message.
# If it is defined, print out the message only if DEBUG is set to TRUE.
# If it is defined, print out the message only if DEBUG is set to "TRUE".
#
#-----------------------------------------------------------------------
#
Expand Down
Loading