mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-01 18:47:48 +00:00
YANG: tests: validate our sample data against the YANG model
I'm using the yagnson library for this, and that library needs two
pieces of data as its inputs:
- a "YANG Module Library", which is usually a JSON description of all
available and activated YANG modules along its enabled features, etc,
- actual YANG models, typically specified as a list of filesystem paths
which hold them.
I generated that ietf-yanglib file via something like:
$ python path/to/yangson/tools/python/mkylib.py \
gnpy/yang/ext \
gnpy/yang/tip \
> gnpy/yang/yanglib.json`
When this adds support for `ietf-geo-location` in future, make sure to
edit the output so that it does not accidentally enable all of the
geolocation features (but that's for later, anyway). And we might
actually not end up doing that.
Change-Id: I51e342cd556ecc381ff0bf35df2bfa70f5f83ba8
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#
|
||||
|
||||
from pathlib import Path
|
||||
from yangson import DataModel
|
||||
|
||||
|
||||
def model_path() -> Path:
|
||||
@@ -17,3 +18,13 @@ def model_path() -> Path:
|
||||
def external_path() -> Path:
|
||||
'''Filesystem path to third-party YANG models that are shipped with GNPy'''
|
||||
return Path(__file__).parent / 'ext'
|
||||
|
||||
|
||||
def _yang_library() -> Path:
|
||||
'''Filesystem path the the ietf-yanglib JSON file'''
|
||||
return Path(__file__).parent / 'yanglib.json'
|
||||
|
||||
|
||||
def create_datamodel() -> DataModel:
|
||||
'''Create a new yangson.DataModel'''
|
||||
return DataModel.from_file(_yang_library(), (external_path(), model_path()))
|
||||
|
||||
31
gnpy/yang/yanglib.json
Normal file
31
gnpy/yang/yanglib.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"ietf-yang-library:modules-state": {
|
||||
"module-set-id": "",
|
||||
"module": [
|
||||
{
|
||||
"name": "ietf-inet-types",
|
||||
"revision": "2013-07-15",
|
||||
"namespace": "urn:ietf:params:xml:ns:yang:ietf-inet-types",
|
||||
"conformance-type": "import"
|
||||
},
|
||||
{
|
||||
"name": "ietf-yang-types",
|
||||
"revision": "2013-07-15",
|
||||
"namespace": "urn:ietf:params:xml:ns:yang:ietf-yang-types",
|
||||
"conformance-type": "import"
|
||||
},
|
||||
{
|
||||
"name": "ietf-network-topology",
|
||||
"revision": "2018-02-26",
|
||||
"namespace": "urn:ietf:params:xml:ns:yang:ietf-network-topology",
|
||||
"conformance-type": "implement"
|
||||
},
|
||||
{
|
||||
"name": "ietf-network",
|
||||
"revision": "2018-02-26",
|
||||
"namespace": "urn:ietf:params:xml:ns:yang:ietf-network",
|
||||
"conformance-type": "implement"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,4 @@ pbr>=5.5.1,<6
|
||||
pyang>=2.4.0,<3
|
||||
scipy>=1.5.4,<2
|
||||
xlrd>=1.2.0,<2
|
||||
yangson>=1.4.8,<2
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
# see LICENSE.md for a list of contributors
|
||||
#
|
||||
|
||||
from gnpy.yang import external_path, model_path
|
||||
from gnpy.yang import external_path, model_path, create_datamodel
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
import pytest
|
||||
import subprocess
|
||||
import json
|
||||
|
||||
|
||||
def _get_basename(filename: Path) -> str:
|
||||
@@ -44,3 +45,18 @@ def _validate_yang_model(filename: Path, options: List[str]):
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, universal_newlines=True)
|
||||
assert proc.stderr == ''
|
||||
assert proc.stdout == ''
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _yangson_datamodel():
|
||||
return create_datamodel
|
||||
|
||||
|
||||
@pytest.mark.parametrize("filename", (Path(__file__).parent / 'yang').glob('*.json'), ids=_get_basename)
|
||||
def test_validate_yang_data(_yangson_datamodel, filename: Path):
|
||||
'''Validate a JSON file against our YANG models'''
|
||||
dm = _yangson_datamodel()
|
||||
with open(filename, 'r') as f:
|
||||
raw_json = json.load(f)
|
||||
data = dm.from_raw(raw_json)
|
||||
data.validate()
|
||||
|
||||
1
tests/yang/00-empty.json
Normal file
1
tests/yang/00-empty.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
Reference in New Issue
Block a user