Ticket 8821 - Export (setenv) environment variables in from cli_filter (C and lua)
Summary: Export (setenv) environment variables in from cli_filter (C and lua)
Status: RESOLVED INFOGIVEN
Alias: None
Product: Slurm
Classification: Unclassified
Component: User Commands (show other tickets)
Version: 19.05.6
Hardware: Linux Linux
: 4 - Minor Issue
Assignee: Marcin Stolarek
QA Contact:
URL:
: 8808 (view as ticket list)
Depends on:
Blocks:
 
Reported: 2020-04-09 01:08 MDT by Chrysovalantis Paschoulas
Modified: 2020-04-15 03:20 MDT (History)
2 users (show)

See Also:
Site: Jülich
Slinky Site: ---
Alineos Sites: ---
Atos/Eviden Sites: ---
Confidential Site: ---
Coreweave sites: ---
Cray Sites: ---
DS9 clusters: ---
Google sites: ---
HPCnow Sites: ---
HPE Sites: ---
IBM Sites: ---
NOAA SIte: ---
NoveTech Sites: ---
Nvidia HWinf-CS Sites: ---
OCF Sites: ---
Recursion Pharma Sites: ---
SFW Sites: ---
SNIC sites: ---
Tzag Elita Sites: ---
Linux Distro: ---
Machine Name:
CLE Version:
Version Fixed:
Target Release: ---
DevPrio: ---
Emory-Cloud Sites: ---


Attachments
search_by_reporter_email (158.78 KB, image/png)
2020-04-09 04:47 MDT, Marcin Stolarek
Details

Note You need to log in before you can comment on or make changes to this ticket.
Description Chrysovalantis Paschoulas 2020-04-09 01:08:46 MDT
Hi!

How can I export env vars to the job from cli_filter (preferably from lua plugin)? In another ticket someone from SchedMD suggested to do this, when we asked for a --hint output env var, but I cannot find an elegant way..

The only workaround I can think of is to:

- create a new option with spank, e.g. --myhint, which should be hidden from the users

- and then in cli_filter/lua do checks if --hint or input env var was given and add --myhint, then spank will export the env var we want..

Is there another way?

-Valantis

[As we discussed, I moved ticket 8808 here]
Comment 1 Chrysovalantis Paschoulas 2020-04-09 01:10:22 MDT
*** Ticket 8808 has been marked as a duplicate of this ticket. ***
Comment 2 Marcin Stolarek 2020-04-09 02:56:54 MDT
Valantis,

>In another ticket someone from SchedMD suggested to do this,
Could you please reference the ticket? I think that we need to fully understand what are you trying to achieve.

cheers,
Marcin
Comment 3 Chrysovalantis Paschoulas 2020-04-09 03:09:18 MDT
(In reply to Marcin Stolarek from comment #2)
> Valantis,
> 
> >In another ticket someone from SchedMD suggested to do this,
> Could you please reference the ticket? I think that we need to fully
> understand what are you trying to achieve.
> 
> cheers,
> Marcin

Hi Marcin!

Sorry but I cannot search my old tickets in your bugzilla... Why is that so? It's not the first time I complained about this :P Can you search my old tickets about option --hint or SLURM_HINT?

For some reasons, no need to explain in full details here why, we need to have an output env var in job's environment for option `--hint` or its input env var SLURM_HINT. We just want to export e.g. SLURM_HINT in job's env.

In the other ticket I have been told that I can do this with cli_filter. But I cannot find an easy way... As I explained the only working solution I can think of is yhe combination of a spank plugin and the lua cli_filter (which we have already).
Comment 4 Marcin Stolarek 2020-04-09 04:03:45 MDT
Valantis,

Do you mean Bug 8554?

The --hint is really tricky in terms of how it works, it's really kind of meta option that just sets other options. You may want to check some explanation in Bug 8147 comment 15. The options set by specific values of --hint can be found in src/common/proc_args.c verify_hint function.

>For some reasons, no need to explain in full details here[...]
However, I cannot recommend manipulating SLURM_* variables because we don't know the case a code snippet you're looking for can look like:


>extern int pre_submit(slurm_opt_t *opt, int offset)                              
>{                                                                                
>        char *name = NULL;                                                       
>        char *value = NULL;                                                      
>        size_t st = 0;                                                           
>                                                                                 
>        st = 0;                                                                  
>        while (slurm_option_get_next_set(opt, &name, &value, &st)) {             
>                if(!xstrncmp(name,"hint",4)) {                                   
>                        setenv("MY_HINT", value, 1);                              
>                }                                                                
>                xfree(name);                                                     
>                xfree(value);                                                    
>        }                                                                        
>        return SLURM_SUCCESS;                                                    
>}      

The easiest way to use it on 19.05 is probably to update the code in cli_fliter/none plugin and run make/make install, add CliFilterPlugins=none to slurm.conf. The result looks like:
# scontrol show config | grep CliFi
CliFilterPlugins        = none
# env | grep MY_HINT
# srun -v  --hint=compute_bound /bin/bash -c "env" |& grep HIN
MY_HINT=compute_bound

Is there anything else I can help you with?

cheers,
Marcin
Comment 5 Chrysovalantis Paschoulas 2020-04-09 04:21:18 MDT
(In reply to Marcin Stolarek from comment #4)
> Valantis,
> 
> Do you mean Bug 8554?
> 
> The --hint is really tricky in terms of how it works, it's really kind of
> meta option that just sets other options. You may want to check some
> explanation in Bug 8147 comment 15. The options set by specific values of
> --hint can be found in src/common/proc_args.c verify_hint function.
> 
> >For some reasons, no need to explain in full details here[...]
> However, I cannot recommend manipulating SLURM_* variables because we don't
> know the case a code snippet you're looking for can look like:
> 
> 
> >extern int pre_submit(slurm_opt_t *opt, int offset)                              
> >{                                                                                
> >        char *name = NULL;                                                       
> >        char *value = NULL;                                                      
> >        size_t st = 0;                                                           
> >                                                                                 
> >        st = 0;                                                                  
> >        while (slurm_option_get_next_set(opt, &name, &value, &st)) {             
> >                if(!xstrncmp(name,"hint",4)) {                                   
> >                        setenv("MY_HINT", value, 1);                              
> >                }                                                                
> >                xfree(name);                                                     
> >                xfree(value);                                                    
> >        }                                                                        
> >        return SLURM_SUCCESS;                                                    
> >}      
> 
> The easiest way to use it on 19.05 is probably to update the code in
> cli_fliter/none plugin and run make/make install, add CliFilterPlugins=none
> to slurm.conf. The result looks like:
> # scontrol show config | grep CliFi
> CliFilterPlugins        = none
> # env | grep MY_HINT
> # srun -v  --hint=compute_bound /bin/bash -c "env" |& grep HIN
> MY_HINT=compute_bound
> 
> Is there anything else I can help you with?
> 
> cheers,
> Marcin

Yes this is the ticket and I couldn't find it. How can I search my old resolved tickets??? This is weird, I don't know what filters to put.

Also, we could name that env var MY_HINT or something else it's not that important.

We currently use the lua cli_filter, but it seems that it is impossible to export env vars with that plugin, right?

The only way is to use the none, or create another one..
Comment 6 Marcin Stolarek 2020-04-09 04:47:04 MDT
Created attachment 13685 [details]
search_by_reporter_email

Valantis,

>Yes this is the ticket and I couldn't find it. How can I search my old resolved tickets??? This is weird, I don't know what filters to put.

You can find the form I used to find your cases in attached screenshot it wasn't that many so I did ctrl+f --hint after that.

>We currently use the lua cli_filter, but it seems that it is impossible to export env vars with that plugin, right?
Did you migrate to 20.02(the ticket is for 19.05 where we didn't have cli_filter/lua) or do you have your own cli_filter/lua?

cheers,
Marcin
Comment 7 Chrysovalantis Paschoulas 2020-04-09 05:16:15 MDT
(In reply to Marcin Stolarek from comment #6)
> Created attachment 13685 [details]
> search_by_reporter_email
> 
> Valantis,
> 
> >Yes this is the ticket and I couldn't find it. How can I search my old resolved tickets??? This is weird, I don't know what filters to put.
> 
> You can find the form I used to find your cases in attached screenshot it
> wasn't that many so I did ctrl+f --hint after that.
> 
> >We currently use the lua cli_filter, but it seems that it is impossible to export env vars with that plugin, right?
> Did you migrate to 20.02(the ticket is for 19.05 where we didn't have
> cli_filter/lua) or do you have your own cli_filter/lua?
> 
> cheers,
> Marcin

We had just backported/patched the lua cli_filter plugin on our 19.05 from the actual PR of its original creator (the patch was provided to us). If with current cli_filter/lua on 20.02 is possible to export env vars then I can check if it's easy to backport it.
Comment 8 Chrysovalantis Paschoulas 2020-04-09 05:51:54 MDT
OK I just checked, it is the same plugin more or less, so I guess it is not possible to export env vars from cli_filter/lua..

I think I will modify the cli_filter/none as it was suggested and use both plugins ;)

A devel question: in pre_submit() of cli_filter how can I check if SLURM_HINT input env var is defined and get it's contents?

Thank you!
Comment 9 Marcin Stolarek 2020-04-09 06:08:10 MDT
Well.. if you have the same code, it should work. I thought that Lua is not an option because of Slurm version. You can use cli_filter.lua like:
>local M = reqlocal M = require 'posix'
>function slurm_cli_setup_defaults(options, cli_type)
>        return slurm.SUCCESS
>end
>function slurm_cli_post_submit(options, cli_type)
>        return slurm.SUCCESS
>end
>function slurm_cli_pre_submit(options, cli_type)
>        if options['hint'] ~= nil then
>                M.setenv("MY_HINT",options["hint"]);
>        end
>        return slurm.SUCCESS
>end

results:
# scontrol show config | grep CliFi
CliFilterPlugins        = none
# srun --hint=compute_bound "env" | grep -i hint
MY_HINT=compute_bound
# srun  "env" | grep -i hint

You just have to use a library providing posix bindings, since setenv is not ANSI C.

cheers,
Marcin
Comment 10 Marcin Stolarek 2020-04-09 06:09:14 MDT
PS. I just found that first line of script got broken during copy&paste it should be:
>local M = require 'posix'
Comment 11 Marcin Stolarek 2020-04-09 06:16:52 MDT
>A devel question: in pre_submit() of cli_filter how can I check if SLURM_HINT input env var is defined and get it's contents?

You can use os.getenv, just check if you really have to, for instance:

>local os = require 'os'
>function slurm_cli_pre_submit(options, cli_type)
>        local asd = os.getenv("SLURM_HINT")
>        slurm.log_info("%s",asd);
>        if options['hint'] ~= nil then
>                M.setenv("MY_HINT",options["hint"]);
>        end
>        return slurm.SUCCESS
>end


# env | grep HINT
SLURM_HINT=compute_bound
# srun env | grep -i hint
srun: lua: compute_bound
SLURM_HINT=compute_bound
MY_HINT=compute_bound

cheers,
Marcin
Comment 12 Chrysovalantis Paschoulas 2020-04-09 06:18:05 MDT
(In reply to Marcin Stolarek from comment #10)
> PS. I just found that first line of script got broken during copy&paste it
> should be:
> >local M = require 'posix'

OK I see... That was my original problem and this is why I created the ticket ;) I can solve it easily with lua I just need a setenv lua library with posix bindings... (e..g in centos 7 I will install lua-posix, right?)

Thanks for the fix, I was about to ask you about that line :P

Thank you very much Marcin!

Let's keep this ticket open until I finish with the plugin..
Comment 13 Marcin Stolarek 2020-04-09 06:44:38 MDT
>(e..g in centos 7 I will install lua-posix, right?)
lua-posix from epel should work for you on CentOS7

cheers,
Marcin
Comment 14 Chrysovalantis Paschoulas 2020-04-15 02:43:45 MDT
OK it was tested and works as expected! Thank you Marcin :)

Now you can close this ticket.