Skip to content

Commit fe00bbf

Browse files
authored
Revert "[sonic-package-manager] support sonic-cli-gen and packages with YANG model (sonic-net#1650)" (sonic-net#1972)
This reverts commit f5e5a56.
1 parent 5fe6d92 commit fe00bbf

File tree

9 files changed

+96
-380
lines changed

9 files changed

+96
-380
lines changed

config/config_mgmt.py

+19-91
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
config_mgmt.py provides classes for configuration validation and for Dynamic
33
Port Breakout.
44
'''
5-
6-
import os
75
import re
8-
import shutil
96
import syslog
10-
import tempfile
11-
import yang as ly
127
from json import load
138
from sys import flags
149
from time import sleep as tsleep
@@ -51,38 +46,34 @@ def __init__(self, source="configDB", debug=False, allowTablesWithoutYang=True):
5146
try:
5247
self.configdbJsonIn = None
5348
self.configdbJsonOut = None
54-
self.source = source
5549
self.allowTablesWithoutYang = allowTablesWithoutYang
5650

5751
# logging vars
5852
self.SYSLOG_IDENTIFIER = "ConfigMgmt"
5953
self.DEBUG = debug
6054

61-
self.__init_sonic_yang()
55+
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=debug)
56+
# load yang models
57+
self.sy.loadYangModel()
58+
# load jIn from config DB or from config DB json file.
59+
if source.lower() == 'configdb':
60+
self.readConfigDB()
61+
# treat any other source as file input
62+
else:
63+
self.readConfigDBJson(source)
64+
# this will crop config, xlate and load.
65+
self.sy.loadData(self.configdbJsonIn)
66+
67+
# Raise if tables without YANG models are not allowed but exist.
68+
if not allowTablesWithoutYang and len(self.sy.tablesWithOutYang):
69+
raise Exception('Config has tables without YANG models')
6270

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

6775
return
6876

69-
def __init_sonic_yang(self):
70-
self.sy = sonic_yang.SonicYang(YANG_DIR, debug=self.DEBUG)
71-
# load yang models
72-
self.sy.loadYangModel()
73-
# load jIn from config DB or from config DB json file.
74-
if self.source.lower() == 'configdb':
75-
self.readConfigDB()
76-
# treat any other source as file input
77-
else:
78-
self.readConfigDBJson(self.source)
79-
# this will crop config, xlate and load.
80-
self.sy.loadData(self.configdbJsonIn)
81-
82-
# Raise if tables without YANG models are not allowed but exist.
83-
if not self.allowTablesWithoutYang and len(self.sy.tablesWithOutYang):
84-
raise Exception('Config has tables without YANG models')
85-
8677
def __del__(self):
8778
pass
8879

@@ -222,69 +213,6 @@ def writeConfigDB(self, jDiff):
222213

223214
return
224215

225-
def add_module(self, yang_module_str):
226-
"""
227-
Validate and add new YANG module to the system.
228-
229-
Parameters:
230-
yang_module_str (str): YANG module in string representation.
231-
232-
Returns:
233-
None
234-
"""
235-
236-
module_name = self.get_module_name(yang_module_str)
237-
module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
238-
if os.path.exists(module_path):
239-
raise Exception('{} already exists'.format(module_name))
240-
with open(module_path, 'w') as module_file:
241-
module_file.write(yang_module_str)
242-
try:
243-
self.__init_sonic_yang()
244-
except Exception:
245-
os.remove(module_path)
246-
raise
247-
248-
def remove_module(self, module_name):
249-
"""
250-
Remove YANG module from the system and validate.
251-
252-
Parameters:
253-
module_name (str): YANG module name.
254-
255-
Returns:
256-
None
257-
"""
258-
259-
module_path = os.path.join(YANG_DIR, '{}.yang'.format(module_name))
260-
if not os.path.exists(module_path):
261-
return
262-
temp = tempfile.NamedTemporaryFile(delete=False)
263-
try:
264-
shutil.move(module_path, temp.name)
265-
self.__init_sonic_yang()
266-
except Exception:
267-
shutil.move(temp.name, module_path)
268-
raise
269-
270-
@staticmethod
271-
def get_module_name(yang_module_str):
272-
"""
273-
Read yangs module name from yang_module_str
274-
275-
Parameters:
276-
yang_module_str(str): YANG module string.
277-
278-
Returns:
279-
str: Module name
280-
"""
281-
282-
# Instantiate new context since parse_module_mem() loads the module into context.
283-
sy = sonic_yang.SonicYang(YANG_DIR)
284-
module = sy.ctx.parse_module_mem(yang_module_str, ly.LYS_IN_YANG)
285-
return module.name()
286-
287-
288216
# End of Class ConfigMgmt
289217

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

491419
# No further action with no force and deps exist
492-
if not force and deps:
493-
return configToLoad, deps, False
420+
if force == False and deps:
421+
return configToLoad, deps, False;
494422

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

510438
# Let`s Validate the tree now
511-
if not self.validateConfigData():
512-
return configToLoad, deps, False
439+
if self.validateConfigData()==False:
440+
return configToLoad, deps, False;
513441

514442
# All great if we are here, Lets get the diff
515443
self.configdbJsonOut = self.sy.getData()

sonic_package_manager/main.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,10 @@ def reset(ctx, name, force, yes, skip_host_plugins):
414414

415415
@cli.command()
416416
@add_options(PACKAGE_COMMON_OPERATION_OPTIONS)
417-
@click.option('--keep-config', is_flag=True, help='Keep features configuration in CONFIG DB.')
418417
@click.argument('name')
419418
@click.pass_context
420419
@root_privileges_required
421-
def uninstall(ctx, name, force, yes, keep_config):
420+
def uninstall(ctx, name, force, yes):
422421
""" Uninstall package. """
423422

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

430429
uninstall_opts = {
431430
'force': force,
432-
'keep_config': keep_config,
433431
}
434432

435433
try:

sonic_package_manager/manager.py

+4-17
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010

1111
import docker
1212
import filelock
13-
from config import config_mgmt
1413
from sonic_py_common import device_info
1514

16-
from sonic_cli_gen.generator import CliGenerator
17-
1815
from sonic_package_manager import utils
1916
from sonic_package_manager.constraint import (
2017
VersionConstraint,
@@ -48,10 +45,7 @@
4845
run_command
4946
)
5047
from sonic_package_manager.service_creator.feature import FeatureRegistry
51-
from sonic_package_manager.service_creator.sonic_db import (
52-
INIT_CFG_JSON,
53-
SonicDB
54-
)
48+
from sonic_package_manager.service_creator.sonic_db import SonicDB
5549
from sonic_package_manager.service_creator.utils import in_chroot
5650
from sonic_package_manager.source import (
5751
PackageSource,
@@ -441,16 +435,13 @@ def install_from_source(self,
441435

442436
@under_lock
443437
@opt_check
444-
def uninstall(self, name: str,
445-
force: bool = False,
446-
keep_config: bool = False):
438+
def uninstall(self, name: str, force=False):
447439
""" Uninstall SONiC Package referenced by name. The uninstallation
448440
can be forced if force argument is True.
449441
450442
Args:
451443
name: SONiC Package name.
452444
force: Force the installation.
453-
keep_config: Keep feature configuration in databases.
454445
Raises:
455446
PackageManagerError
456447
"""
@@ -491,7 +482,7 @@ def uninstall(self, name: str,
491482
self._systemctl_action(package, 'stop')
492483
self._systemctl_action(package, 'disable')
493484
self._uninstall_cli_plugins(package)
494-
self.service_creator.remove(package, keep_config=keep_config)
485+
self.service_creator.remove(package)
495486
self.service_creator.generate_shutdown_sequence_files(
496487
self._get_installed_packages_except(package)
497488
)
@@ -1009,13 +1000,9 @@ def get_manager() -> 'PackageManager':
10091000
docker_api = DockerApi(docker.from_env(), ProgressManager())
10101001
registry_resolver = RegistryResolver()
10111002
metadata_resolver = MetadataResolver(docker_api, registry_resolver)
1012-
cfg_mgmt = config_mgmt.ConfigMgmt(source=INIT_CFG_JSON)
1013-
cli_generator = CliGenerator(log)
10141003
feature_registry = FeatureRegistry(SonicDB)
10151004
service_creator = ServiceCreator(feature_registry,
1016-
SonicDB,
1017-
cli_generator,
1018-
cfg_mgmt)
1005+
SonicDB)
10191006

10201007
return PackageManager(docker_api,
10211008
registry_resolver,

sonic_package_manager/manifest.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,7 @@ def unmarshal(self, value):
205205
ManifestField('mandatory', DefaultMarshaller(bool), False),
206206
ManifestField('show', DefaultMarshaller(str), ''),
207207
ManifestField('config', DefaultMarshaller(str), ''),
208-
ManifestField('clear', DefaultMarshaller(str), ''),
209-
ManifestField('auto-generate-show', DefaultMarshaller(bool), False),
210-
ManifestField('auto-generate-config', DefaultMarshaller(bool), False),
208+
ManifestField('clear', DefaultMarshaller(str), '')
211209
])
212210
])
213211

sonic_package_manager/metadata.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import json
66
import tarfile
7-
from typing import Dict, Optional
7+
from typing import Dict
88

99
from sonic_package_manager import utils
1010
from sonic_package_manager.errors import MetadataError
@@ -54,7 +54,6 @@ class Metadata:
5454

5555
manifest: Manifest
5656
components: Dict[str, Version] = field(default_factory=dict)
57-
yang_module_str: Optional[str] = None
5857

5958

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

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

169-
return Metadata(Manifest.marshal(manifest_dict), components, yang_module_str)

0 commit comments

Comments
 (0)