libvirt: Make `fakelibvirt.libvirtError` match

When test code uses `libvirtError`, it may refer to
`libvirt.libvirtError` or `fakelibvirt.libvirtError` depending on
whether `libvirt-python` is installed.

The existing code had incompatible `__init__` singatures between the
two, meaning that a test could pass locally but fail when run on
Jenkins.

The solution is to make `fakelibvirt.libvirtError` match libvirt 1.2.3
exactly.

A convenience function, `make_libvirtError`, is introduced so that
exceptions can still be created in one shot.

Change-Id: I5aaecc57504c4aea3c049610ef188978c25cfdc4
Closes-Bug: 1305186
(cherry picked from commit 78156a7650237bd4875fbbf9cad8db87348f333f)
libvirt: Handle unsupported host capabilities

Neither libvirt-xen nor libvirt-lxc support
VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES so check for the proper error
code that is returned by libvirt.

The existing code was performing this check improperly by trying to
catch an enum value; instead, we need to catch the `libvirtError`
exception and then check its return code.

Co-Authored-By: Rick Harris <rconradharris@gmail.com>
Co-Authored-By: Andrew Melton <andrew.melton@rackspace.com>
Closes-Bug: 1297962
Change-Id: Ie8bf5c9d1f2a27c387f8b2f54a9bb729fa2f0985
(cherry picked from commit 5fc157e0f5245eb79be90cbc8ed545c396fd38af)
Ignore errors when deleting non-existing vifs

If an instance fails during its network creation (for example
if the network-vif-plugged event doesn't arrive in time) a
subsequent delete will also fail when it tries to delete the
vif, leaving the instance in a Error(deleting) state.

This can be avoided by including the "--if-exists" option to
the ovs-vsctl command so that the command doesn't fail if the
vif doesn't exist.

Change-Id: Ic613c9d6e0619f51fcd931e62f6d6bce404ebe81
Closes-bug: #1308544
(cherry picked from commit 476dc5efcdb11c9859b062dc69a8c205e69be861)
Fix instance cross AZ check when attaching volumes

For CONF.cinder_cross_az_attach=False, we currently only check the desired AZ
during scheduling but don't actually check the final AZ of the node.

When attaching volumes to running instances we need to check the actual
AZ on the instance and not the desired AZ at boot time. The desired AZ
attribute is optional at boot and may not be set or the desired AZ
could be different from the final AZ.
When we are booting with a volume however we don't know the final AZ so we
check on the desired AZ.

Closes-Bug: #1255347
Change-Id: Ied912c171100a450754d315027bf5c407ac067bb
(cherry picked from commit 18a1486293b15c5713ac1352b9b9b30fdf2b7413)
Fixes missing ec2 api address disassociate error on failure

Fixes ec2 api address disassociate so that the ec2 error
InvalidAssociationID.NotFound is returned when it is passed an
invalid association rather than returning success. Note this is
slightly different than the original bug report but the type
of failure has changed since the bug was originally filed.

Change-Id: I10034a2fed62d4e93bc384aef3ff594b66e285f2
Closes-Bug: 1179816
(cherry picked from commit 00d8c334bbfaef3ffec4b04b494e609740b96253)
Raise descriptive error for over volume quota

If you attempt to create a new instance booting from an image and you
were over your quota on cinder, the nova manager would see that as an
invalid block device. This raises a more descriptive error message in
the logs.

Closes-bug: #1013417
Change-Id: Ie50b97c31580da7fc38c6891d1f3646b91f8aa10
(cherry picked from commit 4711ff3adff2b4c9a54f5fb4448ace6558f82f6b)
Fixes Hyper-V volume mapping issue on reboot

Hyper-V does not manage iSCSI mounted passthrough disks
correctly on reboot in some circumstances where disk
number assignment can change, resulting in instances potentially
booting with the wrong volume attached.

Co-Authored-By: Adelina Tuvenie <atuvenie@cloudbasesolutions.com>
Co-Authored-By: Adrian Bora <abora@cloudbasesolutions.com>

Closes-Bug: #1322926
(cherry picked from commit 50636a881b60f112027494bcd84af66888db8c1c)

Conflicts:
	nova/tests/virt/hyperv/test_vmutils.py
	nova/tests/virt/hyperv/test_vmutilsv2.py
	nova/virt/hyperv/vmutils.py
	nova/virt/hyperv/vmutilsv2.py

Change-Id: I99fa75aaa950de2ada8a03bd23c910c3ff810d69
VMware: prevent race condition with VNC port allocation

When spawning some instances, nova VMware driver could have a race condition
in VNC port allocation. This fix ensures that the lock is done on the
actual setting in the VM configuration spec.

Co-authored-by: Marcio Roberto Starke <marcio.starke@serpro.gov.br>

Change-Id: I70fab021bbf2df418df53e5f47e19cf16dbe45ac
Closes-bug: #1357372
(cherry picked from commit 948ff4f3d0a159f1aed9fab65d205ede845b3eb9)
Merge "Raise descriptive error for over volume quota" into stable/icehouse
Merge "libvirt: Make `fakelibvirt.libvirtError` match" into stable/icehouse
Merge "libvirt: Handle unsupported host capabilities" into stable/icehouse
Sync process utils from oslo

This patch backports the missing change to fix ssh_execute password leak

------------------------------------------------
The sync pulls in the following changes:

105169f8 - Mask passwords in exceptions and error messages (SSH)
-----------------------------------------------

Closes-Bug: 1377981
Change-Id: Ie0caf32469126dd9feb44867adf27acb6e383958
VMWare: Fix VM leak when deletion of VM during resizing

During the VM resizing, before VM arrive RESIZED state, driver
migrate_disk_and_power_off will initially rename orginal vm
'uuid' to be 'uuid-orig' and clone a new vm with 'uuid' name.
When deletion VM is triggered at this time window, it wouldn't
be able to delete the VM uuid-orig in VCenter and so cause VM leak.
As VM task state will be set to 'deleting' and it can not be used to
determine the resize migrating/migrated state, this fix will
attempt to delete orig VM within destroy phase.

Conflicts:
	nova/tests/virt/vmwareapi/test_driver_api.py
	nova/virt/vmwareapi/vmops.py

Closes-Bug: #1359138

NOTE: the aformentioned patch broke Minesweeper. The fix was also
cherry picked from commit e464bc518e8590d59c2741948466777982ca3319.
This was to do two things:
1. Solve the actual bug
2. Ensure that the unit tests and Minesweeper passed

Change-Id: I7598afbf0dc3c527471af34224003d28e64daaff
(cherry-picked from e1f8664c9fa83f77f5bb763ffcc3157905ed954c)
Merge "Fixes Hyper-V volume mapping issue on reboot" into stable/icehouse
Merge "VMware: prevent race condition with VNC port allocation" into stable/icehouse
Merge "VMWare: Fix VM leak when deletion of VM during resizing" into stable/icehouse
VMware: validate that VM exists on backend prior to deletion

Attempting to delete an instance that does not exist on the backend
throws an exception (for example UnregisterVM may return this when
running the CI).

Fixes: bug #1300788

(cherry picked from commit 98fb5e56ef96c0c6a8754276e5f8c9c0b7e50fed)

Change-Id: I1b95caec2dad6580db576aa6f80f47913b7c066e
Merge "Sync process utils from oslo" into stable/icehouse
Merge "VMware: validate that VM exists on backend prior to deletion" into stable/icehouse
Merge "Fixes missing ec2 api address disassociate error on failure" into stable/icehouse