Skip to content

Commit 3610ce9

Browse files
[sonic-package-manager] Fix YANG validation failure on upgrade when feature has constraints in YANG model on FEATURE table (#2933)
* [sonic-package-manager] Fix YANG validation failure on upgrade when feature has constraints in YANG model on FEATURE table Signed-off-by: Stepan Blyschak <[email protected]>
1 parent cfd2dd3 commit 3610ce9

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

sonic_package_manager/manager.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
from sonic_package_manager.reference import PackageReference
4545
from sonic_package_manager.registry import RegistryResolver
4646
from sonic_package_manager.service_creator import SONIC_CLI_COMMANDS
47-
from sonic_package_manager.service_creator.creator import ServiceCreator
47+
from sonic_package_manager.service_creator.creator import (
48+
ServiceCreator,
49+
run_command
50+
)
4851
from sonic_package_manager.service_creator.feature import FeatureRegistry
4952
from sonic_package_manager.service_creator.sonic_db import (
5053
INIT_CFG_JSON,
@@ -483,7 +486,7 @@ def uninstall(self, name: str,
483486
# After all checks are passed we proceed to actual uninstallation
484487

485488
try:
486-
self._stop_feature(package)
489+
self._disable_feature(package)
487490
self._uninstall_cli_plugins(package)
488491
self.service_creator.remove(package, keep_config=keep_config)
489492
self.service_creator.generate_shutdown_sequence_files(
@@ -934,18 +937,29 @@ def _get_installed_packages_except(self, package: Package) -> Dict[str, Package]
934937
packages.pop(package.name)
935938
return packages
936939

937-
def _start_feature(self, package: Package, block: bool = True):
938-
""" Starts the feature and blocks till operation is finished if
939-
block argument is set to True.
940+
def _stop_feature(self, package: Package):
941+
self._systemctl_action(package, 'stop')
940942

941-
Args:
942-
package: Package object of the feature that will be started.
943-
block: Whether to block for operation completion.
944-
"""
943+
def _start_feature(self, package: Package):
944+
self._systemctl_action(package, 'start')
945+
946+
def _systemctl_action(self, package: Package, action: str):
947+
""" Execute systemctl action for a service. """
948+
949+
name = package.manifest['service']['name']
950+
log.info('Execute systemctl action {} on {} service'.format(action, name))
945951

946-
self._set_feature_state(package, 'enabled', block)
952+
host_service = package.manifest['service']['host-service']
953+
asic_service = package.manifest['service']['asic-service']
954+
single_instance = host_service or (asic_service and not self.is_multi_npu)
955+
multi_instance = asic_service and self.is_multi_npu
956+
if single_instance:
957+
run_command(['systemctl', action, name])
958+
if multi_instance:
959+
for npu in range(self.num_npus):
960+
run_command(['systemctl', action, f'{name}@{npu}'])
947961

948-
def _stop_feature(self, package: Package, block: bool = True):
962+
def _disable_feature(self, package: Package, block: bool = True):
949963
""" Stops the feature and blocks till operation is finished if
950964
block argument is set to True.
951965

tests/sonic_package_manager/test_manager.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from sonic_package_manager.errors import *
1010
from sonic_package_manager.version import Version
1111

12+
@pytest.fixture(autouse=True)
13+
def mock_run_command():
14+
with patch('sonic_package_manager.manager.run_command') as run_command:
15+
yield run_command
16+
1217

1318
def test_installation_not_installed(package_manager):
1419
package_manager.install('test-package')

0 commit comments

Comments
 (0)