Fixes race condition of deleting floating ip

Fixes bug #1172599
reproduce steps:
1. create an instance
2. get a floating ip from pool
3. associate the ip to instance created at step 1
4. delete the instance and the ip at a very little interval

reason may be that:
1. the action of delete ip find the ip is associated to a fixed ip at
   first(at api level)
2. and then the fixed ip is released when the instance is deleted
3. so nova-network manager findes this issue and raises
   exception.FloatingIpNotAssociated(address=floating_address)

Change-Id: I253d0b240451e8a728532639e9857894f6fc6870
(cherry picked from commit a5923541e990326a9b850926e74026d5947ae142)
Reset migrating task state for MigrationError exceptions

Create an exception type for pre-check errors and add it to the list
of exceptions for which instance task state is reset to ACTIVE to
avoid cases where an instance get stuck in MIGRATING state.

Convert existing instances of raise MigrationError in scheduler and
driver pre-checks to have them raise the new MigrationPreCheckError
exception instead.

In addition, also make sure that expected exceptions are passed over
RPC silently.

Resolves bug 1171526.

Conflicts:
	nova/scheduler/filter_scheduler.py
	nova/scheduler/manager.py
	nova/virt/xenapi/vmops.py

Change-Id: I00fa0962e555f895dd98861684ec7767fed3b37b
(cherry picked from commit 9eb3dc7ed44d99652a17238724842e3067d46120)
Guard against content being None

`content` can be passed in as None, so we need to set it to the empty
list if that occurs.

This also fixes the bad-practice of using a mutable data-type as a
default argument.

Fixes bug 1163598

Change-Id: Ie991c9452a21cfb036d3955a094ec345805d63d1
(cherry picked from commit 782bab8dd2930a4479d84dcb906321313d06b25b)
xenapi: Don't swallow missing SR exception

The existing code would catch a missing SR exception and bail out of the
`update_status` method before finishing, causing required keys to be missing.
The end-result was code breaking later on when it tried to access these keys.

Since an SR is required to generate these required stats keys, we shouldn't
swallow the StorageRepositoryNotFound exception and instead should fail-fast.

Fixes bug 1175357

Change-Id: I3d65ae807fb2d86277bc0061c1967a87792b6662
(cherry picked from commit b6aac988e46147154d49e938ecf9b67831613636)
Fix building quantumapi network model with network list

Bug 1171636 occurs when _build_network_info_model() receives a list
of networks that does not fully map all of an instance's ports.
It crashes in _ensure_requested_network_ordering() when the list of
all ports is sorted by the subset of networks provided.

This change simplifies the early part of that function to only
consider ports within the networks provided, and to always sort those
ports in network order. This allows us to remove some error path
code from the loop below that iterates over the ports (which contained
a fatal typo, by the way) which is now dead code.

The affected code is really untested at the moment, due to the
structure of the method, making it hard to add a unit test to cover
this fix. In order to make the change clear from the existing code,
this fix is provided here first, and the following patch restructures
the method and add tests for this change and the rest of the surrounding
code.

Fixes bug 1171636

Change-Id: Idf519a88415844451b18959b38cc48ce92c090d1
(cherry picked from commit 08c7cf5c67a75dea9b453bd915a0cd55e67c4adc)
nova coverage creates lots of empty folders

With nova coverage extension disabled as a default behaviour,
nova will create lots of empty folders under /tmp folder. And also
with each time the nova service reboot, it will create a new
directory with name like nova_coverage_*. There will be number of
the empty folders accumulated.

Patch-Set 3: Rebase for merging code
Fixes: bug 1169005

Conflicts:
	nova/api/openstack/compute/contrib/coverage_ext.py

Change-Id: I26d1037eb66d781ac6ef6b600cca04a709bff3f7
(cherry picked from commit b6e072a84a31eca1f7d7c44117327c5042e153c2)
vmwareapi: Add supported_instances to host state

The VMWareVCDriver uses the VCState class to report host state,
but VCState.update_status() does not include supported_instances.
Add supported_instances to the data returned by update_status(),
similar to HostState.update_status().

Change-Id: I15c0f930dd9e540f6fdb0d7246661a0c98e35ed4
(cherry picked from commit 7e86ab000e5b897d3b7fac6aca0c11f4db51ef7d)
Update hypervisor_hostname after live migration

After a live migration, the OS-EXT-SRV-ATTR:hypervisor_hostname
attribute of the instance is not updated correctly.  This change
adds a parameter to the call to _instance_update that fixes the
problem.

Fixes bug 1173376

Change-Id: I40f1ead2d93c7a9979a914e0fb96e3e5bb287b48
(cherry picked from commit 8c8e44cf37be9c6a9f418e923c9ff16df8619832)
Make sure confirm_resize finishes before setting vm_state to ACTIVE

Setting it to ACTIVE to early will allow new resize or whatever
operations to start before the current confirm has finished which
might result in all sorts of conflicts.

Resolves bug 1161529 where an intermittent failure in a tempest test
happens because a confirm operation conflicts with a later resize
carried out on the same instance. As the new resize starts to move
around instance disks, the still not finished confirm operation might
fail at recalculating total disk usage due to a missing disk.

Other possible conflicts might be due to system_metadata and/or quota
not being up-to-date at the moment the instance becomes ACTIVE.

Change-Id: I079da4e271469739504fa87e23149d03652d98f0
(cherry picked from commit fd26589afa2852762575feaae95a0c9b0c091461)
Fix zookeeper import and tests

Import zookeeper.membership rather than zookeeper.membersip.
Also fixed some issues with setting up the tests for the zookeeper
servicegroup driver.  Config options were not being set before
initializing the driver leading to failures.

There is no added test for this because the bug is indistinguishable
from not having the zookeeper python modules installed, which leads to
skipping these servicegroup tests.

Bug 1177776

Change-Id: Idd6dca2e03169399b930cc1fc1a85636497cb0b5
(cherry picked from commit 4a2845095c0e35336c60836050ca11c71898fb8c)
Fix variable referenced before assginment in vmwareapi code.

Add unitests for VMwareapi vm_util.
fix bug #1177689

Change-Id: If16109ee626c197227affba122c2e4986d92d2df
(cherry picked from commit aeef5c3f1917969fc2dc524346784b197729a9e9)
Fix powervm driver resize instance error

During a resize operation in powervm, the logical volume
of the instance will be copied and compressed to a file.
Current logic decompresses it twice before copying this file
to a new volume which will cause the new instance to not
boot properly.

Fixes bug #1169848

Change-Id: I91f536919511aafbf7dbe14abbee48dbceb189b2
(cherry picked from commit 5643bd5d9bf17335e109d4b2d93e161f4d12c6f9)
Make nova.virt.fake.FakeDriver useable in integration testing

With this change nova.virt.fake.FakeDriver can be used for scale testing
using devstack. By setting 'compute_driver = nova.virt.fake.FakeDriver'
in nova.conf and disabiling quota and other limits, we can load up nova
to think it is running 1000's of instances.  This particular scenario is
analagous to how the baremetal driver will work (one machine managing
100's to 1000's of instances).

Make nova.virt.fake.FakeDriver use CONF.host for hostname.

Change-Id: I731ca2968176b4e39dd2fe7fc99f479cc568398b
(cherry picked from commit 03a2463be8034ee4764ac97e8020fc3d3a32f1fd)
Make sure that hypervisor nodename is set correctly in FakeDriver

This resolves an issue where the wrong host name is used when
executing some sample_api tests individually.

Resolves bug 1177802.

Change-Id: I29af026e29ff8c70bb6b4c81f1bdf28cdea11140
(cherry picked from commit 8b79ac24a83854de9f57bb3526a2edbd0b6d64d2)
Catch volume create exception

Catch InvalidInput exception from cinder when the parameters
are invalid such as an invalid size. Currently the exception
is not caught which results in a 400 Bad Request correctly being
returned, but also leaving a traceback in the logs. Correctly
catching the exception and explicitly raising an HTTPBadRequest
removes the production of the traceback

Fixes bug #1098048

Change-Id: Ia66e67f302cf20e96417f4ff3c1430b755a4a861
(cherry picked from commit 46ce2e345bce18c2e2f645bb90aea11ca53ba825)
Fix for missing multipath device name

Due to formatting changes in the multipath -l output
we were sometimes missing the device name for each of the
multipath devices which gave us a device of '/dev/'.  This
causes problems on detach.

Fixes Bug: #1180497

Change-Id: I6017dda149776624fac452140d3d0f5df3f5fd5a
(cherry picked from commit 565dfc65fbab1df4ec5e83be627805c313aab04b)
Support FlatDHCP network for VMware Hyper.

Auto create bridge when using FlatDHCP network, Add unittests for vif.

Fix bug #1171783
Fix bug #1177635

Change-Id: Ibb75c8e3174283f0f5e94bacfd61ee93e8bd6227
(cherry picked from commit bc66b8aa968a0c0b74e2f21ed0fc856f8933c6d3)
Don't raise unnecessary stack traces in EC2 API

exception.EC2APIError exceptions are always expected, so no reason to have a
LOG.exception when one is raised.  Furthermore nova.api.ec2.ec2_error already
logs the exception so the duplicate log statement is just removed

Fix Bug 1180973

Change-Id: I4b42a9a764f6e15bb94a383e8a725d52d7436bd7
(cherry picked from commit dc887267572c821ce97bec9536a699b72bdae443)
Reverse path SNAT for DNAT floating-ip.

This patch applies a reverse SNAT rule to allow instances that have an
assigned floating IP to communicate with other instances in the same
OpenStack deployment, security group rules permitting. The patch
allows members of the same private network to communicate with each
other using their floating-ips in a more consistent fashion. The rule
also addresses the situation where the target is on another private
network.

This will only work for interaction between two servers that both have
floating IPs assigned to them.

Specifically, this patch solves the problem where a target server
"sees" the private address of the client. By SNAT'ing to the client's
floating-IP, the "sees" the correct reply address and the reverse
route follows the same path that an actual external connection would
take. The SNAT ONLY occurs if a DNAT occurred before hand, allowing
communication on private networks using private IPs to remain fully
private and internal. The limitation is of course if a DNAT occurs for
other reasons, there may be issues.

Resolves bug 1178745

Change-Id: I55b7131cff5fd5a2ebf826945370d4d550e74136
(cherry picked from commit 314c419323ddd512babc4504ef8a4be1e04f2af7)
Merge "xenapi: Don't swallow missing SR exception" into stable/grizzly