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
(cherry picked from commit 72cd430e971589f7872a9d4e8f173c68b4955375)
Moved the registration of lifecycle event handler in init_host()

The event handler has to be registered before the libvirt connection
is used for the first time.  Otherwise it doesn't register and events
such as shut down initiated from within the instance are not registered
in nova until a period task compares the content of hypervisor with
content of database.

Closes bug: #1297485

Change-Id: I70887bea343734a977f621fedc634b6fab0e4ad5
(cherry picked from commit 8a430da045d86ccb8daee6e082c12890ce5c5276)
InvalidCPUInfo exception added to except block

When a live migration between two nodes with different
CPU info features is launched, an InvalidCPUInfo exception
is raised and not captured. That lets the vm in an
unusable state because the task_state rollback is not
executed.

Change-Id: Ib418fa324964cabd5f342d1b764f9ac7608b7ade
Closes-Bug: #1294210
(cherry picked from commit 7a3b4033f07f8c2144a36c1f12b1b9281cfb9a69)
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
(cherry picked from commit 1e1915aaaca38b5691794e0e052a42b9d95dd3c2)
VMWare - Check for compute node before triggering destroy

While booting an instance, if Claim on that compute node is not successful
compute manager triggers a call to destroy instance. Destroy fails since the
compute node (Cluster/ESX host) is set only after claim is successful.
Hence the check for node is made before destroy, to ensure that exception
does not get thrown. This ensures that the instance gets rescheduled
Closes-Bug: #1307408

Change-Id: Iaaf931e9c1e6cf046497e2c64952f92e802ad4be
(cherry picked from commit aadfffaaa69c6a8939f6c88cfbaeb026c7604163)
Use one query instead of two for quota_usages

The second query was unnecessary and not using a proper index. It
seemed to be contributing to a deadlock issue as well.

Change-Id: I1031451b25140d71380c8149d3c83827eec0d4a9
Closes-Bug: #1308715
Co-Authored-by: Chris Behrens <cbehrens@codestud.com>
(cherry picked from commit da1fa5dc93e6e64d397e8d00769e34828669e010)
Fixes arguments parsing when executing command

A regression was caused by changing the eventlet.subprocess.Popen
with the builtin subprocess.Popen (by using the nova.utils execute
method) without changing the way the arguments were parsed.

In the v1 volume utilities module, the execution args were parsed
separated by whitespaces, which is not allowed by the builtin
subprocess.Popen, causing a "not found" error.

This error is returned for example when attaching a volume, at the
point where iscsicli tool is used to login the iSCSI target or portal.

This patch fixes the issue by simply splitting the args.

Closes-bug: #1317180

Change-Id: Iee7d5de0dde8b68d8f2bab4214e9b6779ad9f722
(cherry picked from commit 40a790c32ee4ea7b9d79e259545f07409fd618fa)
Reap child processes gracefully if greenlet thread gets killed

If ProcessLauncher is run from within a thread we should be able to
call wait after the thread is killed to reap the child processes.
Catching this exception and then proceeding to the cleanup phase
accomplishes this.

Conflicts:
	nova/openstack/common/service.py

Closes-Bug: #1282206
Change-Id: I9c863864c25c0478b720fc57cf0dccbe9bc9d9f6
(cherry picked from commit a6fec438abe61d40fc4fb6907ea1fefd4dd93e22)
Do not wait for neutron event if not powering on libvirt domain

When resizing/migrating a stopped instance, the power_on flag is False
in _create_domain_and_network so virtual interfaces are not plugged and
we are waiting for an event callback from Neutron that won't happen.
This leads to an eventlet timeout and subsequent attempt to destroy the
non-running domain, which results in a libvirtError.

This change just adds the power_on flag to the list of conditions for
determining if we should wait for an event callback from Neutron.

Closes-Bug: #1321872

Change-Id: Id87ed125db8b1e807b7fa0d99180d0820edbed3e
(cherry picked from commit e0228eb7e739956978f002f58edf35bc4d698022)
Catch InstanceNotFound exception if migration fails

When a VM with an attached iSCSI disk fails to migrate, the rollback methods
does not detach the disk from target host. What happens is _lookup_by_name()
fails, since the VM does not exist on the target host. In detach_volume(), it
is supposed to print a warning based on the correct error code being returned,
instead of throwing the exception. However, this is not happening, because
_lookup_by_name() throws an InstanceNotFound exception, rather than a
libvirt.libvirtError exception. So we also need to catch InstanceNotFound
exception, so that detach_volume() can continue to execute as expected.

Change-Id: I396c23d8137bf1e2834769c5483d2494506949ad
Closes-Bug: #1321082
(cherry picked from commit 52b57e82c7ef972508777a8bd3c7b937a3673d2d)
VMware: uncaught exception during snapshot deletion

During the image upload of the snapshot to glance, an exception is
thrown that ends up getting ignored.  As a result, the instance gets
stuck in the "Image Uploading" state.

Change-Id: Id2cb3c244edd831939794da9dcc1fd9fce59991c
Closes-bug: #1249519
(cherry picked from commit 56607f9af4495e76edf6675a984a66da907c89f8)
Merge "Use one query instead of two for quota_usages" into stable/icehouse
Add info_cache as expected attribute when evacuate instance

Nova evacuates instance failed with neutron. The reason is
when nova-conductor try to get network info for instance, it
need instance include 'info_cache', but the instance dict which
passed didn't include it. This patch adds 'info_cache' as the
expected attribute for get instance.

Change-Id: I6f110c607e32b0ab536916741605b25d572331dc
Closes-Bug: #1284709
(cherry picked from commit 4c68f19cd8d1f045bde02be7eec50c34c1d87932)
VMware: Log additional details of suds faults

When a suds requests results in a fault response, the current
code loses details on that fault in the sequence of exceptions
propagated through the driver.  A NoPermission fault will contain
additional metadata on the privilegeId and object type which
needs to be logged.  The fault string will be propagated with this
fix, along with details of a NoPermission fault.

An example of the new exception:
NoPermissionException: Permission to perform this operation was denied.
{u'privilegeId': Resource.AssignVMToPool, u'object': domain-c7}

An example of new exception within retrieveproperties_fault_checker:
Error(s) NoPermission occurred in the call to RetrievePropertiesEx
{'privilegeId': System.Read, 'object': datacenter-16}

Change-Id: Iafbf052750c2835f304b2edf21d7300d1fbd7e5a
Closes-bug: #1289627
(cherry picked from commit 62cb0dc6257daac5ec9fd1a90ee5721e6543dd76)
Merge "Change errors_out_migration decorator to work with RPC" into stable/icehouse
Merge "Moved the registration of lifecycle event handler in init_host()" into stable/icehouse
VMware: ensure rescue instance is deleted when instance is deleted

If the user creates a rescue instance and then proceeded to delete
the original instance then the rescue instance would still be up
and running on the backend.

This patch ensures that the rescue instance is cleaned up if
necessary.

The vmops unrescue method has a new parameter indicating if
the original VM should be powered on.

Closes-bug: 1269418
(cherry picked from commit efb66531bc37ee416778a70d46c657608ca767af)

Conflicts:

	nova/virt/vmwareapi/vmops.py

Change-Id: I3c1d0b1d003392b306094b80ea1ac99377441fbf
Merge "VMWare: add power off vm before detach disk during unrescue" into stable/icehouse
Merge "VMware: ensure rescue instance is deleted when instance is deleted" into stable/icehouse
Merge "Fixes arguments parsing when executing command" into stable/icehouse