diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack.yml b/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack.yml new file mode 100644 index 000000000..929b585ec --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack.yml @@ -0,0 +1,13 @@ +buildspecs: + additionalProperties_spack_field: + type: spack + executor: generic.local.sh + description: additional Properties can't be specified in spack section + spack: + root: $HOME/spack + FOO: BAR + env: + create: + name: myproject + specs: + - zlib diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack_test.yml b/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack_test.yml new file mode 100644 index 000000000..64ec59030 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/invalid/additionalProperties/spack_test.yml @@ -0,0 +1,19 @@ +buildspecs: + spack_test_additionalProperties: + type: spack + executor: generic.local.sh + description: "Check for additionalProperties in test section. FOO key is not allowed" + tags: [spack] + pre_cmds: | + cd /tmp + git clone https://github.com/spack/spack + spack: + root: /tmp/spack + verify_spack: false + install: + specs: ['m4', 'zlib'] + test: + FOO: BAR + remove_tests: true + run: + specs: ['m4', 'zlib'] diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/examples.yml b/buildtest/schemas/examples/spack.schema.json/invalid/examples.yml deleted file mode 100644 index 6d4454de4..000000000 --- a/buildtest/schemas/examples/spack.schema.json/invalid/examples.yml +++ /dev/null @@ -1,81 +0,0 @@ -buildspecs: - specs_must_be_list_of_strings: - type: spack - executor: generic.local.sh - description: 'specs must be a list of strings ' - spack: - root: $HOME/spack - env: - create: - name: myproject - specs: - - 1 - - zlib - - additionalProperties_spack_field: - type: spack - executor: generic.local.sh - description: additional Properties can't be specified in spack section - spack: - root: $HOME/spack - FOO: BAR - env: - create: - name: myproject - specs: - - zlib - - invalid_type_mirror_field: - type: spack - executor: generic.local.sh - description: The mirror field must be a key value pair - spack: - root: $HOME/spack - mirror: https://caches.e4s.io - env: - create: - name: myproject - specs: - - zlib - - spack_test_additionalProperties: - type: spack - executor: generic.local.sh - description: "Check for additionalProperties in test section. FOO key is not allowed" - tags: [spack] - pre_cmds: | - cd /tmp - git clone https://github.com/spack/spack - spack: - root: /tmp/spack - verify_spack: false - install: - specs: ['m4', 'zlib'] - test: - FOO: BAR - remove_tests: true - run: - specs: ['m4', 'zlib'] - - spack_test_run_invalid_spec: - type: spack - executor: generic.local.sh - description: "specs property requires a list of strings. " - tags: [spack] - pre_cmds: | - cd /tmp - git clone https://github.com/spack/spack - spack: - root: /tmp/spack - verify_spack: false - install: - specs: ['m4', 'zlib'] - test: - remove_tests: true - run: - specs: ['m4', 1] - results: - option: '-f' - post_cmds: | - spack find - rm -rf $SPACK_ROOT diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/mirror_type.yml b/buildtest/schemas/examples/spack.schema.json/invalid/mirror_type.yml new file mode 100644 index 000000000..ff1beab24 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/invalid/mirror_type.yml @@ -0,0 +1,13 @@ +buildspecs: + invalid_type_mirror_field: + type: spack + executor: generic.local.sh + description: The mirror field must be a key value pair + spack: + root: $HOME/spack + mirror: https://caches.e4s.io + env: + create: + name: myproject + specs: + - zlib diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/spack_test_run_invalid_spec.yml b/buildtest/schemas/examples/spack.schema.json/invalid/spack_test_run_invalid_spec.yml new file mode 100644 index 000000000..46a3a3f30 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/invalid/spack_test_run_invalid_spec.yml @@ -0,0 +1,23 @@ +buildspecs: + spack_test_run_invalid_spec: + type: spack + executor: generic.local.sh + description: "specs property requires a list of strings. " + tags: [spack] + pre_cmds: | + cd /tmp + git clone https://github.com/spack/spack + spack: + root: /tmp/spack + verify_spack: false + install: + specs: ['m4', 'zlib'] + test: + remove_tests: true + run: + specs: ['m4', 1] + results: + option: '-f' + post_cmds: | + spack find + rm -rf $SPACK_ROOT diff --git a/buildtest/schemas/examples/spack.schema.json/invalid/specs_list_check_string.yml b/buildtest/schemas/examples/spack.schema.json/invalid/specs_list_check_string.yml new file mode 100644 index 000000000..c0a0a67a0 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/invalid/specs_list_check_string.yml @@ -0,0 +1,11 @@ +buildspecs: + specs_must_be_list_of_strings: + type: spack + executor: generic.local.sh + description: 'specs must be a list of strings' + spack: + root: $HOME/spack + env: + create: + name: myproject + specs: [1, zlib] diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_activate.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_activate.yml new file mode 100644 index 000000000..3d8cb1032 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_activate.yml @@ -0,0 +1,15 @@ +buildspecs: + env_activate: + type: spack + executor: generic.local.sh + description: Activate spack environment by name + spack: + root: $HOME/spack/ + env: + activate: + name: myproject + specs: + - m4 + - zlib + install: + options: '' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_concretize.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_concretize.yml new file mode 100644 index 000000000..8107ad588 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_concretize.yml @@ -0,0 +1,14 @@ +buildspecs: + env_concretized_install: + type: spack + description: run 'spack concretize -f' in an environment and install specs + executor: generic.local.sh + spack: + root: $HOME/spack/ + env: + create: + name: myproject + manifest: $HOME/spack.yaml + concretize: true + install: + options: '--cache-only' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_create_directory.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_create_directory.yml new file mode 100644 index 000000000..043877d28 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_create_directory.yml @@ -0,0 +1,15 @@ +buildspecs: + env_create_directory: + type: spack + executor: generic.local.sh + description: Create spack environment by directory + spack: + root: $HOME/spack/ + env: + create: + dir: $HOME/spack-env/myproject + specs: + - 'm4' + - 'zlib@1.2.11' + install: + options: '--cache-only' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_create_manifest.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_create_manifest.yml new file mode 100644 index 000000000..dd004951a --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_create_manifest.yml @@ -0,0 +1,13 @@ +buildspecs: + env_create_from_manifest: + type: spack + executor: generic.local.sh + description: Create spack enviromment from manifest file + spack: + root: $HOME/spack/ + env: + create: + name: myproject + manifest: $HOME/spack.yaml + install: + options: '--cache-only' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_create_name.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_create_name.yml new file mode 100644 index 000000000..c1f454648 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_create_name.yml @@ -0,0 +1,15 @@ +buildspecs: + env_create_name: + type: spack + executor: generic.local.sh + description: Create spack environment by name + spack: + root: $HOME/spack/ + env: + create: + name: myproject + specs: + - m4 + - zlib + install: + options: '' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/env_mirror.yml b/buildtest/schemas/examples/spack.schema.json/valid/env_mirror.yml new file mode 100644 index 000000000..915171f91 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/env_mirror.yml @@ -0,0 +1,15 @@ +buildspecs: + env_mirror: + type: spack + executor: generic.local.sh + description: declare spack mirror 'spack mirror add h5 /path/to/mirror' in environment + spack: + root: $HOME/spack/ + env: + mirror: + h5: /path/to/mirror + create: + name: myproject + manifest: $HOME/spack.yaml + install: + options: '--cache-only' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/examples.yml b/buildtest/schemas/examples/spack.schema.json/valid/examples.yml deleted file mode 100644 index 591042efb..000000000 --- a/buildtest/schemas/examples/spack.schema.json/valid/examples.yml +++ /dev/null @@ -1,224 +0,0 @@ -buildspecs: - env_create_name: - type: spack - executor: generic.local.sh - description: Create spack environment by name - spack: - root: $HOME/spack/ - env: - create: - name: myproject - specs: - - m4 - - zlib - install: - options: '' - - env_activate: - type: spack - executor: generic.local.sh - description: Activate spack environment by name - spack: - root: $HOME/spack/ - env: - activate: - name: myproject - specs: - - m4 - - zlib - install: - options: '' - - env_create_directory: - type: spack - executor: generic.local.sh - description: Create spack environment by directory - spack: - root: $HOME/spack/ - env: - create: - dir: $HOME/spack-env/myproject - specs: - - 'm4' - - 'zlib@1.2.11' - install: - options: '--cache-only' - - env_create_from_manifest: - type: spack - executor: generic.local.sh - description: Create spack enviromment from manifest file - spack: - root: $HOME/spack/ - env: - create: - name: myproject - manifest: $HOME/spack.yaml - install: - options: '--cache-only' - - env_concretized_install: - type: spack - description: run 'spack concretize -f' in an environment and install specs - executor: generic.local.sh - spack: - root: $HOME/spack/ - env: - create: - name: myproject - manifest: $HOME/spack.yaml - concretize: true - install: - options: '--cache-only' - - env_mirror: - type: spack - executor: generic.local.sh - description: declare spack mirror 'spack mirror add h5 /path/to/mirror' in environment - spack: - root: $HOME/spack/ - env: - mirror: - h5: /path/to/mirror - create: - name: myproject - manifest: $HOME/spack.yaml - install: - options: '--cache-only' - - install_without_env: - type: spack - executor: generic.local.sh - description: install specs without environment - spack: - root: $HOME/spack/ - install: - options: '--cache-only' - specs: ['m4', 'bzip2'] - - - pre_post_cmd_spack_install: - type: spack - executor: generic.local.sh - description: run commands before and after spack using pre_cmds and post_cmds - pre_cmds: | - cd $HOME - git clone https://github.com/spack/spack - spack: - root: $HOME/spack/ - install: - options: '--cache-only' - specs: ['m4', 'bzip2'] - post_cmds: | - spack find - - remove_spack_environment: - type: spack - executor: generic.local.sh - description: remove spack environment explicitly before creating environment - spack: - root: $HOME/spack - env: - rm: - name: m4 - create: - name: m4 - activate: - name: m4 - specs: - - 'm4' - - remove_spack_environment_automatically: - type: spack - executor: generic.local.sh - description: remove spack environment automatically - spack: - root: $HOME/spack - env: - create: - remove_environment: true - name: m4 - activate: - name: m4 - specs: - - 'm4' - - post_cmds: | - spack find - rm -rf $SPACK_ROOT - - sbatch_field_with_spack: - type: spack - executor: generic.local.sh - description: Specify sbatch field with spack schema - sbatch: ["-N1", "-q normal", "-t 10", "-M 30M"] - spack: - root: $HOME/spack - install: - specs: ['m4'] - options: "-v" - - skip_test_in_spack: - skip: True - type: spack - executor: generic.local.sh - description: This test will be skipped - spack: - root: $HOME/spack - install: - specs: ['m4'] - options: "-v" - - var_declaration_in_spack: - type: spack - executor: generic.local.sh - description: Define variables and environment variables in spack - vars: - FOO: "BAR" - env: - SPACK_GNUPGHOME: "$HOME/.gnupg" - spack: - root: $HOME/spack - install: - specs: ['m4'] - options: "-v" - - spack_sbatch_multi_executors: - type: spack - executor: "generic.local.(sh|bash)" - description: "sbatch directives can be defined in spack schema" - tags: [spack] - executors: - generic.local.sh: - sbatch: ["-N 1", "-t 20"] - generic.local.bash: - sbatch: ["-N 8", "-t 10"] - spack: - root: $HOME/spack - env: - specs: - - 'm4' - activate: - name: m4 - concretize: true - - vars_multi_executors: - type: spack - executor: "generic.local.(sh|bash)" - description: "variable declaration with multiple executors" - tags: [spack] - executors: - generic.local.sh: - vars: - FOO: BAR - generic.local.bash: - vars: - HELLO: WORLD - spack: - root: $HOME/spack - env: - specs: - - 'm4' - activate: - name: m4 - concretize: true diff --git a/buildtest/schemas/examples/spack.schema.json/valid/install_without_env.yml b/buildtest/schemas/examples/spack.schema.json/valid/install_without_env.yml new file mode 100644 index 000000000..2c8c0c111 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/install_without_env.yml @@ -0,0 +1,10 @@ +buildspecs: + install_without_env: + type: spack + executor: generic.local.sh + description: install specs without environment + spack: + root: $HOME/spack/ + install: + options: '--cache-only' + specs: ['m4', 'bzip2'] diff --git a/buildtest/schemas/examples/spack.schema.json/valid/pre_post.yml b/buildtest/schemas/examples/spack.schema.json/valid/pre_post.yml new file mode 100644 index 000000000..b3e9837e7 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/pre_post.yml @@ -0,0 +1,15 @@ +buildspecs: + pre_post_cmd_spack_install: + type: spack + executor: generic.local.sh + description: run commands before and after spack using pre_cmds and post_cmds + pre_cmds: | + cd $HOME + git clone https://github.com/spack/spack + spack: + root: $HOME/spack/ + install: + options: '--cache-only' + specs: ['m4', 'bzip2'] + post_cmds: | + spack find diff --git a/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_env_automatically.yml b/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_env_automatically.yml new file mode 100644 index 000000000..4f0909b25 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_env_automatically.yml @@ -0,0 +1,19 @@ +buildspecs: + remove_spack_environment_automatically: + type: spack + executor: generic.local.sh + description: remove spack environment automatically + spack: + root: $HOME/spack + env: + create: + remove_environment: true + name: m4 + activate: + name: m4 + specs: + - 'm4' + + post_cmds: | + spack find + rm -rf $SPACK_ROOT diff --git a/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_environment.yml b/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_environment.yml new file mode 100644 index 000000000..36845a812 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/remove_spack_environment.yml @@ -0,0 +1,16 @@ +buildspecs: + remove_spack_environment: + type: spack + executor: generic.local.sh + description: remove spack environment explicitly before creating environment + spack: + root: $HOME/spack + env: + rm: + name: m4 + create: + name: m4 + activate: + name: m4 + specs: + - 'm4' diff --git a/buildtest/schemas/examples/spack.schema.json/valid/sbatch_multi_executors.yml b/buildtest/schemas/examples/spack.schema.json/valid/sbatch_multi_executors.yml new file mode 100644 index 000000000..13919d76f --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/sbatch_multi_executors.yml @@ -0,0 +1,19 @@ +buildspecs: + spack_sbatch_multi_executors: + type: spack + executor: "generic.local.(sh|bash)" + description: "sbatch directives can be defined in spack schema" + tags: [spack] + executors: + generic.local.sh: + sbatch: ["-N 1", "-t 20"] + generic.local.bash: + sbatch: ["-N 8", "-t 10"] + spack: + root: $HOME/spack + env: + specs: + - 'm4' + activate: + name: m4 + concretize: true diff --git a/buildtest/schemas/examples/spack.schema.json/valid/sbatch_with_spack.yml b/buildtest/schemas/examples/spack.schema.json/valid/sbatch_with_spack.yml new file mode 100644 index 000000000..167bc6eb9 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/sbatch_with_spack.yml @@ -0,0 +1,11 @@ +buildspecs: + sbatch_field_with_spack: + type: spack + executor: generic.local.sh + description: Specify sbatch field with spack schema + sbatch: ["-N1", "-q normal", "-t 10", "-M 30M"] + spack: + root: $HOME/spack + install: + specs: ['m4'] + options: "-v" diff --git a/buildtest/schemas/examples/spack.schema.json/valid/skip_test.yml b/buildtest/schemas/examples/spack.schema.json/valid/skip_test.yml new file mode 100644 index 000000000..66a30beb7 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/skip_test.yml @@ -0,0 +1,11 @@ +buildspecs: + skip_test_in_spack: + skip: True + type: spack + executor: generic.local.sh + description: This test will be skipped + spack: + root: $HOME/spack + install: + specs: ['m4'] + options: "-v" diff --git a/buildtest/schemas/examples/spack.schema.json/valid/var_and_env_declaration.yml b/buildtest/schemas/examples/spack.schema.json/valid/var_and_env_declaration.yml new file mode 100644 index 000000000..860a50ed7 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/var_and_env_declaration.yml @@ -0,0 +1,14 @@ +buildspecs: + var_declaration_in_spack: + type: spack + executor: generic.local.sh + description: Define variables and environment variables in spack + vars: + FOO: "BAR" + env: + SPACK_GNUPGHOME: "$HOME/.gnupg" + spack: + root: $HOME/spack + install: + specs: ['m4'] + options: "-v" diff --git a/buildtest/schemas/examples/spack.schema.json/valid/vars_multi_executors.yml b/buildtest/schemas/examples/spack.schema.json/valid/vars_multi_executors.yml new file mode 100644 index 000000000..9f1376028 --- /dev/null +++ b/buildtest/schemas/examples/spack.schema.json/valid/vars_multi_executors.yml @@ -0,0 +1,21 @@ +buildspecs: + vars_multi_executors: + type: spack + executor: "generic.local.(sh|bash)" + description: "variable declaration with multiple executors" + tags: [spack] + executors: + generic.local.sh: + vars: + FOO: BAR + generic.local.bash: + vars: + HELLO: WORLD + spack: + root: $HOME/spack + env: + specs: + - 'm4' + activate: + name: m4 + concretize: true diff --git a/tests/schema_tests/test_script.py b/tests/schema_tests/test_script_compiler_and_spack.py similarity index 96% rename from tests/schema_tests/test_script.py rename to tests/schema_tests/test_script_compiler_and_spack.py index 3285efa2a..69e6101e8 100644 --- a/tests/schema_tests/test_script.py +++ b/tests/schema_tests/test_script_compiler_and_spack.py @@ -71,6 +71,11 @@ def test_compiler_examples(): validate_examples(schema_file="compiler.schema.json") +@pytest.mark.schema +def test_spack_examples(): + validate_examples(schema_file="spack.schema.json") + + def test_missing_type(): """Test that exception is raised when schema type is missing""" buildspec = os.path.join( diff --git a/tests/schema_tests/test_spack.py b/tests/schema_tests/test_spack.py deleted file mode 100644 index f09a0ca71..000000000 --- a/tests/schema_tests/test_spack.py +++ /dev/null @@ -1,63 +0,0 @@ -import os -import re - -import pytest -from buildtest.defaults import SCHEMA_ROOT -from buildtest.schemas.defaults import custom_validator -from buildtest.schemas.utils import load_recipe, load_schema -from jsonschema.exceptions import ValidationError - -here = os.path.dirname(os.path.abspath(__file__)) -schemaroot = os.path.join(os.path.dirname(here), "schemas") - -schema_name = "spack" -schema_file = f"{schema_name}.schema.json" -schema_path = os.path.join(SCHEMA_ROOT, schema_file) - -spack_schema_examples = os.path.join(SCHEMA_ROOT, "examples", schema_file) - - -def check_invalid_recipes(recipes, invalids, loaded): - for recipe in recipes: - assert recipe - assert re.search("(yml|yaml)$", recipe) - recipe_path = os.path.join(invalids, recipe) - content = load_recipe(recipe_path) - - # For each section, assume folder type and validate - for name in content["buildspecs"].keys(): - with pytest.raises(ValidationError) as excinfo: - custom_validator(recipe=content["buildspecs"][name], schema=loaded) - print(excinfo.type, excinfo.value) - print("Testing %s from recipe %s should be invalid" % (name, recipe)) - - -def check_valid_recipes(recipes, valids, loaded): - for recipe in recipes: - assert recipe - assert re.search("(yml|yaml)$", recipe) - recipe_path = os.path.join(valids, recipe) - content = load_recipe(recipe_path) - - # For each section, assume folder type and validate - for name in content["buildspecs"].keys(): - print("Testing %s from recipe %s should be valid" % (name, recipe)) - custom_validator(recipe=content["buildspecs"][name], schema=loaded) - - -@pytest.mark.schema -def test_spack_examples(): - print("Testing schema %s" % schema_file) - loaded = load_schema(schema_path) - - invalids = os.path.join(spack_schema_examples, "invalid") - valids = os.path.join(spack_schema_examples, "valid") - - invalid_recipes = os.listdir(invalids) - valid_recipes = os.listdir(valids) - - assert invalid_recipes - assert valid_recipes - - check_valid_recipes(valid_recipes, valids, loaded) - check_invalid_recipes(invalid_recipes, invalids, loaded)