Whamcloud - gitweb
LU-13006 jobid: enhance tests to check per-session jobids. 56/39656/4
authorMr NeilBrown <neilb@suse.de>
Mon, 10 Aug 2020 22:45:44 +0000 (08:45 +1000)
committerOleg Drokin <green@whamcloud.com>
Fri, 2 Oct 2020 00:19:14 +0000 (00:19 +0000)
Lustre allows per-session jobids by writing to "jobid_this_session".

The upstream-linux client does *not* support jobids using the process
environment.

Update the sanity tests to recognize this.

1/ Allow setting jobid_var=USER to fail - if it fails, don't
   test use of envionment variables
2/ Check if "jobid_this_session tests - if it does, check
   that it is used for generating jobids.
3/ Some tests use jobid_var to test general assignment
   to config values.  Change those to use jobid_name if
   it is available.

Also if jobid_var is set to 'session' and jobid_name contains %j -
use jobid_name as is done when jobid_var is a variable name.

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ia7d01b8ffb9c6c910d2ce8f0615c802485604bf9
Reviewed-on: https://review.whamcloud.com/39656
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/jobid.c
lustre/tests/sanity.sh

index 939fec1..2ba4141 100644 (file)
@@ -697,26 +697,19 @@ int lustre_get_jobid(char *jobid, size_t joblen)
                rc = jobid_interpret_string(obd_jobid_name, jobid, joblen);
        } else if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) {
                rc = jobid_interpret_string("%e.%u", jobid, joblen);
-       } else if (strcmp(obd_jobid_var, JOBSTATS_SESSION) == 0) {
-               char *jid;
-
-               rcu_read_lock();
-               jid = jobid_current();
-               if (jid)
-                       strlcpy(jobid, jid, sizeof(jobid));
-               rcu_read_unlock();
-       } else if (jobid_name_is_valid(current->comm)) {
+       } else if (strcmp(obd_jobid_var, JOBSTATS_SESSION) == 0 ||
+                  jobid_name_is_valid(current->comm)) {
                /*
-                * obd_jobid_var holds the jobid environment variable name.
-                * Skip initial check if obd_jobid_name already uses "%j",
-                * otherwise try just "%j" first, then fall back to whatever
-                * is in obd_jobid_name if obd_jobid_var is not found.
+                * per-process jobid wanted, either from environment or from
+                * per-session setting.
+                * If obd_jobid_name contains "%j" or if getting the pre-process
+                * jobid directly fails, fall back to using obd_jobid_name.
                 */
                rc = -EAGAIN;
                if (!strnstr(obd_jobid_name, "%j", joblen))
                        rc = jobid_get_from_cache(jobid, joblen);
 
-               /* fall back to jobid_node if jobid_var not in environment */
+               /* fall back to jobid_node if jobid_var not available */
                if (rc < 0) {
                        int rc2 = jobid_interpret_string(obd_jobid_name,
                                                         jobid, joblen);
index e215505..52699a6 100755 (executable)
@@ -16566,11 +16566,25 @@ test_205a() { # Job stats
                        error "Unexpected jobids when jobid_var=$JOBENV"
        fi
 
-       lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"
-       JOBENV="JOBCOMPLEX"
-       JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
+       # test '%j' access to environment variable - if supported
+       if lctl set_param jobid_var=USER jobid_name="S.%j.%e.%u.%h.E"; then
+               JOBENV="JOBCOMPLEX"
+               JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
 
-       verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
+               verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
+       fi
+
+       # test '%j' access to per-session jobid - if supported
+       if lctl list_param jobid_this_session > /dev/null 2>&1
+       then
+               lctl set_param jobid_var=session jobid_name="S.%j.%e.%u.%h.E"
+               lctl set_param jobid_this_session=$USER
+
+               JOBENV="JOBCOMPLEX"
+               JOBCOMPLEX="S.$USER.touch.$(id -u).$(hostname).E"
+
+               verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
+       fi
 }
 run_test 205a "Verify job stats"
 
@@ -16578,7 +16592,9 @@ run_test 205a "Verify job stats"
 test_205b() {
        job_stats="mdt.*.job_stats"
        $LCTL set_param $job_stats=clear
-       $LCTL set_param jobid_var=USER jobid_name="%e.%u"
+       # Setting jobid_var to USER might not be supported
+       $LCTL set_param jobid_var=USER || true
+       $LCTL set_param jobid_name="%e.%u"
        env -i USERTESTJOBSTATS=foolish touch $DIR/$tfile.1
        do_facet $SINGLEMDS $LCTL get_param $job_stats |
                grep "job_id:.*foolish" &&
@@ -22220,70 +22236,92 @@ test_401a() { #LU-7437
 run_test 401a "Verify if 'lctl list_param -R' can list parameters recursively"
 
 test_401b() {
-       local save=$($LCTL get_param -n jobid_var)
-       local tmp=testing
+       # jobid_var may not allow arbitrary values, so use jobid_name
+       # if available
+       if $LCTL list_param jobid_name > /dev/null 2>&1; then
+               local testname=jobid_name tmp='testing%p'
+       else
+               local testname=jobid_var tmp=testing
+       fi
 
-       $LCTL set_param foo=bar jobid_var=$tmp bar=baz &&
+       local save=$($LCTL get_param -n $testname)
+
+       $LCTL set_param foo=bar $testname=$tmp bar=baz &&
                error "no error returned when setting bad parameters"
 
-       local jobid_new=$($LCTL get_param -n foe jobid_var baz)
+       local jobid_new=$($LCTL get_param -n foe $testname baz)
        [[ "$jobid_new" == "$tmp" ]] || error "jobid tmp $jobid_new != $tmp"
 
-       $LCTL set_param -n fog=bam jobid_var=$save bat=fog
-       local jobid_old=$($LCTL get_param -n foe jobid_var bag)
+       $LCTL set_param -n fog=bam $testname=$save bat=fog
+       local jobid_old=$($LCTL get_param -n foe $testname bag)
        [[ "$jobid_old" == "$save" ]] || error "jobid new $jobid_old != $save"
 }
 run_test 401b "Verify 'lctl {get,set}_param' continue after error"
 
 test_401c() {
-       local jobid_var_old=$($LCTL get_param -n jobid_var)
+       # jobid_var may not allow arbitrary values, so use jobid_name
+       # if available
+       if $LCTL list_param jobid_name > /dev/null 2>&1; then
+               local testname=jobid_name
+       else
+               local testname=jobid_var
+       fi
+
+       local jobid_var_old=$($LCTL get_param -n $testname)
        local jobid_var_new
 
-       $LCTL set_param jobid_var= &&
+       $LCTL set_param $testname= &&
                error "no error returned for 'set_param a='"
 
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
-               error "jobid_var was changed by setting without value"
+               error "$testname was changed by setting without value"
 
-       $LCTL set_param jobid_var &&
+       $LCTL set_param $testname &&
                error "no error returned for 'set_param a'"
 
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_old" == "$jobid_var_new" ]] ||
-               error "jobid_var was changed by setting without value"
+               error "$testname was changed by setting without value"
 }
 run_test 401c "Verify 'lctl set_param' without value fails in either format."
 
 test_401d() {
-       local jobid_var_old=$($LCTL get_param -n jobid_var)
+       # jobid_var may not allow arbitrary values, so use jobid_name
+       # if available
+       if $LCTL list_param jobid_name > /dev/null 2>&1; then
+               local testname=jobid_name new_value='foo=bar%p'
+       else
+               local testname=jobid_var new_valuie=foo=bar
+       fi
+
+       local jobid_var_old=$($LCTL get_param -n $testname)
        local jobid_var_new
-       local new_value="foo=bar"
 
-       $LCTL set_param jobid_var=$new_value ||
+       $LCTL set_param $testname=$new_value ||
                error "'set_param a=b' did not accept a value containing '='"
 
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_new" == "$new_value" ]] ||
                error "'set_param a=b' failed on a value containing '='"
 
-       # Reset the jobid_var to test the other format
-       $LCTL set_param jobid_var=$jobid_var_old
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       # Reset the $testname to test the other format
+       $LCTL set_param $testname=$jobid_var_old
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
-               error "failed to reset jobid_var"
+               error "failed to reset $testname"
 
-       $LCTL set_param jobid_var $new_value ||
+       $LCTL set_param $testname $new_value ||
                error "'set_param a b' did not accept a value containing '='"
 
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_new" == "$new_value" ]] ||
                error "'set_param a b' failed on a value containing '='"
 
-       $LCTL set_param jobid_var $jobid_var_old
-       jobid_var_new=$($LCTL get_param -n jobid_var)
+       $LCTL set_param $testname $jobid_var_old
+       jobid_var_new=$($LCTL get_param -n $testname)
        [[ "$jobid_var_new" == "$jobid_var_old" ]] ||
-               error "failed to reset jobid_var"
+               error "failed to reset $testname"
 }
 run_test 401d "Verify 'lctl set_param' accepts values containing '='"