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-package-manager] support sonic-cli-gen and packages with YANG model #1650

Merged
merged 223 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
223 commits
Select commit Hold shift + click to select a range
2356869
[sonic-installer] migrate SONiC packages
stepanblyschak Nov 3, 2020
ece3845
fix temp dir path for chroot
stepanblyschak Nov 3, 2020
8bc75a7
fix for install of already installed image
stepanblyschak Nov 3, 2020
e72f540
move constants to the top
stepanblyschak Dec 15, 2020
1a6d5d9
Merge branch 'master' of github.com:azure/sonic-utilities into sonic-…
stepanblyschak Jan 5, 2021
be4f089
[sonic_installer] migrate packages from old docker library
stepanblyschak Jan 21, 2021
2240308
Merge branch 'master' of github.com:azure/sonic-utilities into sonic-…
stepanblyschak Mar 18, 2021
9fd283d
remove unused imports
stepanblyschak Mar 18, 2021
0cbaa3e
fix redefining path
stepanblyschak Mar 19, 2021
1a99797
[sonic-package-manager] add new utility to manage SONiC packages
stepanblyschak Mar 23, 2021
a80ecb0
Merge branch 'sonic-packages-migration' into spm
stepanblyschak Mar 23, 2021
06dfd30
add help for some options
stepanblyschak Mar 23, 2021
725210d
add command line reference for sonic-package-manager
stepanblyschak Mar 23, 2021
f2ee39f
fix upgrade command missing argument
stepanblyschak Mar 23, 2021
7bf937e
warm-reboot support for sonic packages
stepanblyschak Mar 25, 2021
c724569
iteritems -> items
stepanblyschak Mar 25, 2021
ac011a3
Merge branch 'spm' into spm_warm
stepanblyschak Mar 25, 2021
3dc793f
fix issue in metadata dict generation
stepanblyschak Mar 25, 2021
4e4a9ea
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Mar 25, 2021
ea14867
fix creator with service name
stepanblyschak Mar 25, 2021
faeadcf
default value for component constraint
stepanblyschak Mar 25, 2021
cd7d387
Merge branch 'spm' into spm_warm
stepanblyschak Mar 25, 2021
31138d0
fix passing installed_packages
stepanblyschak Mar 26, 2021
ae1ce45
Update doc/Command-Reference.md
stepanblyschak Mar 29, 2021
5c045e0
use defaultdict
stepanblyschak Mar 30, 2021
a1a97f9
fix internal review comments
stepanblyschak Mar 30, 2021
7a6c8d1
fix internal review comments
stepanblyschak Mar 30, 2021
c4b4225
use get_installed_packages_list() function
stepanblyschak Mar 31, 2021
f32d038
dont fail uninstall when no package in installed list
stepanblyschak Mar 31, 2021
83f2af6
drop support for monit as monit is getting deprecated
stepanblyschak Apr 1, 2021
d31497a
fix manifest representation
stepanblyschak Apr 1, 2021
c2eacdf
fix LGTM warning
stepanblyschak Apr 1, 2021
801ff85
Merge branch 'master' into spm
stepanblyschak Apr 8, 2021
f5ba246
fix review comments
stepanblyschak Apr 9, 2021
2dee5c6
fix review comments
stepanblyschak Apr 14, 2021
08c9c6d
[sonic_package_manager] add reset command
stepanblyschak Apr 15, 2021
42a2665
Merge branch 'master' into spm
stepanblyschak Apr 15, 2021
8bd4f5e
add yang
stepanblyschak Apr 16, 2021
413b44f
[doc] fix formatting
stepanblyschak Apr 16, 2021
78afedd
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into spm
stepanblyschak Apr 16, 2021
f101f1f
install takes a digest or tag as well
stepanblyschak Apr 16, 2021
4d03aa8
resolve review comments
stepanblyschak Apr 20, 2021
180eae3
remove config when uninstalling
stepanblyschak Apr 20, 2021
3b98489
fix lgtm error
stepanblyschak Apr 20, 2021
3280b5b
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
21ae66b
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
5548976
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
5a2675d
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
68f90f5
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
e7f1c59
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
ae5bad9
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
909079a
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
a394b27
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
9653c61
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
0e96ddb
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
9090a47
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
b2eeb59
Update doc/Command-Reference.md
stepanblyschak Apr 21, 2021
e765d5d
review comments
stepanblyschak Apr 21, 2021
24fb439
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into spm
stepanblyschak Apr 21, 2021
5991557
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 22, 2021
fd46c34
fix upgrade rollback
stepanblyschak Apr 22, 2021
c8a3cbf
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 22, 2021
1348a6e
remove trailing spaces
stepanblyschak Apr 22, 2021
f4449c1
remove trailing spaces
stepanblyschak Apr 22, 2021
8fd0084
remove trailing spaces
stepanblyschak Apr 22, 2021
b065eaf
yang
stepanblyschak Apr 23, 2021
86bf53f
address review comments
stepanblyschak Apr 23, 2021
3f9c317
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 23, 2021
84e0b58
yang
stepanblyschak Apr 26, 2021
1ace0e1
fix command line options for install/upgrade
stepanblyschak Apr 26, 2021
4578e87
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 26, 2021
5133947
yang
stepanblyschak Apr 26, 2021
0fc6463
fix bug when have components constraints
stepanblyschak Apr 26, 2021
b23ac17
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 26, 2021
6feda36
fix bug when have components constraints
stepanblyschak Apr 26, 2021
e0f9699
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 26, 2021
a2f7649
Merge branch 'master' into spm
stepanblyschak Apr 26, 2021
548896a
Worked version
vadymhlushko-mlnx Apr 22, 2021
3350f27
added stub for function to determine static or dynamic YANG
vadymhlushko-mlnx Apr 23, 2021
1d1643a
_find_index_of_yang_model()
vadymhlushko-mlnx Apr 26, 2021
cd31f0d
added function to init list's for module, top, tables
vadymhlushko-mlnx Apr 26, 2021
81b803d
Added func to determine - static or list, +comments
vadymhlushko-mlnx Apr 26, 2021
ecdf8b6
Added auto compleation file
vadymhlushko-mlnx Apr 28, 2021
42779c7
Add CLI Jinja templates
stepanblyschak Apr 28, 2021
12bf0b2
Fix the generated function name is incorrect
stepanblyschak Apr 28, 2021
0d5dfcf
Fix review comments
stepanblyschak Apr 28, 2021
4c2f986
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into spm
stepanblyschak Apr 28, 2021
c8eaa66
update and enhance templates with multiple lists in container
stepanblyschak Apr 29, 2021
dd29e33
fix cli templates
stepanblyschak Apr 29, 2021
0b0a0c1
Merge branch 'master' of github.com:azure/sonic-utilities into sonic-…
stepanblyschak Apr 29, 2021
3c1b429
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak Apr 30, 2021
e91ff81
fix script
stepanblyschak Apr 30, 2021
b87e6fd
Merge branch 'master' of github.com:azure/sonic-utilities into spm_warm
stepanblyschak Apr 30, 2021
62e2646
fix unresolved conftest.py
stepanblyschak Apr 30, 2021
79cabb2
fix unresolved test_service_creator.py
stepanblyschak Apr 30, 2021
a23fe44
fix lgtm warning
stepanblyschak Apr 30, 2021
16857c4
add clear list command
stepanblyschak Apr 29, 2021
f4be579
fix lgtm warning
stepanblyschak Apr 30, 2021
dfa3ccc
Parsing for static YANG models - sonic-flex_counter.yang, sonic-devic…
vadymhlushko-mlnx Apr 30, 2021
6b75f4b
Done refactoring for parsing 'static' YANG models
vadymhlushko-mlnx May 5, 2021
d2be52b
Added parsing for 'dynamic' YANG models, done refactoring of whole code
vadymhlushko-mlnx May 6, 2021
73a3b12
Done parser for 'grouping' BUT need to deeply test it, added function…
vadymhlushko-mlnx May 12, 2021
718f8ab
align with implementation
May 12, 2021
647537c
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
May 12, 2021
fa6299c
generate cli from templates
May 12, 2021
9d9f66b
Table can only have 'static-objects' OR 'dynamic-objects'
vadymhlushko-mlnx May 12, 2021
38f4365
add missing " in help for option
May 12, 2021
591aced
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
May 12, 2021
0826ac5
Added remove_keys(), get_mandatory()
vadymhlushko-mlnx May 12, 2021
069000f
fix issues
May 12, 2021
594acce
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
May 12, 2021
53111a8
Merge branch 'master' of github.com:azure/sonic-utilities into spm_warm
stepanblyschak May 13, 2021
0ba3cf4
improve manifest types validation
stepanblyschak May 13, 2021
9ec118c
Merge branch 'spm' of github.com:stepanblyschak/sonic-utilities into …
stepanblyschak May 13, 2021
b33c79a
Merge branch 'master' of github.com:azure/sonic-utilities into spm-yang
stepanblyschak May 13, 2021
782a353
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 13, 2021
1723f0f
Refactored generator.py: generate_cli_plugin(), get_cli_plugin_path()
vadymhlushko-mlnx May 13, 2021
bfc08e8
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 13, 2021
705d4e6
Merge branch 'spm_warm' of github.com:stepanblyschak/sonic-utilities …
stepanblyschak May 13, 2021
3f03594
remove redundant file
stepanblyschak May 13, 2021
1554f00
fix docstrings
stepanblyschak May 13, 2021
f7681b0
Merge branch 'spm_warm' of github.com:stepanblyschak/sonic-utilities …
stepanblyschak May 13, 2021
dccff0b
use swsscommon.ConfigDBConnector
stepanblyschak May 13, 2021
0a78e19
Removed arguments from constructor of class CliGenerator, added funct…
vadymhlushko-mlnx May 13, 2021
f0fdbe2
integrate with cli generation tool
stepanblyschak May 14, 2021
5784d6c
fix manager
stepanblyschak May 14, 2021
65b125c
[sonic-cli-gen]
stepanblyschak May 14, 2021
134b21e
[sonic-cli-gen]
stepanblyschak May 14, 2021
049823f
manager fixes
stepanblyschak May 14, 2021
30d2cb9
Added sceleton for UT, added additional check for yang_parser.py, cha…
vadymhlushko-mlnx May 14, 2021
0d371de
Refactored _init_yang_module_and_containers()
vadymhlushko-mlnx May 14, 2021
1593039
added 2 test cases
vadymhlushko-mlnx May 14, 2021
867d9c1
[sonic_package_manager] flush once finished saving docker image into …
stepanblyschak May 17, 2021
3f00843
move cli autogen to ServiceCreator
stepanblyschak May 17, 2021
b3b0a8e
Revert "[sonic-cli-gen]"
stepanblyschak May 17, 2021
def7607
Revert "[sonic-cli-gen]"
stepanblyschak May 17, 2021
79071b1
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 17, 2021
ada4ca4
[sonic-cli-gen] add remove plugin method
stepanblyschak May 17, 2021
661aefb
align method signature with CliGenerator
stepanblyschak May 17, 2021
ad7ee33
[sonic-cli-gen] put autogenerated plugins into plugins.auto
stepanblyschak May 17, 2021
087c527
fix wrong parameters order when creating ServiceCreator
stepanblyschak May 17, 2021
471a128
[sonic-cli-gen] fix show.py.j2 template
stepanblyschak May 17, 2021
9c0aa8b
add an option to keep features config
stepanblyschak May 17, 2021
c3350d3
fix remove() got an unexpected keyword argumet register_feature
stepanblyschak May 17, 2021
9004c1c
[sonic-cli-gen] put autogenerated plugins into plugins.auto
stepanblyschak May 17, 2021
32e27a2
[sonic-cli-gen] fix show.py.j2 template
stepanblyschak May 17, 2021
02e6d27
[sonic-cli-gen] add remove plugin method
stepanblyschak May 17, 2021
41da5ed
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 17, 2021
ea97d66
python module name in plugins can be just simply a package name
stepanblyschak May 17, 2021
0f7e896
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 17, 2021
562a008
Merge branch 'sae-integration' of github.com:stepanblyschak/sonic-uti…
stepanblyschak May 17, 2021
cb7fa06
refactored past test cases, added new
vadymhlushko-mlnx May 17, 2021
5737f5f
added test_dynamic_object_complex
vadymhlushko-mlnx May 17, 2021
a56bbb0
[sonic-cli-gen] implement grouping in show template
stepanblyschak May 18, 2021
7b167a6
[sonic-cli-gen] implement grouping in show template
stepanblyschak May 18, 2021
16e0cca
Reworked 'grouping' parser
vadymhlushko-mlnx May 18, 2021
b0fb3a9
Added 'group' to 'attrs'
vadymhlushko-mlnx May 18, 2021
2008cbc
[sonic-package-manager] update feature configuration in case it requi…
stepanblyschak May 18, 2021
a282872
Improvements and fixes
stepanblyschak May 19, 2021
e2acf73
Fixed 'grouping' parsing
vadymhlushko-mlnx May 19, 2021
3305faa
DONE. ALL UT PASSED
vadymhlushko-mlnx May 19, 2021
30e8ac9
Refactored UT
vadymhlushko-mlnx May 19, 2021
15aeb8c
Added docstrings, fixed names of variables
vadymhlushko-mlnx May 19, 2021
ea2c838
Added test_grouping_complex to the execution pipeline
vadymhlushko-mlnx May 19, 2021
f7a7ed2
Merge remote-tracking branch 'vadymh/sonic-cli-gen' into sonic-cli-gen
vadymhlushko-mlnx May 20, 2021
e18c888
Removed unused test YANG model
vadymhlushko-mlnx May 20, 2021
7bd3ec9
Fixed indentation
vadymhlushko-mlnx May 21, 2021
d5dea7f
Added sonic-cli-gen remove cmd, reworked private initializer functions
vadymhlushko-mlnx May 21, 2021
b0d2171
[sonic-cli-gen] address review comments
stepanblyschak May 21, 2021
aa4af1c
Added new lines, fixed some docstrings
vadymhlushko-mlnx May 24, 2021
718a431
removed type from docstring
vadymhlushko-mlnx May 24, 2021
2907523
Added list_handler()
vadymhlushko-mlnx May 24, 2021
c2b1a32
[sonic-cli-gen] fix review comments
stepanblyschak May 24, 2021
a005d6d
[sonic-cli-gen] address review comments
stepanblyschak May 21, 2021
aa00b61
[sonic-cli-gen] fix review comments
stepanblyschak May 24, 2021
fd931ad
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 24, 2021
5c4e219
Fixed comments, added list_handler() where needed
vadymhlushko-mlnx May 24, 2021
6de672c
Added logger to CliGenerator class constructor
vadymhlushko-mlnx May 24, 2021
2a2f9f2
Merge remote-tracking branch 'vadymh/sonic-cli-gen' into sonic-cli-gen
vadymhlushko-mlnx May 24, 2021
1584fe3
pep8 for generator.py
vadymhlushko-mlnx May 25, 2021
8f27d03
pep8 for the rest of files
vadymhlushko-mlnx May 25, 2021
aa6f806
pep8 for tests files, added comments to YANG models
vadymhlushko-mlnx May 25, 2021
83ce9ee
Added handler for 1 'choice' 'case'
vadymhlushko-mlnx May 25, 2021
702be74
Code style
vadymhlushko-mlnx May 25, 2021
c433a4c
Fixed review comments
vadymhlushko-mlnx May 26, 2021
ba45666
Merge branch 'spm_warm' of github.com:stepanblyschak/sonic-utilities …
stepanblyschak May 27, 2021
aa3a04d
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 27, 2021
a0c15ac
Merge branch 'sae-integration' into spm-yang
stepanblyschak May 27, 2021
6244efe
fix review comments
stepanblyschak May 31, 2021
fc771e1
Merge branch 'sonic-cli-gen' of github.com:vadymhlushko-mlnx/sonic-ut…
stepanblyschak May 31, 2021
8424b0b
fix review comments
stepanblyschak May 31, 2021
62b929f
Merge branch 'spm-yang' of github.com:stepanblyschak/sonic-utilities …
stepanblyschak Jun 1, 2021
fab17a9
fix review comments
stepanblyschak Jun 1, 2021
d64b04f
Merge branch 'master' of github.com:azure/sonic-utilities into spm-yang
stepanblyschak Jul 8, 2021
0aa7df7
fix LGTM warning
stepanblyschak Jul 8, 2021
b66a76d
Merge branch 'master' of github.com:azure/sonic-utilities into HEAD
stepanblyschak Jul 20, 2021
4345a6a
initialize ConfigMgmt with init_cfg.json instead of running config to…
stepanblyschak Jul 20, 2021
94cde8e
Changed tabs to spaces
vadymhlushko-mlnx Aug 30, 2021
5fec4a7
Removed unnecessary config_db.json file
vadymhlushko-mlnx Aug 31, 2021
96ccbf6
Merge branch 'master' into spm-yang
stepanblyschak Sep 2, 2021
3cd8ad9
Added test case, added support for UT for sonic-cli-gen implementation
vadymhlushko-mlnx Sep 7, 2021
607b254
Added registering of plugins to UT
vadymhlushko-mlnx Sep 7, 2021
6816903
Fixed name
vadymhlushko-mlnx Sep 7, 2021
2aee883
Added helper.load_and_register_plugins()
vadymhlushko-mlnx Sep 8, 2021
9fea6db
Added test cases for sonic-device_metadata
vadymhlushko-mlnx Sep 9, 2021
69926ed
Added cli_autogen_common.py, added separate dir for each cli_autogen …
vadymhlushko-mlnx Sep 10, 2021
dd7ec5e
Added backup and restore func for yang models
vadymhlushko-mlnx Sep 10, 2021
eb85200
Removed if-else UT login from generator.py
vadymhlushko-mlnx Sep 10, 2021
5ccefa6
Added couple UT for device-neighbor
vadymhlushko-mlnx Sep 13, 2021
37ac0b7
Added UT for update flow
vadymhlushko-mlnx Sep 14, 2021
4402203
Fixed codestyle
vadymhlushko-mlnx Sep 14, 2021
9d07092
Fixed codestyle
vadymhlushko-mlnx Sep 14, 2021
5b6a8aa
Fixed test path variables
vadymhlushko-mlnx Sep 14, 2021
df1d329
[sonic-cli-gen] add docstrings
stepanblyschak Oct 21, 2021
33bb73a
Merge branch 'master' into spm-yang
stepanblyschak Oct 29, 2021
a6d36dc
Merge commit 'refs/pull/1644/head' of github.com:azure/sonic-utilitie…
stepanblyschak Nov 1, 2021
4ed03b2
Merge branch 'master' of github.com:azure/sonic-utilities into spm-yang
stepanblyschak Nov 1, 2021
d531699
remove sonic_cli_gen PR part
stepanblyschak Nov 10, 2021
5219909
remove sonic_cli_gen PR part
stepanblyschak Nov 10, 2021
987c085
remove sonic_cli_gen PR part
stepanblyschak Nov 10, 2021
eb57015
Merge branch 'master' of https://github.com/Azure/sonic-utilities int…
stepanblyschak Nov 17, 2021
bf05d42
handle review comments
stepanblyschak Nov 17, 2021
d0a2ff7
fix LGTM warning
stepanblyschak Nov 17, 2021
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
110 changes: 91 additions & 19 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
config_mgmt.py provides classes for configuration validation and for Dynamic
Port Breakout.
'''

import os
import re
import shutil
import syslog
import tempfile
import yang as ly
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
from json import load
from sys import flags
from time import sleep as tsleep
Expand Down Expand Up @@ -46,34 +51,38 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True):
try:
self.configdbJsonIn = None
self.configdbJsonOut = None
self.source = source
self.allowTablesWithoutYang = allowTablesWithoutYang

# logging vars
self.SYSLOG_IDENTIFIER = "ConfigMgmt"
self.DEBUG = debug

self.sy = sonic_yang.SonicYang(YANG_DIR, debug=debug)
# load yang models
self.sy.loadYangModel()
# load jIn from config DB or from config DB json file.
if source.lower() == 'configdb':
self.readConfigDB()
# treat any other source as file input
else:
self.readConfigDBJson(source)
# this will crop config, xlate and load.
self.sy.loadData(self.configdbJsonIn)

# Raise if tables without YANG models are not allowed but exist.
if not allowTablesWithoutYang and len(self.sy.tablesWithOutYang):
raise Exception('Config has tables without YANG models')
self.__init_sonic_yang()

except Exception as e:
self.sysLog(doPrint=True, logLevel=syslog.LOG_ERR, msg=str(e))
raise Exception('ConfigMgmt Class creation failed')

return

def __init_sonic_yang(self):
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG)
# load yang models
self.sy.loadYangModel()
# load jIn from config DB or from config DB json file.
if self.source.lower() == 'configdb':
self.readConfigDB()
# treat any other source as file input
else:
self.readConfigDBJson(self.source)
# this will crop config, xlate and load.
self.sy.loadData(self.configdbJsonIn)

# Raise if tables without YANG models are not allowed but exist.
if not self.allowTablesWithoutYang and len(self.sy.tablesWithOutYang):
raise Exception('Config has tables without YANG models')

def __del__(self):
pass

Expand Down Expand Up @@ -213,6 +222,69 @@ def writeConfigDB(self, jDiff):

return

def add_module(self, yang_module_str):
"""
Validate and add new YANG module to the system.

Parameters:
yang_module_str (str): YANG module in string representation.

Returns:
None
"""

module_name = self.get_module_name(yang_module_str)
module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
if os.path.exists(module_path):
raise Exception('{} already exists'.format(module_name))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caller of add_module should be able to handle it gracefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller can catch the exception and handle it gracefully.

with open(module_path, 'w') as module_file:
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
module_file.write(yang_module_str)
try:
self.__init_sonic_yang()
except Exception:
os.remove(module_path)
raise

def remove_module(self, module_name):
"""
Remove YANG module from the system and validate.

Parameters:
module_name (str): YANG module name.

Returns:
None
"""

module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
if not os.path.exists(module_path):
return
temp = tempfile.NamedTemporaryFile(delete=False)
try:
shutil.move(module_path, temp.name)
self.__init_sonic_yang()
except Exception:
shutil.move(temp.name, module_path)
raise

@staticmethod
def get_module_name(yang_module_str):
"""
Read yangs module name from yang_module_str

Parameters:
yang_module_str(str): YANG module string.

Returns:
str: Module name
"""

# Instantiate new context since parse_module_mem() loads the module into context.
sy = sonic_yang.SonicYang(YANG_DIR)
module = sy.ctx.parse_module_mem(yang_module_str, ly.LYS_IN_YANG)
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
return module.name()


# End of Class ConfigMgmt

class ConfigMgmtDPB(ConfigMgmt):
Expand Down Expand Up @@ -417,8 +489,8 @@ def _deletePorts(self, ports=list(), force=False):
deps.extend(dep)

# No further action with no force and deps exist
if force == False and deps:
return configToLoad, deps, False;
if not force and deps:
return configToLoad, deps, False

# delets all deps, No topological sort is needed as of now, if deletion
# of deps fails, return immediately
Expand All @@ -436,8 +508,8 @@ def _deletePorts(self, ports=list(), force=False):
self.sy.deleteNode(str(xPathPort))

# Let`s Validate the tree now
if self.validateConfigData()==False:
return configToLoad, deps, False;
if not self.validateConfigData():
return configToLoad, deps, False

# All great if we are here, Lets get the diff
self.configdbJsonOut = self.sy.getData()
Expand Down
4 changes: 3 additions & 1 deletion sonic_package_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ def reset(ctx, name, force, yes, skip_host_plugins):

@cli.command()
@add_options(PACKAGE_COMMON_OPERATION_OPTIONS)
@click.option('--keep-config', is_flag=True, help='Keep features configuration in CONFIG DB.')
@click.argument('name')
@click.pass_context
@root_privileges_required
def uninstall(ctx, name, force, yes):
def uninstall(ctx, name, force, yes, keep_config):
renukamanavalan marked this conversation as resolved.
Show resolved Hide resolved
""" Uninstall package. """

manager: PackageManager = ctx.obj
Expand All @@ -428,6 +429,7 @@ def uninstall(ctx, name, force, yes):

uninstall_opts = {
'force': force,
'keep_config': keep_config,
}

try:
Expand Down
21 changes: 17 additions & 4 deletions sonic_package_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

import docker
import filelock
from config import config_mgmt
from sonic_py_common import device_info

from sonic_cli_gen.generator import CliGenerator

from sonic_package_manager import utils
from sonic_package_manager.constraint import (
VersionConstraint,
Expand Down Expand Up @@ -45,7 +48,10 @@
run_command
)
from sonic_package_manager.service_creator.feature import FeatureRegistry
from sonic_package_manager.service_creator.sonic_db import SonicDB
from sonic_package_manager.service_creator.sonic_db import (
INIT_CFG_JSON,
SonicDB
)
from sonic_package_manager.service_creator.utils import in_chroot
from sonic_package_manager.source import (
PackageSource,
Expand Down Expand Up @@ -435,13 +441,16 @@ def install_from_source(self,

@under_lock
@opt_check
def uninstall(self, name: str, force=False):
def uninstall(self, name: str,
force: bool = False,
keep_config: bool = False):
""" Uninstall SONiC Package referenced by name. The uninstallation
can be forced if force argument is True.

Args:
name: SONiC Package name.
force: Force the installation.
keep_config: Keep feature configuration in databases.
Raises:
PackageManagerError
"""
Expand Down Expand Up @@ -482,7 +491,7 @@ def uninstall(self, name: str, force=False):
self._systemctl_action(package, 'stop')
self._systemctl_action(package, 'disable')
self._uninstall_cli_plugins(package)
self.service_creator.remove(package)
self.service_creator.remove(package, keep_config=keep_config)
self.service_creator.generate_shutdown_sequence_files(
self._get_installed_packages_except(package)
)
Expand Down Expand Up @@ -1000,9 +1009,13 @@ def get_manager() -> 'PackageManager':
docker_api = DockerApi(docker.from_env(), ProgressManager())
registry_resolver = RegistryResolver()
metadata_resolver = MetadataResolver(docker_api, registry_resolver)
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON)
cli_generator = CliGenerator(log)
feature_registry = FeatureRegistry(SonicDB)
service_creator = ServiceCreator(feature_registry,
SonicDB)
SonicDB,
cli_generator,
cfg_mgmt)

return PackageManager(docker_api,
registry_resolver,
Expand Down
4 changes: 3 additions & 1 deletion sonic_package_manager/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ def unmarshal(self, value):
ManifestField('mandatory', DefaultMarshaller(bool), False),
ManifestField('show', DefaultMarshaller(str), ''),
ManifestField('config', DefaultMarshaller(str), ''),
ManifestField('clear', DefaultMarshaller(str), '')
ManifestField('clear', DefaultMarshaller(str), ''),
ManifestField('auto-generate-show', DefaultMarshaller(bool), False),
ManifestField('auto-generate-config', DefaultMarshaller(bool), False),
])
])

Expand Down
6 changes: 4 additions & 2 deletions sonic_package_manager/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
import tarfile
from typing import Dict
from typing import Dict, Optional

from sonic_package_manager import utils
from sonic_package_manager.errors import MetadataError
Expand Down Expand Up @@ -54,6 +54,7 @@ class Metadata:

manifest: Manifest
components: Dict[str, Version] = field(default_factory=dict)
yang_module_str: Optional[str] = None


class MetadataResolver:
Expand Down Expand Up @@ -163,5 +164,6 @@ def from_labels(cls, labels: Dict[str, str]) -> Metadata:
except ValueError as err:
raise MetadataError(f'Failed to parse component version: {err}')

return Metadata(Manifest.marshal(manifest_dict), components)
yang_module_str = sonic_metadata.get('yang-module')

return Metadata(Manifest.marshal(manifest_dict), components, yang_module_str)
Loading