From 0fb7190c062a08a3969a71955c014e3a572cdc9e Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 5 Apr 2022 17:48:01 +0100 Subject: Deprecate nova CLI It is time to signal that we're fully committed to delivering a pure OSC experience. Based on the neutron change from 6 (!!) years ago [1] [1] https://github.com/openstack/python-neutronclient/commit/3a64a7a166be25d40436fd40c8351a79267bd3c4 Change-Id: Ib80548e104a751179f36f2a6ebff9916d38fdf1e Signed-off-by: Stephen Finucane --- novaclient/shell.py | 15 +++++++++++-- novaclient/tests/unit/test_shell.py | 26 ++++++++++++++++------ .../notes/deprecate-cli-75074850847a8452.yaml | 9 ++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/deprecate-cli-75074850847a8452.yaml diff --git a/novaclient/shell.py b/novaclient/shell.py index 7762be9b..468e889b 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -20,6 +20,7 @@ Command-line interface to the OpenStack Nova API. import argparse import logging +import os import sys from keystoneauth1 import loading @@ -816,9 +817,19 @@ class OpenStackHelpFormatter(argparse.HelpFormatter): super(OpenStackHelpFormatter, self).start_section(heading) -def main(): +def main(argv=sys.argv[1:]): try: - argv = [encodeutils.safe_decode(a) for a in sys.argv[1:]] + # Special dansmith envvar to hide the warning. Don't rely on this + # because we will eventually remove all this stuff. + if os.environ.get("NOVACLIENT_ISHOULDNTBEDOINGTHIS") != "1": + print( + _( + "nova CLI is deprecated and will be a removed in a future " + "release" + ), + file=sys.stderr, + ) + argv = [encodeutils.safe_decode(a) for a in argv] OpenStackComputeShell().main(argv) except Exception as exc: logger.debug(exc, exc_info=1) diff --git a/novaclient/tests/unit/test_shell.py b/novaclient/tests/unit/test_shell.py index 64195291..b6b708a8 100644 --- a/novaclient/tests/unit/test_shell.py +++ b/novaclient/tests/unit/test_shell.py @@ -624,26 +624,32 @@ class ShellTest(utils.TestCase): self._test_service_type, 'unknown', 'compute', self.mock_client) - @mock.patch('sys.argv', ['nova']) @mock.patch('sys.stdout', io.StringIO()) @mock.patch('sys.stderr', io.StringIO()) def test_main_noargs(self): # Ensure that main works with no command-line arguments try: - novaclient.shell.main() + novaclient.shell.main([]) except SystemExit: self.fail('Unexpected SystemExit') # We expect the normal usage as a result - self.assertIn('Command-line interface to the OpenStack Nova API', - sys.stdout.getvalue()) + self.assertIn( + 'Command-line interface to the OpenStack Nova API', + sys.stdout.getvalue(), + ) + # We also expect to see the deprecation warning + self.assertIn( + 'nova CLI is deprecated and will be a removed in a future release', + sys.stderr.getvalue(), + ) @mock.patch.object(novaclient.shell.OpenStackComputeShell, 'main') def test_main_keyboard_interrupt(self, mock_compute_shell): # Ensure that exit code is 130 for KeyboardInterrupt mock_compute_shell.side_effect = KeyboardInterrupt() try: - novaclient.shell.main() + novaclient.shell.main([]) except SystemExit as ex: self.assertEqual(ex.code, 130) @@ -766,9 +772,15 @@ class ShellTest(utils.TestCase): pass with mock.patch('sys.stderr', io.StringIO()): mock_compute_shell.side_effect = MyException('message') - self.assertRaises(SystemExit, novaclient.shell.main) + self.assertRaises(SystemExit, novaclient.shell.main, []) err = sys.stderr.getvalue() - self.assertEqual(err, 'ERROR (MyException): message\n') + # We expect to see the error propagated + self.assertIn('ERROR (MyException): message\n', err) + # We also expect to see the deprecation warning + self.assertIn( + 'nova CLI is deprecated and will be a removed in a future release', + err, + ) class TestLoadVersionedActions(utils.TestCase): diff --git a/releasenotes/notes/deprecate-cli-75074850847a8452.yaml b/releasenotes/notes/deprecate-cli-75074850847a8452.yaml new file mode 100644 index 00000000..6d51ce03 --- /dev/null +++ b/releasenotes/notes/deprecate-cli-75074850847a8452.yaml @@ -0,0 +1,9 @@ +--- +deprecations: + - | + The ``nova`` CLI is now deprecated. This is the signal that it is + time to start using the openstack CLI. No new features will be + added to the ``nova`` CLI, though fixes to the CLI will be assessed + on a case by case basis. Fixes to the API bindings, development of + new API bindings, and changes to the compute commands in the openstack + CLI are exempt from this deprecation. -- cgit v1.2.1