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
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
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
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
Merge "Avoid the possibility of truncating disk info file"
Merge "compute: using format_message() to convert exception to string"
Merge "Add test cases for validate_extra_spec_keys"
Merge "Check image exists before calling inject_data"
Merge "attach/detach interface should raise exception when instance is locked"
Merge "VMware: remove double import"
Merge "Add exception handling in "nova diagnostics""