From 9d9070b558165a2a3fadc645bf087aabb3c6f0a8 Mon Sep 17 00:00:00 2001 From: Shahzeb Siddiqui Date: Tue, 17 Dec 2024 13:28:43 -0500 Subject: [PATCH] add regression test using example configuration file with file_traversal_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 --- buildtest/cli/build.py | 10 +++- buildtest/cli/buildspec.py | 3 + .../configuration/file_traversal_example.yml | 59 +++++++++++++++++++ tests/cli/test_config.py | 19 +++++- 4 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 tests/cli/configuration/file_traversal_example.yml diff --git a/buildtest/cli/build.py b/buildtest/cli/build.py index 0184123c3..3c79065a1 100644 --- a/buildtest/cli/build.py +++ b/buildtest/cli/build.py @@ -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 @@ -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): diff --git a/buildtest/cli/buildspec.py b/buildtest/cli/buildspec.py index 36bc27bc7..c3aea79ea 100644 --- a/buildtest/cli/buildspec.py +++ b/buildtest/cli/buildspec.py @@ -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: @@ -1254,6 +1256,7 @@ def buildspec_validate_command( tags=tags, executors=executors, name=name, + site_config=configuration, ) detected_buildspecs = buildspecs_dict["detected"] diff --git a/tests/cli/configuration/file_traversal_example.yml b/tests/cli/configuration/file_traversal_example.yml new file mode 100644 index 000000000..6e57dde9a --- /dev/null +++ b/tests/cli/configuration/file_traversal_example.yml @@ -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++ diff --git a/tests/cli/test_config.py b/tests/cli/test_config.py index eda98e773..f263eb8b6 100644 --- a/tests/cli/test_config.py +++ b/tests/cli/test_config.py @@ -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, @@ -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 @@ -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, + )