Catch more accuracy exception for _lookup_by_name

When an instance is not found by libvirtd, _lookup_by_name in libvirt
driver raises InstanceNotFound. This patch catchs this exception instead
of NotFound who is the father of InstanceNotFound.

Closes-Bug: #1222663
Change-Id: I1b4ce8f6c44eef29617a42151152cda2159a0088
xenapi: ensure pool based migrate is live

The current code is missing a flag to pool_migrate that should be
included to ensure the migrate is live. This change adds that flag to
both uses of VM.pool_migrate, namely the live-migrate call and the
host_maintenance call.

Fixes bug 1201795
Change-Id: I265baaba5e9bd9132bd5e1c6f9fb18cefab02cfb
xenapi: add tests for finish_migration and spawn

Before making finish_migration and spawn share more code, lock down the
current code with unit tests.

There are also some methods that are split up, to help with some of the
next refactoring steps.

Change-Id: Icfc214ea2c7470705f5605816b8313e0ba2a1429
xenapi: stop injecting the hostname during resize

The windows PV tools will set the hostname of a server to the value
given in the hostname xenstore key. If we inject that during resize, the
users will be unable to change their server hostname, and in addition it
will be reset to the original name.

Fixes bug 1207829
Change-Id: I49ba9d9f4f8b4a86488e427d99f69236bd959c78
xenapi: regroup spawn steps for better progress

Currently the operations are not very logically grouped. Now we can see
all the individual actions more clearly, we can re-arrange the
operations so each step make more sense, and should be better at
reporting progress.

Rather than checking very late that there is no duplicate VM and enough
memory, I have moved these checks before the expensive operation of
downloading the disk.

After this change there are 10 clear steps during spawn:
* initial step so progress is not zero during download disks
* download and create disks step
* download and create kernel and ramdisk step
* create the VM record, now the disks have been downloaded
* setup the disks; resizingi up disk, and attaching, adding rescue disk
* injecting instance data, currently this means writing to xenstore
* setting up the networking, including the initial firewall setup
* starting the VM and waiting for it to boot
* configuring the VM using the agent (takes a long time on windows)
* applying the final firewall filters, now the VM is running

With this in place, it will be easy to decide which steps are required
and which are not required when reusing the spawn code to implement
finish_migration in a later change.

Change-Id: I0e33dd7d298390630f632e116c8866a64e769102
xenapi: ensure finish_migration cleans on errors

This change makes finish_migration share code with spawn.

This fixes some inconsistencies, such as applying the security
group filters during finish_migration.

Fixes bug 1073303
Fixes bug 1073306

Change-Id: Ib4f2a96618692c141708535f9463c856f3395922
Fix snapshot failure with VMwareVCDriver

The snapshot operation was failing because it calls
VirtualDiskManager.CopyVirtualDisk with a destination disk spec, which
is not supported when called through VC. The fix is to not supply a spec
when calling through VC, in which case the disk is consolidated and
copied without type transformation.

While the fix is to use spec-less CopyVirtualDisk in VC, doing so in ESX
too will result in unintended transformation (because it ESX will
default to busLogic/preallocated), so the use of the spec was retained
in ESX-mode instead.

Another issue found and fixed is that the name of the snapshot image is
incorrectly set when uploading to glance.

The following tempest tests are now unbroken against the VC and ESX
nodes:
  tempest.api.compute.images.
     test_images_oneserver.ImagesOneServerTest{JSON,XML}.
        test_create_delete_image
        test_create_second_image_when_first_image_is_being_saved
        test_delete_image_of_another_tenant
     test_list_image_filters
  tempest.api.compute.test_authorization.AuthorizationTestJSON
  tempest.api.compute.test_authorization.AuthorizationTestXML

Fixes bug 1184807

Change-Id: I7ec49859fb2842cc02cdc87a6434aa58612a2964
Fix problem with starting Windows 7 instances using VMware Driver

The default controller for a Windows 7 virtual machine is the
LSI Logic SAS. When the disk adapter type is specified as 'lsiLogic'
via glance image metadata, VMware driver defaults to LSI Logic Parallel
controller. With this fix the driver will honor a property 'lsiLogicsas'
to distinguish the right adapter and enable booting Windows instances.

Fixes: bug #1187853
Change-Id: Idb36a784a31e4938e8951adeb83335b3890dac85
xenapi: Make rescue safer

If rescue setup fails, detach the root disk from the rescue VM so it
doesn't get nuked by the undo stack logic in spawn()

bug 1227898

Change-Id: I8864b4c524f04f7b387be1018fea9919a461c48b
Fix for os-availability-zone/detail returning 500

if there are no enabled_services, then zone_hosts is very likely
to be empty, which means zone_hosts['nova'] will fail. So let's
use get with a default of empty array to cover this case. Added
a fix/test for v3 API as well.

Fixes LP# 1226791

Change-Id: I602c96242291fd9a4bdf67af6445aa935ec7f7e3
Merge "xenapi: ensure pool based migrate is live"
libvirt: ignore false exception due to slow NFS on resize-revert

When resize revert one VM instance, if the NFS is slow, the NFS
mounted on source host might not respond quickly. This will cause
that even if the VM instance configuration files was deleted from
resize target host, the NFS on source host may still think the
files were not deleted. Then in driver.py::finish_revert_migration,
the driver try to delete the file again, this will lead nova compute
throw exception.

The fix was ignore exception for such case: if failed to delete the
instance with error no as 2 (No such file or directory)

Fix bug 1206312

Change-Id: I89990c1750a7fd7f421cab03780e7704ee661de1
Merge "xenapi: add tests for finish_migration and spawn"
Merge "xenapi: stop injecting the hostname during resize"
Merge "xenapi: regroup spawn steps for better progress"
Merge "xenapi: ensure finish_migration cleans on errors"
Actually fix info_cache healing lazy load

system_metadata is still being lazy loaded as a part of healing the
instance info_cache.  A previous attempt to fix this issue missed the
more important call.

It's actually more efficient to not load the system_metadata when getting
the list and allow the 1 instance to lazy load.  For the cached instances,
we will ask for system_metadata when getting a fresh copy from the DB.

Fixes bug 1223969

Change-Id: Ib95e868135ed2b36af7ddbcfb8d5905bfe14d1fe
Merge "Fix for os-availability-zone/detail returning 500"
Merge "Fix snapshot failure with VMwareVCDriver"
Merge "Actually fix info_cache healing lazy load"