Skip to content

Commit a9b34a1

Browse files
lyarwoodauniyal61
authored andcommitted
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 bbcd7d2)
1 parent 797c5fa commit a9b34a1

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

nova/cmd/manage.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,9 @@ def get_machine_type(self, instance_uuid=None):
26622662
exception.InstanceMappingNotFound) as e:
26632663
print(str(e))
26642664
return 2
2665-
except Exception:
2665+
except Exception as e:
2666+
print('Unexpected error, see nova-manage.log for the full '
2667+
'trace: %s ' % str(e))
26662668
LOG.exception('Unexpected error')
26672669
return 1
26682670

@@ -2716,7 +2718,9 @@ def update_machine_type(
27162718
) as e:
27172719
print(str(e))
27182720
return 2
2719-
except Exception:
2721+
except Exception as e:
2722+
print('Unexpected error, see nova-manage.log for the full '
2723+
'trace: %s ' % str(e))
27202724
LOG.exception('Unexpected error')
27212725
return 1
27222726

@@ -2747,7 +2751,9 @@ def list_unset_machine_type(self, cell_uuid=None):
27472751
except exception.CellMappingNotFound as e:
27482752
print(str(e))
27492753
return 2
2750-
except Exception:
2754+
except Exception as e:
2755+
print('Unexpected error, see nova-manage.log for the full '
2756+
'trace: %s ' % str(e))
27512757
LOG.exception('Unexpected error')
27522758
return 1
27532759

nova/tests/unit/cmd/test_manage.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,10 +3050,14 @@ def test_get(self, mock_get_context, mock_get_machine_type):
30503050
def test_get_unknown_failure(
30513051
self, mock_get_context, mock_get_machine_type
30523052
):
3053-
mock_get_machine_type.side_effect = Exception()
3053+
mock_get_machine_type.side_effect = Exception('oops')
30543054
ret = self.commands.get_machine_type(
30553055
instance_uuid=uuidsentinel.instance
30563056
)
3057+
output = self.output.getvalue().strip()
3058+
self.assertIn(
3059+
'Unexpected error, see nova-manage.log for the full trace: oops',
3060+
output)
30573061
self.assertEqual(1, ret)
30583062

30593063
@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):
31453149
@mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type')
31463150
@mock.patch('nova.context.get_admin_context', new=mock.Mock())
31473151
def test_update_unknown_failure(self, mock_update):
3148-
mock_update.side_effect = Exception()
3152+
mock_update.side_effect = Exception('oops')
31493153
ret = self.commands.update_machine_type(
31503154
instance_uuid=uuidsentinel.instance,
31513155
machine_type=mock.sentinel.machine_type
31523156
)
3157+
output = self.output.getvalue().strip()
3158+
self.assertIn(
3159+
'Unexpected error, see nova-manage.log for the full trace: oops',
3160+
output)
31533161
self.assertEqual(1, ret)
31543162

31553163
@mock.patch('nova.virt.libvirt.machine_type_utils.update_machine_type')
@@ -3269,9 +3277,13 @@ def test_list_unset_machine_type_none_found(
32693277
def test_list_unset_machine_type_unknown_failure(
32703278
self, mock_get_context, mock_get_instances
32713279
):
3272-
mock_get_instances.side_effect = Exception()
3280+
mock_get_instances.side_effect = Exception('oops')
32733281
ret = self.commands.list_unset_machine_type(
32743282
cell_uuid=uuidsentinel.cell_uuid)
3283+
output = self.output.getvalue().strip()
3284+
self.assertIn(
3285+
'Unexpected error, see nova-manage.log for the full trace: oops',
3286+
output)
32753287
self.assertEqual(1, ret)
32763288

32773289
@mock.patch(

0 commit comments

Comments
 (0)