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
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>
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
Merge "Update usage of 'ip' to handle more return codes"
Merge "Check instance lock in compute/api"
Merge "Simple refactor of some db api tests."
Merge "Fix regression with nova-manage floating list"
Fix broken pep8 exclude processing.

First of all, our pep8 exclude was excluding openstack, to trap
for not doing pep8 checks on openstack/common, which comes from elsewhere.
But, pep8 strips filenames down to basename when doing exclude checks on
them, which makes no sense. To fix this, grab the two functions from pep8,
fix them, and monkeypatch them from within hacking.py.

Patch has been submitted upstream as:

  https://github.com/jcrocholl/pep8/pull/111

Also, changed the exclude to catch just openstack/common.

Change-Id: If0b18ae828e74203f84a8b6f8b4ba0100b3bbc59
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
Remove unused variables

Change-Id: I137c9522257e8b5fcb13c1e9fe6cb4e0c442e33c
import missing module time

time is used in line 2450 but is never imported

Change-Id: I8b5690c5562768050416d0921cbae7dd0af769c9
Rename _self to self according to Python convention

If self is never used, it should probably be defined as a classmethod
or a staticmethod, instead of _self. Use "self" for now to stick
to python convention, and leave proper refactor to other patches.

Change-Id: I71de42ffd3e83c57772b6490c52f24bcd9d1f1ea
Merge "Rename _self to self according to Python convention"
Merge "Remove unused variables"
Merge "Fix broken pep8 exclude processing."
Merge "Partially revert "Remove unused scheduler functions""
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