Skip to content

Commit a02255e

Browse files
author
Praveen Chaudhary
authored
[sonic-yang-models]: First version of yang models for Port, VLan, Interface, PortChannel, loopback and ACL. (#3730)
[sonic-yang-models]: First version of yang models for Port, VLan, Interface, PortChannel, loopback and ACL. YANG models as per Guidelines. Guideline doc: https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md [sonic-yang-models/tests]: YANG model test code and JSON input for testing. [sonic-yang-models/setup.py]: Build infra for yang models. **- What I did** Created Yang model for Sonic. Tables: PORT, VLAN, VLAN_INTERFACE, VLAN_MEMBER, ACL_RULE, ACL_TABLE, INTERFACE. Created build infra files using which a new package (sonic-yang-models) can be build and can be deployed on sonic switches. Yang models will be part of this new package. **- How I did it** Wrote yang models based on Guideline doc: https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md and https://github.com/Azure/SONiC/wiki/Configuration. Wrote python wheel Package infra which runs test for these Yang models using a json files which consists configuration as per yang models. These configs are for negative tests, which means we want to test that most must condition, pattern and when condition works as expected. **- How to verify it** Build Logs and testing: ——————————————————————————————————— ``` /sonic/src/sonic-yang-models /sonic running test running egg_info writing top-level names to sonic_yang_models.egg-info/top_level.txt writing dependency_links to sonic_yang_models.egg-info/dependency_links.txt writing sonic_yang_models.egg-info/PKG-INFO reading manifest file 'sonic_yang_models.egg-info/SOURCES.txt' writing manifest file 'sonic_yang_models.egg-info/SOURCES.txt' running build_ext ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK running bdist_wheel running build running build_py (Reading database ... 155852 files and directories currently installed.) Preparing to unpack .../libyang_1.0.73_amd64.deb ... Unpacking libyang (1.0.73) over (1.0.73) ... Setting up libyang (1.0.73) ... Processing triggers for libc-bin (2.24-11+deb9u4) ... Processing triggers for man-db (2.7.6.1-2) ... (Reading database ... 155852 files and directories currently installed.) Preparing to unpack .../libyang-cpp_1.0.73_amd64.deb ... Unpacking libyang-cpp (1.0.73) over (1.0.73) ... Setting up libyang-cpp (1.0.73) ... Processing triggers for libc-bin (2.24-11+deb9u4) ... (Reading database ... 155852 files and directories currently installed.) Preparing to unpack .../python3-yang_1.0.73_amd64.deb ... Unpacking python3-yang (1.0.73) over (1.0.73) ... Setting up python3-yang (1.0.73) ... INFO:YANG-TEST:module: sonic-vlan is loaded successfully ERROR:YANG-TEST:Could not get module: sonic-head INFO:YANG-TEST:module: sonic-portchannel is loaded successfully INFO:YANG-TEST:module: sonic-acl is loaded successfully INFO:YANG-TEST:module: sonic-loopback-interface is loaded successfully ERROR:YANG-TEST:Could not get module: sonic-port INFO:YANG-TEST:module: sonic-interface is loaded successfully INFO:YANG-TEST: ------------------- Test 1: Configure a member port in VLAN_MEMBER table which does not exist.--------------------- libyang[0]: Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:port_name" of value "Ethernet156" points to a non -existing leaf. (path: /sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlan_name='Vlan100'][port='Ethernet156']/port) INFO:YANG-TEST:Configure a member port in VLAN_MEMBER table which does not exist. Passed INFO:YANG-TEST: ------------------- Test 2: Configure non-existing ACL_TABLE in ACL_RULE.--------------------- libyang[0]: Leafref "/sonic-acl:sonic-acl/sonic-acl:ACL_TABLE/sonic-acl:ACL_TABLE_LIST/sonic-acl:ACL_TABLE_NAME" of value "NOT-EXIST" points to a non-existing leaf. (path: /sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='NOT-EXIST'][RULE_NAME='Rule_20']/ACL_TABLE_NAME) INFO:YANG-TEST:Configure non-existing ACL_TABLE in ACL_RULE. Passed INFO:YANG-TEST: ------------------- Test 3: Configure IP_TYPE as ARP and ICMPV6_CODE in ACL_RULE.--------------------- libyang[0]: When condition "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPv6ANY'])" not satisfied. (path: /sonic-acl:sonic-acl/ACL_RU LE/ACL_RULE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4'][RULE_NAME='Rule_40']/ICMPV6_CODE) INFO:YANG-TEST:Configure IP_TYPE as ARP and ICMPV6_CODE in ACL_RULE. Passed INFO:YANG-TEST: INFO:YANG-TEST: ------------------- Test 4: Configure IP_TYPE as ipv4any and SRC_IPV6 in ACL_RULE.--------------------- libyang[0]: When condition "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPv6ANY'])" not satisfied. (path: /sonic-acl:sonic-acl/ACL_RU LE/ACL_RULE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4'][RULE_NAME='Rule_20']/SRC_IPV6) INFO:YANG-TEST:Configure IP_TYPE as ipv4any and SRC_IPV6 in ACL_RULE. Passed ------------------- Test 5: Configure l4_src_port_range as 99999-99999 in ACL_RULE--------------------- libyang[0]: Value "99999-99999" does not satisfy the constraint "([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])-([0-9]{1,4}|[0-5][0-9]{4}|[6][0-4][0-9]{3}|[6][5][0-2][0-9]{2}|[6][5][3][0-5]{2}|[6][5][3][6][0-5])" (range, length, or pattern). (path: /sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V6'][RULE_NAME='Rule_20']/L4_SRC_PORT_RANGE) INFO:YANG-TEST:Configure l4_src_port_range as 99999-99999 in ACL_RULE Passed INFO:YANG-TEST: ------------------- Test 6: Configure empty string as ip-prefix in INTERFACE table.--------------------- libyang[0]: Invalid value "" in "ip-prefix" element. (path: /sonic-interface:sonic-interface/INTERFACE/INTERFACE_LIST[interface='Ethernet8'][ip-prefix='']/ip-prefix) INFO:YANG-TEST:Configure empty string as ip-prefix in INTERFACE table. Passed INFO:YANG-TEST: ------------------- Test 7: Configure Wrong family with ip-prefix for VLAN_Interface Table--------------------- libyang[0]: Must condition "(contains(../ip-prefix, ':') and current()='IPv6') or (contains(../ip-prefix, '.') and current()='IPv4')" not satisfied. (path: /sonic-vlan:sonic-vlan/VLAN_INTERFACE/VLAN_INTERFACE_LIST[vlanid='100'][ip-prefix='2a04:5555:66:7777::1/64']/family) INFO:YANG-TEST:Configure Wrong family with ip-prefix for VLAN_Interface Table Passed INFO:YANG-TEST: ------------------- Test 8: Configure IP_TYPE as ARP and DST_IPV6 in ACL_RULE.--------------------- libyang[0]: When condition "boolean(IP_TYPE[.='ANY' or .='IP' or .='IPV6' or .='IPV6ANY'])" not satisfied. (path: /sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='NO-NS W-PACL-V6'][RULE_NAME='Rule_20']/DST_IPV6) INFO:YANG-TEST:Configure IP_TYPE as ARP and DST_IPV6 in ACL_RULE. Passed INFO:YANG-TEST: ------------------- Test 9: Configure INNER_ETHER_TYPE as 0x080C in ACL_RULE.--------------------- libyang[0]: Value "0x080C" does not satisfy the constraint "(0x88CC|0x8100|0x8915|0x0806|0x0800|0x86DD|0x8847)" (range, length, or pattern). (path: /sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V4'][RULE_NAME='Rule_40']/INNER_ETHER_TYPE) INFO:YANG-TEST:Configure INNER_ETHER_TYPE as 0x080C in ACL_RULE. Passed INFO:YANG-TEST: ------------------- Test 10: Add dhcp_server which is not in correct ip-prefix format.--------------------- libyang[0]: Invalid value "10.186.72.566" in "dhcp_servers" element. (path: /sonic-vlan:sonic-vlan/VLAN/VLAN_LIST/dhcp_servers[.='10.186.72.566']) INFO:YANG-TEST:Add dhcp_server which is not in correct ip-prefix format. Passed INFO:YANG-TEST: ------------------- Test 11: Configure undefined acl_table_type in ACL_TABLE table.--------------------- libyang[0]: Invalid value "LAYER3V4" in "type" element. (path: /sonic-acl:sonic-acl/ACL_TABLE/ACL_TABLE_LIST[ACL_TABLE_NAME='NO-NSW-PACL-V6']/type) INFO:YANG-TEST:Configure undefined acl_table_type in ACL_TABLE table. Passed INFO:YANG-TEST: ------------------- Test 12: Configure undefined packet_action in ACL_RULE table.--------------------- libyang[0]: Invalid value "SEND" in "PACKET_ACTION" element. (path: /sonic-acl:sonic-acl/ACL_RULE/ACL_RULE_LIST/PACKET_ACTION) INFO:YANG-TEST:Configure undefined packet_action in ACL_RULE table. Passed INFO:YANG-TEST: ------------------- Test 13: Configure wrong value for tagging_mode.--------------------- libyang[0]: Invalid value "non-tagged" in "tagging_mode" element. (path: /sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST/tagging_mode) INFO:YANG-TEST:Configure wrong value for tagging_mode. Passed INFO:YANG-TEST: ------------------- Test 14: Configure vlan-id in VLAN_MEMBER table which does not exist in VLAN table.--------------------- libyang[0]: Leafref "../../../VLAN/VLAN_LIST/vlanid" of value "200" points to a non-existing leaf. (path: /sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='200'][port='Ethernet0']/vlanid) libyang[0]: Leafref "../../../VLAN/VLAN_LIST/vlanid" of value "200" points to a non-existing leaf. (path: /sonic-vlan:sonic-vlan/VLAN_MEMBER/VLAN_MEMBER_LIST[vlanid='200'][port='Ethernet0']/vlanid) INFO:YANG-TEST:Configure vlan-id in VLAN_MEMBER table which does not exist in VLAN table. Passed INFO:YANG-TEST:All Test Passed ../../target/debs/stretch/libyang0.16_0.16.105-1_amd64.deb installtion failed ../../target/debs/stretch/libyang-cpp0.16_0.16.105-1_amd64.deb installtion failed ../../target/debs/stretch/python2-yang_0.16.105-1_amd64.deb installtion failed YANG Tests passed Passed: pyang -f tree ./yang-models/*.yang > ./yang-models/sonic_yang_tree copying tests/yangModelTesting.py -> build/lib/tests copying tests/test_sonic_yang_models.py -> build/lib/tests copying tests/__init__.py -> build/lib/tests running egg_info writing top-level names to sonic_yang_models.egg-info/top_level.txt writing dependency_links to sonic_yang_models.egg-info/dependency_links.txt writing sonic_yang_models.egg-info/PKG-INFO reading manifest file 'sonic_yang_models.egg-info/SOURCES.txt' writing manifest file 'sonic_yang_models.egg-info/SOURCES.txt' installing to build/bdist.linux-x86_64/wheel running install running install_lib creating build/bdist.linux-x86_64/wheel creating build/bdist.linux-x86_64/wheel/tests copying build/lib/tests/yangModelTesting.py -> build/bdist.linux-x86_64/wheel/tests copying build/lib/tests/test_sonic_yang_models.py -> build/bdist.linux-x86_64/wheel/tests copying build/lib/tests/__init__.py -> build/bdist.linux-x86_64/wheel/tests running install_data creating build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data creating build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data creating build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-head.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-acl.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-interface.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-loopback-interface.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-port.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-portchannel.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models copying ./yang-models/sonic-vlan.yang -> build/bdist.linux-x86_64/wheel/sonic_yang_models-1.0.data/data/yang-models ```
1 parent e04eb80 commit a02255e

20 files changed

+2795
-2
lines changed

files/build_templates/sonic_debian_extension.j2

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ sudo cp {{swsssdk_py2_wheel_path}} $FILESYSTEM_ROOT/$SWSSSDK_PY2_WHEEL_NAME
116116
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $SWSSSDK_PY2_WHEEL_NAME
117117
sudo rm -rf $FILESYSTEM_ROOT/$SWSSSDK_PY2_WHEEL_NAME
118118

119+
# Install sonic-yang-models py3 package, install dependencies
120+
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang_*.deb
121+
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/libyang-cpp_*.deb
122+
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/python2-yang_*.deb
123+
SONIC_YANG_MODEL_PY3_WHEEL_NAME=$(basename {{sonic_yang_models_py3_wheel_path}})
124+
sudo cp {{sonic_yang_models_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_YANG_MODEL_PY3_WHEEL_NAME
125+
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_YANG_MODEL_PY3_WHEEL_NAME
126+
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_YANG_MODEL_PY3_WHEEL_NAME
127+
119128
# Install sonic-platform-common Python 2 package
120129
PLATFORM_COMMON_PY2_WHEEL_NAME=$(basename {{platform_common_py2_wheel_path}})
121130
sudo cp {{platform_common_py2_wheel_path}} $FILESYSTEM_ROOT/$PLATFORM_COMMON_PY2_WHEEL_NAME

rules/sonic-yang-models-py3.mk

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SONIC_YANG_MODELS_PY3 = sonic_yang_models-1.0-py3-none-any.whl
2+
$(SONIC_YANG_MODELS_PY3)_SRC_PATH = $(SRC_PATH)/sonic-yang-models
3+
$(SONIC_YANG_MODELS_PY3)_PYTHON_VERSION = 3
4+
$(SONIC_YANG_MODELS_PY3)_DEBS_DEPENDS = $(LIBYANG)
5+
6+
SONIC_PYTHON_WHEELS += $(SONIC_YANG_MODELS_PY3)
7+
export SONIC_YANG_MODELS_PY3

slave.mk

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export BUILD_NUMBER
4949
export BUILD_TIMESTAMP
5050
export CONFIGURED_PLATFORM
5151
export CONFIGURED_ARCH
52+
export STRETCH_DEBS_PATH
53+
export PYTHON_WHEELS_PATH
5254

5355
###############################################################################
5456
## Utility rules
@@ -525,7 +527,8 @@ SONIC_TARGET_LIST += $(addprefix $(PYTHON_DEBS_PATH)/, $(SONIC_PYTHON_STDEB_DEBS
525527
# $(SOME_NEW_WHL)_DEPENDS = $(SOME_OTHER_WHL1) $(SOME_OTHER_WHL2) ...
526528
# SONIC_PYTHON_WHEELS += $(SOME_NEW_WHL)
527529
$(addprefix $(PYTHON_WHEELS_PATH)/, $(SONIC_PYTHON_WHEELS)) : $(PYTHON_WHEELS_PATH)/% : .platform $$(addsuffix -install,$$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*_DEPENDS))) \
528-
$(call dpkg_depend,$(PYTHON_WHEELS_PATH)/%.dep)
530+
$(call dpkg_depend,$(PYTHON_WHEELS_PATH)/%.dep) \
531+
$$(addsuffix -install,$$(addprefix $(DEBS_PATH)/,$$($$*_DEBS_DEPENDS)))
529532

530533
$(HEADER)
531534

@@ -750,7 +753,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
750753
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CONFIG_ENGINE)) \
751754
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_COMMON_PY2)) \
752755
$(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2)) \
753-
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2))
756+
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2)) \
757+
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3))
754758
$(HEADER)
755759
# Pass initramfs and linux kernel explicitly. They are used for all platforms
756760
export debs_path="$(STRETCH_DEBS_PATH)"
@@ -780,6 +784,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
780784
export platform_common_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_COMMON_PY2))"
781785
export redis_dump_load_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2))"
782786
export install_debug_image="$(INSTALL_DEBUG_TOOLS)"
787+
export sonic_yang_models_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3))"
783788
export multi_instance="false"
784789

785790
$(foreach docker, $($*_DOCKERS),\

sonic-slave-stretch/Dockerfile.j2

+7
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ RUN pip install mockredispy==2.9.3
367367
RUN pip install pytest-runner==4.4
368368
RUN pip install setuptools==40.8.0
369369

370+
# For sonic_yang_mgmt build
371+
RUN pip install ijson==2.6.1
372+
RUN pip3 install ijson==2.6.1
373+
RUN pip install jsondiff==1.2.0
374+
RUN pip install xmltodict==0.12.0
375+
RUN pip install pyang==2.1.1
376+
370377
# For mgmt-framework build
371378
RUN pip install mmh3
372379

src/sonic-yang-models/AUTHORS.rst

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=======
2+
Credits
3+
=======
4+
5+
Development Lead
6+
----------------
7+
8+
LNOS-CODERS <[email protected]>
9+
MSFT-LINUX-DEV <[email protected]>
10+
11+
Contributors
12+
------------
13+
14+
Praveen Chaudhary <[email protected]>

src/sonic-yang-models/LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2019 Microsoft, Inc
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

src/sonic-yang-models/README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"
2+
This Package contains YANG models for sonic which are written with guidelines mentioned in
3+
https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md.
4+
"

src/sonic-yang-models/setup.py

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""The setup script."""
5+
6+
from setuptools import setup, find_packages
7+
from setuptools.command.build_py import build_py
8+
from os import system, environ
9+
from sys import exit
10+
11+
# find path of pkgs from environment vars
12+
prefix = '/sonic'; debs = environ["STRETCH_DEBS_PATH"]
13+
deps_path = '{}/{}'.format(prefix, debs)
14+
# dependencies
15+
libyang = '{}/{}'.format(deps_path, environ["LIBYANG"])
16+
libyangCpp = '{}/{}'.format(deps_path, environ["LIBYANG_CPP"])
17+
libyangPy2 = '{}/{}'.format(deps_path, environ["LIBYANG_PY2"])
18+
libyangPy3 = '{}/{}'.format(deps_path, environ["LIBYANG_PY3"])
19+
20+
# important reuirements parameters
21+
build_requirements = [libyang, libyangCpp, libyangPy2, libyangPy3,]
22+
23+
setup_requirements = ['pytest-runner']
24+
25+
test_requirements = ['pytest>=3']
26+
27+
# read me
28+
with open('README.rst') as readme_file:
29+
readme = readme_file.read()
30+
31+
# class for prerequisites to build this package
32+
class pkgBuild(build_py):
33+
"""Custom Build PLY"""
34+
35+
def run (self):
36+
# install libyang
37+
for req in build_requirements:
38+
if '.deb'in req:
39+
pkg_install_cmd = "sudo dpkg -i {}".format(req)
40+
if (system(pkg_install_cmd)):
41+
print("{} installation failed".format(req))
42+
exit(1)
43+
else:
44+
print("{} installed".format(req))
45+
46+
# json file for YANG model test cases.
47+
test_yangJson_file = './tests/yang_model_tests/yangTest.json'
48+
# YANG models are in below dir
49+
yang_model_dir = './yang-models/'
50+
# yang model tester python module
51+
yang_test_py = './tests/yang_model_tests/yangModelTesting.py'
52+
# run tests for yang models
53+
test_yang_cmd = "python {} -f {} -y {}".format(yang_test_py, test_yangJson_file, yang_model_dir)
54+
if (system(test_yang_cmd)):
55+
print("YANG Tests failed\n")
56+
# below line will be uncommented after libyang python support PR #
57+
exit(1)
58+
else:
59+
print("YANG Tests passed\n")
60+
61+
# Generate YANG Tree
62+
pyang_tree_cmd = "pyang -f tree ./yang-models/*.yang > ./yang-models/sonic_yang_tree"
63+
if (system(pyang_tree_cmd)):
64+
print("Failed: {}".format(pyang_tree_cmd))
65+
else:
66+
print("Passed: {}".format(pyang_tree_cmd))
67+
68+
# Continue usual build steps
69+
build_py.run(self)
70+
71+
setup(
72+
cmdclass={
73+
'build_py': pkgBuild,
74+
},
75+
author="lnos-coders",
76+
author_email='[email protected]',
77+
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
78+
classifiers=[
79+
'Development Status :: 2 - Pre-Alpha',
80+
'Intended Audience :: Developers',
81+
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
82+
'Natural Language :: English',
83+
"Programming Language :: Python :: 2",
84+
'Programming Language :: Python :: 2.7',
85+
'Programming Language :: Python :: 3',
86+
'Programming Language :: Python :: 3.5',
87+
'Programming Language :: Python :: 3.6',
88+
'Programming Language :: Python :: 3.7',
89+
'Programming Language :: Python :: 3.8',
90+
],
91+
description="Package contains YANG models for sonic.",
92+
tests_require = test_requirements,
93+
license="GNU General Public License v3",
94+
long_description=readme + '\n\n',
95+
include_package_data=True,
96+
keywords='sonic_yang_models',
97+
name='sonic_yang_models',
98+
py_modules=[],
99+
packages=find_packages(),
100+
setup_requires=setup_requirements,
101+
version='1.0',
102+
data_files=[
103+
('yang-models', ['./yang-models/sonic-types.yang',
104+
'./yang-models/sonic-extension.yang',
105+
'./yang-models/sonic-acl.yang',
106+
'./yang-models/sonic-interface.yang',
107+
'./yang-models/sonic-loopback-interface.yang',
108+
'./yang-models/sonic-port.yang',
109+
'./yang-models/sonic-portchannel.yang',
110+
'./yang-models/sonic-vlan.yang',
111+
'./yang-models/sonic_yang_tree']),
112+
],
113+
zip_safe=False,
114+
)
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""Unit test package for sonic_yang_models."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
"""Tests for `sonic_yang_models` package."""
5+
6+
import pytest
7+
8+
@pytest.fixture
9+
def response():
10+
"""Sample pytest fixture.
11+
12+
See more at: http://doc.pytest.org/en/latest/fixture.html
13+
"""
14+
# import requests
15+
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')
16+
17+
18+
def test_content(response):
19+
"""Sample pytest test function with the pytest fixture as an argument."""
20+
# from bs4 import BeautifulSoup
21+
# assert 'GitHub' in BeautifulSoup(response.content).title.string

0 commit comments

Comments
 (0)