attach/detach interface should raise exception when instance is locked

when instance is locked, exception should be raised if attach and
detach an interface operation is performed. This patch add instance
lock check for the 2 APIs, catch and process the exception at API layer.

Change-Id: I6c0b05dafb9d480c8f0002bcc8306cb65a32aaf7
Closes-Bug: #1275741
Bypass the database if limit=0 for server-list requests

Not all database engines handle fetching 0 rows the same and there isn't
really a point in going to the database to return nothing, so bypass the
DB query if limit=0.

The Nova API is explicitly checking if limit >= 0 so we can't make any
changes there since they would be backwards incompatible, i.e. to start
enforcing limit > 0.

Closes-Bug: #1296929

Change-Id: Ib3d0318bec972af5f1f25202101e76066f930f34
Use instance data instead of flavor in simple_tenant_usage extension

The simple_tenant_usage extension gets the flavor data from the instance
and then looks up the flavor from the database to return usage information.
Since we now store all of the flavor data in the instance itself,
we should use that information instead of what the flavor currently
says is right. This both (a) makes it more accurate and (b)
avoids us failing to return usage info if a flavor disappears.

Change-Id: I1472d78e8e920013a1db5c76e04715fa04b696c2
Closes-Bug: #1276731
Add test cases for validate_extra_spec_keys

There is no unit test cases for function flavors.validate_extra_spec_keys,
this patch adds for it

Change-Id: I689aad1ce7428687c723ecd2eba243fccb3342bf
Closes-Bug: #1292316
VMware: remove double import

"import mock" was done twice.

Change-Id: Ibc38d27d7fd8b57b193cbe37d2abd89b823ed43f
Change errors_out_migration decorator to work with RPC

This decorator in nova/compute/manager.py was written to work with
positional arguments, but at run time the decorated methods are
called via RPC with keyword arguments.  This change fixes the
decorator and the associated test cases.

Closes-Bug: #1300380

Change-Id: I9f87151a71e5217e7eff97cdc5cad2c85b620fa5
xenapi: add a test for _get_partitions

Currently vm_utils._get_partitions is not covered by any unit tests.
This patch adds a unit test for that code.

Change-Id: I3ff612ca88250ad3d4d3e19aa12d299e12e442ed
VMWare: add power off vm before detach disk during unrescue

Non Hot Plug type disk like IDE can only be detached when the VM is power off.

Change-Id: Ib1f387a41abe2b52357854e90c2535ebb7b43f18
Close-bug: #1279199
Check for None or timestamp in availability zone api sample

test_availability_zone_detail depends on the services not having an
updated_at time set in the database.  This is set by a periodic task so
it's not guaranteed to be set, or not, shortly after the service starts.
On a fast system the test reliably passes, but adding a delay causes the
test to start failing.  Introducing a time.sleep(5) in the test seems to
make it reliably fail for me.  The test should pass if updated_at is set
to None or a timestamp.

Change-Id: I976ddf5354a52ca06a6419a92abcacb7d2379a37
Closes-bug: 1300810
Add exception handling in "nova diagnostics"

when using "nova diagnostics" with a not running
instance, user will get an incorrect message. This
change handles that exception.

Change-Id: Ia2aa76a5c2c2aeed446411700d74d547dd73cf90
Closes-bug: #1289079
libvirt: remove_logical_volumes should remove each separately

Currently, remove_logical_volumes() is trying to remove
all of the provided volumes path in a single lvremove command,
while retrying it several times.
This is causing the command to fail, when the deleted volumes
are reappearing in the next iteration of the retry loop.

Handling the removal of each volume separately
and raising an exception for volumes which failed to be removed.
This will increase the chance for individual volume to be removed.

Closes-Bug: #1282423
Change-Id: Ib25f5603929c3038716661a589a41116b4c48909
Remove redundant tests from Qcow2TestCase

Qcow2TestCase had exact copies of two tests in the parent
_ImageTestCase so remove them. I'm assuming the tests originated
in Qcow2TestCase but later more image types were added and the
tests were pulled up into the common parent mixin since they
applied to all types of images, but the redundant tests from
Qcow2TestCase weren't cleaned up.

Related-Bug: #1302211

Change-Id: I031516b555ead5a3769fb62d90e373aac1b6baf1
Missing catch InstanceNotFound in v3 API

After apply instance look helper, some compute api
will invoke instance.save(), it will raise
InstanceNotFound also.
This patch adds them.

Closes-Bug: #1280067
Change-Id: I73cb35c90f1e46a447ae1807a997713105e08bde
Check image exists before calling inject_data

os.stat removal is needed for network-based image backends

Partly revert Change-Id: I264540de736c2bcb92567826fe5ba672e1244ba2
Partly fixes bug #1257674

Change-Id: I83e95fec6f08bc36f0e2b299fb269ceaa3500243
compute: using format_message() to convert exception to string

We probably need to use format_message when converting a
NovaException to a string.
As well we can remove the cast to unicode of the parameter msg
from the local method notify since this method will only get
message in a string format.

Change-Id: I6fddfb9e124b4096f0ebc3da81c3044b1b24cedf
Avoid the possibility of truncating disk info file

Commit dc8de42 makes nova persist image format to a file to avoid
attacks based on changing it later. However the way it was implemented
leaves a small window of opportunity for the file to be truncated before
it gets written back to effectively making it possible for data to get
lost leaving us with a potential problem next time it is attempted to be
read.

This patch changes the way file is updated to be atomic, thus closing
the race window (and also removes the chown that we did not really
need).

It is worth noting that a better solution to this would be
to allow the code calling the imagebackend to write the file (once!)
and make it impossible to update after the boot process is done. This
approach would require more refactoring of the libvirt driver code, and
may be done in the future.

Partial-bug: #1221190
Change-Id: Ia1b073f38e096989f34d1774a12a1b4151773fc7
Update user_id length to match Keystone schema in volume_usage_cache

Update the maximum length to match the Keystone schema for maximum
user_id length in volume_usage_cache. In the case that Keystone were
to leverage the full varchar 64, there would potentially be data loss
and/or collision of user_ids across records.

This change originates from the conversation about increasing the
length of user_ids in Keystone:

http://lists.openstack.org/pipermail/openstack-dev/2014-February/028125.html

Even with the length not changing, it is important to ensure there is no
loss of data/resolution when relying on user_id to identify users uniquely.

Closes-Bug: #1226171
Change-Id: I05a5644a29d6e2432311c2ee5331970d5e8b0683
Allow user to specify image to use during rescue

This commit includes the compute changes to accept a parameter
rescue_image_ref in the rescue_instance method.
If specified, this image_ref will be used to rescue the instance.
If the image is not specified, then the base image ref is used by default.

Partially Implements: blueprint allow-image-to-be-specified-during-rescue

DocImpact

Change-Id: I59311fcfcb8eb54701618e92e5cdada109235b38
Make compute manager use network api method return values

Calls to network api methods add_fixed_ip_to_instance() and
remove_fixed_ip_from_instance() return updated nw_info models
so there is no need to make separate calls to get this info.

This change refactors the affected code to avoid such extra
calls. Related methods in the neutron api are updated to return
the same information as their nova-network api counterparts.

Change-Id: I39dcf257ed5c101b13c2243266eed265c64e3c98
Closes-Bug: #1284345
Merge "Remove redundant tests from Qcow2TestCase"