def wrapped(*args, **kwargs): instance = _find_argument(instance_reference, *args, **kwargs) try: result = function(*args, **kwargs) cpo.add_successful_event(instance) return result except Exception as exception: cpo.add_fail_event(instance, exception) raise exception
def test_add_fail_event(self, conductor, get_step, ctx): instance = FakeInstance() self.override_config("disable_event_log", True) cpo.add_fail_event(instance, Exception('oops')) self.assertEqual(0, conductor.cluster_event_add.call_count) self.override_config("disable_event_log", False) cpo.add_fail_event(instance, Exception('oops')) self.assertEqual(1, conductor.cluster_event_add.call_count) args, kwargs = conductor.cluster_event_add.call_args self.assertEqual('step_id', args[1]) req_dict = { 'successful': False, 'node_group_id': instance.node_group_id, 'instance_id': instance.instance_id, 'instance_name': instance.instance_name, 'event_info': 'oops', } self.assertEqual(req_dict, args[2])
def test_add_fail_event(self, conductor, get_step, ctx): instance = FakeInstance() self.override_config("disable_event_log", True) cpo.add_fail_event(instance, Exception("oops")) self.assertEqual(0, conductor.cluster_event_add.call_count) self.override_config("disable_event_log", False) cpo.add_fail_event(instance, Exception("oops")) self.assertEqual(1, conductor.cluster_event_add.call_count) args, kwargs = conductor.cluster_event_add.call_args self.assertEqual("step_id", args[1]) req_dict = { "successful": False, "node_group_id": instance.node_group_id, "instance_id": instance.instance_id, "instance_name": instance.instance_name, "event_info": "oops", } self.assertEqual(req_dict, args[2])
def _format_device(instance, device, use_xfs, formatted_devices=None, lock=None): with instance.remote() as r: try: timeout = _get_timeout_for_disk_preparing(instance.cluster) # Format devices with better performance options: # - reduce number of blocks reserved for root to 1% # - use 'dir_index' for faster directory listings # - use 'extents' to work faster with large files # - disable journaling fs_opts = "-F -m 1 -O dir_index,extents,^has_journal" command = "sudo mkfs.ext4 %s %s" % (fs_opts, device) if use_xfs: command = "sudo mkfs.xfs -f %s" % device r.execute_command(command, timeout=timeout) if lock: with lock: formatted_devices.append(device) except Exception as e: LOG.warning(_LW("Device {dev} cannot be formatted: {reason}").format(dev=device, reason=e)) cpo.add_fail_event(instance, e)
def add_fail_event(instance, exception, **kwargs): ops.add_fail_event(instance, exception)