Skip to content

Commit

Permalink
[SPM] Add logic to disable the feature before stopping it and enablin…
Browse files Browse the repository at this point in the history
…g 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 <featureX> <URL>
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
  • Loading branch information
vadymhlushko-mlnx authored Nov 11, 2024
1 parent 7d013df commit 093ed4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sonic_package_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 11 additions & 2 deletions tests/sonic_package_manager/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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')
Expand Down Expand Up @@ -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()]

Expand Down

0 comments on commit 093ed4a

Please sign in to comment.