From 0eb43b81e4d070af6882601bcc42c60e8fffaba3 Mon Sep 17 00:00:00 2001 From: mathieu-rohon Date: Sat, 7 Mar 2015 21:05:08 +0100 Subject: [PATCH] Add commands from extensions to available commands Any project can extend available commands in neutronclient thanks to change : I5b2fe530c90b5ce1243fc10341d6d434a1ecea7a However, commands submitted by external modules are not correctly added to available commands in the client. Change-Id: I53783f18e7811deee9ae7e1f48fc429afcba8936 Closes-bug: #1430825 --- neutronclient/shell.py | 1 + neutronclient/tests/unit/test_client_extension.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/neutronclient/shell.py b/neutronclient/shell.py index 2619363..7b20bd7 100644 --- a/neutronclient/shell.py +++ b/neutronclient/shell.py @@ -692,6 +692,7 @@ class NeutronShell(app.App): continue try: self.command_manager.add_command(cmd, cls) + self.commands[version][cmd] = cls except TypeError: pass diff --git a/neutronclient/tests/unit/test_client_extension.py b/neutronclient/tests/unit/test_client_extension.py index fe1712b..0ac8cc8 100644 --- a/neutronclient/tests/unit/test_client_extension.py +++ b/neutronclient/tests/unit/test_client_extension.py @@ -19,6 +19,7 @@ import sys import mock from neutronclient.neutron.v2_0.contrib import _fox_sockets as fox_sockets +from neutronclient import shell from neutronclient.tests.unit import test_cli20 @@ -37,10 +38,18 @@ class CLITestV20ExtensionJSON(test_cli20.CLITestV20Base): def _mock_extension_loading(self): ext_pkg = 'neutronclient.common.extension' contrib = self._create_patch(ext_pkg + '._discover_via_entry_points') - iterator = iter([("_fox_sockets", fox_sockets)]) - contrib.return_value.__iter__.return_value = iterator + contrib.return_value = [("_fox_sockets", fox_sockets)] return contrib + def test_ext_cmd_loaded(self): + shell.NeutronShell('2.0') + ext_cmd = {'fox-sockets-list': fox_sockets.FoxInSocketsList, + 'fox-sockets-create': fox_sockets.FoxInSocketsCreate, + 'fox-sockets-update': fox_sockets.FoxInSocketsUpdate, + 'fox-sockets-delete': fox_sockets.FoxInSocketsDelete, + 'fox-sockets-show': fox_sockets.FoxInSocketsShow} + self.assertDictContainsSubset(ext_cmd, shell.COMMANDS['2.0']) + def test_delete_fox_socket(self): """Delete fox socket: myid.""" resource = 'fox_socket'