From a9b34a1ce2dcebfb7bf85b9117b73d277997c483 Mon Sep 17 00:00:00 2001 From: Lee Yarwood Date: Fri, 3 Sep 2021 16:13:34 +0100 Subject: [PATCH] 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. Conflicts: nova/cmd/manage.py nova/tests/unit/cmd/test_manage.py NOTE(auniyal): changes for class VolumeAttachmentCommands are not required to backport as class does not exists in stable/wallaby Change-Id: I28ed8e35e057e5b57d1da437616f8aff1a184fe4 (cherry picked from commit bbcd7d2fd03c0717af18f2724c75c1447e430fb1) --- nova/cmd/manage.py | 12 +++++++++--- nova/tests/unit/cmd/test_manage.py | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 3d33602f56f..1329774754c 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -2662,7 +2662,9 @@ def get_machine_type(self, instance_uuid=None): exception.InstanceMappingNotFound) as e: print(str(e)) return 2 - except Exception: + except Exception as e: + print('Unexpected error, see nova-manage.log for the full ' + 'trace: %s ' % str(e)) LOG.exception('Unexpected error') return 1 @@ -2716,7 +2718,9 @@ def update_machine_type( ) as e: print(str(e)) return 2 - except Exception: + except Exception as e: + print('Unexpected error, see nova-manage.log for the full ' + 'trace: %s ' % str(e)) LOG.exception('Unexpected error') return 1 @@ -2747,7 +2751,9 @@ def list_unset_machine_type(self, cell_uuid=None): except exception.CellMappingNotFound as e: print(str(e)) return 2 - except Exception: + except Exception as e: + print('Unexpected error, see nova-manage.log for the full ' + 'trace: %s ' % str(e)) LOG.exception('Unexpected error') return 1 diff --git a/nova/tests/unit/cmd/test_manage.py b/nova/tests/unit/cmd/test_manage.py index 875345d35bf..c926f344d31 100644 --- a/nova/tests/unit/cmd/test_manage.py +++ b/nova/tests/unit/cmd/test_manage.py @@ -3050,10 +3050,14 @@ def test_get(self, mock_get_context, mock_get_machine_type): def test_get_unknown_failure( self, mock_get_context, mock_get_machine_type ): - mock_get_machine_type.side_effect = Exception() + mock_get_machine_type.side_effect = Exception('oops') ret = self.commands.get_machine_type( instance_uuid=uuidsentinel.instance ) + output = self.output.getvalue().strip() + self.assertIn( + 'Unexpected error, see nova-manage.log for the full trace: oops', + output) self.assertEqual(1, ret) @mock.patch('nova.virt.libvirt.machine_type_utils.get_machine_type') @@ -3145,11 +3149,15 @@ def test_update_force(self, mock_get_context, mock_update): @mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type') @mock.patch('nova.context.get_admin_context', new=mock.Mock()) def test_update_unknown_failure(self, mock_update): - mock_update.side_effect = Exception() + mock_update.side_effect = Exception('oops') ret = self.commands.update_machine_type( instance_uuid=uuidsentinel.instance, machine_type=mock.sentinel.machine_type ) + output = self.output.getvalue().strip() + self.assertIn( + 'Unexpected error, see nova-manage.log for the full trace: oops', + output) self.assertEqual(1, ret) @mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type') @@ -3269,9 +3277,13 @@ def test_list_unset_machine_type_none_found( def test_list_unset_machine_type_unknown_failure( self, mock_get_context, mock_get_instances ): - mock_get_instances.side_effect = Exception() + mock_get_instances.side_effect = Exception('oops') ret = self.commands.list_unset_machine_type( cell_uuid=uuidsentinel.cell_uuid) + output = self.output.getvalue().strip() + self.assertIn( + 'Unexpected error, see nova-manage.log for the full trace: oops', + output) self.assertEqual(1, ret) @mock.patch(