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

[setup.py]: Build infrastructure files for sonic_yang_mgmt Package. #6

Merged
merged 3 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
6 changes: 6 additions & 0 deletions rules/sonic-yang-mgmt-py2.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# sonic-yang-mgmt python2 wheel

SONIC_YANG_MGMT_PY2 = sonic_yang_mgmt-1.0-py2-none-any.whl
$(SONIC_YANG_MGMT_PY2)_SRC_PATH = $(SRC_PATH)/sonic-yang-mgmt
$(SONIC_YANG_MGMT_PY2)_PYTHON_VERSION = 2
SONIC_PYTHON_WHEELS += $(SONIC_YANG_MGMT_PY2)
3 changes: 3 additions & 0 deletions sonic-slave-stretch/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ RUN pip install mockredispy==2.9.3
RUN pip install pytest-runner==4.4
RUN pip install setuptools==40.8.0

# For sonic_yang_mgmt build
RUN pip install ijson

# Install dependencies for isc-dhcp-relay build
RUN apt-get -y build-dep isc-dhcp

Expand Down
3 changes: 3 additions & 0 deletions sonic-slave/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ RUN pip install mockredispy==2.9.3
RUN pip install pytest-runner==4.4
RUN pip install setuptools==40.8.0

# For sonic_yang_mgmt build
RUN pip install ijson

# Install dependencies for isc-dhcp-relay build
RUN apt-get -y build-dep isc-dhcp

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 <[email protected]>
MSFT-LINUX-DEV <[email protected]>

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

Praveen Chaudhary <[email protected]>
Ping Mao <[email protected]>
32 changes: 32 additions & 0 deletions src/sonic-yang-mgmt/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2019 Praveen Chaudhary

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

7 changes: 7 additions & 0 deletions src/sonic-yang-mgmt/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"
This Package contains YANG models for sonic which are written with guidelines mentioned in
https://github.com/Azure/SONiC/blob/master/doc/mgmt/SONiC_YANG_Model_Guidelines.md.

In future this package will include python yang libraries which will be used with sonic utilities
pacakge to validate the config.
"
99 changes: 99 additions & 0 deletions src/sonic-yang-mgmt/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""

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


# important reuirements parameters
build_requirements = ['../../target/debs/stretch/libyang0.16_0.16.105-1_amd64.deb',
praveen-li marked this conversation as resolved.
Show resolved Hide resolved
'../../target/debs/stretch/libyang-cpp0.16_0.16.105-1_amd64.deb',
'../../target/debs/stretch/python2-yang_0.16.105-1_amd64.deb']

install_requirements = []

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):
# json file for YANG model test cases.
test_yangJson_file = './tests/yang-model-tests/yangTest.json'
# YANG models are in below dir
yang_model_dir = './yang-models/'
# yang model tester python module
yang_test_py = './tests/yang-model-tests/yangModelTesting.py'
# install libyang
for req in build_requirements:
if 'target/debs'in req:
pkg_install_cmd = "sudo dpkg -i {}".format(req)
if (system(pkg_install_cmd)):
print("{} installed".format(req))
else:
print("{} installtion failed".format(req))

# run tests for yang models
test_yang_cmd = "python {} -f {} -y {}".format(yang_test_py, test_yangJson_file, yang_model_dir)
if (system(test_yang_cmd)):
print("YANG Tests failed\n")
# below line will be uncommented after libyang python support PR #
exit(1)
else:
print("YANG Tests passed\n")

# Continue usual build steps
build_py.run(self)


setup(
cmdclass={
'build_py': pkgBuild,
},
author="lnos-coders",
author_email='[email protected]',
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 YANG models for sonic.",
install_requires=install_requirements,
license="GNU General Public License v3",
long_description=readme + '\n\n',
include_package_data=True,
keywords='sonic_yang_mgmt',
name='sonic_yang_mgmt',
packages=find_packages(),
setup_requires=setup_requirements,
version='1.0',
data_files=[
('yang-models', ['./yang-models/sonic-head.yang',
'./yang-models/sonic-acl.yang',
'./yang-models/sonic-interface.yang',
'./yang-models/sonic-port.yang',
'./yang-models/sonic-portchannel.yang',
'./yang-models/sonic-vlan.yang']),
],
zip_safe=False,
)
3 changes: 3 additions & 0 deletions src/sonic-yang-mgmt/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

"""Unit test package for sonic_yang_mgmt."""
21 changes: 21 additions & 0 deletions src/sonic-yang-mgmt/tests/test_sonic_yang_mgmt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for `sonic_yang_mgmt` package."""

import pytest

@pytest.fixture
def response():
"""Sample pytest fixture.

See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string
2 changes: 2 additions & 0 deletions src/sonic-yang-mgmt/yang-models/sonic-acl.yang
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module sonic-acl {

yang-version 1.1;

namespace "http://github.com/Azure/sonic-acl";
prefix acl;

Expand Down