Handle UnicodeEncodeError in validate_integer

validate_integer can be potentially passed user
supplied data which causes a UnicodeEncodeError
exception during validation rather than just ValueError.
This change handles the UnicodeEncode exception
so validate_integer treats it as invalid input.

Change-Id: I5177789299b02448ed53e1b7fc23ccdaee1b70d3
Partial-Bug: 1243037
Fix docstring on SnapshotController

Change-Id: I66a8b15ef700253bbad54ee3955550aeb2a522b7
Closes-Bug: #1257151
Enforce permissions in snapshots temporary dir

Live snapshots creates a temporary directory where libvirt driver
creates a new image from the instance's disk using blockRebase.
Currently this directory is created with 777 permissions making this
directory accessible by all the users in the system.

This patch changes the tempdir permissions so they have the o+x
flag set, which is what libvirt needs to be able to write in it and

Closes-Bug: #1227027
Change-Id: I767ff5247b4452821727e92b668276004fc0f84d
Delete iSCSI devices after volume detached

Previously, after detaching from a volume, the iSCSI device
remains attached on the compute node until all LUNs for a given
IQN are detached -- causing issues when LUNs are reused for
different volumes. This change will delete the device(s)
associated with the detached volume so LUNs can be reused.

Fixes bug 1112483
Change-Id: Icae3ec4d1ee2036fbba7b9eb5c03a1c86014fcc0
Add boolean convertor to cells sync_instances API

cells sync_instances API contains "deleted" as the parameter, and the
parameter should be boolean. There are the other boolean parameters
such as "on_shared_storage" of evacuate API, they can be passed with
either boolean or string(e.g. "True").
For the consistency of whole Nova APIs, this patch adds boolean conv-
ertors to cells sync_instances API.

Change-Id: I4776539cfd723f302d10350757e1c341384c9ba2
Closes-Bug: #1261287
Changed error message to match usage

InstanceDiskTypeTooSmall is not the proper error message, it should be
FlavorDiskTooSmall.

Change-Id: Id928015534161cba296c17114ef2d19d96e8781d
Allow some instance polling periodic tasks to hit db slave

If your deployment has a slave configured, poll_*instance* periodic
tasks will send their reads to the slave. If you have no slave
configured, there is no change to behavior.

Note for developers, I have targeted all the easy tasks. By this I
mean tasks that were already using the InstanceList object and the
get_all_by_filters or get_all_by_host methods. I will slaveify the
other tasks in seperate reviews since they also require conversion
to using objects.

Change-Id: I4bead5d350d633d726d4564b4bc1baec2e2977b7
Partially-implements: blueprint periodic-tasks-to-db-slave
Fix image cache periodic task concurrent access bug

This fix catch the exception and ignore a disk file absent
exception. It will defer the image cache clean to next round
image cache periodic task because it's not harmful.
Refer to detailed info, log analysis and root cause in defect.

Change-Id: I3a431bf389658f976edf5c847c04b7e0aac496fd
Closes-Bug: #1261442
Add API schema for v3 admin_password API

By defining the API schema, it is possible to separate the validation
code from the API method. The API method can be more simple.
In addition, a response of API validation error can be consistent for
the whole Nova API.

Partially implements blueprint nova-api-validation-fw

Change-Id: I97a412aa23db75e3d892a113733e732eeb8008c1
Catch InstanceIsLocked exception on server actions

If the server is locked, server actions raise 409 error, and the error
message is like "Instance is in an invalid state for 'pause(action name)'". The
error message is inappropriate, two points:
1. the state is valid for pause
2. the message doesn't tell that the instance is locked

The patch fixes the problem, and will modify on v2 and v3.

Change-Id: I7e21037b9abca5a3fd0f64dd5621e88dcf1a3c21
Closes-Bug: #1256873
Fix lxc rootfs attached two devices in some action

During resizing/rebooting a lxc container, create_domain action
will be called and lxc rootfs will be attached to device again.
So before this action, We need to teardown the container to
make sure lxc_root_device is detached when container is destroyed.

Closes-bug: #1243083
Related-bug: #1208387

Change-Id: Idd1862c7f212dc253b6273b07b020c86a94e658e
Change when exists notification is sent for rescue

The exists notification is now generated only after the rescue
operation completes successfully.

Closes-Bug:1262639
Change-Id: If79eb5065b11f28320e8a13de2ad15b2ef3119a9
Rename instance_type to flavor in xenapi virt driver

Renames 'instance_type' to 'flavor' in the xenapi virt driver and
associated tests.

Part of blueprint flavor-instance-type-dedup

Change-Id: I0f1a17b725102eab30ce90714b50444d8d140da0
Prevent Instance.refresh() from returning a new info cache

If an older node does a refresh() on an instance, conductor will
return a new copy of the InstanceInfoCache, which the client
will balk at. Instead, add a refresh() method to info_cache and
call it from Instance.refresh().

Closes-bug: #1265607
Change-Id: I6a4787a23cd851cf56958c61f8b0559a79847ca0
Translate the snapshot_pending state for old instances

Icehouse introduced an image_snapshot_pending state which Havana
compute nodes do not understand. This adds a translation for that
state when we are handling save() for a havana-era Instance object.

Closes-bug: #1265618
Change-Id: I36028defc3591cc6e31c7ba763a5c7f076832179
Better exception handling for deletes during build

To retain parity with the current run_instance boot process we should
not set the instance to ERROR if a delete occurs while it's building.

Some instance updates were moved into try/except blocks so the
task_state check failures are handled properly.  And a test for a
condition that can't occur was removed.

Part of bp remove-cast-to-schedule-run-instance

Change-Id: I688059404d6b697bd21f6037252dbe628c1b24f2
Whitelist external netaddr requirement

* tox.ini(testenv.install_command): Use the --allow-external and
--allow-insecure options so that pip 1.5 and later will assent to
retrieve the netaddr package even though it's not hosted on PyPI.
The --allow-insecure option is aliased to a clearer
--allow-unverified wording in 1.5, but the old form is being used to
avoid breaking users of 1.4.x and will be valid at least through
1.6.x according to comments in the pip source.

Partial-Bug: #1266513

Change-Id: I005e752c8cb9bca78b1ebe777eb5230e9bf05bd8
Remove unused variables in imagebackend.py

The method create() in /nova/virt/libvirt/ imagebackend.py has two unused
variable: old_format and features.These should be removed.

Change-Id: Id7b8661a162fbdf33de21b29892b5244ef301da7
Closes-Bug: #1266450
Cleanup object usage in the rebuild path

This patch removes a redundant fetch of instance system_metadata
that was used to refresh our notion since the first get. Now that
the rest of the code is using instance.save(), it has an updated
view of system_metadata at effectively the same point.

Related to blueprint icehouse-objects

Change-Id: I357daa5ae627e8959b77bd0cb00e152810f9c0eb
Don't deallocate/reallocate networks on reschedules

If network allocation is not host dependent we don't need to deallocate
and reallocate a network for each reschedule.  Only baremetal has host
dependent allocation so for that driver networks are de/reallocated on a
reschedule.

The current method in the code which checks for the length of the list
returned from _get_instance_nw_info() doesn't work because it can't
distinguish between an unallocated network and one that doesn't return
network information.

Part of bp remove-cast-to-schedule-run-instance

Change-Id: Ic427715f46cb5179a37c593c4217f239c65544c3