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)
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 nova-network support requested nic ordering

The nova-network did not honor nic ordering, so nics were attached in db
natural order. This patch sorts the networks honor requested nic
ordering when Nova calls the nova-network API.

Fixes bug: #1170725

Change-Id: I7dd04ac7bdda95c626cbb0fe35be0aadacb4bd2a
Signed-off-by: zhiyanl-cn <zhiyanl@cn.ibm.com>
(cherry picked from commit 90d3371be6c7ec2fc85c92f4744adf4f83003522)
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)
Pass None to image if booted from volume in live migration

The destination check in live migration will fetch the image
information from glance and it will throw ImageNotFound if
the instance is booted from volume since there is no image id
on the instance

Fix bug 1170596

Conflicts:

	nova/scheduler/driver.py

Change-Id: Ie683a3ca5d6430c52ead77b41f98fbcb4114ea1e
Raise InstanceInvalidState for double hard reboot

A hard reboot is not allowed if the instance task_state is
REBOOTING_HARD so check for that state and raise InstanceInvalidState.
This returns the correct status of 409 to the caller.

Previously the hard reboot would fail the the expected_task_state check
on db.instance_update_and_get_original which would log a traceback and
return a 500 to the caller.

Bug 1157237

Change-Id: Ifb6111790352da5c404289b218c50d8104384301
(cherry picked from commit 662a793056d4544c9c9d73fc21b99d77404537cc)
Fix quantum security group driver to accept none for from/to_port

The quantum security group driver did not accept none values for
from_port/to_port which the nova security group api supports. This
patch allows None values to be passed in for those params and adds a unit test.

In addition the from/to_port responses would be different if using quantum
instead of nova. This patch fixes that and adds unit tests.

Fixes bug 1176027

Change-Id: Id57e253c9dd1787ee25fc5cbb562743692d7abe4
(cherry picked from commit 78e2e2128992527407f99743340692ef3be75210)
Pass the proper admin context to update_dhcp

Bug 1180111

Commit 14e2ed3ace769c4deaca3c48a2fa59863f637a5f introduced changes
to contexts passed around during resize. One of the calls to
update_dhcp was missed and was causing stack traces on
resize-revert.

Change-Id: Ib7bec51324c7bced009407af13a7fff7a724e020
(cherry picked from commit 42cc18da31ceb10ec0b26fe734e7556873f6fe71)
Merge "Pass the proper admin context to update_dhcp" into stable/grizzly
Detach volume fails when using multipath iscsi

Enabled multipath for libvirt iscsi volume driver. Attach volume worked,
however, detach volume failed. It failed because it can't find multipath
device "/dev/mapper/xxxxxxxx" from connection_info and block device
mapping table.

The fix is to retrieve multipath device info dynamically at detach time.

Fixes: bug #1178893

Change-Id: I53a3888daef93b57bf7f57438f74cee05e794b52
(cherry picked from commit fc786dd469a15bda1b9d3c7bacf9f1771b9b9956)
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)