Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use api to get driver schema file #3898

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/molecule/driver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def get_playbook(self, step):
return p
return None

def schema_file(self):
return None

def modules_dir(self):
"""Return path to ansible modules included with driver."""
p = os.path.join(self._path, "modules")
Expand Down
5 changes: 5 additions & 0 deletions src/molecule/driver/delegated.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
"""Delegated Driver Module."""

import logging
import os

from molecule import util
from molecule.api import Driver
from molecule.data import __file__ as data_module

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -253,3 +255,6 @@ def _get_instance_config(self, instance_name):
def sanity_checks(self):
# Note(decentral1se): Cannot implement driver specifics are unknown
pass

def schema_file(self):
return os.path.join(os.path.dirname(data_module), "driver.json")
24 changes: 10 additions & 14 deletions src/molecule/model/schema_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
# DEALINGS IN THE SOFTWARE.
"""Schema v3 Validation Module."""

import importlib.resources as pkg_resources
import json
import logging
import os

from jsonschema import validate as jsonschema_validate
from jsonschema.exceptions import ValidationError

from molecule import api
from molecule.data import __file__ as data_module

LOG = logging.getLogger(__name__)
Expand All @@ -39,22 +39,18 @@ def validate(c):

schema_files = [os.path.dirname(data_module) + "/molecule.json"]
driver_name = c["driver"]["name"]

driver_schema_file = None
if driver_name in api.drivers():
driver_schema_file = api.drivers()[driver_name].schema_file()

if driver_name == "delegated":
driver_schema_file = os.path.dirname(data_module) + "/driver.json"
if driver_schema_file is None:
msg = f"Driver {driver_name} does not provide a schema."
LOG.warning(msg)
elif not os.path.exists(driver_schema_file):
msg = f"Schema {driver_schema_file} for driver {driver_name} not found."
LOG.warning(msg)
else:
try:
with pkg_resources.path(f"molecule_{driver_name}", "driver.json") as p:
driver_schema_file = p.as_posix()
except FileNotFoundError:
msg = f"No schema found in {driver_name} driver."
LOG.warning(msg)
except ModuleNotFoundError:
msg = f"{driver_name} driver is not installed."
LOG.warning(msg)

if driver_schema_file:
schema_files.append(driver_schema_file)

for schema_file in schema_files:
Expand Down