Skip to content

Commit bbcd7d2

Browse files
committed
fup: Print message logging uncaught nova-manage exceptions
While these commands would previously use LOG.exception to at least log the exceptions in nova-manage.log the user wouldn't see anything printed to stdout by default. This change logs a simple message to the user pointing them in the direction of the more verbose log if they need more help. Change-Id: I28ed8e35e057e5b57d1da437616f8aff1a184fe4
1 parent 713b653 commit bbcd7d2

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

nova/cmd/manage.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,7 +2729,9 @@ def get_machine_type(self, instance_uuid=None):
27292729
exception.InstanceMappingNotFound) as e:
27302730
print(str(e))
27312731
return 2
2732-
except Exception:
2732+
except Exception as e:
2733+
print('Unexpected error, see nova-manage.log for the full '
2734+
'trace: %s ' % str(e))
27332735
LOG.exception('Unexpected error')
27342736
return 1
27352737

@@ -2783,7 +2785,9 @@ def update_machine_type(
27832785
) as e:
27842786
print(str(e))
27852787
return 2
2786-
except Exception:
2788+
except Exception as e:
2789+
print('Unexpected error, see nova-manage.log for the full '
2790+
'trace: %s ' % str(e))
27872791
LOG.exception('Unexpected error')
27882792
return 1
27892793

@@ -2814,7 +2818,9 @@ def list_unset_machine_type(self, cell_uuid=None):
28142818
except exception.CellMappingNotFound as e:
28152819
print(str(e))
28162820
return 2
2817-
except Exception:
2821+
except Exception as e:
2822+
print('Unexpected error, see nova-manage.log for the full '
2823+
'trace: %s ' % str(e))
28182824
LOG.exception('Unexpected error')
28192825
return 1
28202826

@@ -2883,7 +2889,9 @@ def show(
28832889
) as e:
28842890
print(str(e))
28852891
return 2
2886-
except Exception:
2892+
except Exception as e:
2893+
print('Unexpected error, see nova-manage.log for the full '
2894+
'trace: %s ' % str(e))
28872895
LOG.exception('Unexpected error')
28882896
return 1
28892897

@@ -2911,7 +2919,9 @@ def get_connector(self, json=False):
29112919
else:
29122920
print(format_dict(host_connector))
29132921
return 0
2914-
except Exception:
2922+
except Exception as e:
2923+
print('Unexpected error, see nova-manage.log for the full '
2924+
'trace: %s ' % str(e))
29152925
LOG.exception('Unexpected error')
29162926
return 1
29172927

@@ -3114,7 +3124,9 @@ def refresh(self, instance_uuid=None, volume_id=None, connector_path=None):
31143124
except exception.InvalidInput as e:
31153125
print(str(e))
31163126
return 2
3117-
except Exception:
3127+
except Exception as e:
3128+
print('Unexpected error, see nova-manage.log for the full '
3129+
'trace: %s ' % str(e))
31183130
LOG.exception('Unexpected error')
31193131
return 1
31203132

nova/tests/unit/cmd/test_manage.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import textwrap
2020
import warnings
2121

22-
from cinderclient import exceptions as cinder_exception
2322
import ddt
2423
import fixtures
2524
import mock
@@ -3247,6 +3246,10 @@ def test_show_unknown_failure(self, mock_get_context):
32473246
"""Test the 'show' command with an unknown failure"""
32483247
mock_get_context.side_effect = test.TestingException('oops')
32493248
ret = self.commands.show(uuidsentinel.instance, uuidsentinel.volume)
3249+
output = self.output.getvalue().strip()
3250+
self.assertIn(
3251+
'Unexpected error, see nova-manage.log for the full trace: oops',
3252+
output)
32503253
self.assertEqual(1, ret)
32513254

32523255
@mock.patch(
@@ -3350,6 +3353,10 @@ def test_get_connector_unknown_failure(
33503353
mock_get_connector.side_effect = test.TestingException('oops')
33513354
ret = self.commands.get_connector()
33523355

3356+
output = self.output.getvalue().strip()
3357+
self.assertIn(
3358+
'Unexpected error, see nova-manage.log for the full trace: oops',
3359+
output)
33533360
self.assertEqual(1, ret)
33543361
mock_get_root.assert_called_once_with()
33553362
mock_get_connector.assert_called_once_with(
@@ -3491,7 +3498,7 @@ def test_refresh_invalid_volume_id(self, mock_get_instance, mock_get_bdm):
34913498
objects.BlockDeviceMapping, 'get_by_volume_and_instance')
34923499
@mock.patch.object(objects.Instance, 'get_by_uuid')
34933500
@mock.patch.object(objects.InstanceAction, 'action_start')
3494-
def test_refresh_attachment_create_failure(
3501+
def test_refresh_attachment_unknown_failure(
34953502
self, mock_action_start, mock_get_instance, mock_get_bdm, mock_lock,
34963503
mock_unlock, mock_attachment_create, mock_attachment_delete,
34973504
mock_attachment_get
@@ -3505,14 +3512,16 @@ def test_refresh_attachment_create_failure(
35053512
mock_get_bdm.return_value = objects.BlockDeviceMapping(
35063513
uuid=uuidsentinel.bdm, volume_id=uuidsentinel.volume,
35073514
attachment_id=uuidsentinel.attachment)
3508-
mock_attachment_create.side_effect = \
3509-
cinder_exception.ClientException(400, '400')
3515+
mock_attachment_create.side_effect = Exception('oops')
35103516
mock_action = mock.Mock(spec=objects.InstanceAction)
35113517
mock_action_start.return_value = mock_action
35123518

35133519
ret = self._test_refresh()
35143520
self.assertEqual(1, ret)
3515-
3521+
output = self.output.getvalue().strip()
3522+
self.assertIn(
3523+
'Unexpected error, see nova-manage.log for the full trace: oops',
3524+
output)
35163525
mock_attachment_create.assert_called_once_with(
35173526
mock.ANY, uuidsentinel.volume, uuidsentinel.instance)
35183527
mock_attachment_delete.assert_not_called()
@@ -3640,10 +3649,14 @@ def test_get(self, mock_get_context, mock_get_machine_type):
36403649
def test_get_unknown_failure(
36413650
self, mock_get_context, mock_get_machine_type
36423651
):
3643-
mock_get_machine_type.side_effect = Exception()
3652+
mock_get_machine_type.side_effect = Exception('oops')
36443653
ret = self.commands.get_machine_type(
36453654
instance_uuid=uuidsentinel.instance
36463655
)
3656+
output = self.output.getvalue().strip()
3657+
self.assertIn(
3658+
'Unexpected error, see nova-manage.log for the full trace: oops',
3659+
output)
36473660
self.assertEqual(1, ret)
36483661

36493662
@mock.patch('nova.virt.libvirt.machine_type_utils.get_machine_type')
@@ -3735,11 +3748,15 @@ def test_update_force(self, mock_get_context, mock_update):
37353748
@mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type')
37363749
@mock.patch('nova.context.get_admin_context', new=mock.Mock())
37373750
def test_update_unknown_failure(self, mock_update):
3738-
mock_update.side_effect = Exception()
3751+
mock_update.side_effect = Exception('oops')
37393752
ret = self.commands.update_machine_type(
37403753
instance_uuid=uuidsentinel.instance,
37413754
machine_type=mock.sentinel.machine_type
37423755
)
3756+
output = self.output.getvalue().strip()
3757+
self.assertIn(
3758+
'Unexpected error, see nova-manage.log for the full trace: oops',
3759+
output)
37433760
self.assertEqual(1, ret)
37443761

37453762
@mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type')
@@ -3859,9 +3876,13 @@ def test_list_unset_machine_type_none_found(
38593876
def test_list_unset_machine_type_unknown_failure(
38603877
self, mock_get_context, mock_get_instances
38613878
):
3862-
mock_get_instances.side_effect = Exception()
3879+
mock_get_instances.side_effect = Exception('oops')
38633880
ret = self.commands.list_unset_machine_type(
38643881
cell_uuid=uuidsentinel.cell_uuid)
3882+
output = self.output.getvalue().strip()
3883+
self.assertIn(
3884+
'Unexpected error, see nova-manage.log for the full trace: oops',
3885+
output)
38653886
self.assertEqual(1, ret)
38663887

38673888
@mock.patch(

0 commit comments

Comments
 (0)