Loosen import_exceptions to cover all of gettextutils

Now that we are starting to move over to multiple log domains we want to
import multiple items on the same line for gettextutils.

Change-Id: Icd88774a0f1087270234a6849bf96a93c0927534
(cherry picked from commit 2d75fafb88f7e871ae63304f88eb34e48edac2e1)
_translate_from_glance() can cause an unnecessary HTTP request

After returning from a get() call to python-glanceclient, nova runs a
translation function on the returned Image to get the data it wants. Part of
this process is checking for an expected set of attributes, one of which is
the deletion time ('deleted_at'). However, if the image has not been deleted,
deleted_at key will not exist. This forces another call to glance to occur for
the same image. A similar problem exists for the checksum attribute, which does
not exist before an image is active. The fix here is to only consider
deleted_at and checksum if they are expected to be present.

Change-Id: I67b7dd16a94fe60d873c012f6bd246ab24500d5a
Closes-Bug: #1275173
(cherry picked from commit 8fcefef5c6db3bb7f182df62de9c5bf986f97303)
Fix nova image-show with queued image

Currently, the nova image-show command cannot be used with queued images,
because they don't have certain attributes set yet. Nova will raise
AttributeError, which causes a 500 to be returned from the API.

Change-Id: I7d73b891545492e3e247eebdf02507cb630eb250
Closes-bug: #1321186
(cherry picked from commit 4c5dea6a5103a141b0ca13dcd57b32b3261180d1)
libvirt: return the correct instance path while cleanup_resize

If we resized a pre-grizzly instance with grizzly or later nova
to another host, while the resize confirmation process,
_cleanup_resize will find the instance resize backup dir and
delete it, but a wrong xxx_resize dir like ${uuid}_resize,
instead of the correct ${name}_resize will be found.
This is because the instance is a resized one which original
instance dir exists on another host(the dest host),
get_instance_path method could not find the original instance
dir on the source host, so the path with uuid will be returned,
and the `target` existing check in _cleanup_resize is failed,
then the ${name}_resize dir will never be deleted.

Closes-bug: #1290294
Change-Id: I904b6751dec740e001f5ec29f637ef456528746f
(cherry picked from b4964eb6a570e290545f95d45411dc8441985cd5)
shelve doesn't work on nova-cells environment

The compute_api shelve/unshelve methods expect an Instance object,
but cell is still passing the sqlalchemy form.
So adding shelve/unshelve to the list of methods that will receive an
Instance object when using nova-cell.

When shelving instance with nova-cell environment,
instance object needs to contain 'metadata' and 'info_cache'.
So fetching the same from databse and adding it to
instance object before calling shelve/unshelve methods.

Conflicts:
    nova/cells/messaging.py

Closes-Bug: #1338451
Change-Id: Ia31b33c9a1d347f15d3e0a67fa31ef6b25a7407a
(cherry picked from commit 9d4b49c542e2076c8a572d1e8c6d50e255efe087)
VM in rescue state must have a restricted set of actions

Right now it is possible to pause, suspend and stop a VM in state RESCUED,
so after the state is changed, it's not possible to trigger unrescue anymore
since the original state is lost.

This patch remove vm_states.RESCUED as valid state from stop,
pause and suspend actions.

The vm_states devref is also updated to reflect this change including the
current reboot flow.( vm_states.RESCUED cannot be rebooted as per
today code)

This is a backport of 8ff170dc95bf3101fe38a2624e941bfa3b7c1138 .

DocImpact
Closes-Bug: #1319182
Co-Authored-By: Cyril Roelandt <cyril.roelandt@enovance.com>
Change-Id: I531dea5a5499bf93c24bea37850d562134dee281
Delete image when backup operation failed on snapshot step

when we snapshot an instance, we will use @delete_image_on_error to
delete any failed snapshot, however, the image will not be removed
by backup code flow, it will be an issue if too many backup failed
at last ,all useful image will be removed and we have only 'error'
image left in host

Change-Id: Ib527ade86aef52a8445b57fa03fed434578c4204
Closes-Bug: #1288574
(cherry picked from commit 3824051b1e5618388a17c88867a3037397bc96b7)
libvirt: convert cpu features attribute from list to a set

Currently, the cpu features list which is being sent to libvirt,
when creating a domain or calling compareCPU, must contain only
unique entries. Multiple issues arise when we are updating the
features attribute in LibvirtConfigCPU class (for example during
migration).

This change will change the features attribute from being a list
to a set. This make the LibvirtConfigCPU class keep only unique
features.
Adjusting the LibvirtConfigCPUFeature class to support set
operations by overriding the __eq__, __ne__ and __hash__
methods.

Closes-Bug: #1303536
Change-Id: I6350fe0e827c860aea77cc4fe56f18f5c1483580
Cherry-pick-x: 60c899b9da8d64b4a5979b69c43c77ed9d5bf248
replace NovaException with VirtualInterfaceCreate when neutron fails

Currently NovaException is being raised by the _neutron_failed_callback()
and being treated in a try..except block that wraps the _crate_domain method.
The exception is too generic and will catch any exceptions, which are
subclasses of NovaException (for example: ObjectActionError),
making the domain variable not be defined and will mask the original exception.

Suggesting to raise and catch the VirtualInterfaceCreateException and
treat the domain destroy and cleanup with save_and_reraise_exception
in the except block.

Conflicts:
        nova/virt/libvirt/driver.py

Related-Bug: #1337860

Change-Id: Ic972e286ded4e8b9d79ce1b0aa514bb4623d5f0b
(cherry picked from commit f0388d6fec0c4830c730af1adb3d02027eb2cd1d)
Avoid traceback logs from simple tenant usage extension

Avoid generating traceback logs when invalid formatted datetime
parameters are passed to the simple tenant usage
extension. Exceptions have not been correctly handled by the
os-simple-tenant usage extension which results in tracebacks
being output to the log files. This patch correctly handles
exceptions as a result of badly formatted datetime strings.

Conflicts:
        nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py

Change-Id: Iecd42239357b96450b6530c0486b27c68995c37f
Partial-Bug: 1300972
(cherry picked from commit f60c72fac04a97b321a7f2bd0865c1ae81250882)
Fix _parse_datetime in simple tenant usage extension

_parse_datetime in os-simple-tenant-usage incorrectly attempts
to parse the datetime string even when it is None. As a result
a 400 BadRequest is returned. This has the overall effect of making
the start and end datetime parameters compulsory when they are meant
to be optional.

Note that this restores the behavior where start/end are optional which is
in contradiction to the API docs, but is the long standing API behaviour.
This was an API change which was accidentally applied in commit
I8e0e870727d687da165c809ffb7a4456bff81122 as part of some nova internal
changes but not picked up by the unitests

Change-Id: I00427379dc7aa39770f9a16ff026addb6e311735
Closes-Bug: 1300972
(cherry picked from commit 99e6ec9131c2e3eeb5fe3e1a4dc5a26e6302ebd2)
VMware: do not cache image when root_gb is 0

Save space on datastore when the instance size has root_gb of
0. There is no need to cache the disk as it already exists on
the datastore.

TrivialFix

Closes-bug: #1304593
(cherry picked from commit 9b14ae62a6396a2599c8a2ada1a50e3f69a2eddc)

Conflicts:
	nova/tests/virt/vmwareapi/test_driver_api.py
	nova/virt/vmwareapi/vmops.py

Change-Id: Iac75d97f40a1a91b8fa2df7fb4318fc2965fd93a
Fixes Hyper-V SCSI slot selection

Currently, when attaching volumes, the Hyper-V driver selects the
slot on the SCSI controller by using the number of drives
attached to that controller.

This leads to exceptions when detaching volumes having lower
numbered slots and then attaching a new volume, as Hyper-V will
then try to use an occupied slot.

This patch fixes the issue by simply getting a list of used slots
and getting a slot that it's not among those. It also checks
for the slot number to be smaller than the maximum number of slots
per SCSI controller.

Fixes bug: #1329764

(cherry-picked from commit a73e31022c9fef532cc2d66462d13f4ab2358565)

Change-Id: Id0c09c4debc848004a78971670cc3caef2f77ce3
Add expire reservations in backport position.

Change-Id: If0e58da50ebe9b50b414737a9bd81d93752506e2
Related-bug: #1348720
(cherry picked from commit f4454f4c6962dd2c57c08dc7fecfcdebe7924e3b)
Add a retry_on_deadlock to reservations_expire

Now that we have an index for the reservations_expire query, we
have uncovered a race with quota usage updates due to the foreign
key on the table, so just retry if there is a deadlock. This is
a fix to unblock the gate while we try to remove the deadlocks
completely.

Change-Id: I1993c3bd1f81facf1d98a4e29f9e8df4858a7d66
Partial-bug: #1350466
(cherry picked from commit 3619c1914e9925e18c062bc11bc3e708137f8322)
Read deleted instances during lifecycle events

This prevents us from failing to find the associated instance if
the lifecycle event happens after the instance has been deleted,
as in the case of a ... delete.

Change-Id: I819ddf8ff68edc407d7932bf43771c440f514f26
Closes-bug: #1304968
(cherry picked from commit 53ad788af6ced83bd9d6e58a25196a325d60fc4e)
Fix FloatingIP.save() passing FixedIP object to sqlalchemy

This prevents the FloatingIP.save() method from passing the
calculated FixedIP object to the sqlalchemy floating_ip_update()
function, which would expect it to be an SA object. It also
aborts any attempt to save the object with a modified fixed_ip_id
linkage, as associate/disassociate should be used for that.

This also fixes a bug where FloatingIP expects the result of
floating_ip_update() to be a FloatingIp SA object.

Added missing import to allow tests to work in stable/icehouse.

Change-Id: I065caedf4d81c8583a3b390934a1d403cf2e87bd
Closes-bug: #1334164
(cherry picked from commit 48de2895b9a550a0944b31212349275605a4061d)
Bump stable/icehouse next version to 2014.1.3

Bump stable/icehouse next version to 2014.1.3

Change-Id: If0b0267b047e9a9e1e67c49f62f2e11e9a9b18ea
Signed-off-by: Chuck Short <chuck.short@canonical.com>
Include next link when default limit is reached

The /servers and /servers/detail APIs support pagination and a
"next" link should be included when more data is available, see
http://docs.openstack.org/api/openstack-compute/2/content/
Paginated_Collections-d1e664.html. In the documentation it states
that 'collections are required to contain atom "next" links'.

When the default "osapi_max" limit is reached then the "next" link
is not included in the API reply. In this case, the caller cannot
determine if there are any more servers and has no marker value
such that they can retrieve the rest of the servers.

For example, assume that there are 1050 VMs and the osapi_max value
is the default of 1000. The /servers API will return the first 1000
VMs but it will not include the "next" link; the caller has no way
to determine if there are more then 1000 VMs and no way to retrieve
the other 50 VMs.

The fix for this is to include the "next" link when the number of
servers being returned is the maximum limit, even if the "limit"
parameter is not supplied. Note: the caller could workaround this
by specifying the exact "osapi_max" limit value (ie, limit=1000)
on the API call but this requires that the caller knows the
configured limit.

Change-Id: I9b3da852b0ab11dc980524e2317ee876a3ec28b8
Closes-bug: 1288466
(cherry picked from commit 968c01afe7ff43346f5817e2a3adf97fd03106b1)
Merge "shelve doesn't work on nova-cells environment" into stable/icehouse