本文整理汇总了Python中nova.compute.utils.add_instance_fault_from_exc函数的典型用法代码示例。如果您正苦于以下问题:Python add_instance_fault_from_exc函数的具体用法?Python add_instance_fault_from_exc怎么用?Python add_instance_fault_from_exc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_instance_fault_from_exc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle_schedule_error
def handle_schedule_error(context, ex, instance_uuid, request_spec):
"""On run_instance failure, update instance state and
send notifications.
"""
if not isinstance(ex, exception.NoValidHost):
LOG.exception(_("Exception during scheduler.run_instance"))
state = vm_states.ERROR.upper()
LOG.warning(_("Setting instance to %s state."), state, instance_uuid=instance_uuid)
(old_ref, new_ref) = db.instance_update_and_get_original(
context, instance_uuid, {"vm_state": vm_states.ERROR, "task_state": None}
)
notifications.send_update(context, old_ref, new_ref, service="scheduler")
compute_utils.add_instance_fault_from_exc(context, conductor_api.LocalAPI(), new_ref, ex, sys.exc_info())
properties = request_spec.get("instance_properties", {})
payload = dict(
request_spec=request_spec,
instance_properties=properties,
instance_id=instance_uuid,
state=vm_states.ERROR,
method="run_instance",
reason=ex,
)
notifier.get_notifier("scheduler").error(context, "scheduler.run_instance", payload)
示例2: set_vm_state_and_notify
def set_vm_state_and_notify(context, service, method, updates, ex, request_spec, db):
"""changes VM state and notifies."""
LOG.warning(_("Failed to %(service)s_%(method)s: %(ex)s"), {"service": service, "method": method, "ex": ex})
vm_state = updates["vm_state"]
properties = request_spec.get("instance_properties", {})
# NOTE(vish): We shouldn't get here unless we have a catastrophic
# failure, so just set all instances to error. if uuid
# is not set, instance_uuids will be set to [None], this
# is solely to preserve existing behavior and can
# be removed along with the 'if instance_uuid:' if we can
# verify that uuid is always set.
uuids = [properties.get("uuid")]
notifier = rpc.get_notifier(service)
for instance_uuid in request_spec.get("instance_uuids") or uuids:
if instance_uuid:
state = vm_state.upper()
LOG.warning(_("Setting instance to %s state."), state, instance_uuid=instance_uuid)
# update instance state and notify on the transition
(old_ref, new_ref) = db.instance_update_and_get_original(context, instance_uuid, updates)
notifications.send_update(context, old_ref, new_ref, service=service)
compute_utils.add_instance_fault_from_exc(context, new_ref, ex, sys.exc_info())
payload = dict(
request_spec=request_spec,
instance_properties=properties,
instance_id=instance_uuid,
state=vm_state,
method=method,
reason=ex,
)
event_type = "%s.%s" % (service, method)
notifier.error(context, event_type, payload)
示例3: set_vm_state_and_notify
def set_vm_state_and_notify(context, instance_uuid, service, method, updates,
ex, request_spec):
"""changes VM state and notifies."""
LOG.warning(_LW("Failed to %(service)s_%(method)s: %(ex)s"),
{'service': service, 'method': method, 'ex': ex})
vm_state = updates['vm_state']
properties = request_spec.get('instance_properties', {})
# NOTE(vish): We shouldn't get here unless we have a catastrophic
# failure, so just set the instance to its internal state
notifier = rpc.get_notifier(service)
state = vm_state.upper()
LOG.warning(_LW('Setting instance to %s state.'), state,
instance_uuid=instance_uuid)
instance = objects.Instance(context=context, uuid=instance_uuid,
**updates)
instance.obj_reset_changes(['uuid'])
instance.save()
compute_utils.add_instance_fault_from_exc(context,
instance, ex, sys.exc_info())
payload = dict(request_spec=request_spec,
instance_properties=properties,
instance_id=instance_uuid,
state=vm_state,
method=method,
reason=ex)
event_type = '%s.%s' % (service, method)
notifier.error(context, event_type, payload)
示例4: test_basic_schedule_run_instance_no_hosts
def test_basic_schedule_run_instance_no_hosts(self):
ctxt = context.RequestContext('fake', 'fake', False)
ctxt_elevated = 'fake-context-elevated'
fake_args = (1, 2, 3)
uuid = 'fake-uuid1'
instance_opts = {'fake_opt1': 'meow', 'launch_index': -1}
request_spec = {'instance_uuids': [uuid],
'instance_properties': instance_opts}
self.mox.StubOutWithMock(ctxt, 'elevated')
self.mox.StubOutWithMock(self.driver, 'hosts_up')
self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
# instance 1
ctxt.elevated().AndReturn(ctxt_elevated)
self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn([])
old_ref, new_ref = db.instance_update_and_get_original(ctxt, uuid,
{'vm_state': vm_states.ERROR,
'task_state': None}).AndReturn(({}, {}))
compute_utils.add_instance_fault_from_exc(ctxt,
new_ref, mox.IsA(exception.NoValidHost), mox.IgnoreArg())
self.mox.ReplayAll()
self.driver.schedule_run_instance(
ctxt, request_spec, None, None, None, None, {})
示例5: test_run_instance_non_admin
def test_run_instance_non_admin(self):
self.was_admin = False
def fake_get(context, *args, **kwargs):
# make sure this is called with admin context, even though
# we're using user context below
self.was_admin = context.is_admin
return {}
sched = fakes.FakeFilterScheduler()
self.stubs.Set(sched.host_manager, "get_all_host_states", fake_get)
fake_context = context.RequestContext("user", "project")
uuid = "fake-uuid1"
instance_properties = {"project_id": 1, "os_type": "Linux"}
request_spec = {
"instance_type": {"memory_mb": 1, "local_gb": 1},
"instance_properties": instance_properties,
"instance_uuids": [uuid],
}
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
old_ref, new_ref = db.instance_update_and_get_original(
fake_context, uuid, {"vm_state": vm_states.ERROR, "task_state": None}
).AndReturn(({}, {}))
compute_utils.add_instance_fault_from_exc(
fake_context, mox.IsA(conductor_api.LocalAPI), new_ref, mox.IsA(exception.NoValidHost), mox.IgnoreArg()
)
self.mox.ReplayAll()
sched.schedule_run_instance(fake_context, request_spec, None, None, None, None, {}, False)
self.assertTrue(self.was_admin)
示例6: test_run_instance_no_hosts
def test_run_instance_no_hosts(self):
def _fake_empty_call_zone_method(*args, **kwargs):
return []
sched = fakes.FakeFilterScheduler()
uuid = "fake-uuid1"
fake_context = context.RequestContext("user", "project")
instance_properties = {"project_id": 1, "os_type": "Linux"}
request_spec = {
"instance_type": {"memory_mb": 1, "root_gb": 1, "ephemeral_gb": 0},
"instance_properties": instance_properties,
"instance_uuids": [uuid],
}
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
old_ref, new_ref = db.instance_update_and_get_original(
fake_context, uuid, {"vm_state": vm_states.ERROR, "task_state": None}
).AndReturn(({}, {}))
compute_utils.add_instance_fault_from_exc(
fake_context, mox.IsA(conductor_api.LocalAPI), new_ref, mox.IsA(exception.NoValidHost), mox.IgnoreArg()
)
self.mox.StubOutWithMock(db, "compute_node_get_all")
db.compute_node_get_all(mox.IgnoreArg()).AndReturn([])
self.mox.ReplayAll()
sched.schedule_run_instance(fake_context, request_spec, None, None, None, None, {}, False)
示例7: handle_schedule_error
def handle_schedule_error(context, ex, instance_uuid, request_spec):
if not isinstance(ex, exception.NoValidHost):
LOG.exception(_("Exception during scheduler.run_instance"))
compute_utils.add_instance_fault_from_exc(context,
instance_uuid, ex, sys.exc_info())
state = vm_states.ERROR.upper()
LOG.warning(_('Setting instance to %(state)s state.'),
locals(), instance_uuid=instance_uuid)
# update instance state and notify on the transition
(old_ref, new_ref) = db.instance_update_and_get_original(context,
instance_uuid, {'vm_state': vm_states.ERROR,
'task_state': None})
notifications.send_update(context, old_ref, new_ref,
service="scheduler")
properties = request_spec.get('instance_properties', {})
payload = dict(request_spec=request_spec,
instance_properties=properties,
instance_id=instance_uuid,
state=vm_states.ERROR,
method='run_instance',
reason=ex)
notifier.notify(context, notifier.publisher_id("scheduler"),
'scheduler.run_instance', notifier.ERROR, payload)
示例8: test_live_migration_set_vmstate_error
def test_live_migration_set_vmstate_error(self):
inst = {"uuid": "fake-instance-id", "vm_state": vm_states.ACTIVE}
dest = "fake_host"
block_migration = False
disk_over_commit = False
self._mox_schedule_method_helper("schedule_live_migration")
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
self.manager.driver.schedule_live_migration(
self.context, inst, dest, block_migration, disk_over_commit
).AndRaise(ValueError)
db.instance_update_and_get_original(self.context, inst["uuid"], {"vm_state": vm_states.ERROR}).AndReturn(
(inst, inst)
)
compute_utils.add_instance_fault_from_exc(
self.context, mox.IsA(conductor_api.LocalAPI), inst, mox.IsA(ValueError), mox.IgnoreArg()
)
self.mox.ReplayAll()
self.stub_out_client_exceptions()
self.assertRaises(
ValueError, self.manager.live_migration, self.context, inst, dest, block_migration, disk_over_commit
)
示例9: test_live_migration_compute_service_notavailable
def test_live_migration_compute_service_notavailable(self):
inst = {"uuid": "fake-instance-id",
"vm_state": vm_states.ACTIVE,
"task_state": task_states.MIGRATING, }
dest = 'fake_host'
block_migration = False
disk_over_commit = False
self._mox_schedule_method_helper('schedule_live_migration')
self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
self.manager.driver.schedule_live_migration(self.context,
inst, dest, block_migration, disk_over_commit).AndRaise(
exception.ComputeServiceUnavailable(host="src"))
db.instance_update_and_get_original(self.context, inst["uuid"],
{"vm_state": inst['vm_state'],
"task_state": None,
"expected_task_state": task_states.MIGRATING,
}).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(self.context,
mox.IsA(conductor_api.LocalAPI), inst,
mox.IsA(exception.ComputeServiceUnavailable),
mox.IgnoreArg())
self.mox.ReplayAll()
self.stub_out_client_exceptions()
self.assertRaises(exception.ComputeServiceUnavailable,
self.manager.live_migration,
self.context, inst, dest, block_migration,
disk_over_commit)
示例10: test_prep_resize_no_valid_host_back_in_active_state
def test_prep_resize_no_valid_host_back_in_active_state(self):
fake_instance_uuid = 'fake-instance-id'
fake_instance = {'uuid': fake_instance_uuid}
inst = {"vm_state": "", "task_state": ""}
self._mox_schedule_method_helper('schedule_prep_resize')
self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
request_spec = {'instance_type': 'fake_type',
'instance_uuids': [fake_instance_uuid],
'instance_properties': {'uuid': fake_instance_uuid}}
kwargs = {
'context': self.context,
'image': 'fake_image',
'request_spec': request_spec,
'filter_properties': 'fake_props',
'instance': fake_instance,
'instance_type': 'fake_type',
'reservations': list('fake_res'),
}
self.manager.driver.schedule_prep_resize(**kwargs).AndRaise(
exception.NoValidHost(reason=""))
old_ref, new_ref = db.instance_update_and_get_original(self.context,
fake_instance_uuid,
{"vm_state": vm_states.ACTIVE, "task_state": None}).AndReturn(
(inst, inst))
compute_utils.add_instance_fault_from_exc(self.context,
mox.IsA(conductor_api.LocalAPI), new_ref,
mox.IsA(exception.NoValidHost), mox.IgnoreArg())
self.mox.ReplayAll()
self.manager.prep_resize(**kwargs)
示例11: test_prep_resize_exception_host_in_error_state_and_raise
def test_prep_resize_exception_host_in_error_state_and_raise(self):
fake_instance_uuid = "fake-instance-id"
fake_instance = {"uuid": fake_instance_uuid}
self._mox_schedule_method_helper("schedule_prep_resize")
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
request_spec = {"instance_properties": {"uuid": fake_instance_uuid}}
kwargs = {
"context": self.context,
"image": "fake_image",
"request_spec": request_spec,
"filter_properties": "fake_props",
"instance": fake_instance,
"instance_type": "fake_type",
"reservations": list("fake_res"),
}
self.manager.driver.schedule_prep_resize(**kwargs).AndRaise(test.TestingException("something happened"))
inst = {"vm_state": "", "task_state": ""}
old_ref, new_ref = db.instance_update_and_get_original(
self.context, fake_instance_uuid, {"vm_state": vm_states.ERROR, "task_state": None}
).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(
self.context, mox.IsA(conductor_api.LocalAPI), new_ref, mox.IsA(test.TestingException), mox.IgnoreArg()
)
self.mox.ReplayAll()
self.assertRaises(test.TestingException, self.manager.prep_resize, **kwargs)
示例12: test_run_instance_exception_puts_instance_in_error_state
def test_run_instance_exception_puts_instance_in_error_state(self):
fake_instance_uuid = 'fake-instance-id'
inst = {"vm_state": "", "task_state": ""}
self._mox_schedule_method_helper('schedule_run_instance')
self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
request_spec = {'instance_properties': inst,
'instance_uuids': [fake_instance_uuid]}
self.manager.driver.schedule_run_instance(self.context,
request_spec, None, None, None, None, {}).AndRaise(
exception.NoValidHost(reason=""))
old, new_ref = db.instance_update_and_get_original(self.context,
fake_instance_uuid,
{"vm_state": vm_states.ERROR,
"task_state": None}).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(self.context,
mox.IsA(conductor_api.LocalAPI), new_ref,
mox.IsA(exception.NoValidHost), mox.IgnoreArg())
self.mox.ReplayAll()
self.manager.run_instance(self.context, request_spec,
None, None, None, None, {})
示例13: test_live_migration_schedule_novalidhost
def test_live_migration_schedule_novalidhost(self):
inst = {"uuid": "fake-instance-id",
"vm_state": vm_states.ACTIVE,
"task_state": task_states.MIGRATING, }
dest = None
block_migration = False
disk_over_commit = False
pclm = "pclm"
self.mox.StubOutWithMock(self.manager, '_schedule_live_migration')
self.mox.StubOutWithMock(compute_utils, 'add_instance_fault_from_exc')
self.mox.StubOutWithMock(db, 'instance_update_and_get_original')
self.manager._schedule_live_migration(self.context,
inst, dest, block_migration, disk_over_commit, pclm).AndRaise(
exception.NoValidHost(reason=""))
db.instance_update_and_get_original(self.context, inst["uuid"],
{"vm_state": inst['vm_state'],
"task_state": None,
"expected_task_state": task_states.MIGRATING,
}).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(self.context,
mox.IsA(conductor_api.LocalAPI), inst,
mox.IsA(exception.NoValidHost),
mox.IgnoreArg())
self.mox.ReplayAll()
self.manager = utils.ExceptionHelper(self.manager)
self.assertRaises(exception.NoValidHost,
self.manager.live_migration,
self.context, inst, dest, block_migration,
disk_over_commit, pclm)
示例14: test_prep_resize_no_valid_host_back_in_active_state
def test_prep_resize_no_valid_host_back_in_active_state(self):
fake_instance_uuid = "fake-instance-id"
fake_instance = {"uuid": fake_instance_uuid}
inst = {"vm_state": "", "task_state": ""}
self._mox_schedule_method_helper("schedule_prep_resize")
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
request_spec = {
"instance_type": "fake_type",
"instance_uuids": [fake_instance_uuid],
"instance_properties": {"uuid": fake_instance_uuid},
}
kwargs = {
"context": self.context,
"image": "fake_image",
"request_spec": request_spec,
"filter_properties": "fake_props",
"instance": fake_instance,
"instance_type": "fake_type",
"reservations": list("fake_res"),
}
self.manager.driver.schedule_prep_resize(**kwargs).AndRaise(exception.NoValidHost(reason=""))
old_ref, new_ref = db.instance_update_and_get_original(
self.context, fake_instance_uuid, {"vm_state": vm_states.ACTIVE, "task_state": None}
).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(
self.context, mox.IsA(conductor_api.LocalAPI), new_ref, mox.IsA(exception.NoValidHost), mox.IgnoreArg()
)
self.mox.ReplayAll()
self.manager.prep_resize(**kwargs)
示例15: test_live_migration_schedule_novalidhost
def test_live_migration_schedule_novalidhost(self):
inst = {"uuid": "fake-instance-id", "vm_state": vm_states.ACTIVE, "task_state": task_states.MIGRATING}
dest = None
block_migration = False
disk_over_commit = False
self._mox_schedule_method_helper("schedule_live_migration")
self.mox.StubOutWithMock(compute_utils, "add_instance_fault_from_exc")
self.mox.StubOutWithMock(db, "instance_update_and_get_original")
self.manager.driver.schedule_live_migration(
self.context, inst, dest, block_migration, disk_over_commit
).AndRaise(exception.NoValidHost(reason=""))
db.instance_update_and_get_original(
self.context,
inst["uuid"],
{"vm_state": inst["vm_state"], "task_state": None, "expected_task_state": task_states.MIGRATING},
).AndReturn((inst, inst))
compute_utils.add_instance_fault_from_exc(
self.context, mox.IsA(conductor_api.LocalAPI), inst, mox.IsA(exception.NoValidHost), mox.IgnoreArg()
)
self.mox.ReplayAll()
self.stub_out_client_exceptions()
self.assertRaises(
exception.NoValidHost,
self.manager.live_migration,
self.context,
inst,
dest,
block_migration,
disk_over_commit,
)