Pass volume_api to get_encryption_metadata

The module encryptors was creating a volume API instance in the module
scope which caused all the modules importing it to depend on
cinderclient.

This was affecting scheduler and cert services which at some point import
the compute manager module only to access their config options. It makes
no sense to force scheduler and cert services to require cinderclient.

This patch makes the callers of get_encryption_metadata to pass the
volume api object to this method to prevent this dependency.

Closes-Bug: #1246103
Change-Id: I9eb4ae3754fa2a5ac646560a62477d6ed672e272
(cherry picked from commit a3aeace9afd5c533f040452f33482fdb55d93927)
Check for None when cleaning PCI dev usage

The PCI manager needs to check for instance UUIDs mapped to
None when cleaning up it's internal claims/allocations maps.

Also adds a check so the claims dict doesn't map to None in
the first place.  There was already a check like this when
setting a value in the allocations dict.

Closes-Bug: #1238374

Change-Id: I7ac010f7d50ad85c145e536cfd48e07c8f4602d3
(cherry picked from commit c28c87db4c2b20e0f6c1375d2d4433e06c4e1743)
VMware: Handle cases when there are no hosts in cluster

When there are no hosts defined in a cluster the host value will be an empty
string. For example:

    obj_context: (RetrieveResult){
       objects[] =
          (ObjectContent){
             obj =
                (obj){
                   value = "domain-c185"
                   _type = "ClusterComputeResource"
                }
             propSet[] =
                (DynamicProperty){
                   name = "host"
                   val = ""
                },
          },
     }

This causes an data access exception.

The code will now raise an NoValidHost exception.

Fixes bug: 1197041

Change-Id: I75b1f069e0b27eebd63c280e36533354c04e246a
(cherry picked from commit 89e18d8c64b11630d2f21563c95b01452057a897)
VMware: Detach volume should not delete vmdk

During volume detach a delete_virtual_disk_spec is used to remove
the device from the running instance. This spec also "destroy" the
underlying vmdk file, this is not right, we should not delete vmdk
file when detach it from a VM instance.

The fix was remove the fileOperation field when detach vmdk volume
so as to make sure the volume will not be destroyed; but for iscsi
we still need to destroy the volume.

Also I changed the function name from delete_virtual_disk_spec to
detach_virtual_disk_spec which is more accurate.

Change-Id: Ibd218d6a8cfeede4f5ca74f28bc0c3d0c185bb14
Closes-Bug: #1241350
(cherry picked from commit 0405d7b937fdeece46efc1ba90171163f3286a56)
Add missing argument max_size in libvirt driver

max_size argument was added in commit 3cdfe894ab58f7b91bf7fb690fc5bc724e44066f,
but missing  in _create_ephemeral and _create_swap method, which cause
exception raised when caching ephemeral and swap disk files of the instance.

Add test for _create_ephemeral used with max_size parameter
and test _create_swap method

Closes-Bug: 1251152
Closes-Bug: 1250032
(cherry picked from commit 384f55bcb32251698cc2ce839a0286ef99e74984)

Conflicts:
	nova/tests/virt/libvirt/test_libvirt.py
	nova/virt/libvirt/driver.py

Change-Id: I46032ad32f317c923692b8b3d40cedd0dce06cad
Address infinite loop in nova compute when getting network info

Move the refresh_cache decorator to get_instance_nw_info.
In fact, _get_instance_nw_info is called by the decorator
itself, potentially causing an infinite loop in case nw_info
is not of the expected value. This is also inline with
the method's purpose, as stated by the docstring. At the
same time, ensure that delete_port_for_instance and
allocate_for_instance continue to refresh the cache by
using the decorated version.

Also, add a couple of debug traces that are friendly to
the developer.

Partial-bug: 1235435
Related-bug: 1251792

Change-Id: I06f8634ea241d05ac8fbcc290adf0cb23829f3e4
(cherry picked from commit 2e520496c369a8ef646820ec068cc4416ab50eca)
Merge "Check for None when cleaning PCI dev usage" into stable/havana
Merge "Pass volume_api to get_encryption_metadata" into stable/havana
Merge "VMware: Handle cases when there are no hosts in cluster" into stable/havana
Merge "VMware: Detach volume should not delete vmdk" into stable/havana
Merge "Add missing argument max_size in libvirt driver" into stable/havana