VMware: fix VM resize bug

The following operations would fail due to invalid references, either by name
or UUID:
    - resize
    - resize-confirm
    - resize-revert

Closes-bug: #1199954

(cherry picked from commit c586d635387e9baa3c0857afb56d05137fcddd7c)

Conflicts:

	nova/tests/virt/vmwareapi/test_vmwareapi.py

Change-Id: I39b804ed3c0c57455547d9ece0ef779cf73a5926
Prevent rescheduling on block device failure

Due to a race condition - it is possible for more instances to race for
the same volume. In such a scenario, the one that fails will get
rescheduled, and in the process detach the volume of a successful
instance.

To prevent this, this patch makes nova not reschedule on block device
failures. This is actually reasonable behaviour as block device failures
are rarely related to the compute host itself and so rescheduling is not
usually useful.

This is a stable/havana only fix! This same issue is addressed on the
master branch by Iefab71047996b7cc08107794d5bc628c11680a70.

Closes-bug: 1195947

Change-Id: I6b68965ac65cdb0e1da3b44e83428f056b1693aa
Fix OLE error for HyperV

When run live-migration on HyperV, an OLE error
will occur. This is because we use wrong WQL
sentence when we try to query table
'Msvm_ResourceAllocationSettingData'.

This commit fixes the wrong WQL sentence.

Closes-Bug: #1246592

Change-Id: Iabb4096002a5be1fb930b077fbf5ef734893c258
(cherry picked from commit e74ceb68e1642d773f2ad0c655e6354f7a7fb362)
Add log_handler to implement the publish_errors config option

Synced from Olso.
Commit Id is Ibf28ba17f81b5ddeda653f6a3501ecac18ffcd42

This handler sends all error logs as rpc notifications.
Note: when using publish_errors you also need to set the
notification_driver option too.

Change-Id: Ic97b9c8b84d51c84a53ace5b86cc2e72c744f136
Closes-bug: #1240349
(cherry picked from commit 1c4e279e187d1b864680c9be7849130cb7f12801)
Moved quota headroom calculations into quota_reserve

Moved headroom calculations into quota_reserve and modified headroom
calculations to take into account -ve quota limits (unlimited) on
cores and ram.

Updated test cases to generate OverQuota exceptions with new headroom
parameter.

Added new tests for 'unlimited' quotas to test_quota.py in
 QuotaIntegrationTestCase and DbQuotaDriverTestCase classes.

Add Exception kwargs checking for OverQuota and QuotaError exceptions.

Change-Id: I855b0cad495182c5c4ee42b2acf5eedd198557b5
Closes-Bug: #1224453 min_count ignored for instance create
(cherry picked from commit 30fa37e7776831d6f8022f52d3d92f62189fb702)
Sync local from oslo.

local has a broken TLS symbol - strong_store - in Nova today, fixed in oslo
some time ago in Ib544be1485823f6c619312fdee5a04031f48bbb4

Change-Id: If4dd973acc23921dbc2bc69bb76225deb2802dad
Closes-Bug: #1251920
(cherry picked from commit 9b44d9d75d3767c6b7d1af4f237da8c1cf16266a)
Fix `NoopQuotaDriver.get_(project|user)_quotas` format

The quota API extension expects `get_project_quotas` and `get_user_quotas` to
return a dictionary where the value is another dictionary with a `limit` key.

The `DbQuotaDriver` adhered to this spec, but the `NoopQuotaDriver` didn't.

This fixes the `NoopQuotaDriver` to return the results in the correct format.

Fixes bug 1244842

Change-Id: Iea274dab1c3f10c3cb0a2815f431e15b4d4934b1
(cherry picked from commit 711a12b4029cd1544d26d147d8a67e110e056124)
Clean BDM when snapshoting volume-backed instances

When snapshoting a volume-backed instance, its block device mapping is
copied entirely into the image properties of the resulting snapshot.

This may lead to some errors when booting from that snapshot because the
fields 'id', 'insance_uuid' and 'connection_info' must be generated for
each instance instead of reusing the ones from the original instance.
For example, sharing the connection_info will cause the new instance to
try to connect to the original volume instead of creating a new one.

This patch cleans all the database-specific plus the connection_info
fields from the block device mapping when creating the snapshot.

Change-Id: I4190e9519d641c61b00b5d86c3885f2ae4fa86f3
Partial-Bug: #1246327
(cherry picked from commit eddd8a14cd2393ce7bdb0ec1c7366177371192b2)
Process image BDM earlier to avoid duplicates

If the block device mapping from the image properties are not handled at
the same time as the ones defined from the API, we might make the false
assumption that the instance has no root and failing or, in the case
we're booting from an image that only defines a BDM and has no disk,
creating a local disk BDM as root and ending up with two root devices
which is forbidden.

This patch moves the handling of the image block device mappings to the
same method were we check the ones provided throught the API. This
allows nova to decide wether the instance needs a local disk from an
image if no root device is defined in any of the block device mappings.

Change-Id: Ide95357895ab4dd1338ab5ee3ec25294af1d010b
Closes-Bug: #1246327
(cherry picked from commit 482dfeb113f1e0ff814aa1fc980d67e0c8b06d76)
Include image block device maps in info

In cases for example soft/hard reboot, we were just getting volume and
snapshot block device maps. For block devices with a source type image,
Nova would fall back on a local disk location and fail.

This change allows us to include block devices with a source of an
image, so that we correctly get the right the location of the block
device.

Closes-Bug: #1245719
Change-Id: I1f726293e85183d4b84c05b635a7c606a092992f
(cherry picked from commit 85d0ace169be513c30b09e13a35fa7d912f5b380)
Fix libvirt evacuate instance on shared storage fails

When evacuate instance which has config drive enabled on shared storage,
disk.config file can't be created because of permision error, chowns
disk.config if it already exists.

Change-Id: I20bafc3482ead30297ad5402a09e97141816f4d1
Closes-Bug: 1247526
(cherry picked from commit 3dfa2f9fd4a3084ae3fb8a7ba5d8a7458ae1c3bc)
Fix interface-attach removes existing interfaces from db

The following commit 394c693e359ed4f19cc2f7d975b1f9ee5500b7f6 changed
allocate_port_for_instance() to only return the ports that were created
rather than all of the ports on the instance which broke the attach-interface
code.

This patch fixes this issue by remove the sync decorators from:
allocate_for_instance, allocate_port_for_instance, and
deallocate_port_for_instance to just _build_instance_nw_info which
is called in all these cases instead.

Closes-bug: #1223859

(cherry picked from commit 1957339df302e2da75e0dbe78b5d566194ab2c08)

Conflicts:
	nova/network/neutronv2/api.py

Change-Id: I66eb0c0ab926e0a8d1e2c9cfe1f7fd579ea3aa27
Fix up spelling mistake

Fixes bug 1253510

This was causing a KeyError when e2label didn't work

Change-Id: I0646409cdffa4d6d5d8b2c7a9e3c300022d1c9b8
(cherry picked from commit 22d1c2458623a1cfbb91a50c13f18329c863f70b)
libvirt: Allow delete to complete when a volume disconnect fails

If an instance which was booted from a volume fails to spawn, the
instance is left in an ERROR state.  If the failure is in the networking
stage Nova will not have attached the volume via the Cinder driver,
and so the volume remains in an available state.  In this state the
volume may be deleted or assigned to another instance.
During the subsequent delete an exception may be thrown from
the cinder driver which prevents the instance from completing the
deletion process leaving the instance stuck in Error and unable to
be deleted.

Volume exceptions should be logged and ignored when the instance
is being deleted.

Closes-Bug #1222979

(cherry picked from commit 506a8f58cf4b8cecf90b647c7deba47da2a4dfec)
Conflicts:
	nova/tests/virt/libvirt/test_libvirt.py

Change-Id: Icb3796b0ddba25cf344953a649b2e762fab6d782
VMware: fix snapshot failure when host in maintenance mode

The root cause is due to a bug in the VC's handling of the
VirtualDiskManager.DeleteVirtualDisk_Task API, which allows the picking
of any host in a datacenter with access to the datastore participating
in the disk deletion picked be to perform the operation, even when the
host is in maintenance mode and hence will always reject the call when
sent.

The fix uses an alternative API (FileManager.DeleteDatastoreFile_Task)
to delete the vmdk and -flat vmdk files separately. This API does not
suffer from the above-mentioned failure mode.

Closes-Bug: #1229994

(cherry picked from commit 7910385825ccfa705785af360fcd5717656e3557)

Conflicts:
	nova/virt/vmwareapi/fake.py
	nova/virt/vmwareapi/vmops.py

Change-Id: I786365847673e5192a21b654cba951b2e7a6f291
Fix migration 185 to work with old fkey names

Due to different versions of MySQL it is possible to end up with
different FK's then what is expected. For example the FK constraint
on instance_info_caches changed from instance_info_caches_ibfk_1
to instance_info_caches_instance_uuid_fkey and on virtual_interfaces
from virtual_interfaces_ibfk_1 to
virtual_interfaces_instance_uuid_fkey meaning databases who have
upgraded from before folsom may have the old fkey.

This patch adds a check for those with the old fkey name to make sure
it is dropped before changing unique constraints (as is required by
MySQL). It also fixes the fkey name to be as defined in 133 if it
wasn't before (which will persist on downgrade being consistent with
those who have come in after folsom).

Closes-Bug: #1245502

Change-Id: Ib0dcd04fcb9ed776c76d40561181abad2e14f76f
(cherry picked from commit c620cafb700ca195db0bd0ef9d62a0c9459bdc38)
Add context as parameter for resume

Now for KVM when resume an instance with block storage, nova
compute will throw exception and failed to resume the VM.

The root cause is that when resume a VM with block storage,
libvirt driver needs to call conductor via rpcapi to update
block device, but the function of resume() do not have context,
this will cause RPC api failed.

Change-Id: I712777ed1d893a2b6463d30c407b0a677e37b602
Closes-Bug: #1241337
(cherry picked from commit de4158861000dedc204314c545cc5682aa38f5f1)
Merge "Fix OLE error for HyperV" into stable/havana
Merge "Fix libvirt evacuate instance on shared storage fails" into stable/havana
Merge "Fix up spelling mistake" into stable/havana