Update usage of 'ip' to handle more return codes

Make sure that ip raises an exception.ProcessExecutionError unless
'ip' exits with a 0, 2, or 254.

0 = command executed correctly
2/254 = command has already been executed.

Change-Id: I55dd63ca7fc22bc133ab5fe722df4141c332a819
Signed-off-by: Chuck Short <chuck.short@canonical.com>
Check instance lock in compute/api

This adds a check for the instance lock in compute/api.py, which:
1. Helps avoid the need to call into the manager just to be stopped
   by the lock there
2. Returns a failure to the user right away when an operation cannot
   be completed due to the lock
3. Avoids the potential for task_state to get into an unhappy state
   because a user unknowingly attempts an action whilst an instance
   is locked
4. Avoids the manager from having to re-do the lock check by
   stuffing a flag into RequestContext when the check has already
   been done by api.py

Various tests needed to be fixed up in order to pass fake instances
with the locked attribute. We could make the decorator ignore
instances without it, but I think it's more explicit to push that
requirement into the tests.

This fixes bug 872541

Change-Id: I1127e31d86a061a93a64ee1eb4a4d900d8bf49b5
Simple refactor of some db api tests.

A few tests were using context.elevated instead of just passing the correct
project id to the instance_create function.

Change-Id: Ib54d079cbad823abd85dcca9e5cd813887169fb0
Fix regression with nova-manage floating list

Fixes bug #1032177

If a floating IP is not associated with an instance, nova-manage fails
with:

  local variable 'instance_uuid' referenced before assignment

This is a regression introduced by commit fc82c6d. Simply rename
the local variable to instance_uuid.

Change-Id: Ia6df23c945f0815c65bcfd2f49e8ba3225d03d7f
Handle InstanceNotFound in libvirt list_instances.

Updates the libvirt driver so that InstanceNotFound is
handled within the list_instances function. This
can occur if an instance is deleted while the
list_instances function is processing.

Fixes LP Bug #1032741.
Change-Id: I97c9533f8b37957e71237c610ac360fbf9f57b9a
Updates to the prep_resize scheduler rpc call.

I started looking at this because of the prep_resize rpc call in the compute
manager.  An API server calls prep_resize on the scheduler which then calls it
on a compute node.  I will need to make the same changes on the compute side,
but this is the first step.

The prep_resize call was taking two object IDs, an instance UUID and an
instance_type ID.  Both of these have been converted.  It now takes an instance
dict and an instance_type dict, instead.  It can also handle receiving the old
IDs for backwards compatibility.  prep_resize also took a topic argument that
was unused, so it has just been removed.

There are a number of changes in the scheduler code tied up in this to make it
more explicit about exactly what arguments are expected instead of just using
*args, **kwargs.

Part of blueprint no-db-messaging.

Change-Id: I4af18e5575e2bb60a410fc8edabf3d607c72aabc
Remove **kwargs from prep_resize in compute manager.

The only place where additional arguments were being passed in was via
the unit tests, and they aren't used.

Part of blueprint no-db-messaging.

Change-Id: I13f4a209ac9acc732966cb6e01bdbbcc3e3bd3c8
Remove instance_id fallback from cast_to_compute_host().

This removes some code that supported using either an instance id or
uuid when doing an instance update.  The db API no longer accepts an ID.
A UUID must be used or it will raise an exception.  I also updated the
unit tests to reflect this.

Change-Id: I5a9442f3b571f37950676e96e2f129ea45c55d78
Reduce db access in prep_resize in the compute manager.

This patch changes the arguments passed to prep_resize in the compute
manager.  Previously it took instance and instance_type IDs.  It now
receives a full dict for both of these.  This cuts down on database
access needed on the compute node.

This method was not previously in the compute rpcapi module, so it has
been added there.  The scheduler had a bit of work done ot get it to use
the rpcapi module for prep_resize, as well.

Part of blueprint no-db-messaging.

Change-Id: Idadbf4fc624d5d1b128f758a46c61b3c840b9898
Update args to _set_vm_state_and_notify.

This patch removes *args and **kwargs from _set_vm_state_and_notify.
The only additional argument used was request_spec, so just list it out
explicitly.

Change-Id: I64590a2d79c2d303e7c936a4c3b1545eecfd0f2b
Use explicit args in run_instance scheduler code.

This patch goes through code paths related to run_instance in the
scheduler to use explicit arguments instead of **kwargs.  I'm trying to
work out exactly what data is getting passed through the system when an
instance is created, so that I can make the no-db-messaging related
changes.  This patch helps clarify some things.

Part of blueprint no-db-messaging.

Change-Id: Id83fc1e399e1d5c75af6dd3c8972b8ba9d706af1
Remove topic from scheduler run_instance.

This argument to run_instance was unused, so just remove it.

Change-Id: I42366514285a2355f647c776af140effc1618b7d
Use explicit arguments in compute manager run_instance.

Use explicit arguments in functions in the run_instance code path of the
compute manager.  I think methods of the rpc API are better this way as
we have to be careful when changing these functions so we handle
versioning and backwards compatibility properly.  Spelling out all of
the arguments like this makes it easier to catch when things change and
to make sure they are changed properly.

This is in preparation of changing the instance_uuid to an instance
dict, instead.

Part of blueprint no-db-messaging.

Change-Id: I1e141b471040b0fd4833d4e08d44166a9d12bcad
Send full instance to run_instance.

This patch updates run_instance in the compute manager to take a full
instance instead of just an instance UUID.  This reduces db access
required by the compute nodes.  The scheduler code needed some work here
as well since it wasn't using the compute rpcapi for calling
run_instance.

Part of blueprint no-db-messaging.

Change-Id: If5545748122b4ff9e2da6788cbd4b0fa26c4db99