From d4847a53c7b103e8d4400f5c815ea6e5cb5b60f6 Mon Sep 17 00:00:00 2001 From: Ankit R Gadiya Date: Thu, 20 Apr 2023 11:11:40 +0530 Subject: [PATCH] fix(apply): fixes the schema not found errors The recent change in JSON Schema validation made it such that the Schemas are loaded at runtime. But, the Schemas were not being shipped in the Python wheel. This was leading to schema not found error upon running the apply command. This commit adds schemas as part of the shipped Wheel to fix the issue. --- .gitignore | 2 +- jsonschema | 1 + riocli/build/model.py | 2 +- riocli/deployment/model.py | 2 +- riocli/device/model.py | 2 +- riocli/disk/model.py | 2 +- riocli/jsonschema/__init__.py | 0 {jsonschema => riocli/jsonschema/schemas}/build-schema.yaml | 0 .../jsonschema/schemas}/deployment-schema.yaml | 0 {jsonschema => riocli/jsonschema/schemas}/device-schema.yaml | 0 {jsonschema => riocli/jsonschema/schemas}/disk-schema.yaml | 0 .../jsonschema/schemas}/managedservice-schema.yaml | 0 .../jsonschema/schemas}/network-schema.yaml | 0 .../jsonschema/schemas}/package-schema.yaml | 0 {jsonschema => riocli/jsonschema/schemas}/primitives.yaml | 0 .../jsonschema/schemas}/project-schema.yaml | 0 {jsonschema => riocli/jsonschema/schemas}/secret-schema.yaml | 0 .../jsonschema/schemas}/static_route-schema.yaml | 0 riocli/{utils => jsonschema}/validate.py | 2 +- riocli/managedservice/model.py | 2 +- riocli/model/base.py | 5 ----- riocli/network/model.py | 2 +- riocli/package/model.py | 2 +- riocli/project/model.py | 2 +- riocli/secret/model.py | 2 +- riocli/static_route/model.py | 2 +- setup.py | 3 ++- 27 files changed, 15 insertions(+), 18 deletions(-) create mode 120000 jsonschema create mode 100644 riocli/jsonschema/__init__.py rename {jsonschema => riocli/jsonschema/schemas}/build-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/deployment-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/device-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/disk-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/managedservice-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/network-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/package-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/primitives.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/project-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/secret-schema.yaml (100%) rename {jsonschema => riocli/jsonschema/schemas}/static_route-schema.yaml (100%) rename riocli/{utils => jsonschema}/validate.py (94%) diff --git a/.gitignore b/.gitignore index 1d19183e..bcf1c7b2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ # Node artifact files node_modules/ dist/ -jsonschema/json/ +riocli/jsonschema/schemas/json/ # Compiled Java class files *.class diff --git a/jsonschema b/jsonschema new file mode 120000 index 00000000..e5dc27d3 --- /dev/null +++ b/jsonschema @@ -0,0 +1 @@ +riocli/jsonschema/schemas/ \ No newline at end of file diff --git a/riocli/build/model.py b/riocli/build/model.py index b5bf26ef..7b307795 100644 --- a/riocli/build/model.py +++ b/riocli/build/model.py @@ -16,7 +16,7 @@ from rapyuta_io import Build as v1Build, Client, BuildOptions, CatkinOption from riocli.model import Model -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Build(Model): diff --git a/riocli/deployment/model.py b/riocli/deployment/model.py index c7bbea70..38dab18b 100644 --- a/riocli/deployment/model.py +++ b/riocli/deployment/model.py @@ -32,7 +32,7 @@ from riocli.model import Model from riocli.package.util import find_package_guid from riocli.static_route.util import find_static_route_guid -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Deployment(Model): diff --git a/riocli/device/model.py b/riocli/device/model.py index f8bfe188..1f467c30 100644 --- a/riocli/device/model.py +++ b/riocli/device/model.py @@ -17,7 +17,7 @@ from rapyuta_io.clients.device import Device as v1Device, DevicePythonVersion from riocli.model import Model -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Device(Model): diff --git a/riocli/disk/model.py b/riocli/disk/model.py index f94043fe..93238b29 100644 --- a/riocli/disk/model.py +++ b/riocli/disk/model.py @@ -22,7 +22,7 @@ from riocli.disk.util import _api_call from riocli.model import Model -from riocli.utils.validate import load_schema, validate_manifest +from riocli.jsonschema.validate import load_schema, validate_manifest class Disk(Model): diff --git a/riocli/jsonschema/__init__.py b/riocli/jsonschema/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/jsonschema/build-schema.yaml b/riocli/jsonschema/schemas/build-schema.yaml similarity index 100% rename from jsonschema/build-schema.yaml rename to riocli/jsonschema/schemas/build-schema.yaml diff --git a/jsonschema/deployment-schema.yaml b/riocli/jsonschema/schemas/deployment-schema.yaml similarity index 100% rename from jsonschema/deployment-schema.yaml rename to riocli/jsonschema/schemas/deployment-schema.yaml diff --git a/jsonschema/device-schema.yaml b/riocli/jsonschema/schemas/device-schema.yaml similarity index 100% rename from jsonschema/device-schema.yaml rename to riocli/jsonschema/schemas/device-schema.yaml diff --git a/jsonschema/disk-schema.yaml b/riocli/jsonschema/schemas/disk-schema.yaml similarity index 100% rename from jsonschema/disk-schema.yaml rename to riocli/jsonschema/schemas/disk-schema.yaml diff --git a/jsonschema/managedservice-schema.yaml b/riocli/jsonschema/schemas/managedservice-schema.yaml similarity index 100% rename from jsonschema/managedservice-schema.yaml rename to riocli/jsonschema/schemas/managedservice-schema.yaml diff --git a/jsonschema/network-schema.yaml b/riocli/jsonschema/schemas/network-schema.yaml similarity index 100% rename from jsonschema/network-schema.yaml rename to riocli/jsonschema/schemas/network-schema.yaml diff --git a/jsonschema/package-schema.yaml b/riocli/jsonschema/schemas/package-schema.yaml similarity index 100% rename from jsonschema/package-schema.yaml rename to riocli/jsonschema/schemas/package-schema.yaml diff --git a/jsonschema/primitives.yaml b/riocli/jsonschema/schemas/primitives.yaml similarity index 100% rename from jsonschema/primitives.yaml rename to riocli/jsonschema/schemas/primitives.yaml diff --git a/jsonschema/project-schema.yaml b/riocli/jsonschema/schemas/project-schema.yaml similarity index 100% rename from jsonschema/project-schema.yaml rename to riocli/jsonschema/schemas/project-schema.yaml diff --git a/jsonschema/secret-schema.yaml b/riocli/jsonschema/schemas/secret-schema.yaml similarity index 100% rename from jsonschema/secret-schema.yaml rename to riocli/jsonschema/schemas/secret-schema.yaml diff --git a/jsonschema/static_route-schema.yaml b/riocli/jsonschema/schemas/static_route-schema.yaml similarity index 100% rename from jsonschema/static_route-schema.yaml rename to riocli/jsonschema/schemas/static_route-schema.yaml diff --git a/riocli/utils/validate.py b/riocli/jsonschema/validate.py similarity index 94% rename from riocli/utils/validate.py rename to riocli/jsonschema/validate.py index 24555fec..5a82bfc4 100644 --- a/riocli/utils/validate.py +++ b/riocli/jsonschema/validate.py @@ -25,7 +25,7 @@ def load_schema(resource: str) -> dict: """ Reads JSON schema yaml and returns a dict. """ - schema_dir = Path('jsonschema') + schema_dir = Path(__file__).parent.joinpath('schemas') with open(schema_dir.joinpath(resource + "-schema.yaml")) as f: return yaml.safe_load(f) diff --git a/riocli/managedservice/model.py b/riocli/managedservice/model.py index b8c6c12e..dfb6a09d 100644 --- a/riocli/managedservice/model.py +++ b/riocli/managedservice/model.py @@ -18,7 +18,7 @@ from riocli.managedservice.util import ManagedServicesClient from riocli.model import Model -from riocli.utils.validate import load_schema, validate_manifest +from riocli.jsonschema.validate import load_schema, validate_manifest class ManagedService(Model): diff --git a/riocli/model/base.py b/riocli/model/base.py index 04558d1c..d10c712c 100644 --- a/riocli/model/base.py +++ b/riocli/model/base.py @@ -15,13 +15,10 @@ from abc import ABC, abstractmethod from datetime import datetime from shutil import get_terminal_size -import yaml -import os import click from munch import Munch, munchify from rapyuta_io import Client -from pathlib import Path from riocli.project.util import find_project_guid @@ -29,8 +26,6 @@ DELETE_POLICY_LABEL = 'rapyuta.io/deletionPolicy' -schema_dir = Path('jsonschema') - def message_with_prompt(msg, right_msg="", fg='white', with_time=True): columns, _ = get_terminal_size() time = datetime.now().isoformat('T') diff --git a/riocli/network/model.py b/riocli/network/model.py index 2fb13dd3..831e131e 100644 --- a/riocli/network/model.py +++ b/riocli/network/model.py @@ -20,7 +20,7 @@ from riocli.model import Model from riocli.network.util import find_network_name, NetworkNotFound -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Network(Model): diff --git a/riocli/package/model.py b/riocli/package/model.py index 9b434588..3290a6e8 100644 --- a/riocli/package/model.py +++ b/riocli/package/model.py @@ -19,7 +19,7 @@ from rapyuta_io.clients.package import RestartPolicy from riocli.model import Model -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Package(Model): diff --git a/riocli/project/model.py b/riocli/project/model.py index db31004d..1b1cd897 100644 --- a/riocli/project/model.py +++ b/riocli/project/model.py @@ -16,7 +16,7 @@ from rapyuta_io import Project as v1Project, Client from riocli.model import Model -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class Project(Model): diff --git a/riocli/secret/model.py b/riocli/secret/model.py index 3cbcadf4..1ab5ca8b 100644 --- a/riocli/secret/model.py +++ b/riocli/secret/model.py @@ -18,7 +18,7 @@ SecretConfigSourceSSHAuth, Client from riocli.model import Model -from riocli.utils.validate import load_schema, validate_manifest +from riocli.jsonschema.validate import load_schema, validate_manifest class Secret(Model): diff --git a/riocli/static_route/model.py b/riocli/static_route/model.py index d6b3f885..48bdc085 100644 --- a/riocli/static_route/model.py +++ b/riocli/static_route/model.py @@ -17,7 +17,7 @@ from rapyuta_io.clients.static_route import StaticRoute as v1StaticRoute from riocli.model import Model -from riocli.utils.validate import validate_manifest, load_schema +from riocli.jsonschema.validate import validate_manifest, load_schema class StaticRoute(Model): diff --git a/setup.py b/setup.py index 763aa3bf..ca9b4aad 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,8 @@ packages=find_packages(), package_data={ 'riocli': [ - 'apply/manifests/*.yaml' + 'apply/manifests/*.yaml', + 'jsonschema/schemas/*.yaml' ] }, include_package_data=True,