Skip to content

Commit ac542f6

Browse files
kcgthbthiell
authored andcommitted
Introduce CLUSTERSHELL_CFGDIR as an alternate location for global
configuration files. Keep the default `/etc/clustershell` when the environment variable is not defined.
1 parent 796549c commit ac542f6

File tree

8 files changed

+98
-25
lines changed

8 files changed

+98
-25
lines changed

doc/examples/defaults.conf-rsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# Example defaults.conf file for clusters using rsh instead of ssh.
55
#
66
# To enable this file, install it in one of the following locations:
7-
# /etc/clustershell/defaults.conf (system-wide)
7+
# $CLUSTERSHELL_CFGDIR/defaults.conf (global configuration, default to
8+
# /etc/clustershell/defaults.conf)
89
# $XDG_CONFIG_HOME/clustershell/defaults.conf (per-user)
910
# $HOME/.local/etc/clustershell/defaults.conf (per-user)
1011
#

doc/sphinx/config.rst

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ Configuration
88
clush
99
-----
1010

11-
The following configuration file defines system-wide default values for
11+
The following configuration file defines global default values for
1212
several *clush* tool parameters::
1313

14-
/etc/clustershell/clush.conf
14+
$CLUSTERSHELL_CFGDIR/clush.conf
15+
16+
If *$CLUSTERSHELL_CFGDIR* is not defined, */etc/clustershell/clush.conf* will
17+
be used,
1518

16-
*clush* settings might then be overridden per user if one of the following
17-
files is found, in priority order::
19+
*clush* settings might then be overridden (globally, or per user) if one of the
20+
following files is found, in priority order::
1821

1922
$XDG_CONFIG_HOME/clustershell/clush.conf
2023
$HOME/.config/clustershell/clush.conf (only if $XDG_CONFIG_HOME is not defined)
@@ -126,13 +129,16 @@ ClusterShell loads *groups.conf* configuration files that define how to
126129
obtain node groups configuration, ie. the way the library should access
127130
file-based or external node group **sources**.
128131

129-
The following configuration file defines system-wide default values for
132+
The following configuration file defines global default values for
130133
*groups.conf*::
131134

132-
/etc/clustershell/groups.conf
135+
$CLUSTERSHELL_CFGDIR/groups.conf
136+
137+
If *$CLUSTERSHELL_CFGDIR* is not defined, */etc/clustershell/groups.conf* will
138+
be used,
133139

134-
*groups.conf* settings might then be overridden per user if one of the
135-
following files is found, in priority order::
140+
*groups.conf* settings might then be overridden (globally, or per user) if one
141+
of the following files is found, in priority order::
136142

137143
$XDG_CONFIG_HOME/clustershell/groups.conf
138144
$HOME/.config/clustershell/groups.conf (only if $XDG_CONFIG_HOME is not defined)
@@ -545,10 +551,13 @@ in *defaults.conf*.
545551

546552
The following configuration file defines ClusterShell system-wide defaults::
547553

548-
/etc/clustershell/defaults.conf
554+
$CLUSTERSHELL_CFGDIR/defaults.conf
549555

550-
*defaults.conf* settings might then be overridden per user if one of the
551-
following files is found, in priority order::
556+
If *$CLUSTERSHELL_CFGDIR* is not defined, */etc/clustershell/defaults.conf*
557+
will be used,
558+
559+
*defaults.conf* settings might then be overridden (globally, or per user) if
560+
one of the following files is found, in priority order::
552561

553562
$XDG_CONFIG_HOME/clustershell/defaults.conf
554563
$HOME/.config/clustershell/defaults.conf (only if $XDG_CONFIG_HOME is not defined)

doc/sphinx/release.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,11 @@ versions.
564564
Configuration files
565565
"""""""""""""""""""
566566

567-
When ``$XDG_CONFIG_HOME`` is defined, ClusterShell will use it to search for
568-
additional configuration files.
567+
When ``$CLUSTERSHELL_CFGDIR`` or ``$XDG_CONFIG_HOME`` are defined,
568+
ClusterShell will use them to search for additional configuration files.
569+
570+
If ``$CLUSTERSHELL_CFGDIR`` is not defined, the global configuration files will
571+
be searched for in `/etc/clustershell`
569572

570573
PIP user installation support
571574
"""""""""""""""""""""""""""""

doc/txt/clush.conf.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ following order:
2323
1. command-line options
2424
2. user configuration file (*$XDG_CONFIG_HOME/clustershell/clush.conf*)
2525
3. local pip user installation (*$HOME/.local/etc/clustershell/clush.conf*)
26-
4. system-wide configuration file (*/etc/clustershell/clush.conf*)
26+
4. global configuration file (*$CLUSTERSHELL_CFGDIR/clush.conf*, defaults to
27+
*/etc/clustershell/clush.conf*)
2728

2829
For each parameter, the first obtained value will be used.
2930

@@ -124,8 +125,9 @@ Simple configuration file.
124125
FILES
125126
=====
126127

127-
*/etc/clustershell/clush.conf*
128-
System-wide clush configuration file.
128+
*$CLUSTERSHELL_CFGDIR/clush.conf*
129+
Global clush configuration file. If $CLUSTERSHELL_CFGDIR is not defined,
130+
*/etc/slutershell/clush.conf* is used instead.
129131

130132
*$XDG_CONFIG_HOME/clustershell/clush.conf*
131133
User configuration file for clush. If $XDG_CONFIG_HOME is not defined,

doc/txt/clush.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ Copy files
279279
FILES
280280
=====
281281

282-
*/etc/clustershell/clush.conf*
283-
System-wide clush configuration file.
282+
*$CLUSTERSHELL_CFGDIR/clush.conf*
283+
Global clush configuration file. If $CLUSTERSHELL_CFGDIR is not defined,
284+
*/etc/clustershell/clush.conf* is used instead.
284285

285286
*$XDG_CONFIG_HOME/clustershell/clush.conf*
286287
User configuration file for clush. If $XDG_CONFIG_HOME is not defined,

doc/txt/groups.conf.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ following sources in the following order:
2222

2323
1. user configuration file (*$XDG_CONFIG_HOME/clustershell/groups.conf*)
2424
2. local pip user installation (*$HOME/.local/etc/clustershell/groups.conf*)
25-
3. system-wide configuration file (*/etc/clustershell/groups.conf*)
25+
3. Global configuration file (*$CLUSTERSHELL_CFGDIR/groups.conf*, defaults to
26+
*/etc/clustershell/groups.conf*)
2627

2728
If no *groups.conf* is found, group support will be disabled.
2829

@@ -159,13 +160,14 @@ Simple configuration file for local groups and slurm partitions binding.
159160
FILES
160161
=====
161162

162-
*/etc/clustershell/groups.conf*
163-
System-wide node groups configuration file.
163+
*$CLUSTERSHELL_CFGDIR/groups.conf* (defaults to */etc/clustershell/groups.conf*)
164+
Global node groups configuration file.
164165

165-
*/etc/clustershell/groups.conf.d/*
166+
*$CLUSTERSHELL_CFGDIR/groups.conf.d/* (defaults to
167+
*/etc/clustershell/groups.conf.d/*)
166168
Recommended directory for additional configuration files.
167169

168-
*/etc/clustershell/groups.d/*
170+
*$CLUSTERSHELL_CFGDIR/groups.d/* (defaults to */etc/clustershell/groups.d/*)
169171
Recommended directory for *autodir*, where native group definition files
170172
(.yaml files) are found.
171173

lib/ClusterShell/Defaults.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def _distant_workerclass(defaults):
9191

9292
def config_paths(config_name):
9393
"""Return default path list for a ClusterShell config file name."""
94-
return ['/etc/clustershell/%s' % config_name, # system-wide config file
94+
return [os.path.join(os.environ.get('CLUSTERSHELL_CFGDIR',
95+
'/etc/clustershell/%s'),
96+
config_name), # global config file
9597
# default pip --user config file
9698
os.path.expanduser('~/.local/etc/clustershell/%s' % config_name),
9799
# per-user config (top override)

tests/CLIConfigTest.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,59 @@ def testClushConfigWithInstalledConfig(self):
319319
options, _ = parser.parse_args([])
320320
config = ClushConfig(options)
321321

322+
def testClushConfigCustomGlobal(self):
323+
"""test CLI.Config.ClushConfig (CLUSTERSHELL_CFGDIR global custom
324+
config)
325+
"""
326+
327+
# Save existing environment variable, if it's defined
328+
custom_config_save = os.environ.get('CLUSTERSHELL_CFGDIR')
329+
330+
# Create fake CLUSTERSHELL_CFGDIR
331+
custom_cfg_dir = make_temp_dir()
332+
333+
try:
334+
os.environ['CLUSTERSHELL_CFGDIR'] = custom_cfg_dir
335+
336+
cfgfile = open(os.path.join(custom_cfg_dir, 'clush.conf'), 'w')
337+
cfgfile.write(dedent("""
338+
[Main]
339+
fanout: 42
340+
connect_timeout: 14
341+
command_timeout: 0
342+
history_size: 100
343+
color: never
344+
verbosity: 2
345+
ssh_user: joebar
346+
ssh_path: ~/bin/ssh
347+
ssh_options: -oSomeDummyUserOption=yes
348+
"""))
349+
350+
cfgfile.flush()
351+
parser = OptionParser("dummy")
352+
parser.install_clush_config_options()
353+
parser.install_display_options(verbose_options=True)
354+
parser.install_connector_options()
355+
options, _ = parser.parse_args([])
356+
config = ClushConfig(options) # filename=None to use defaults!
357+
self.assertEqual(config.color, THREE_CHOICES[1])
358+
self.assertEqual(config.verbosity, VERB_VERB) # takes biggest
359+
self.assertEqual(config.fanout, 42)
360+
self.assertEqual(config.connect_timeout, 14)
361+
self.assertEqual(config.command_timeout, 0)
362+
self.assertEqual(config.ssh_user, 'joebar')
363+
self.assertEqual(config.ssh_path, '~/bin/ssh')
364+
self.assertEqual(config.ssh_options, '-oSomeDummyUserOption=yes')
365+
cfgfile.close()
366+
367+
finally:
368+
if custom_config_save:
369+
os.environ['CLUSTERSHELL_CFGDIR'] = custom_config_save
370+
else:
371+
del os.environ['CLUSTERSHELL_CFGDIR']
372+
shutil.rmtree(custom_cfg_dir, ignore_errors=True)
373+
374+
322375
def testClushConfigUserOverride(self):
323376
"""test CLI.Config.ClushConfig (XDG_CONFIG_HOME user config)"""
324377

0 commit comments

Comments
 (0)