VMware: prevent image snapshot if no root disk defined

If there is no root disk defined then the snapshot should
throw an exception.

Change-Id: I0549b8ca9ba41b734277600cb66a74b27ca72d88
Related-bug: #1297605
(cherry picked from commit e0638e29cda39c609ecf518e5adacf70e158d71a)
Prevent clean-up of migrating instances on compute init

During compute manager startup init_host is called. One
of the functions this carries out is to delete instance
data that doesn't belong to this host this function only
checks if the local instance belongs to the host or not.
It doesn't check the task_state. This could result in the
loss of all instance data if it occured at the wrong
point during live migration.

This change checks if the task_state of the instance to
be deleted is MIGRATING and if so it does not delete the
instance. Similarily for the task state RESIZE_MIGRATING.

This change adjust little about the unit test according to
actual code path in icehouse.
Conflicts:
	nova/tests/compute/test_compute_mgr.py

Change-Id: Ia8c67acf93d71af868907f0711dcc1dfe103560c
Closes-Bug: 1319797
(cherry picked from commit 340cae5466eaf5568c4f0eecb2a2fa7cdbcc0ba4)
Turn periodic tasks off in all unit tests

We shouldn't rely on periodic tasks to randomly run in unit tests,
instead if we need them to run we should explicitly call them out.

Change-Id: I35850c47288e50d3146771dc7a9a54d62e36c3cf
Related-Bug: 1311778
(cherry picked from commit f3f07f4401ff8be25598493c088e4e100b387fe4)
Handle service creation race by service workers

This handle a race where a sibling has already created the service
record in the database.  This fix is similar to that of commit
f6c341b4.

Change-Id: I7975fc632eee34390c5d7dc275b52363ad45475e
Closes-bug: 1326901
(cherry picked from commit 37247aba813fbc408901a2f1b1ad88e2acb796a1)
Fixes rbd backend image size

The original fix for bug 1219658 introduced a factor of 1024 error
in the resulting rbd image size.

Fix bug #1219658

Change-Id: I3ec53b3617d52f75784ebb3b0dad92ca815f8876
Co-authored-by: Nikola Dipanov <ndipanov@redhat.com>
Signed-off-by: Haomai Wang <haomai@unitedstack.com>
(cherry picked from commit f27ca3134743b45e55afd6c73abbb83c87ba8489)
Fixes hyper-v volume attach when host is AD member

The domain name gets added to the initiator name used by the host
if it's an Active Directory member.

Currently the method which gets the initiator name does not take
this into account when retrieving the default initiator name.

Trying to use a wrong initiator name will lead to an exception when
trying to log in to the according iSCSI target.

This patch simply appends the domain name (when the host is an AD
member) to the initiator name used to log in to iSCSI targets.

Closes-Bug: #1328870
(cherry-picked from commit 0a7527c71228c8e776ad40cedd2cf137fd99f43d)

Change-Id: Ifbe762c685e46081059a01043431b2c4ac5473fc
VMware: Add check for datacenter with no datastore

When there is a datacenter with no datastore in it,
nova boot fails.

This patch addresses the issue by adding a check
and ignoring the empty datacenter.

closes-bug: #1302482
(cherry picked from commit 529e7d14a716fcc1264b2e8053be3c842afd2153)

Conflicts:
	nova/tests/virt/vmwareapi/test_vmops.py

Change-Id: I3c8242767f5991d4aeffab09c763a21493fc363e
Mask block_device_info auth_password in virt driver debug logs

The block_device_info object can have an auth_password key which is
getting logged at debug level in several virt drivers so we need to
sanitize the message getting logged.

Adds tests to ensure the logged messages are properly sanitized.

Note that bug 1321785 was opened to track the long-term design issues
with storing the password in the block_device_info dict since this can
crop up elsewhere if it's logged.  The immediate fix here is to mask
what's already exposed.

Closes-Bug: #1319943

(cherry picked from commit 5dda3a6ab2becb5dd0b58c088f6daad807e12276)

Conflicts:
	nova/tests/virt/libvirt/test_libvirt.py
	nova/tests/virt/vmwareapi/test_vmops.py

Change-Id: I0eae07ce3f0f39861eb97ec3dec44895386c7d04
Adds files from upstream 2014.1.2 release package

The Nova 2014.1.2 release package contains a few additional deployment
related changes not present in the upstream git repository:

https://launchpad.net/nova/icehouse/2014.1.2/+download/nova-2014.1.2.tar.gz

This commits adds the release specific content.
HyperV Driver - Fix to implement hypervisor-uptime

The hyperv driver currently does not return the hypervisor-uptime.
This fix does the necessary changes to return the hypervisor-uptime.
The uptime returned is in similar format to libvirt driver uptime

The uptime is calculated using the windows function GetTickCount64
More details about this function available at
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724411%28v=vs.85%29.aspx

The function GetTickCount64 returns in millisecs the time since the host
is up.

Change-Id: Ib3cd90b17f64e369badaddb764ac9e6b9f6c1a4b
Closes-Bug: #1335559
(cherry picked from commit a41543820a8f0686612213b12ab07cf70b3d997f)
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