hyperv: Initialize target_iqn in attach_volume

The target_iqn is referenced before it is declared in the
case that an exception is encountered in _login_storage_target
or _get_mounted_disk_from_lun.  This causes the exception path
to cause an additional, misleading, traceback to be printed
after an exception is encountered.

This commit initializes target_iqn at the beginning of
attach_volume to avoid the traceback.

Change-Id: I1cdfb9dfa054ee4f4f6918d7bc49081ccaebab9d
Close-Bug: 1233837
Plug Vif into Midonet using Neutron port binding

Currently Midokura uses its own script (mm-ctl) to bind ports. However, support
for using this script is left out of the nova and neutron projects. This causes
confusion and makes deployments unnecessarily complicated for customers using
Havana. This fix is to change nova to properly use mm-ctl. Corresponding
changes will be submitted to devstack and neutron.

Change-Id: I7c9edded5ab6fe19b63e54cd6905d9242e4a90cc
Closes-Bug: 1235132
Fix status code of server's action confirm_resize for v3

The status code of confirm_resize should be 202, but it
returns 204 now. That because it returns HTTPNoContent
that overwrites the status code of decorator 'wsgi.response(202)'

And adds API samples for confirm_resize that used to test
the status code of confirm_resize.

Partially implements blueprint v3-api-unittests
Closes-bug: #1233561

Change-Id: I50a3046866af0a1efdb5c41ded40f973b02843e8
Replace incorrect Null checking to return correctly

Null checking for metadata in check_img_metadata_properties_
quota function doesn't work as designed, fix incorrect Null
checking code.

Change-Id: Id3f971091d857d6b2aebc4985cb932417c21b5dc
Fixes: bug #1220120
Utilizes assertIn - tests/api/v3

Using assertTrue and the 'in' operator to test
if an element is in a sequence is too python2.4.
Our unit testing framework supports assertIn,
which was created for these types of tests.
Using assertIn will enhance readability of the test scripts.

Change-Id: Ic3ae0a0eca219bd7d114580ad3642e7df04ad1f4
Utilizes assertIn - tests/api/contrib

Using assertTrue and the 'in' operator to test
if an element is in a sequence is too python2.4.
Our unit testing framework supports assertIn,
which was created for these types of tests.
Adapting assertIn will enhance the readability of the test scripts.

Change-Id: Id2237b7a35c5c759e571b138faa8d1bef46a7e27
Utilizes assertIn - tests/virt

Using assertTrue and the 'in' operator to test
if an element is in a sequence is too python2.4.
Our unit testing framework supports assertIn,
which was created for these types of tests.
Using assertIn will enhance readability of the test scripts.

Change-Id: Ifa0f7e12a1ba84052e1e64ed2775056fafd2b13b
Utilizes assertIn - tests/api/etc

Using assertTrue and the 'in' operator to test
if an element is in a sequence is too python2.4.
Our unit testing framework supports assertIn,
which was created for these types of tests.
Adapting assertIn will enhance the readability of the test scripts.

Change-Id: I9995c6668710e94902d97da21303274965df17e9
Improve logging messages in libvirt driver

This is a trivial change to correct an uninformative log message.
There are two checks in get_instance_disk_info that look at a disk.
One checks for the type of a disk and logs its path if it is not a file.
The other checks for the path and logs the instance name it belongs to
if it does not exist. The first will log None if the path does not exist,
so reverse the order of the checks.

Closes-Bug: #1239747
Change-Id: Ieb52ba0584ad789dc55f40e0172cf5ed41e86fbe
Uses oslo.imageutils

Commit 035668 had the QemuImgInfo class moved to Oslo.
This class was copied from Nova to Cinder and diverged since then.
The two projects will be able to use identical classes by importing imageutils.

Change-Id: If1962680906b3736d3f16f306b077483b122f878
Add extension access_ips for v3 API

The functionality of access ips overlaps heavily with floating ips,
and the most deployments don't use access ips now. So we decided to
demote access_ips to extensions, the more detail discussion at:
https://etherpad.openstack.org/NovaV3APICore

New extension add prefix 'os-access-ips' for properties 'access_ip_v4' and
'access_ip_v6' to follow v3 API rules. And add unittest for new extension.

For making this patch small, this patch just add the code of extension
and related unittest, without enable the new extension and remove the
old access_ips attributes. That will be done by next patch.

If you want to test this new extension, you can enable it by adding
'access_ips = nova.api.openstack.compute.plugins.v3.access_ips:AccessIPs'
to entry point 'nova.api.v3.extensions' and
'nova.api.v3.extensions.server.create*/rebuild*/update' in setup.cfg.

DocImpact

Partially implements bp nova-v3-api

Change-Id: Ib56e4ff9145798792f062fc107390565673ac9a1
Fix docstring related to create_backup API

This patch adds "returns" of backup() and removes unnecessary
"backup_type" from _create_image().

Change-Id: If00c6437ee8415ba1e21ae2cceba0817606f27b0
Update timeutils.py from oslo

This fix is related to oslo-incubator commits:
3bc6f79d794aee9d51abc0be10e846b971fae847
af76064855c5bb888e1a0d2800d1f49470e19091
df3f2bafbe76d78d017d40e7dc08909fee7dbe34

Change-Id: I1194df94d85d3dde29e81003c0c3db735c66b35f
Adding Read-Only volume attaching support to Nova

Supporting attach a volume with Read-Only mode in libvirt driver.

Implements bp: read-only-volumes

Related-Id: I4c84614d6541d5f7c358abadb957da7b8c3d9c48
Change-Id: Id5ef7b25350cb1bde9d30fbfa98fb7a80081827f
Signed-off-by: Zhi Yan Liu <lzy.dev@gmail.com>
Validate parameters of agent API

The agent API has some parameters, but they are not validated.
Each parameter is stored to the table "agent_builds", and each column
is defined as varchar(255).

mysql> desc agent_builds;
+--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| created_at   | datetime     | YES  |     | NULL    |                |
| updated_at   | datetime     | YES  |     | NULL    |                |
| deleted_at   | datetime     | YES  |     | NULL    |                |
| id           | int(11)      | NO   | PRI | NULL    | auto_increment |
| hypervisor   | varchar(255) | YES  | MUL | NULL    |                |
| os           | varchar(255) | YES  |     | NULL    |                |
| architecture | varchar(255) | YES  |     | NULL    |                |
| version      | varchar(255) | YES  |     | NULL    |                |
| url          | varchar(255) | YES  |     | NULL    |                |
| md5hash      | varchar(255) | YES  |     | NULL    |                |
| deleted      | int(11)      | YES  |     | NULL    |                |
+--------------+--------------+------+-----+---------+----------------+

This patch adds the validation with the type and the length.

Closes-Bug: 1240458

Change-Id: Id06235ebde62f7b96c55b0bd2be5d941bfd2e999
Manage None value for the 'os_type' property

The I2bab617f6c1e8866650ca7dc5178b640738c9ae6 introduced a way to pass the
'os_type' property to glance when we are doing a snapshot in the libvirt
driver. Currently the code doesn't manage properly the None value for this
property and so None value is passed to glance which creates an image with
a property called 'os_type' with value 'None'.
As results of that all instances booted from a snapshot with this property will
have None value in the os_type field.
That field is used to create file name for backing images for ephemeral disks.
Now consider this scenario:
we boot an instance from an image without the os_type property defined and
with an ephemeral disk of 50 G
the resulting backing file will be called ephemeral_50_default.
At this point we take a snapshot from that instance and we boot a new instance
using this snapshot, and because of this bug we will have a new backing file
called ephemeral_50_None.
That is bad because is leaking resources in the host.

Please note that I did a small refactor of the code to make my change testable.

Change-Id: I40bca2732ee2c911344e9d361612007da1c7c3cf
Closes-bug: #1240542
Improve object instantiation syntax in some tests

This makes the base and instance tests use the improved
instantiation syntax.

Change-Id: I60aa64603a4ed225cc978f4b5b86ade759242276
Remove .pyc files before generating sample conf.

Updates the generate_samples.sh script so that we remove
.pyc files in the nova source tree before generating the sample file.

If you don't run unit tests the .pyc files won't get regenerated.
This can cause cryptic errors if you run tests, switch branches,
and then try to regenerate your config files if there are module
differences, etc.

Change-Id: I784a22c1cd7fb2c69ea1d9e02f87bd7da19d76aa
Change tab to blank space in hypervisors-detail-resp

We should not use tab in hypervisors-detail-resp.json.tpl and
hypervisors-detail-resp.xml.tpl, the fix was change tab to blank
space for those two files.

Change-Id: I21be0d806e4238228dfb068f7937bdc6c81e62b0
Fix i18n issue for nova/compute/manager.py

There are some log message in nova/compute/manager.py does not follow
I18n coding style, we should update this.

Change-Id: Ia566b5377e27bc9883a3d191346ba4a83df385ff