From 3a6c1f7f293956d6b0cff1593ca248b19e63334f Mon Sep 17 00:00:00 2001 From: paweldenst Date: Wed, 23 Nov 2022 15:07:46 +0000 Subject: Use the latest JSON Schema on ONAP data provider Changes in samples Issue-ID: INT-2175 Signed-off-by: paweldenst Change-Id: I79f21c3bdad9d1f0a5dcb8a6bbf759dc3f4c41ba --- onap_data_provider/resources/resource_creator.py | 27 +- onap_data_provider/schemas/infra_2_0.schema | 757 +++++++++++++++++++++++ onap_data_provider/validator.py | 2 +- onap_data_provider/versions.py | 5 + samples/aai_business.yaml | 2 +- samples/complex.yaml | 2 +- samples/vendor.yaml | 2 +- tests/test-data-2-0-version.yaml | 48 ++ tests/test_config_parser.py | 3 + tox.ini | 1 + 10 files changed, 842 insertions(+), 7 deletions(-) create mode 100644 onap_data_provider/schemas/infra_2_0.schema create mode 100644 tests/test-data-2-0-version.yaml diff --git a/onap_data_provider/resources/resource_creator.py b/onap_data_provider/resources/resource_creator.py index 7bd61bc..35959f1 100644 --- a/onap_data_provider/resources/resource_creator.py +++ b/onap_data_provider/resources/resource_creator.py @@ -61,96 +61,117 @@ class ResourceCreator(ABC): VersionsEnum.NONE: AaiServiceResource, VersionsEnum.V1_0: AaiServiceResource, VersionsEnum.V1_1: AaiServiceResource, + VersionsEnum.V2_0: AaiServiceResource, }, "cloud-region": { VersionsEnum.NONE: CloudRegionResource, VersionsEnum.V1_0: CloudRegionResource, VersionsEnum.V1_1: CloudRegionResource, + VersionsEnum.V2_0: CloudRegionResource, }, "complex": { VersionsEnum.NONE: ComplexResource, VersionsEnum.V1_0: ComplexResource, VersionsEnum.V1_1: ComplexResource, + VersionsEnum.V2_0: ComplexResource, }, "customer": { VersionsEnum.NONE: CustomerResource, VersionsEnum.V1_0: CustomerResource, VersionsEnum.V1_1: CustomerResource, + VersionsEnum.V2_0: CustomerResource, }, "vsp": { VersionsEnum.NONE: VspResource, VersionsEnum.V1_0: VspResource, VersionsEnum.V1_1: VspResource, + VersionsEnum.V2_0: VspResource, }, "service": { VersionsEnum.NONE: ServiceResource, VersionsEnum.V1_0: ServiceResource, VersionsEnum.V1_1: ServiceResource, + VersionsEnum.V2_0: ServiceResource, }, "vendor": { VersionsEnum.NONE: VendorResource, VersionsEnum.V1_0: VendorResource, VersionsEnum.V1_1: VendorResource, + VersionsEnum.V2_0: VendorResource, }, "pnf": { VersionsEnum.NONE: PnfResource, VersionsEnum.V1_0: PnfResource, VersionsEnum.V1_1: PnfResource, + VersionsEnum.V2_0: PnfResource, }, "vnf": { VersionsEnum.NONE: VnfResource, VersionsEnum.V1_0: VnfResource, VersionsEnum.V1_1: VnfResource, + VersionsEnum.V2_0: VnfResource, }, "service-instance": { VersionsEnum.NONE: ServiceInstanceResource, VersionsEnum.V1_0: ServiceInstanceResource, VersionsEnum.V1_1: ServiceInstanceResource_1_1, + VersionsEnum.V2_0: ServiceInstanceResource_1_1, }, "line-of-business": { VersionsEnum.NONE: LineOfBusinessResource, VersionsEnum.V1_0: LineOfBusinessResource, VersionsEnum.V1_1: LineOfBusinessResource, + VersionsEnum.V2_0: LineOfBusinessResource, }, "project": { VersionsEnum.NONE: ProjectResource, VersionsEnum.V1_0: ProjectResource, VersionsEnum.V1_1: ProjectResource, + VersionsEnum.V2_0: ProjectResource, }, "platform": { VersionsEnum.NONE: PlatformResource, VersionsEnum.V1_0: PlatformResource, VersionsEnum.V1_1: PlatformResource, + VersionsEnum.V2_0: PlatformResource, }, "owning-entity": { VersionsEnum.NONE: OwningEntityResource, VersionsEnum.V1_0: OwningEntityResource, VersionsEnum.V1_1: OwningEntityResource, + VersionsEnum.V2_0: OwningEntityResource, }, "msb-k8s-definition": { VersionsEnum.NONE: MsbK8SDefinitionResource, VersionsEnum.V1_0: MsbK8SDefinitionResource, VersionsEnum.V1_1: MsbK8SDefinitionResource, + VersionsEnum.V2_0: MsbK8SDefinitionResource, }, "data-dictionaries": { VersionsEnum.NONE: DataDictionarySetResource, VersionsEnum.V1_0: DataDictionarySetResource, VersionsEnum.V1_1: DataDictionarySetResource, + VersionsEnum.V2_0: DataDictionarySetResource, }, "blueprint": { VersionsEnum.V1_1: BlueprintResource, + VersionsEnum.V2_0: BlueprintResource, }, "blueprint-resource-template": { VersionsEnum.V1_1: BlueprintResourceTemplateResource, + VersionsEnum.V2_0: BlueprintResourceTemplateResource, }, "cps-dataspace": { - VersionsEnum.V1_1: DataspaceResource + VersionsEnum.V1_1: DataspaceResource, + VersionsEnum.V2_0: DataspaceResource }, "cps-schema-set": { - VersionsEnum.V1_1: SchemaSetResource + VersionsEnum.V1_1: SchemaSetResource, + VersionsEnum.V2_0: SchemaSetResource }, "cps-anchor": { - VersionsEnum.V1_1: AnchorResource + VersionsEnum.V1_1: AnchorResource, + VersionsEnum.V2_0: AnchorResource } } diff --git a/onap_data_provider/schemas/infra_2_0.schema b/onap_data_provider/schemas/infra_2_0.schema new file mode 100644 index 0000000..59c6298 --- /dev/null +++ b/onap_data_provider/schemas/infra_2_0.schema @@ -0,0 +1,757 @@ +--- +"$schema": "https://json-schema.org/draft/2020-12/schema" +type: object +properties: + aai-services: + type: array + additionalItems: + - type: object + properties: + aai-service: + type: object + properties: + service-id: + type: string + service-description: + type: string + required: + - service-id + - service-description + required: + - aai-service + owning-entities: &owning_entities + type: array + additionalItems: + type: object + properties: + owning-entity: + type: object + properties: + name: + type: string + $anchor: + type: string + required: + - name + required: + - owning-entity + projects: &projects + type: array + additionalItems: + type: object + properties: + project: + type: object + properties: + name: + type: string + required: + - name + required: + - project + platforms: + type: array + additionalItems: + type: object + properties: + platform: + type: object + properties: + name: + type: string + required: + - name + required: + - platform + lines-of-business: &lines_of_business + type: array + additionalItems: + type: object + properties: + line-of-business: + type: object + properties: + name: + type: string + required: + - name + required: + - line-of-business + complexes: + type: array + additionalItems: + type: object + properties: + complex: + type: object + properties: + physical-location-id: + type: string + complex-name: + type: string + data-center-code: + type: string + identity-url: + type: string + physical-location-type: + type: string + street1: + type: string + street2: + type: string + city: + type: string + state: + type: string + postal-code: + type: string + country: + type: string + region: + type: string + latitude: + type: string + longitude: + type: string + elevation: + type: string + lata: + type: string + required: + - physical-location-id + required: + - complex + cloud-regions: + type: array + additionalItems: + type: object + properties: + cloud-region: + type: object + properties: + cloud-owner: + type: string + cloud-region-id: + type: string + orchestration-disabled: + type: boolean + in-maint: + type: boolean + tenants: + type: array + additionalItems: + type: object + properties: + tenant-id: + type: string + tenant-name: + type: string + tenant-context: + type: string + lines_of_business: *lines_of_business + owning_entities: *owning_entities + required: + - tenant-id + - tenant-name + esr-system-infos: + type: array + additionalItems: + type: object + properties: + esr-system-info-id: + type: string + user-name: + type: string + password: + type: string + system-type: + type: string + service-url: + type: string + cloud-domain: + type: string + default-tenant: + type: string + required: + - esr-system-info-id + - user-name + - password + - system-type + - service-url + - cloud-domain + complex: + type: object + properties: + physical-location-id: + type: string + required: + - physical-location-id + availability-zones: + type: array + additionalItems: + type: object + properties: + availability-zone-name: + type: string + hypervisor-type: + type: string + required: + - availability-zone-name + - hypervisor-type + projects: *projects + required: + - cloud-owner + - cloud-region-id + - orchestration-disabled + - in-maint + required: + - cloud-region + customers: + type: array + additionalItems: + type: object + properties: + customer: + type: object + properties: + global-customer-id: + type: string + subscriber-name: + type: string + subscriber-type: + type: string + service-subscriptions: + type: array + additionalItems: + type: object + properties: + service-type: + type: string + tenants: + type: array + additionalItems: + type: object + properties: + tenant-id: + type: string + cloud-owner: + type: string + cloud-region-id: + type: string + required: + - tenant-id + - cloud-owner + - cloud-region-id + required: + - service-type + required: + - global-customer-id + - subscriber-name + - subscriber-type + required: + - customer + vendors: + type: array + additionalItems: + type: object + properties: + vendor: + type: object + properties: + name: + type: string + required: + - name + required: + - vendor + vsps: + type: array + additionalItems: + type: object + properties: + vsp: + type: object + properties: + name: + type: string + vendor: + type: string + package: + type: string + required: + - name + - vendor + - package + required: + - vsp + services: + type: array + additionalItems: + type: object + properties: + service: + type: object + properties: + name: + type: string + resources: + type: array + additionalItems: + type: object + properties: + name: + type: string + type: + type: string + properties: # Adding a prop to a component is senseless. + type: array + additionalItems: + type: object + properties: + name: + type: string + value: + type: + - string + - number + - boolean + required: + - name + - value + required: + - name + - type + properties: &props + type: array + additionalItems: + type: object + properties: + name: + type: string + type: + type: string + value: + type: + - string + - number + - boolean + anyOf: + - required: + - name + - type + - required: + - name + - value + inputs: &inputs + type: array + additionalItems: + type: object + properties: + name: + type: string + type: + type: string + nested-input: + type: boolean + resource-property: + type: boolean + resource: + type: string + value: + type: + - string + - number + - boolean + anyOf: + - required: + - name + - type + - required: + - name + - value + - required: + - name + - nested-input + - resource + required: + - name + required: + - service + pnfs: + type: array + additionalItems: + type: object + properties: + pnf: + type: object + properties: + name: + type: string + vendor: + type: string + vsp: + type: string + category: + type: string + subcategory: + type: string + vendor: + type: string + deployment_artifact: + type: object + properties: + artifact_type: + type: string + artifact_name: + type: string + artifact_label: + type: string + artifact_file_name: + type: string + required: + - artifact_type + - artifact_name + - artifact_label + - artifact_file_name + properties: *props + inputs: *props + resources: + type: array + additionalItems: + - type: object + properties: + xnf_type: + type: string + name: + type: string + required: + - xnf_type + - name + required: + - name + required: + - pnf + vnfs: + type: array + additionalItems: + type: object + properties: + vnf: + type: object + properties: + name: + type: string + vsp: + type: string + category: + type: string + subcategory: + type: string + vendor: + type: string + deployment_artifact: + type: object + properties: + artifact_type: + type: string + artifact_name: + type: string + artifact_label: + type: string + artifact_file_name: + type: string + required: + - artifact_type + - artifact_name + - artifact_label + - artifact_file_name + properties: *props + inputs: *props + resources: + type: array + additionalItems: + - type: object + properties: + xnf_type: + type: string + name: + type: string + required: + - xnf_type + - name + required: + - name + required: + - vnf + service-instances: + type: array + additionalItems: + type: object + properties: + service-instance: + type: object + properties: + service_instance_name: + type: string + service_name: + type: string + cloud_region: + type: string + customer_id: + type: string + owning_entity: + type: string + project: + type: string + platform: + type: string + line_of_business: + type: string + cloud_region_id: + type: string + cloud_owner: + type: string + timeout: + type: number + minimum: 1 + maximum: 99999 + aai_service: + type: string + tenant_id: + type: string + tenant_name: + type: string + service_subscription_type: + type: string + instantiation_parameters: + type: array + additionalItems: + type: object + properties: + vnf_name: + type: string + sec_group: + type: string + public_net_id: + type: string + onap_private_net_id: + type: string + onap_private_subnet_id: + type: string + image_name: + type: string + flavor_name: + type: string + install_script_version: + type: string + demo_artifacts_version: + type: string + cloud_env: + type: string + aic-cloud-region: + type: string + pub_key: + type: string + required: + - service_instance_name + - service_name + - customer_id + - owning_entity + - project + - platform + - line_of_business + - aai_service + msb-k8s-definitionss: + type: array + additionalItems: + type: object + properties: + name: + type: string + version: + type: string + chart-name: + type: string + description: + type: string + artifact: + type: string + profiles: + type: array + additionalItems: + - type: object + properties: + name: + type: string + namespace: + type: string + k8s-version: + type: string + artifact: + type: string + required: + - name + - namespace + - k8s-version + - artifact + required: + - name + - version + - artifact + data-dictionaries-sets: + type: array + additionalItems: + - type: object + properties: + data-dictionaries: + type: object + properties: + file-path: + type: string + required: + - file-path + required: + - data-dictionaries + blueprints: + type: array + additionalItems: + - type: object + properties: + blueprint: + type: object + properites: + blueprint-file-path: + type: string + required: + - blueprint-file-path + required: + - blueprint + blueprint-resource-templates: + type: array + additionalItems: + - type: object + properties: + blueprint-resource-template: + type: object + properties: + blueprint-name: + type: string + blueprint-version: + type: string + artifact-name: + type: string + resolution-key: + type: string + resource-type: + type: string + resource-id: + type: string + data: + type: string + data-file: + type: string + anyOf: + - required: + - blueprint-name + - blueprint-version + - artifact-name + - resolution-key + - data + - required: + - blueprint-name + - blueprint-version + - artifact-name + - resource-type + - resource-id + - data + - required: + - blueprint-name + - blueprint-version + - artifact-name + - resolution-key + - data-file + - required: + - blueprint-name + - blueprint-version + - artifact-name + - resource-type + - resource-id + - data-file + cps-dataspaces: + type: array + additionalItems: + - type: object + properties: + cps-dataspace: + type: object + properties: + dataspace-name: + type: string + schema-sets: + type: array + additionalItems: + - type: object + properties: + schema-set-name: + type: string + schema-set-file: + type: string + required: + - schema-set-name + - schema-set-file + anchors: + type: array + additionalItems: + - type: object + properties: + anchor-name: + type: string + schema-set-name: + type: string + required: + - anchor-name + - schema-set-name + required: + - dataspace-name + required: + - cps-dataspace + cps-schema-sets: + type: array + additionalItems: + - type: object + properties: + cps-schema-set: + type: object + properties: + schema-set-name: + type: string + schema-set-file: + type: string + dataspace-name: + type: string + required: + - schema-set-name + - schema-set-file + - dataspace-name + required: + - cps-schema-set + cps-anchors: + type: array + additionalItems: + - type: object + properties: + cps-anchor: + type: object + properties: + anchor-name: + type: string + dataspace-name: + type: string + schema-set-name: + type: string + required: + - anchor-name + - dataspace-name + - schema-set-name + required: + - cps-anchor diff --git a/onap_data_provider/validator.py b/onap_data_provider/validator.py index 3589f85..3166deb 100644 --- a/onap_data_provider/validator.py +++ b/onap_data_provider/validator.py @@ -18,7 +18,7 @@ from typing import Any, Dict import yaml -from jsonschema import validate # type: ignore +from jsonschema import validate from .versions import VersionsEnum diff --git a/onap_data_provider/versions.py b/onap_data_provider/versions.py index 7651bec..da31723 100644 --- a/onap_data_provider/versions.py +++ b/onap_data_provider/versions.py @@ -36,6 +36,11 @@ class VersionsEnum(Enum): schema_path=Path(Path(__file__).parent, "schemas/infra.schema"), deprecated=False, ) + V2_0 = Version( + version_number="2.0", + schema_path=Path(Path(__file__).parent, "schemas/infra_2_0.schema"), + deprecated=False, + ) NONE = Version( version_number="None", schema_path=Path(Path(__file__).parent, "schemas/infra.schema"), diff --git a/samples/aai_business.yaml b/samples/aai_business.yaml index 65a70bd..d39d99f 100644 --- a/samples/aai_business.yaml +++ b/samples/aai_business.yaml @@ -1,7 +1,7 @@ # A&AI business sample # Creates one owning entity, project, platform and line of business # -odpSchemaVersion: 1.0 +odpSchemaVersion: 2.0 resources: owning_entities: - owning-entity: diff --git a/samples/complex.yaml b/samples/complex.yaml index 8b989c7..e265163 100644 --- a/samples/complex.yaml +++ b/samples/complex.yaml @@ -1,7 +1,7 @@ # Complex sample # Creates one complex with `sample-complex` physical location id # -odpSchemaVersion: 1.0 +odpSchemaVersion: 2.0 resources: complexes: - complex: diff --git a/samples/vendor.yaml b/samples/vendor.yaml index abffca8..131eae3 100644 --- a/samples/vendor.yaml +++ b/samples/vendor.yaml @@ -1,7 +1,7 @@ # Vendor sample # Using that file you will create one SDC Vendor resource with "sample-vendor" name # -odpSchemaVersion: 1.0 +odpSchemaVersion: 2.0 resources: vendors: - vendor: diff --git a/tests/test-data-2-0-version.yaml b/tests/test-data-2-0-version.yaml new file mode 100644 index 0000000..7e42791 --- /dev/null +++ b/tests/test-data-2-0-version.yaml @@ -0,0 +1,48 @@ +odpSchemaVersion: 2.0 +resources: + complexes: + - complex: + data-center-code: AMICPL1 + complex-name: AMIST-COMPLEX-1 + physical-location-id: &complex_id AMIST-COMPLEX-1 + physical-location-type: Office + street1: '505' + street2: Terry Fox Drive + city: Kanata + state: Ontario + postal-code: A1A1A1 + region: Eastern + country: Canada + + cloud-regions: + - cloud-region: + cloud-owner: &clown AMIST + cloud-region-id: AMCR1 + cloud-region-version: '11.0' + orchestration-disabled: true + in-maint: false + complex: + physical-location-id: *complex_id + tenants: + - tenant-id: !join ['-', [*clown, 'TENANT', 1]] + tenant-name: AMIST-TENANT-1-NAME + - tenant-id: !join [*clown, '-', 'TENANT', '-', 2] + tenant-name: AMIST-TENANT-2-NAME + availability-zones: + - cloud-owner: *clown + availability-zone-name: AMIST-AZ-1 + hypervisor-type: OpenStackAmd + + customers: + - customer: + global-customer-id: AMIST-CUST-11 + subscriber-name: AAIIST-TESTER-11 + subscriber-type: Customer + service-subscriptions: + - service-type: amist-voip + - customer: + global-customer-id: AMIST-CUST-12 + subscriber-name: AAIIST-TESTER-12 + subscriber-type: Customer + service-subscriptions: + - service-type: amist-voip diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index d7eaa4d..ace2361 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -63,3 +63,6 @@ def test_config_parser_versioning(): [parsed_objects[1].data['cloud-owner'], 'TENANT', '1']) assert parsed_objects[1].data['tenants'][1]['tenant-id'] == ''.join( [parsed_objects[1].data['cloud-owner'], '-', 'TENANT', '-', '2']) + + parser = ConfigParser([Path("tests/test-data-2-0-version.yaml")]) + assert parser.configs[0].version.value.version_number == "2.0" \ No newline at end of file diff --git a/tox.ini b/tox.ini index ee753cf..b068f01 100644 --- a/tox.ini +++ b/tox.ini @@ -58,6 +58,7 @@ commands = deps = mypy types-PyYAML + types-jsonschema -rrequirements.txt commands = mypy --strict onap_data_provider/ -- cgit 1.2.3-korg