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
-rw-r--r--novaclient/tests/unit/v2/test_shell.py18
-rw-r--r--novaclient/utils.py9
-rw-r--r--novaclient/v2/shell.py10
5 files changed, 54 insertions, 24 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):
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index e6c0fda7..da70e3cc 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -3397,7 +3397,8 @@ class ShellTest(utils.TestCase):
def test_services_list_v269_with_down_cells(self):
"""Tests nova service-list at the 2.69 microversion."""
stdout, _stderr = self.run_command('service-list', api_version='2.69')
- self.assertEqual('''\
+ self.assertEqual(
+ '''\
+--------------------------------------+--------------+-----------+------+----------+-------+---------------------+-----------------+-------------+
| Id | Binary | Host | Zone | Status | State | Updated_at | Disabled Reason | Forced down |
+--------------------------------------+--------------+-----------+------+----------+-------+---------------------+-----------------+-------------+
@@ -3406,7 +3407,8 @@ class ShellTest(utils.TestCase):
| | nova-compute | host-down | | UNKNOWN | | | | |
+--------------------------------------+--------------+-----------+------+----------+-------+---------------------+-----------------+-------------+
''', # noqa
- stdout)
+ stdout,
+ )
self.assert_called('GET', '/os-services')
def test_services_list_with_host(self):
@@ -4779,7 +4781,8 @@ class ShellTest(utils.TestCase):
def test_list_detail_v269_with_down_cells(self):
"""Tests nova list at the 2.69 microversion."""
stdout, _stderr = self.run_command('list', api_version='2.69')
- self.assertIn('''\
+ self.assertIn(
+ '''\
+------+----------------+---------+------------+-------------+----------------------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+------+----------------+---------+------------+-------------+----------------------------------------------+
@@ -4791,7 +4794,8 @@ class ShellTest(utils.TestCase):
| 9013 | sample-server4 | ACTIVE | N/A | N/A | |
+------+----------------+---------+------------+-------------+----------------------------------------------+
''', # noqa
- stdout)
+ stdout,
+ )
self.assert_called('GET', '/servers/detail')
def test_list_v269_with_down_cells(self):
@@ -4812,7 +4816,8 @@ class ShellTest(utils.TestCase):
def test_show_v269_with_down_cells(self):
stdout, _stderr = self.run_command('show 9015', api_version='2.69')
- self.assertEqual('''\
+ self.assertEqual(
+ '''\
+-----------------------------+---------------------------------------------------+
| Property | Value |
+-----------------------------+---------------------------------------------------+
@@ -4833,7 +4838,8 @@ class ShellTest(utils.TestCase):
| user_id | fake |
+-----------------------------+---------------------------------------------------+
''', # noqa
- stdout)
+ stdout,
+ )
FAKE_UUID_2 = 'c99d7632-bd66-4be9-aed5-3dd14b223a76'
self.assert_called('GET', '/servers?name=9015', pos=0)
self.assert_called('GET', '/servers?name=9015', pos=1)
diff --git a/novaclient/utils.py b/novaclient/utils.py
index fba708b5..d0219795 100644
--- a/novaclient/utils.py
+++ b/novaclient/utils.py
@@ -116,13 +116,14 @@ def service_type(stype):
return inner
-def pretty_choice_list(l):
- return ', '.join("'%s'" % i for i in l)
+def pretty_choice_list(values):
+ return ', '.join("'%s'" % x for x in values)
-def pretty_choice_dict(d):
+def pretty_choice_dict(values):
"""Returns a formatted dict as 'key=value'."""
- return pretty_choice_list(['%s=%s' % (k, d[k]) for k in sorted(d.keys())])
+ return pretty_choice_list(
+ ['%s=%s' % (k, values[k]) for k in sorted(values)])
def print_list(objs, fields, formatters={}, sortby_index=None):
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index dfe93c01..58823fc7 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -3231,15 +3231,15 @@ def _print_absolute_limits(limits):
other = {}
limit_names = []
columns = ['Name', 'Used', 'Max']
- for l in limits:
- map = limit_map.get(l.name, {'name': l.name, 'type': 'other'})
+ for limit in limits:
+ map = limit_map.get(limit.name, {'name': limit.name, 'type': 'other'})
name = map['name']
if map['type'] == 'max':
- max[name] = l.value
+ max[name] = limit.value
elif map['type'] == 'used':
- used[name] = l.value
+ used[name] = limit.value
else:
- other[name] = l.value
+ other[name] = limit.value
if 'Other' not in columns:
columns.append('Other')
if name not in limit_names: