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
Fix "revertResize/confirmResize" for V2.1 API

"revertResize/confirmResize" server actions were missed for V2.1 API.

This patch converts "revertResize/confirmResize" server action
for V2.1 API

The differences between v2 and v3 are described on the wiki page
https://wiki.openstack.org/wiki/NovaAPIv2tov3.

Change-Id: I24bdb5b28fafeb60ea7b4ff044b12a519498e592
Closes-Bug: #1367642
Add good path test cases of osapi_compute_workers

While fixing issues in Cinder for bug 1367454 I discovered
that Nova doesn't have any good path test cases to make
sure that settings to osapi_compute_workers is being handled
as expected.

This commit adds those test cases.

Change-Id: I161adf9e93bd7ff1389fdbc8f712ae67ed98b613
Clarify virt driver test comments & log statement

The current implementation of nova.tests.virt.test_virt_drivers
indicates NotImplementedError should be caught and logged to
dynamically build the hypervisor support matrix. This is not a
realistic / optimal approach for building the support matrix and
thus this patch updates the code comments accordingly for
clarity. This patch also modifies the logging statement outputted
in such scenarios to better clarify which test case method is
executing.

 Partial-Bug: 1209421

Change-Id: I5d80cdc06207071548fdb5f6852ca96fa8d79776
libvirt: support live migration with shared instances dir

If instance path is shared between compute nodes (e.g. over NFS) and image
backend uses files placed in the instance directory (e.g. Raw, Qcow2), live
migration should consider block storage of the instances shared.

Change-Id: I913c57152974562765502ab57be63ccb6dfe5208
Closes-Bug: #1351002
libvirt: log exception info when interface detach failed

The detach_interface method is catching a libvirtError and logging an
error message but it doesn't include the contents of the root
libvirtError, so log that information as well for debugging.

Closes-Bug: #1374140

Change-Id: I042c2956c7393a2ee1ccd026421c8df537aa1a87
Fallback to legacy live migration if config error

Commit ea7da5152cdca7ba674e2137c3899909995e2287 added a path to using
migrateToURI2 for live migration if the version of libvirt used has the
VIR_DOMAIN_XML_MIGRATABLE flag set.

However, a bug in older versions of libvirt causes the live migration to
fail because it's incorrectly validating the old and new domain xml's
for ABI stability.

Not all distros are running with the patched version of libvirt so add a
check in place such that if we fail live migration on the new path with
VIR_ERR_CONFIG_UNSUPPORTED, assume it's due to this issue and attempt
the legacy migrateToURI call.

Closes-Bug: #1362929
Related-Bug: #1279563

Change-Id: Ie82566121c2ed3a6d55919bc111358f4129cb404
Ironic driver must wait for power state changes

The Ironic virt driver was previously returning from power_on,
power_off, and reboot calls immediately after making the request to
Ironic -- but before Ironic had necessarily acted upon it. This could
lead to Nova acting as though the state change was complete before it
actually was.

This patch introduces a new private method which polls Ironic until it
signals that the power state change is complete. With this, the
power_on, power_off, and reboot methods wait for the action to complete
before returning to ComputeManager.

Closes-bug: #1310135

Change-Id: I0bbdd8bc8807a0df43a420825f497842b387c4d5
Fix hook documentation on entry_points config

The syntax suggested for adding hooks to nova via setup.py entrypoints is:

    entry_points = {
        'nova.hooks': [
            'resize_hook': your_package.hooks.YourHookClass,
        ]
    },

But this is incorrect. The proper syntax for an entry_points entry is:

    entry_points = {
        'nova.hooks': [
            'resize_hook=your_package.hooks:YourHookClass',
        ]
    },

Change-Id: Id7bc6891dc542d4317e82e15300c7293eb0d17a0
Closes-bug: #1374666
libvirt: consider vcpu_pin_set when choosing NUMA cells

When we get a single NUMA cell instance scheduled to a NUMA capable
host, we do not account for  cpu_pin_set when choosing viable cells for
the given instance. meaning we could choose a NUMA cell that has no
viable CPUs which we will try to pin to.

This patch changes that behaviour and also adds a test to prevent a
regression. We also fix up how some of the tests mock the random.choice
method, because now we give it a list of sets (of cpus), but also
because it is now easier to catch a regression since we actually use the
passed value.

Change-Id: I0d740170db52a4777924648683ac98de9cf4b3cf
Closes-bug: 1372845
Fix creating bdm for failed volume attachment

This commit modifies the reserve_block_device_name method to return the
bdm object, when the corresponding keyword argument is True. This
ensures the correct bdm is destroyed if the attach fails. Currently the
code assumes only one bdm per volume and so retrieving it can cause the
incorrect db entry to be returned.

Change-Id: I22a6db76d2044331d1a846eb4b6d7338c50270e2
Closes-Bug: #1349888
VMware: Remove tests for None in fake._db_content['files']

This looks like a legacy. _db_content['files'] is always initialised,
and checking it for None distracts from what is actually being tested.

This was also the only use of NoFilesFound, so we remove it entirely.

Change-Id: Ided6c71b68a654476512016ddf886e895d75e571
console: make websocketproxy handles token from path

As part of the blueprint serial-ports when connecting to
the proxy with a plain websocket, make Nova able to retrieve
the token from the request path.

Closes-Bug: #1373950
Change-Id: I0b0b23c954dbb812acfa7616696445c0e167d2c8
cmd: update the default behavior of serial console

When using serial console we are expecting using a plain websocket
so we should to return the 'ws://' scheme as the default one, also
it makes no sense to handle webserving content since currently
nothing has been implemented in favor of this case.

DocImpact: The 'base_url' option serial_console has been updated
Closes-Bug: #1373950
Change-Id: I0d0e4f7060febec5e0a357cd3e8c05486f2afaa5
Merge "Fallback to legacy live migration if config error"
Merge "Fix "revertResize/confirmResize" for V2.1 API"
Merge "libvirt: consider vcpu_pin_set when choosing NUMA cells"
Merge "Fix hook documentation on entry_points config"
Remove duplicate entry from .gitignore file

This commit removes the duplicate entry in the gitignore file for the
sample config file.

Closes-Bug: #1375432

Change-Id: Ied0fb5b38a616bbde871dfc690ccccfd46c94bde
Merge "libvirt: support live migration with shared instances dir"