Skip to content

Commit

Permalink
add regression test using example configuration file with file_traver…
Browse files Browse the repository at this point in the history
…sal_limit set to 1 and run

a buildtest buildspec validate command to see if it works.
Fix a bug when passing discover_buildspec we need to pass configuration variable
  • Loading branch information
shahzebsiddiqui committed Dec 17, 2024
1 parent 95be76f commit 9d9070b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 4 deletions.
10 changes: 7 additions & 3 deletions buildtest/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ def discover_buildspecs(
)

cache = load_json(BUILDSPEC_CACHE_FILE)

# get file_traversal_limit from the config
if site_config and site_config.target_config:
file_traversal_limit = site_config.target_config.get("file_traversal_limit", 1000)
file_traversal_limit = site_config.target_config.get(
"file_traversal_limit", 1000
)
else:
file_traversal_limit = 1000

Expand Down Expand Up @@ -556,7 +558,9 @@ def discover_by_buildspecs(buildspec: str, file_traversal_limit: int) -> list:
logger.debug(
f"Buildspec File: {buildspec} is a directory so traversing directory tree to find all Buildspec files with .yml extension"
)
buildspecs = walk_tree(buildspec, ".yml", file_traverse_limit=file_traversal_limit)
buildspecs = walk_tree(
buildspec, ext=".yml", file_traverse_limit=file_traversal_limit
)
elif os.path.isfile(buildspec):
# if buildspec doesn't end in .yml extension we print message and return None
if not re.search(".yml$", buildspec):
Expand Down
3 changes: 3 additions & 0 deletions buildtest/cli/buildspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def _discover_buildspecs(self):
file_traversal_limit = self.configuration.target_config.get(
"file_traversal_limit", 1000
)
print("file_traversal_limit", file_traversal_limit)

# recursively search all .yml files in directory and add to list
if self.paths:
for path in self.paths:
Expand Down Expand Up @@ -1254,6 +1256,7 @@ def buildspec_validate_command(
tags=tags,
executors=executors,
name=name,
site_config=configuration,
)
detected_buildspecs = buildspecs_dict["detected"]

Expand Down
59 changes: 59 additions & 0 deletions tests/cli/configuration/file_traversal_example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
system:
generic:
# specify a list of hostnames that is a regular expression where buildtest can run.
hostnames: ['.*']
# system description
description: Generic System
# specify module system to use. Supported module systems are lmod, environment-modules or set to N/A if not available
moduletool: none

# specify size of job pool (https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool). This will configure the number of processes that can run in parallel.
# If not specified then buildtest will use all available cores on the system.
poolsize: 1

# maximum number of jobs that can run in parallel. If not specified, buildtest will run all jobs in parallel.
#max_jobs: 1

# test timeout in number of seconds
# timeout: 3600

file_traversal_limit: 1

# enable pagination for buildtest
pager: false

# options for buildtest buildspec find command
buildspecs:
# determine whether to rebuild buildspec cache
rebuild: false
# determine number of records to display
count: 15

# specify format fields
#format: name,description

# display output in terse mode
terse: false

# options for buildtest report command
report:
# number of records to display
count: 25
# specify format fields
format: name,id,state,runtime,returncode

executors:
local:
bash:
description: submit jobs on local machine using bash shell
shell: bash
csh:
description: submit jobs on local machine using csh shell
shell: csh
compilers:
compiler:
gcc:
builtin_gcc:
cc: gcc
fc: gfortran
cxx: g++
19 changes: 18 additions & 1 deletion tests/cli/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from buildtest.cli.build import BuildTest
from buildtest.cli.buildspec import buildspec_validate_command
from buildtest.cli.config import (
list_profiles,
remove_executors,
Expand All @@ -16,7 +17,7 @@
view_system,
)
from buildtest.config import SiteConfiguration
from buildtest.defaults import DEFAULT_SETTINGS_SCHEMA, SCHEMA_ROOT
from buildtest.defaults import BUILDTEST_ROOT, DEFAULT_SETTINGS_SCHEMA, SCHEMA_ROOT
from buildtest.executors.setup import BuildExecutor
from buildtest.schemas.defaults import custom_validator
from buildtest.schemas.utils import load_recipe, load_schema
Expand Down Expand Up @@ -187,3 +188,19 @@ def test_disabled_invalid_executors():

# buildtest config executors list --invalid
view_executors(configuration=configuration, buildexecutor=be, display_invalid=True)


def test_file_traversal_limit_in_config():
here = os.path.dirname(os.path.abspath(__file__))

configfile = os.path.join(here, "configuration", "file_traversal_example.yml")
configuration = SiteConfiguration(settings_file=configfile)
configuration.detect_system()
configuration.validate()

# exception can be raised when buildspec is invalid
with pytest.raises(SystemExit):
buildspec_validate_command(
buildspecs=[os.path.join(BUILDTEST_ROOT, "tutorials")],
configuration=configuration,
)

0 comments on commit 9d9070b

Please sign in to comment.