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

[SPM] Add logic to disable the feature before stopping it and enabling it before starting #3344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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')
Copy link
Contributor

@qiluo-msft qiluo-msft Sep 21, 2024

Choose a reason for hiding this comment

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

_systemctl_action

Seems you are fixing a bug in old code. Could you add a testcase which fails old code and passes new code? #Closed

Copy link
Contributor

Choose a reason for hiding this comment

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

@qiluo-msft UT added


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
Loading