diff --git a/examples/plugins/example/__init__.py b/examples/plugins/example/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/plugins/discover.py b/examples/plugins/example/discover.py similarity index 78% rename from examples/plugins/discover.py rename to examples/plugins/example/discover.py index 0541e5be02..885e06bc28 100644 --- a/examples/plugins/discover.py +++ b/examples/plugins/example/discover.py @@ -1,11 +1,23 @@ +import dataclasses + import tmt import tmt.steps import tmt.steps.discover +import tmt.utils # See the online documentation for more details about writing plugins # https://tmt.readthedocs.io/en/stable/plugins.html +@dataclasses.dataclass +class DiscoverExampleData(tmt.steps.discover.DiscoverStepData): + path: str = tmt.utils.field( + default=".", + option=('-p', '--path'), + metavar='ROOT', + help='Path to the metadata tree root.') + + @tmt.steps.provides_method('example') class DiscoverExample(tmt.steps.discover.DiscoverPlugin): """ @@ -16,6 +28,8 @@ class DiscoverExample(tmt.steps.discover.DiscoverPlugin): of configuration examples as well. """ + _data_class = DiscoverExampleData + def show(self): """ Show plugin details for given or all available keys """ super().show([]) @@ -48,7 +62,8 @@ def go(self): print("Code should prepare environment for tests.") # Discover available tests - self._tests = tmt.Tree(logger=self._logger, path=".").tests() + self._tests = tmt.Tree(logger=self._logger, + path=self.data.path).tests() def tests(self): """ diff --git a/examples/plugins/provision.py b/examples/plugins/example/provision.py similarity index 100% rename from examples/plugins/provision.py rename to examples/plugins/example/provision.py diff --git a/examples/plugins/example/schemas/discover/example.yaml b/examples/plugins/example/schemas/discover/example.yaml new file mode 100644 index 0000000000..18b8b877f4 --- /dev/null +++ b/examples/plugins/example/schemas/discover/example.yaml @@ -0,0 +1,22 @@ +$id: /schemas/discover/example +$schema: https://json-schema.org/draft-07/schema + +type: object +additionalProperties: false + +properties: + how: + type: string + enum: + - example + path: + $ref: "/schemas/common#/definitions/fmf_id/properties/path" + + # Other basic discover properties + name: + type: string + order: + $ref: "/schemas/core#/definitions/order" + +required: + - how diff --git a/examples/plugins/example/schemas/provision/example.yaml b/examples/plugins/example/schemas/provision/example.yaml new file mode 100644 index 0000000000..283e71b03c --- /dev/null +++ b/examples/plugins/example/schemas/provision/example.yaml @@ -0,0 +1,20 @@ +$id: /schemas/provision/example +$schema: https://json-schema.org/draft-07/schema + +type: object +additionalProperties: false + +properties: + how: + type: string + enum: + - example + + # Other basic provision properties + name: + type: string + order: + $ref: "/schemas/core#/definitions/order" + +required: + - how diff --git a/examples/plugins/pyproject.toml b/examples/plugins/pyproject.toml index 126126bf99..a3e57c2c41 100644 --- a/examples/plugins/pyproject.toml +++ b/examples/plugins/pyproject.toml @@ -12,10 +12,12 @@ dependencies = [ [tool.hatch.build.targets.wheel] packages = [ - "discover.py", - "provision.py", + "example", ] [project.entry-points."tmt.plugin"] -ProvisionExample = "provision:ProvisionExample" -DiscoverExample = "discover:DiscoverExample" +ProvisionExample = "example.provision:ProvisionExample" +DiscoverExample = "example.discover:DiscoverExample" + +[project.entry-points."tmt.resources"] +ResourcesExample = "example" diff --git a/tests/plugins/data/.fmf/version b/tests/plugins/data/.fmf/version new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/tests/plugins/data/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/plugins/data/main.fmf b/tests/plugins/data/main.fmf new file mode 100644 index 0000000000..5312d0b083 --- /dev/null +++ b/tests/plugins/data/main.fmf @@ -0,0 +1,8 @@ +summary: Check plugin schema validation +execute: + how: tmt +provision: + how: example +discover: + how: example + path: some/random/path diff --git a/tests/plugins/test.sh b/tests/plugins/test.sh index e5dd76c97a..632c08bf84 100755 --- a/tests/plugins/test.sh +++ b/tests/plugins/test.sh @@ -5,6 +5,7 @@ rlJournalStart rlPhaseStartSetup rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory" rlRun "cp -r $(git rev-parse --show-toplevel)/examples/plugins $tmp" + rlRun "cp -a data $tmp" rlRun "pushd $tmp" # For local development this can run already in venv, do not use venv @@ -27,11 +28,16 @@ rlJournalStart rlAssertGrep "Unsupported discover method" "$rlRun_LOG" rlRun -s "$tmt run provision -h example --help" "2" rlAssertGrep "Unsupported provision method" "$rlRun_LOG" + rlRun -s "$tmt -r data lint --enable-check C000 --enforce-check C000" "1" + rlAssertGrep "fail C000 fmf node failed schema validation" "$rlRun_LOG" + rlAssertGrep "fail C000 key \"path\" not recognized" "$rlRun_LOG" + rlAssertGrep "fail C000 value of \"how\" is not" "$rlRun_LOG" # Install them to entry_point and they work now rlRun "pip install ./plugins" rlRun "$tmt run discover -h example --help" rlRun "$tmt run provision -h example --help" + rlRun -s "$tmt -r data lint --enable-check C000 --enforce-check C000" # Uninstall them rlRun "pip uninstall -y demo-plugins" @@ -47,7 +53,7 @@ rlJournalStart rlAssertGrep "Unsupported provision method" "$rlRun_LOG" # Export variable and plugins work now - rlRun "export TMT_PLUGINS=./plugins" + rlRun "export TMT_PLUGINS=./plugins/example" rlRun "$tmt run discover -h example --help" rlRun "$tmt run provision -h example --help" rlPhaseEnd