summaryrefslogtreecommitdiff
path: root/novaclient
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient')
-rw-r--r--novaclient/shell.py15
-rw-r--r--novaclient/tests/unit/test_shell.py26
2 files changed, 32 insertions, 9 deletions
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):