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_ext.py]: Using python mixin to extend sonic_yang class i… #65

Merged

Conversation

praveen-li
Copy link
Collaborator

@praveen-li praveen-li commented Apr 9, 2020

…nto 2 files and resolving Other LGTM issues.

Changes:
1.) Moved al functions of _sonic_yang_ext.py file in sonic_yang_ext_mixin class.
2.) Use this class in sonic_yang to extend funtionality.
3.) Solve Other LGTM issues from
https://lgtm.com/projects/g/Azure/sonic-buildimage/rev/pr-0f82616403c02577e1155347eb5b693a51c76a9e

Note: Code shows big diff due to TAB, otherwise I am just moving all functions inside a class which does not have init.

Note: Python mixin are different from parent class since it can access all variables

of the class which is using it.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com

- What I did
Using Python Mixine to extend the capability of sonic Yang class.

This is done to avoid below error. This was a warning in PY2 but in PY3, it is treated as high level error. So to convert the package into a PY3 in future, we need to resolve this problem sooner or later.

import * only allowed at module level

due to below line:

import all function from extension file
-    """
-    from _sonic_yang_ext import *

Other minor LGTM issues.

- How I did it

PY mixin is a way, which looks similar to inheritance, but the class which seems like a parent class can access all the variable of child class. So PY mixin in actually extend the functionality of another class. Also it is the recommended way to write a single class into multiple files.

- How to verify it
Mixin testing:
UnInstall previous package and install new package:

admin@lnos-x1-a-fab01:~/test_pc_load_yang$ sudo pip uninstall sonic_yang_mgmt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Found existing installation: sonic-yang-mgmt 1.0
Uninstalling sonic-yang-mgmt-1.0:
  Would remove:
    /usr/local/lib/python2.7/dist-packages/_sonic_yang_ext.py
    /usr/local/lib/python2.7/dist-packages/sonic_yang.py
    /usr/local/lib/python2.7/dist-packages/sonic_yang_mgmt-1.0.dist-info/*
    /usr/local/lib/python2.7/dist-packages/tests/*
Proceed (y/n)? y
  Successfully uninstalled sonic-yang-mgmt-1.0
admin@lnos-x1-a-fab01:~/test_pc_load_yang$ ls
new_port_config.json  _sonic_yang_ext.py_orig  sonic_yang_mgmt-1.0-py2-none-any.whl
admin@lnos-x1-a-fab01:~/test_pc_load_yang$ sudo pip install sonic_yang_mgmt-1.0-py2-none-any.whl
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Processing ./sonic_yang_mgmt-1.0-py2-none-any.whl
Installing collected packages: sonic-yang-mgmt
Successfully installed sonic-yang-mgmt-1.0

Check that files are updated and has new code:

admin@lnos-x1-a-fab01:~/test_pc_load_yang$ head -10 /usr/local/lib/python2.7/dist-packages/sonic_yang.py
import yang as ly
import syslog

from json import dump
from glob import glob
from _sonic_yang_ext import sonic_yang_ext_mixin

"""
Yang schema and data tree python APIs based on libyang python
Here, sonic_yang_ext_mixin extends funtionality of sonic_yang,

Running Breakout

Running Breakout Mode : 2x50G 
Target Breakout Mode : 4x25G

Ports to be deleted : 
 {
    "Ethernet6": "50000", 
    "Ethernet4": "50000"
}
Ports to be added : 
 {
    "Ethernet6": "25000", 
    "Ethernet7": "25000", 
    "Ethernet4": "25000", 
    "Ethernet5": "25000"
}

After running Logic to limit the impact

Final list of ports to be deleted : 
 {
    "Ethernet6": "50000", 
    "Ethernet4": "50000"
} 
Final list of ports to be added :  
 {
    "Ethernet6": "25000", 
    "Ethernet7": "25000", 
    "Ethernet7": "25000", 
    "Ethernet4": "25000", 
    "Ethernet5": "25000"
}


Loaded below Yang Models
['sonic-acl', 'sonic-extension', 'sonic-head', 'sonic-interface', 'sonic-loopback-interface', 'sonic-port', 
'sonic-portchannel', 'sonic-vlan']
Reading data from Redis configDb

Start Port Deletion
Find dependecies for port Ethernet6
Find dependecies for port Ethernet4
Deleting Port: Ethernet6
Deleting Port: Ethernet4
Data Validation successful
Generate Final Config to write in DB

Start Port Addition
Data Validation successful
Generate Final Config to write in DB
Writing in Config DB
Verify Port Deletion from Asic DB, Wait...
sudo redis-cli -n 1 hgetall "ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x1000000000815"
sudo redis-cli -n 1 hgetall "ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000007ec"
Writing in Config DB
Breakout process got successfully completed.

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@zhenggen-xu
Copy link
Owner

@praveen-li Can you resolve the conflicts?

Praveen Chaudhary added 2 commits June 29, 2020 17:29
…nto 2 files.

Changes:
1.) Moved al functions of _sonic_yang_ext.py file in sonic_yang_ext_mixin class.
2.) Use this class in sonic_yang to extend funtionality.

Note: Python mixin are different from parent class since it can access all variables
of the class which is using it.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
Changes:
To address 'import *' related LGTM alerts
1.) Moved all functions of _sonic_yang_ext.py file in sonic_yang_ext_mixin class.
2.) Use this class in sonic_yang to extend funtionality, i.e. python mixin.

Note: Python mixin are different from parent class since it can access all variables
of the class which is using it.

Other LGTM issues
3.) Address Other LGTM minor issues found in below link.
https://lgtm.com/projects/g/Azure/sonic-buildimage/rev/pr-0f82616403c02577e1155347eb5b693a51c76a9e

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
@praveen-li praveen-li merged commit e24eca5 into zhenggen-xu:sonic-cfg-mgmt Jun 30, 2020
zhenggen-xu pushed a commit that referenced this pull request Aug 31, 2020
[configdb.py]: Allow deletion of entire table from mod_config API. (#61)
[MultiDB] mimic redis-dump-load , adding sonic_db_dump_load.py and so… 
[MultiDB] add sonic-db-cli PING all instances support (#65)
Fix sonic-db-cli script to be compatible with python3 and python2.7 (#66)
Namespace support in SonicV2Connector (#63)
[Multiasic]: Add calculation of interface index for backplane interfa… 
praveen-li pushed a commit to praveen-li/sonic-buildimage that referenced this pull request Dec 23, 2022
[sonic-linkmgrd][202012] submodule update

3523738 Jing Zhang      Sun Apr 3 20:54:40 2022 -0700   Reset link prober state when default route is back zhenggen-xu#56
8282e78 Jing Zhang      Fri Apr 15 15:59:34 2022 -0700  Keep incrementing sequence number when link prober is suspended and shutdown zhenggen-xu#55 (zhenggen-xu#65)
8246eb8 Jing Zhang      Thu Apr 14 18:49:36 2022 -0700  Shutdown ICMP heartbeats when default route state is missing and ToR is in auto mode zhenggen-xu#44 (zhenggen-xu#59)

sign-off: Jing Zhang zhangjing@microsoft.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants