From 093ed4aaa555f25d8909c6a63b4b10bb23c06724 Mon Sep 17 00:00:00 2001 From: Vadym Hlushko <62022266+vadymhlushko-mlnx@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:35:45 +0100 Subject: [PATCH] [SPM] Add logic to disable the feature before stopping it and enabling it before starting (#3344) What I did Add logic to disable the feature before stopping and enabling it before starting in order to properly clean the systemd symlinks to avoid issues with delayed attribute explained in the How to verify it section. How I did it Add the systemctl disable ... after the systemctl stop... and the systemctl enable ... before the systemctl start .. for some feature. How to verify it Add repository for some featureX sonic-package-manager repository Install featureX version 1.0.0 where the delayed flag is equal to false (delayed flag means - the feature will be started right after the system boots or after the PortInitDone event) sonic-package-manager install featureX==1.0.0 -y Enable the feature in SONiC config feature state featureX enabled Install featureX version 1.0.1 where the delayed flag is equal to true sonic-package-manager install featureX==1.0.1 -y Check the manifest file to verify the delayed field value sonic-package-manager show package manifest featureX config save -y reboot Check that the featureX is delayed on the system start --- sonic_package_manager/manager.py | 2 ++ tests/sonic_package_manager/test_manager.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/sonic_package_manager/manager.py b/sonic_package_manager/manager.py index a052479607..b6a3be50c3 100644 --- a/sonic_package_manager/manager.py +++ b/sonic_package_manager/manager.py @@ -1017,8 +1017,10 @@ def _get_installed_packages_except(self, package: Package) -> Dict[str, Package] def _stop_feature(self, package: Package): self._systemctl_action(package, 'stop') + self._systemctl_action(package, 'disable') def _start_feature(self, package: Package): + self._systemctl_action(package, 'enable') self._systemctl_action(package, 'start') def _systemctl_action(self, package: Package, action: str): diff --git a/tests/sonic_package_manager/test_manager.py b/tests/sonic_package_manager/test_manager.py index a3a311ebb2..26e838ce6d 100644 --- a/tests/sonic_package_manager/test_manager.py +++ b/tests/sonic_package_manager/test_manager.py @@ -324,7 +324,7 @@ def test_manager_installation_version_range(package_manager): package_manager.install(f'test-package>=1.6.0') -def test_manager_upgrade(package_manager, sonic_fs): +def test_manager_upgrade(package_manager, sonic_fs, mock_run_command): package_manager.install('test-package-6=1.5.0') package = package_manager.get_installed_package('test-package-6') @@ -333,6 +333,15 @@ def test_manager_upgrade(package_manager, sonic_fs): assert upgraded_package.entry.version == Version.parse('2.0.0') assert upgraded_package.entry.default_reference == package.entry.default_reference + mock_run_command.assert_has_calls( + [ + call(['systemctl', 'stop', 'test-package-6']), + call(['systemctl', 'disable', 'test-package-6']), + call(['systemctl', 'enable', 'test-package-6']), + call(['systemctl', 'start', 'test-package-6']), + ] + ) + def test_manager_package_reset(package_manager, sonic_fs): package_manager.install('test-package-6=1.5.0') @@ -370,7 +379,7 @@ def __init__(self, dockerd_sock): class Image: def __init__(self, image_id): self.image_id = image_id - + def save(self, named): return ["named: {}".format(named).encode()]