Skip to content

Commit

Permalink
Expand example to include schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Oct 7, 2024
1 parent 5472222 commit 3a9861e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 6 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand All @@ -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([])
Expand Down Expand Up @@ -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):
"""
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/plugins/example/schemas/discover/example.yaml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions examples/plugins/example/schemas/provision/example.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions examples/plugins/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions tests/plugins/data/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
8 changes: 8 additions & 0 deletions tests/plugins/data/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
summary: Check plugin schema validation
execute:
how: tmt
provision:
how: example
discover:
how: example
path: some/random/path
8 changes: 7 additions & 1 deletion tests/plugins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 3a9861e

Please sign in to comment.