Skip to content

Commit

Permalink
Merge pull request #1331 from buildtesters/debug_file_checks
Browse files Browse the repository at this point in the history
fix bug with file check with slurm jobs
  • Loading branch information
shahzebsiddiqui authored Jan 6, 2023
2 parents bce2306 + f0386e9 commit 7599eb4
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 11 deletions.
26 changes: 19 additions & 7 deletions buildtest/builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,27 @@ def is_local_executor(self):
# import issue when putting this at top of file
from buildtest.executors.local import LocalExecutor

if isinstance(self.buildexecutor.executors[self.executor], LocalExecutor):
return True
return isinstance(self.buildexecutor.executors[self.executor], LocalExecutor)

return False
def is_slurm_executor(self):
"""Return True if current builder executor type is LocalExecutor otherwise returns False.
Returns:
bool: returns True if builder is using executor type LocalExecutor otherwise returns False
"""

# import issue when putting this at top of file
from buildtest.executors.slurm import SlurmExecutor

return isinstance(self.buildexecutor.executors[self.executor], SlurmExecutor)

def is_batch_job(self):
"""Return True/False if builder.job attribute is of type Job instance if not returns False.
This method indicates if builder has a job submitted to queue
"""

if isinstance(self.job, Job):
return True

return False
return isinstance(self.job, Job)

def start(self):
"""Keep internal timer for test using class :class:`buildtest.utils.timer.Timer`. This method will start the timer for builder which is invoked upon running test."""
Expand Down Expand Up @@ -301,6 +308,7 @@ def run(self, cmd, timeout=None):

self.metadata["command"] = cmd

console.print(f"[blue]{self}[/]: Current Working Directory : {os.getcwd()}")
# capture output of 'env' and write to file 'build-env.sh' prior to running test
command = BuildTestCommand("env")
command.execute()
Expand Down Expand Up @@ -889,6 +897,10 @@ def post_run_steps(self):
such as output, error and test script. We will check state of test and mark job is complete.
"""

# ensure we are back in stage directory before processing. For batch jobs like Slurm the
# current working directory is changed to the submit line which can cause issues for file checks
os.chdir(self.stage_dir)

self._output = read_file(self.metadata["outfile"])
self._error = read_file(self.metadata["errfile"])

Expand Down
4 changes: 2 additions & 2 deletions buildtest/buildsystem/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def exists_check(builder, status):
f"[blue]{builder}[/]: Test all files: {status['exists']} existences "
)
for fname in status["exists"]:
resolved_fname = resolve_path(fname, exist=True)
resolved_fname = resolve_path(fname)
if resolved_fname:
console.print(f"[blue]{builder}[/]: file: {resolved_fname} exists")
else:
Expand Down Expand Up @@ -71,7 +71,7 @@ def is_dir_check(builder, status):
f"[blue]{builder}[/]: Test all files: {status['is_dir']} existences "
)
for dirname in status["is_dir"]:
resolved_dirname = resolve_path(dirname, exist=True)
resolved_dirname = resolve_path(dirname)
if is_dir(resolved_dirname):
console.print(
f"[blue]{builder}[/]: file: {resolved_dirname} is a directory "
Expand Down
7 changes: 5 additions & 2 deletions tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
from buildtest.executors.setup import BuildExecutor
from buildtest.schemas.defaults import custom_validator
from buildtest.schemas.utils import load_recipe, load_schema
from buildtest.system import BuildTestSystem
from buildtest.utils.file import walk_tree

pytest_root = os.path.dirname(os.path.dirname(__file__))

system = BuildTestSystem()

configuration = SiteConfiguration()
configuration.detect_system()
configuration.validate()
configuration.validate(moduletool=system.system["moduletool"])


@pytest.mark.cli
Expand Down Expand Up @@ -56,7 +59,7 @@ def test_valid_config_schemas():

@pytest.mark.cli
def test_config_validate():
validate_config(configuration)
validate_config(configuration=configuration, moduletool=system.system["moduletool"])


@pytest.mark.cli
Expand Down
17 changes: 17 additions & 0 deletions tests/examples/cori/exists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
buildspecs:
status_exists_slurm:
type: script
executor: cori.slurm.knl_debug
description: status check based for file and directory
sbatch: ['-n 1', '-t 5', '-C knl']
run: |
mkdir -p a/b/c
touch foo
status:
exists:
- a/b/c
- foo
is_dir:
- a/b/c
is_file:
- foo
25 changes: 25 additions & 0 deletions tests/test_cori.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ def test_cori_slurm_max_pend():
cmd.build()


def test_cori_slurm_file_exists():

if not hostname.startswith("cori"):
pytest.skip("This test runs on Cori Login nodes ('cori*')")

bc = SiteConfiguration(settings_file)
bc.detect_system()
bc.validate(moduletool="environment-modules")

system = BuildTestSystem()

cmd = BuildTest(
configuration=bc,
buildspecs=[
os.path.join(
os.getenv("BUILDTEST_ROOT"), "tests", "examples", "cori", "exists.yml"
)
],
buildtest_system=system,
poll_interval=5,
maxpendtime=120,
)
cmd.build()


def test_compiler_find_cori():

if not hostname.startswith("cori"):
Expand Down

0 comments on commit 7599eb4

Please sign in to comment.