Skip to content

Commit

Permalink
[sonic-package-manager] fix CLI plugin compatibility issue (sonic-net…
Browse files Browse the repository at this point in the history
…#2842)

- What I did
Overcome a CLI plugin compatibility issue

- How I did it
DHCP relay extension expects the spm to name its plugin "dhcp-relay". This change keeps that format if there is just one CLI plugin.

Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak authored and pdhruv-marvell committed Aug 23, 2023
1 parent f87ff27 commit c7b1fa8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion sonic_package_manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ def get_cli_plugin_path(package: Package, index: int, command: str) -> str:
Path generated for this package.
"""

plugin_module_file = f'{package.name}_{index}.py'
if index == 0:
plugin_module_file = f'{package.name}.py'
else:
plugin_module_file = f'{package.name}_{index}.py'

return os.path.join(get_cli_plugin_directory(command), plugin_module_file)


Expand Down
6 changes: 3 additions & 3 deletions tests/sonic_package_manager/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_installation_cli_plugin(package_manager, fake_metadata_resolver, anythi
with patch('sonic_package_manager.manager.get_cli_plugin_directory') as get_dir_mock:
get_dir_mock.return_value = '/'
package_manager.install('test-package')
package_manager.docker.extract.assert_called_once_with(anything, '/cli/plugin.py', '/test-package_0.py')
package_manager.docker.extract.assert_called_once_with(anything, '/cli/plugin.py', '/test-package.py')


def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolver, mock_feature_registry, anything):
Expand All @@ -178,7 +178,7 @@ def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolve
package_manager.install('test-package')
package_manager.docker.extract.assert_has_calls(
[
call(anything, '/cli/plugin.py', '/test-package_0.py'),
call(anything, '/cli/plugin.py', '/test-package.py'),
call(anything, '/cli/plugin2.py', '/test-package_1.py'),
],
any_order=True,
Expand All @@ -188,7 +188,7 @@ def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolve
package_manager.uninstall('test-package', force=True)
remove_mock.assert_has_calls(
[
call('/test-package_0.py'),
call('/test-package.py'),
call('/test-package_1.py'),
],
any_order=True,
Expand Down

0 comments on commit c7b1fa8

Please sign in to comment.