Files
nova/nova/virt/virtapi.py
Dan Smith 56d3cd7aa7 Add a way to exit early from a wait_for_instance_event()
In some situations, we may enter into a race-safe wait context for an
external event and then determine within the context that the event
would have already fired or for some other reason waiting is not required.
In that case, this introduces a VirtAPI method to abort the wait for
specific events in a clean way.

This should be used sparingly and only in certain circumstances where
it is clear that the event has already occurred. For example, if the
action triggering the event was initiated outside of the wait context,
we can enter the wait context (establishing a waiting event to capture),
and then poll once for completion of that thing. If incomplete, we will
block and wait on context exit as usual. If the thing we are waiting for
has already completed, then we can avoid the long wait by calling the
early-exit helper and avoid what would ultimately be a timeout and
failure.

We are specifically adding this to address the cyborg scenario as follows:

Once we select a host in the conductor for an instance build, we can call
to cyborg to start the preparation (i.e. programming) of the device on the
destination host. This takes time, and by kicking it off early, we can
overlap that process with other work we have to do. Because that will send
an event upon completion, which will be routed to the compute, we will race
to start the build process on the compute and begin the race-safe event
wait in the compute manager. Instead of collapsing the window and waiting
synchronously, we can trigger it early, then start the wait in the compute
later, check for early completion *after* the wait has been set up, and then
exit the wait early if we determine that the event had already been sent.
This allows us to be async with cyborg across two services while still being
safe in the critical region where we need to setup the wait before we rely
on the event being sent.

Change-Id: I8e5a0683069b2f322cb059d6eb501d732d1bd851
2019-12-02 07:00:26 -08:00

37 lines
1.4 KiB
Python

# Copyright 2012 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import contextlib
class VirtAPI(object):
@contextlib.contextmanager
def wait_for_instance_event(self, instance, event_names, deadline=300,
error_callback=None):
raise NotImplementedError()
def exit_wait_early(self, events):
raise NotImplementedError()
def update_compute_provider_status(self, context, rp_uuid, enabled):
"""Used to add/remove the COMPUTE_STATUS_DISABLED trait on the provider
:param context: nova auth RequestContext
:param rp_uuid: UUID of a compute node resource provider in Placement
:param enabled: True if the node is enabled in which case the trait
would be removed, False if the node is disabled in which case
the trait would be added.
"""
raise NotImplementedError()