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)
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)
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)
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)
The vm_state should not be modified until the task is complete.

Several methods in nova.compute.api alter the vm_state value before
proceeding with the actual work. The initial vm_state may be changed to
something other than the initial vm_state (which is a problem: since we
do not know what the initial state actually was, we cannot reasonably
recover and set the corresponding ERROR if a problem with the operation
occurs).

Actually done:

Removed vm_state update before executing task

Changed methods:
- reboot
- pause
- unpause
- suspend
- resume
- rescue
- unrescue

Fixes: bug #1158509
Change-Id: I5ee7aebf3c4831dd577ed5ab9aa155095152f8a8
(cherry picked from commit d4e762bd9ecffb6a945fbe938fff78fc2b0681e6)
set bdm['volume_id'] to None rather than delete it

bdm is a sqlalchemy model object, it doesn't make sense to delete
an attribute, so just set it to None

Fix bug 1166160

Change-Id: I41017af602f0c8369d442b4a6936e1a829d2f9a9
(cherry picked from commit 85c3c89f1d44ab4b26755958fec29161b0090ce0)
Fix resize when instance has no image

This patch makes it possible to resize an instance that has no image
supplied (was booted from volume), by avoiding calling the image service
and thus causing an uncaught exception, if there was no image suplied in
the first place.

Fixes bug: 1182114
blueprint: improve-boot-from-volume

Change-Id: I67d63a7aef699b555897582c74b04e857db7aafb
(cherry picked from commit 4465b705fc7cb7a150a7f8d6f70ccf6c20ff3284)
Merge "Fix zookeeper import and tests" into stable/grizzly
Merge "nova coverage creates lots of empty folders" into stable/grizzly
Merge "Guard against content being None" into stable/grizzly
Disallow resize if image not available

If a resize is attempted on an instance that was started from an image
that has since been deleted, a resize will fail. This change makes error
reporting a bit cleaner.

This change is needed since in order to actually properly support
resize/migrate when the image is deleted - it is necessary for nova to keep
a copy of the image metadata and re-use it in case of migration/resize.

Fixes bug: 1160773
Fixes bug: 1177001

Change-Id: Ifaea71f79c97046a4cde094e3a5e676772fcceb4
(cherry picked from commit 65a6264c236a779712694d2379cfe4f9e46e2732)