Fixes Hyper-V SCSI slot selection

Currently, when attaching volumes, the Hyper-V driver selects the
slot on the SCSI controller by using the number of drives
attached to that controller.

This leads to exceptions when detaching volumes having lower
numbered slots and then attaching a new volume, as Hyper-V will
then try to use an occupied slot.

This patch fixes the issue by simply getting a list of used slots
and getting a slot that it's not among those. It also checks
for the slot number to be smaller than the maximum number of slots
per SCSI controller.

Fixes bug: #1329764

(cherry-picked from commit a73e31022c9fef532cc2d66462d13f4ab2358565)

Change-Id: Id0c09c4debc848004a78971670cc3caef2f77ce3

Conflicts:
	nova/tests/virt/hyperv/test_hypervapi.py
Adds list_instance_uuids to the Hyper-V driver

In case of large number of servers, the _destroy_evacuated_instances
fails randomly. Implementing list_instance_uuids solves the issue.

Co-Authored-By: Robert Tingirica <rtingirica@cloudbasesolutions.com>
Change-Id: I9c58168c012b342bb5dfa0c62a7c39a327f442b3
Closes-bug: #1291364

Conflicts:
	nova/tests/virt/hyperv/test_hypervapi.py
	nova/virt/hyperv/vmutils.py
Fixes a Hyper-V list_instances localization issue

The Hyper-V WMI MSVM_ComputerSystem class Caption property can
have different values on various locales. This patch uses a
different query to avoid any localization issue.

Change-Id: I15103b8edb3ff8934c835826ed00e08593cdeacc
Closes-Bug: #1296478
Fix attaching config drive issue on Hyper-V when migrate instances

After instance resized or migrated on Hyper-V hypervisor.
The configdrive iso or vhd is copied to resized or migrated
instance, but is not attached to instance.

Because there are configurations for config drive like
config_drive_cdrom, config_drive_format, and the configurations
on different Hyper-V compute node may be different. it will need
to convert configdrive format after resized or migrated.
It is easy to convert from iso9660 or vfat to vhd, but it seems
impossible to convert from vhd to iso9660 or vfat.
So this commit just ignore the target Hyper-V compute node's
config drive configurations, leave the original config drive format.

Change-Id: I349e3b2221fff0ae217a71a91895afd21ff7d18d
Closes-Bug: #1321640

Conflicts:
	nova/virt/hyperv/pathutils.py
Fixes Hyper-V resize down exception

The Hyper-V driver does not support resize down and is currently
raising an exception if the user attempts to do that, causing the
instance to go in ERROR state.

The driver should use the recently introduced instance faults
"exception.InstanceFaultRollback" instead, which will leave the
instance in ACTIVE state as expected.

Closes-Bug: #1354448

Change-Id: Ibaf8482562094cd2b3165dc62a907fa9e0e56e19

Conflicts:
	nova/virt/hyperv/migrationops.py
Fixes Hyper-V vm state issue

The method which gets VM related information can fail if the
vm is in an intermediary state such as "Shutting down".
The reason is that some of the Hyper-V specific vm states
are not defined as possible states.

This patch assures that a valid state is always returned by
this method.

Change-Id: I64e95f6b537e83a30dd64474f63f140e0e8e7373
Closes-Bug: #1352428
Fixes Hyper-V agent force_hyperv_utils_v1 flag issue

WMI root\virtualization namespace v1 (in Hyper-V) has been removed
from Windows Server / Hyper-V Server 2012 R2.

Hyper-V compute agent now creates instances which uses
root\virtualization\v2 namespace if the agent's OS is
Windows Server / Hyper-V Server 2012 R2 or newer.

Closes-Bug: #1344036

Change-Id: I874ade4456b92a63959a765c7851bcd001befa32
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.

Change-Id: I99fa75aaa950de2ada8a03bd23c910c3ff810d69
Closes-Bug: #1322926

Conflicts:
	nova/tests/virt/hyperv/test_hypervapi.py
	nova/tests/virt/hyperv/test_vmutils.py
	nova/virt/hyperv/vmops.py
	nova/virt/hyperv/vmutils.py
	nova/virt/hyperv/vmutilsv2.py
Add differencing vhdx resize support in Hyper-V Driver

Differencing VHDX images can be resized, unlike differencing VHD images.
Even so, the Nova Hyper-V driver currently does not support this.

This feature is required for resizing existing instances which use CoW
VHDX images and also in order to resize the root disk image when
spawning a new instance.

The methods which get the internal maximum size of a vhd/vhdx
image have been updated to lookup the parent disk and get the according
size instead of raising an exception in case of differencing images.

Change-Id: I867a9b35e5273b96afc443e5c436a15d0c45161b
Implements: blueprint add-differencing-vhdx-resize-support

Conflicts:
	nova/virt/hyperv/vmops.py
Add Hyper-V driver in the "compute_driver" option description

The description of the option "compute_driver" should include
hyperv.HyperVDriver along with the other supported driver.

Change-Id: Ic7e16fd5154609987b2ef0b6f8ee52619ccf489c
Closes-bug: #1347777

Conflicts:
	nova/virt/driver.py
	nova/virt/hyperv/__init__.py
Fixes Hyper-V boot from volume root device issue

Checks that instances are booting from volume by checking
the correct root device obtained from the block device info.

Change-Id: I94941dfe96c1596c8e9b91df3d3d19d33ae7fe92
Co-Authored-By: Zsolt Dudas <zdudas@cloudbasesolutions.com>
Closes-Bug: #1357972
Adds get_instance_disk_info to compute drivers

Solves a live migration regression issue by adding the
get_instance_disk_info to the compute drivers that do not
have it already implemented.

The method is called by the compute manager.

Change-Id: If5cd9a6f5948c08ef5f1cba2eda31f1175709137
Closes-Bug: #1358719
Co-Authored-By: Ionut Balutoiu <ibalutoiu@cloudbasesolutions.com>
Fixes Hyper-V volume discovery exception message

On some editions of Windows / Hyper-V server the SAN policy is set
by default to "Online All", bringing online any disk, local or shared,
attached to the host.

Since only offline disks can be attached as passthrough disks to a Hyper-V
VM, this prevents Cinder volumes from being attached to instances,
resulting in an exception that can be particularly hard to troubleshoot
without a clear knowledge of the context.

This patch includes some details in the exception message for
troubleshooting purposes.

Change-Id: I6d0b49812f8ca965ca53be34ef009997c8e79728
Closes-Bug: #1361419
Fixes Hyper-V boot from volume live migration

Live migration fails on Hyper-V when boot from volume is used with
CoW, as the target host tries to cache the root disk image in
pre_live_migration, but in this case the image_ref is empty.

This patch adds a check to handle the empty image_ref case.

Change-Id: I60cb60ccaeb0cb8c536906d897249e31ae396923
Closes-Bug: #1362075
Removes unnecessary instructions in test_hypervapi

Lines have no actual effect on the tests. Removing them
will facilitate further unit tests.

Partial-Bug: #1220256

Change-Id: I805aba5e75f2640221b2dc0034950c0832841247
Fixes Hyper-V driver WMI issue on 2008 R2

Trying to assign properties on default Hyper-V resource setting data
WMI objects results in an exceptions before Hyper-V 2012.
Cloning the objects before assigning them solves the issue.

A similar approach was previous already implemented and has been
incorrectly removed during a refactoring.

Co-Authored-By: Robert Tingirica <rtingirica@cloudbasesolutions.com>
Change-Id: If119154f8b4756be9f98c8acd376003c52eff44f
Closes-Bug: #1356884

Conflicts:
	nova/tests/virt/hyperv/test_migrationops.py
	nova/tests/virt/hyperv/test_vmops.py
	nova/tests/virt/hyperv/test_vmutils.py
	nova/tests/virt/hyperv/test_vmutilsv2.py
Adds Hyper-V Compute Driver soft reboot implementation

Adds a soft reboot implementation for feature parity with other
Nova drivers as specified in the base virt driver's interface.

Co-Authored-By: Simona Iuliana Toader <itoader@cloudbasesolutions.com>

Change-Id: I963cbdacdfefca47d6e45fa0aafac188963bcaed
Implements: blueprint hyper-v-soft-reboot

Conflicts:
	nova/tests/virt/hyperv/test_vmops.py
	nova/virt/hyperv/vmops.py
	nova/virt/hyperv/vmutils.py
Adds Hyper-V serial console log

Introduces the VM serial output log feature to the Hyper-V Nova
 Compute driver.

The VM serial port COM0 is redirected to a named pipe so that a
worker can take the VM output and write it to a file.

The VM serial output is then read from this file whenever the
console log command is issued.

Implements: blueprint hyper-v-console-log

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

Change-Id: I7d3132c0f934ac3e8d28315f4da766466612a6c0

Conflicts:
	nova/tests/virt/hyperv/test_hypervapi.py
	nova/tests/virt/hyperv/test_vmops.py
	nova/tests/virt/hyperv/test_vmutils.py
	nova/virt/hyperv/vmops.py

Conflicts:
	nova/tests/virt/hyperv/test_vmops.py
	nova/virt/hyperv/vmops.py
Fixes HyperV VM Console Log

This patch intends to fix some small nits introduced along with
the Nova console log patch.

The size of the console log can get bigger than expected because
of a small nit when checking the existing log file size as well
as a wrong size constant.

The method which gets the serial port pipe at the moment returns
a list which contains at most one element being the actual pipe
path. In order to avoid confusion this should return the pipe path
or None instead of a list.

Change-Id: I5ce9d1bea572f9098971990d011fa97ebf09233e
Closes-Bug: #1363899
Fixes Hyper-V should log a clear error message

When failing to access a remote SMB UNC path, Python raises
   WindowsError: [Error 123] The filename, directory name, or volume
label syntax is incorrect: '\\\\'
This issue happens during resize/cold migration.

This fix ensures that the Nova driver will report a clear error
message.

Change-Id: I735987f3c3f8c16759f6fbbb235a0156df832855
Closes-Bug: #1367786