Fix bug in os-availability-zone extension.

Fixes bug 1167956.
The call to get the list of availability zones (GET V2/os-availability-zone)
doesn't hide internal availability zone if all services in that zone are
disabled.

Change-Id: I2c49ad68c2ee5ddea0536dfa770f649fbb392b63
(cherry picked from commit 7172fdc2bf4061039fe34cdb97e442c073a7570a)
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)
Fix key error when create lpar instance failed

With existing code, when create lpar instance
failed, it throws a key error because the parameter
is not being passed to PowerVMLPARCreationFailed
function in exception module.

The fix for this is that in module operator, passing
the 'instance_name' to the called function in exception
module.

Fixes bug 1173303
Change-Id: I688eecf7b649b67ca62f72d6d33fd7cd774047c3
(cherry picked from commit cccca7a4531cdad88655c27533f63c590a5ddfa1)
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)
Adds --addn-hosts to the dnsmasq arg list

When using multi_host=True and update_dns_entries=True, dns records from
other compute hosts were not able to be resolved.  The --addn-host arg was
constructed but not appended to the cmd list.

Change-Id: I9cafb59256e92bdad0df3e9166e0afd079ae0c09
Fixes: bug #1170529
(cherry picked from commit 3922da72b2569976f25183c476cedcc17d32fa13)
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)
Fix EC2 instance bdm response

Make the bdm response respect Amazon EC2 spec:
 * use ec2 volume id instead of uuid
 * use volume attach_status instead of status

References:
http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-ItemType-EbsInstanceBlockDeviceMappingResponseType.html

Resolves bug 1165973.

Change-Id: Ib68397b79f63e01e92ed4bebbc245ba5e0a3ad11
(cherry picked from commit f48a2e1a68cca1ef147279b2ddf713635f494bc0)
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)
Nova evacuate failed when VM is in SHUTOFF status

When the VM is in SHUTOFF status and the original compute host is
down, issue the "nova evacuate" command to rebuild the VM on
another host, it is failed due to a type error: string indices
must be integers.

Fix bug 1176773
Change-Id: I76ebce6882198365717167f29a484e4ec994db0c
(cherry picked from commit 2c1bd79a202c868bfeee7ca92e817ad19ef06b76)
libvirt: ignore NOSTATE in resume_state_on_host_boot() method.

Occasionally, libvirt would get NOSTATE from hypervisor as instance
state. Thus if we don't ignore instances in NOSTATE in
resume_state_on_host_boot() method, we would mistakenly reboot such
instances when we restart nova-compute service or on host boot. This
patch fixes this by adding NOSTATE into ignored_states.

Bug 1176897

Change-Id: I651cb043d7f97fde29b2a62e6ead8222062f01f7
(cherry picked from commit 0098f12e8b1f035c7ecdb952cfcd4bbae86b6246)
Delete InstanceSystemMetadata on instance deletion

Thanks to no-db-compute only pre-delete instance data is used in
notifications. So now we can go back to deleting InstanceSystemMetadata
when an instance is deleted.

Fixes bug 1153827

Change-Id: Ic66b998cde2a15a24f302f08c34753a8b57da73d
(cherry picked from commit 17bca438954638d74035d560e826a26a532b3ea3)
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)
Bump stable/grizzly next version to 2013.1.2

Change-Id: I130528ae946e8888d35c25e468b4ea6ac29db0cf
Merge "Fix EC2 instance bdm response" into stable/grizzly
Merge "Adds --addn-hosts to the dnsmasq arg list" into stable/grizzly
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)