Skip to content

Commit 4fead89

Browse files
[sonic-package-manager] fix CLI plugin compatibility issue (#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]>
1 parent db61efc commit 4fead89

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sonic_package_manager/manager.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ def get_cli_plugin_path(package: Package, index: int, command: str) -> str:
171171
Path generated for this package.
172172
"""
173173

174-
plugin_module_file = f'{package.name}_{index}.py'
174+
if index == 0:
175+
plugin_module_file = f'{package.name}.py'
176+
else:
177+
plugin_module_file = f'{package.name}_{index}.py'
178+
175179
return os.path.join(get_cli_plugin_directory(command), plugin_module_file)
176180

177181

tests/sonic_package_manager/test_manager.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_installation_cli_plugin(package_manager, fake_metadata_resolver, anythi
165165
with patch('sonic_package_manager.manager.get_cli_plugin_directory') as get_dir_mock:
166166
get_dir_mock.return_value = '/'
167167
package_manager.install('test-package')
168-
package_manager.docker.extract.assert_called_once_with(anything, '/cli/plugin.py', '/test-package_0.py')
168+
package_manager.docker.extract.assert_called_once_with(anything, '/cli/plugin.py', '/test-package.py')
169169

170170

171171
def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolver, mock_feature_registry, anything):
@@ -178,7 +178,7 @@ def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolve
178178
package_manager.install('test-package')
179179
package_manager.docker.extract.assert_has_calls(
180180
[
181-
call(anything, '/cli/plugin.py', '/test-package_0.py'),
181+
call(anything, '/cli/plugin.py', '/test-package.py'),
182182
call(anything, '/cli/plugin2.py', '/test-package_1.py'),
183183
],
184184
any_order=True,
@@ -188,7 +188,7 @@ def test_installation_multiple_cli_plugin(package_manager, fake_metadata_resolve
188188
package_manager.uninstall('test-package', force=True)
189189
remove_mock.assert_has_calls(
190190
[
191-
call('/test-package_0.py'),
191+
call('/test-package.py'),
192192
call('/test-package_1.py'),
193193
],
194194
any_order=True,

0 commit comments

Comments
 (0)