-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New host service to support gnmi full config update
- Loading branch information
Showing
6 changed files
with
144 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Yang validation handler""" | ||
|
||
from host_modules import host_service | ||
import json | ||
import sonic_yang | ||
|
||
YANG_MODELS_DIR = "/usr/local/yang-models" | ||
MOD_NAME = 'yang' | ||
|
||
class Yang(host_service.HostModule): | ||
""" | ||
DBus endpoint that runs yang validation | ||
""" | ||
@host_service.method(host_service.bus_name(MOD_NAME), in_signature='s', out_signature='is') | ||
def validate(self, config_db_json): | ||
config = json.loads(config_db_json) | ||
# Run yang validation | ||
yang_parser = sonic_yang.SonicYang(YANG_MODELS_DIR) | ||
yang_parser.loadYangModel() | ||
try: | ||
yang_parser.loadData(configdbJson=config) | ||
yang_parser.validate_data_tree() | ||
except sonic_yang.SonicYangException as e: | ||
return -1, str(e) | ||
if len(yang_parser.tablesWithOutYang): | ||
return -1, "Tables without yang models: " + str(yang_parser.tablesWithOutYang) | ||
return 0, "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
import os | ||
import pytest | ||
from unittest import mock | ||
from host_modules import yang_validator | ||
|
||
class TestConfigEngine(object): | ||
@mock.patch("dbus.SystemBus") | ||
@mock.patch("dbus.service.BusName") | ||
@mock.patch("dbus.service.Object.__init__") | ||
def test_reload(self, MockInit, MockBusName, MockSystemBus): | ||
config_db_json = "{}" | ||
yang_stub = yang_validator.Yang(yang_validator.MOD_NAME) | ||
ret, _ = yang_stub.validate(config_db_json) | ||
assert ret == 0, "Yang validation failed" |