Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sonic-yang-mgmt]: sonic-yang-mgmt package for configuration validation. #3861

Merged
merged 18 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
310bff8
[sonic-yang-mgmt]: Basic build infra for sonic-yang-mgmt package.
Dec 9, 2019
fbfa732
[sonic-yang-mgmt/setup.py]: Change Python tag from Py2 to Py.
Mar 18, 2020
de86133
[sonic_yang.py]: Dev Code for Python Config Validation Librabry.
Mar 20, 2020
15a471c
[libyang-python-tests]: Bring in test code for Python Library.
Apr 7, 2020
ae53c36
[sonic-yang-mgmt-py2.mk]: Falling back to PY2.
Apr 7, 2020
c46dbd5
[sonic-yang-mgmt]: Resolving LGTM.
Apr 9, 2020
a3a8109
[_sonic_yang_ext.py]: Stores modules irrespective of top-level-contai…
Apr 13, 2020
6debe61
[_sonic_yang_ext.py]: Process container and leaves in container.
Apr 17, 2020
7596515
[_sonic_yang_ext.py]: Test Code for Process container and leaves in c…
Apr 23, 2020
334e528
[sonic_yang_ext.py]: Rename _sonic_yang_ext.py as sonic_yang_ext.py.
Apr 24, 2020
524b5cd
[setup.py]: Add IMAGE_DISTRO_DEBS_PATH after recent master branch cha…
Apr 24, 2020
49c46a6
Address feedback from pull request Azure#3874.
li-pingmao Mar 22, 2020
fb66b2c
[libyang-python-tests/test_sonic_yang.py]: Allow extra tables in conf…
Apr 27, 2020
57db247
[sonic-yang-mgmt-py2.dep]: DEP files for sonic-yang-mgmt-py2 PKG
May 8, 2020
f82637a
[tests/libyang-python-tests]: Changing yang models to generic and rem…
May 8, 2020
977df0a
[sonic_yang_ext.py]: Store Tables without YANG models seperately for …
Apr 27, 2020
97c266e
[sonic-yang-mgmt]: Test for Store Tables without YANG models seperate…
Apr 27, 2020
84beafb
[sonic_yang.py]: Categories public and private functions.
May 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ SONIC_YANG_MODEL_PY3_WHEEL_NAME=$(basename {{sonic_yang_models_py3_wheel_path}})
sudo cp {{sonic_yang_models_py3_wheel_path}} $FILESYSTEM_ROOT/$SONIC_YANG_MODEL_PY3_WHEEL_NAME
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install $SONIC_YANG_MODEL_PY3_WHEEL_NAME
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_YANG_MODEL_PY3_WHEEL_NAME
# Install sonic-yang-mgmt Python package
SONIC_YANG_MGMT_PY_WHEEL_NAME=$(basename {{sonic_yang_mgmt_py_wheel_path}})
sudo cp {{sonic_yang_mgmt_py_wheel_path}} $FILESYSTEM_ROOT/$SONIC_YANG_MGMT_PY_WHEEL_NAME
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip install $SONIC_YANG_MGMT_PY_WHEEL_NAME
sudo rm -rf $FILESYSTEM_ROOT/$SONIC_YANG_MGMT_PY_WHEEL_NAME

# Install sonic-platform-common Python 2 package
PLATFORM_COMMON_PY2_WHEEL_NAME=$(basename {{platform_common_py2_wheel_path}})
Expand Down
10 changes: 10 additions & 0 deletions rules/sonic-yang-mgmt-py2.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

SPATH := $($(SONIC_YANG_MGMT_PY)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-yang-mgmt-py2.mk rules/sonic-yang-mgmt-py2.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
DEP_FILES += $(shell git ls-files $(SPATH))

$(SONIC_YANG_MGMT_PY)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_YANG_MGMT_PY)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_YANG_MGMT_PY)_DEP_FILES := $(DEP_FILES)

9 changes: 9 additions & 0 deletions rules/sonic-yang-mgmt-py2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# sonic-yang-mgmt python2 wheel

SONIC_YANG_MGMT_PY = sonic_yang_mgmt-1.0-py2-none-any.whl
$(SONIC_YANG_MGMT_PY)_SRC_PATH = $(SRC_PATH)/sonic-yang-mgmt
$(SONIC_YANG_MGMT_PY)_PYTHON_VERSION = 2
$(SONIC_YANG_MGMT_PY)_DEBS_DEPENDS = $(LIBYANG)
$(SONIC_YANG_MGMT_PY)_DEPENDS = $(SONIC_YANG_MODELS_PY3)

SONIC_PYTHON_WHEELS += $(SONIC_YANG_MGMT_PY)
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 3 additions & 2 deletions slave.mk
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ SONIC_TARGET_LIST += $(addprefix $(PYTHON_DEBS_PATH)/, $(SONIC_PYTHON_STDEB_DEBS
$(addprefix $(PYTHON_WHEELS_PATH)/, $(SONIC_PYTHON_WHEELS)) : $(PYTHON_WHEELS_PATH)/% : .platform $$(addsuffix -install,$$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*_DEPENDS))) \
$(call dpkg_depend,$(PYTHON_WHEELS_PATH)/%.dep) \
$$(addsuffix -install,$$(addprefix $(DEBS_PATH)/,$$($$*_DEBS_DEPENDS)))

$(HEADER)

# Load the target deb from DPKG cache
Expand Down Expand Up @@ -786,7 +785,8 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_COMMON_PY2)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PLATFORM_API_PY2)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3))
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3)) \
$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MGMT_PY))
$(HEADER)
# Pass initramfs and linux kernel explicitly. They are used for all platforms
export debs_path="$(IMAGE_DISTRO_DEBS_PATH)"
Expand Down Expand Up @@ -817,6 +817,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
export redis_dump_load_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(REDIS_DUMP_LOAD_PY2))"
export install_debug_image="$(INSTALL_DEBUG_TOOLS)"
export sonic_yang_models_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MODELS_PY3))"
export sonic_yang_mgmt_py_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_YANG_MGMT_PY))"
export multi_instance="false"

$(foreach docker, $($*_DOCKERS),\
Expand Down
15 changes: 15 additions & 0 deletions src/sonic-yang-mgmt/AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=======
Credits
=======

Development Lead
----------------

LNOS-CODERS <lnos-coders@linkedin.com>
MSFT-LINUX-DEV <linuxnetdev@microsoft.com>

Contributors
------------

Praveen Chaudhary <pchaudhary@linkedin.com>
Ping Mao <pmao@linkedin.com>
13 changes: 13 additions & 0 deletions src/sonic-yang-mgmt/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2019 Microsoft, Inc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
6 changes: 6 additions & 0 deletions src/sonic-yang-mgmt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"
This package includes python yang libraries which will be used with sonic utilities
pacakge to validate the config. This python libraries are written on top of libyang
and also provides functionality to translate the config from SONiC ConfigDB to SONiC
YANG and vice-versa.
"
98 changes: 98 additions & 0 deletions src/sonic-yang-mgmt/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env python
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
# -*- coding: utf-8 -*-

"""The setup script."""

from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
from os import system, environ
from sys import exit
import pytest

# find path of pkgs from os environment vars
prefix = '../../'; debs = environ["IMAGE_DISTRO_DEBS_PATH"]
wheels = environ["PYTHON_WHEELS_PATH"]
wheels_path = '{}/{}'.format(prefix, wheels)
deps_path = '{}/{}'.format(prefix, debs)
# dependencies
libyang = '{}/{}'.format(deps_path, environ["LIBYANG"])
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
libyangCpp = '{}/{}'.format(deps_path, environ["LIBYANG_CPP"])
libyangPy2 = '{}/{}'.format(deps_path, environ["LIBYANG_PY2"])
libyangPy3 = '{}/{}'.format(deps_path, environ["LIBYANG_PY3"])
sonicYangModels = '{}/{}'.format(wheels_path, environ["SONIC_YANG_MODELS_PY3"])

# important reuirements parameters
build_requirements = [libyang, libyangCpp, libyangPy2, libyangPy3, sonicYangModels,]

setup_requirements = ['pytest-runner']

test_requirements = ['pytest>=3']

# read me
with open('README.rst') as readme_file:
readme = readme_file.read()

# class for prerequisites to build this package
class pkgBuild(build_py):
"""Custom Build PLY"""

def run (self):
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
# install libyang and sonic_yang_models
for req in build_requirements:
if '.deb' in req:
pkg_install_cmd = "sudo dpkg -i {}".format(req)
if (system(pkg_install_cmd)):
print("{} installation failed".format(req))
exit(1)
else:
print("{} installed".format(req))
elif '.whl' in req:
pkg_install_cmd = "pip3 install {}".format(req)
if (system(pkg_install_cmd)):
print("{} installation failed".format(req))
exit(1)
else:
print("{} installed".format(req))

praveen-li marked this conversation as resolved.
Show resolved Hide resolved
# run pytest for libyang python APIs
self.pytest_args = []
errno = pytest.main(self.pytest_args)
if (errno):
exit(errno)

# Continue usual build steps
build_py.run(self)

setup(
cmdclass={
'build_py': pkgBuild,
},
author="lnos-coders",
author_email='lnos-coders@linkedin.com',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
'Natural Language :: English',
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
description="Package contains Python Library for YANG for sonic.",
tests_require = test_requirements,
license="GNU General Public License v3",
long_description=readme + '\n\n',
include_package_data=True,
keywords='sonic_yang_mgmt',
name='sonic_yang_mgmt',
py_modules=['sonic_yang', 'sonic_yang_ext'],
packages=find_packages(),
setup_requires=setup_requirements,
version='1.0',
zip_safe=False,
)
Loading