libvirt: test setting of CPU tuning data

The setting of the libvirt guest <cputune> data from the
flavor extra_specs quota parameter was never tested. In
fixing this omission, it was noticed that the data was
incorrectly passed around as a string instead of an int.

Change-Id: Ie8b31feddf6c546eb05ca00ead5c56bcd535dd84
libvirt: introduce separate class for cpu tune XML config

Instead of just setting attributes against the main
LibvirtConfigGuest object, have a LibvirtConfigGuestCPUTune
object. This is more flexible when we have to add support
for further cpu tuning attributes.

Blueprint: virt-driver-cpu-pinning
Change-Id: Id3667752fcbbfe3e55ee221fd2cd364d5cfb2f80
virt: use context & instance as param names in migrate APIs

The vast majority of methods in the ComputeDriver use
'context' and 'instance' as parameter names. The only
exceptions are the migration related methods which use
'ctx' and 'instance_ref'. Change the latter to be
consistently named with the rest of the file

Partial-bug: #1333219
Change-Id: I0457e3e70ee58a9cbfc69f8cfe675de0504cc781
virt: fix signature of set_admin_password method

The compute manager passes (instance, new_pass) to the
set_admin_password method, and the XenAPI driver impl
expects this pair of parameters. The ComputeManager
class, however, declares that it takes (instance, context,
new_pass=None). It makes no sense to default the new
password to None, when the only caller always passes
it, and the context parameter is never passed by the
caller either.

Partial-bug: #1333219
Change-Id: If656da4ef54a0425b9f50ef03af044b803b1afae
virt: add test helper for checking public driver API method names

The virt driver impls of ComputeDriver should only expose public
methods which are already defined by the ComputeDriver base class.
Any other methods should be prefixed with an '_' to indicate that
they are internal helperrs.

Provide a test helper method which the virt driver tests will
call to validate their implementation is in compliance with
the base class signature.

Partial-bug: #1333219
Change-Id: Ibc2369a5f90e09857da29810ac0707614b041d54
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).

Change-Id: I1b95caec2dad6580db576aa6f80f47913b7c066e
Closes-bug: #1300788
Fix bad log message with glance client timeout

Fixes bad log message where when a glance call finally timeouts instead
of a log message saying that it has given up it instead says it is
retrying

Co-Authored-By: qinchenchong@gmail.com

Change-Id: I325918f2d7fa971d4239343131b0f95dae293281
Closes-Bug: 1292993
libvirt: Add configuration of guest VCPU topology

Wire up the libvirt driver to honour the VCPU topology config
requested via the flavor extra specs / image meta. This is
only done for QEMU/KVM guests at this time. Although Xen is
technically capable of supporting this, it is not yet wired
up in libvirt itself.

Blueprint: virt-driver-vcpu-topology
Change-Id: I4540147af7b91e1dc463be63d19afbfcfc1216cb
VMware: add support for driver method instance_exists

The default driver implementation is terribly expensive. This
overrides the implementation with a far more optimum solution.

A similar implementation exists in xen and libvirt drivers.

Change-Id: I656298564077701683a175ca1d1fe788328d0c74
Merge "Fix bad log message with glance client timeout"
VMware: Fix race in spawn() when resizing cached image

spawn() guards against multiple threads simultaneously attempting to
cache the same image, but it wasn't guarding against them
simultanously trying to create a resized copy in the cache. Attempting
to create a large number of images simultaneously of an uncached image
would result in a race to create the resized image. This resulted in 2
classes of failed instance:

1. Instances whose disk was a linked clone of a copy which had been
   subsequently overwritten. These were corrupt.
2. Instances whose spawn() failed in ExtendVirtualDisk_Task due to a
   locked image.

This patch creates a Nova-local lock for the resized image. The image
is in a per-Nova directory on the datastore, so inter-Nova locking is
not a concern. The lock guards both testing for the existence of the
image, and its creation. Therefore when multiple processes race, only
1 will create the resized copy, and all others will find and use it.
In normal usage this will add the overhead of an additional
uncontended local lock creation and deletion in spawn().

In wrapping this code in a lock, we also make certain that any failure
to create the resized image is appropriately cleaned up. Otherwise
subsequent users will attempt to use a corrupt copy.

Change-Id: I3df3d614656e511c909b6c1837582c0d34bf84c6
Closes-bug: 1333587
Merge "virt: use context & instance as param names in migrate APIs"
Merge "virt: fix signature of set_admin_password method"
Merge "virt: add test helper for checking public driver API method names"
Merge "VMware: add support for driver method instance_exists"
Merge "VMware: Fix race in spawn() when resizing cached image"
Merge "libvirt: test setting of CPU tuning data"
Merge "libvirt: Add configuration of guest VCPU topology"
Merge "VMware: validate that VM exists on backend prior to deletion"
Merge "libvirt: introduce separate class for cpu tune XML config"