Skip to content

Commit 44ed410

Browse files
committed
Made some progress
1 parent b4de531 commit 44ed410

File tree

8 files changed

+62
-27
lines changed

8 files changed

+62
-27
lines changed

lib/pavilion/resolver/proto_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def _permute_sched(self, var_man, used_per_vars) -> List[variables.VariableSetMa
329329

330330
sched_name = self.config['scheduler']
331331
sched = schedulers.get_plugin(sched_name)
332+
test_name = self.config.get('name', '<no name>')
332333

333334
# Resolve the variables that don't depend on sched, but have complicated relationships
334335
# we couldn't solve iteratively. If there's anything left at this point, it will

lib/pavilion/schedulers/config.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,6 @@ def check_leaves(cls, elem):
261261
raise ValueError(elem)
262262

263263

264-
class SchedConfigError(ValueError):
265-
"""Raised when there's a problem with the scheduler configuration."""
266-
267-
268264
def min_int(name, min_val, required=True):
269265
"""Return a callback that ensures the argument >= min_val. If not required,
270266
an empty value will return None."""
@@ -567,7 +563,7 @@ def _validate_config(config: Dict[str, str],
567563

568564
except ValueError as err:
569565
raise SchedConfigError("Config value for key '{}' had a validation "
570-
"error.".format(key), err)
566+
"error.".format(key), prior_error=err)
571567

572568
elif isinstance(validator, (tuple, list)):
573569
if value not in validator:

lib/pavilion/scriptcomposer.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ def module_change(self, module, sys_vars, config_wrappers):
132132
def module_purge(self) -> None:
133133
"""Add a module purge to the script."""
134134

135-
self._script_lines.append("module purge")
135+
self._script_lines.extend([
136+
"if which module; then",
137+
"\tmodule purge",
138+
"fi"
139+
])
136140

137141
def newline(self):
138142
"""Function that just adds a newline to the script lines."""

lib/pavilion/series/series.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def check_cancelled(self) -> bool:
418418
return False
419419

420420
def run(self, build_only: bool = False, rebuild: bool = False,
421-
local_builds_only: bool = False, purge: bool = True):
421+
local_builds_only: bool = False):
422422
"""Build and kickoff all of the test sets in the series.
423423
424424
:param build_only: Only build the tests, do not run them.
@@ -471,7 +471,7 @@ def run(self, build_only: bool = False, rebuild: bool = False,
471471

472472
try:
473473
self._run_set(test_set, build_only=build_only,
474-
rebuild=rebuild, local_builds_only=local_builds_only, purge=purge)
474+
rebuild=rebuild, local_builds_only=local_builds_only)
475475
except TestSetError as err:
476476
self.status.set(SERIES_STATES.ERROR,
477477
"Error running test set {}. See the series log "
@@ -506,16 +506,15 @@ def run(self, build_only: bool = False, rebuild: bool = False,
506506
# Completion will be set when looked for.
507507

508508

509-
def _run_set(self, test_set: TestSet, build_only: bool, rebuild: bool, local_builds_only: bool,
510-
purge: bool):
509+
def _run_set(self, test_set: TestSet, build_only: bool, rebuild: bool, local_builds_only: bool):
511510
"""Run all requested tests in the given test set."""
512511

513512
# Track which builds we've already marked as deprecated, when doing rebuilds.
514513
deprecated_builds = set()
515514
failed_builds = dict()
516515
tests_running = 0
517516

518-
for test_batch in test_set.make_iter(build_only, rebuild, local_builds_only, purge):
517+
for test_batch in test_set.make_iter(build_only, rebuild, local_builds_only):
519518

520519
# Add all the tests we created to this test set.
521520
self._add_tests(test_batch, test_set.iter_name)

lib/pavilion/series/test_set.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __ordered_split(self) -> List['TestSet']:
189189

190190
return test_sets
191191

192-
def make_iter(self, build_only=False, rebuild=False, local_builds_only=False, purge=True) \
192+
def make_iter(self, build_only=False, rebuild=False, local_builds_only=False) \
193193
-> Iterator[List[TestRun]]:
194194
"""Resolve the given tests names and options into actual test run objects, and print
195195
the test creation status. This returns an iterator over batches tests, respecting the
@@ -277,7 +277,7 @@ def make_iter(self, build_only=False, rebuild=False, local_builds_only=False, pu
277277
try:
278278
test_run = TestRun(pav_cfg=self.pav_cfg, config=ptest.config,
279279
var_man=ptest.var_man, rebuild=rebuild,
280-
build_only=build_only, purge=purge)
280+
build_only=build_only)
281281
if not test_run.skipped:
282282
test_run.save()
283283
self.tests.append(test_run)
@@ -339,12 +339,12 @@ def make_iter(self, build_only=False, rebuild=False, local_builds_only=False, pu
339339
self.all_tests_made = True
340340

341341

342-
def make(self, build_only=False, rebuild=False, local_builds_only=False, purge=True):
342+
def make(self, build_only=False, rebuild=False, local_builds_only=False):
343343
"""As per make_iter(), but create all of the tests. This doesn't
344344
respect batch sizes, etc, and is entirely for simplifying unit testing."""
345345

346346
all_tests = []
347-
for test_batch in self.make_iter(build_only, rebuild, local_builds_only, purge):
347+
for test_batch in self.make_iter(build_only, rebuild, local_builds_only):
348348
all_tests.extend(test_batch)
349349

350350
return all_tests

lib/pavilion/test_run/test_run.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ class TestRun(TestAttributes):
101101
"""Directory that holds build templates."""
102102

103103
def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager = None,
104-
_id: int = None, rebuild: bool = False, build_only: bool = False,
105-
purge: bool = True):
104+
_id: int = None, rebuild: bool = False, build_only: bool = False):
106105
"""Create an new TestRun object. If loading an existing test
107106
instance, use the ``TestRun.from_id()`` method.
108107
@@ -111,7 +110,6 @@ def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager
111110
:param bool build_only: Only build this test run, do not run it.
112111
:param bool rebuild: After determining the build name, deprecate it and
113112
select a new, non-deprecated build.
114-
:param bool purge: Whether or not to perform a module purge before running/building
115113
:param int _id: The test id of an existing test. (You should be using
116114
TestRun.load)."""
117115

@@ -152,7 +150,6 @@ def __init__(self, pav_cfg: PavConfig, config: Dict, var_man: VariableSetManager
152150
# Set basic attributes
153151
self.id = id_tmp # pylint: disable=invalid-name
154152
self.build_only = build_only
155-
self.purge = purge
156153
self._complete = False
157154
self.created = time.time()
158155
self.name = self.make_name(config)
@@ -1151,7 +1148,9 @@ def _write_script(self, stype: str, path: Path, config: dict, module_wrappers: d
11511148

11521149
script.command(f'echo "(pav) Setting up {stype} environment."')
11531150

1154-
if self.purge:
1151+
purge = config.get(stype, {}).get("purge_modules")
1152+
1153+
if purge:
11551154
script.newline()
11561155
script.comment("Start with a fresh environment")
11571156
script.module_purge()

lib/pavilion/unittest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def _load_test(self, name: str, platform: str = 'this', host: str = 'this',
313313
del __config_lines
314314

315315
def _quick_test(self, cfg=None, name="quick_test",
316-
build=True, finalize=True, purge=True):
316+
build=True, finalize=True):
317317
"""Create a test run object to work with.
318318
The default is a simple hello world test with the raw scheduler.
319319
@@ -347,7 +347,7 @@ def _quick_test(self, cfg=None, name="quick_test",
347347

348348
cfg = resolve.test_config(cfg, var_man)
349349

350-
test = TestRun(pav_cfg=self.pav_cfg, config=cfg, var_man=var_man, purge=purge)
350+
test = TestRun(pav_cfg=self.pav_cfg, config=cfg, var_man=var_man)
351351
if test.skipped:
352352
# You can't proceed further with a skipped test.
353353
return test

test/tests/mod_wrapper_tests.py

+41-5
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,57 @@ def check_test(ctest, expected_lines):
311311

312312
@unittest.skipIf(not has_module_cmd() and find_module_init() is None,
313313
"Could not find a module system.")
314-
def test_module_purge(self):
315-
"""Test that a module purge is performed when building and running tests."""
314+
def test_run_module_purge(self):
315+
"""Test that a module purge is performed when running tests."""
316316

317+
# Test that a module purge is performed by default
317318
test_cfg = self._quick_test_cfg()
318319
test_cfg['run']['cmds'] = [
319320
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
320321
]
321322
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')
322323

323-
test = self._quick_test(test_cfg, purge=False)
324+
test = self._quick_test(test_cfg)
324325
run_result = test.run()
325326

326-
self.assertEqual(run_result, 1)
327+
self.assertEqual(run_result, 0)
327328

329+
# Check that we can disable purging
330+
test_cfg = self._quick_test_cfg()
331+
test_cfg['run']['cmds'] = [
332+
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
333+
]
334+
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')
335+
test_config["run"]["purge_modules"] = False
328336
test = self._quick_test(test_cfg)
329337
run_result = test.run()
330338

331-
self.assertEqual(run_result, 0)
339+
self.assertEqual(run_result, 1)
340+
341+
def test_build_module_purge(self):
342+
"""Test that a module purge is performed when building tests."""
343+
344+
# Test that a module purge is performed by default
345+
test_cfg = self._quick_test_cfg()
346+
test_cfg['build']['cmds'] = [
347+
"# This comment exists so the test hashes to a distinct value"
348+
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
349+
]
350+
test_cfg['run']['preamble'].append('module load test_mod1 || exit 2')
351+
352+
test = self._quick_test(test_cfg)
353+
build_result = test.build()
354+
355+
self.assertEqual(build_result, 0)
356+
357+
# Check that we can disable purging
358+
test_cfg = self._quick_test_cfg()
359+
test_cfg['build']['cmds'] = [
360+
'[[ $(module -t list 2>&1) = "No modules loaded" ]] || exit 1',
361+
]
362+
test_cfg['build']['preamble'].append('module load test_mod1 || exit 2')
363+
test_cfg["build"]["purge_modules"] = False
364+
test = self._quick_test(test_cfg)
365+
build_result = test.build()
366+
367+
self.assertEqual(build_result, 1)

0 commit comments

Comments
 (0)