xenapi: test functions for _stream_disk

Add test cases to cover nova.virt.xenapi.vm_utils:_stream_disk, so that
it could be refactored/extended without fear.

Change-Id: Ice43218680d2d5dffad51155cd8da2c2ad2e2cfa
xenapi: refactor - extract get_stream_funct_for

This change extracts the get_stream_funct_for function. As we would like
to support tar.gz compressed raw images, the stream function for them
should be different from the plain ones.

related to blueprint xenapi-supported-image-import-export

Change-Id: I27681da069ba2cd23670ef41f54ed9ac5af31ae6
xenapi: refactor - extract get_virtual_size

This change extracts a function get_virtual_size. This is needed,
because we would like to support tar.gz files, in which case the image's
virtual size will be determined by looking at the tar.gz stream. The
first tarinfo will tell us the size.

related to blueprint xenapi-supported-image-import-export

Change-Id: If34bb8849ad2dacf471f1bec5e72a37ddda79464
Remove unsafe XML parsing

Move to using xmlutils for XML parsing. Fixes missing patch
for the V3 API in commit 0ef2c55d804e0dab58cb5419a0cafd6a805315c7
and fixes bug 1210529

Change-Id: I6dc6111844277565d075a4ff5a08fdee5bc99344
Remove trivial cases of unused variables

Removes trivial cases of unused variables from V3 API version of
servers.py. This was applied to the V2 API but not the V3 API
in commit 9f7eaca80d259201844f097fec24d1e9fe9fb5e3.

Change-Id: I42c1eb73a502afb61bf9c2dd81b79266e0966b5f
Fix message for server name with whitespace

Change-Id: I9007ada4db6502da084fe44ab585e62e689e2f4f
Fixes: bug #1207625
Fix logic in add_host_to_aggregate()

Commit I788782a9f21ec2672551f75123753175bb268586 introduced some
changes into the add_host_to_aggregate() method to catch adding an
host to an availability zone when the host was already a member of
a different availability zone. However there were a couple of issues
with this change. There was no check that the availability_zone was
in the metadata grabbed from the database which would raise a
KeyError back to the api. Additionally, the check wouldn't always
work as expected because the database returned a set of availability
zones (including sometimes an empty set) so the check would fail in
some conditions when it was expected to pass.

This commit fixes the logic for checking if the host is already in an
availability zone. It also replaces the try/except block in the
aggregates extension to check up front if the action is valid instead
of waiting for a key error when it goes to use the action.

Fixes bug 1208627
Fixes bug 1208628

Change-Id: I81b79602e23e78c8b077d313e556796de1255bbf
Refactor integrated tests to support V2 and V3 API testing Part 2

This changeset moves the APISampleTestBase class out into its own
file so the V3 versions of the tests can cleanly import it separate
from the V2 code.

Partially implements v3-api-unittests
Partially implements v3-api-specification

Change-Id: If0994934edb2ab19004353f9a4089ce525ed31dd
Port integrated tests for V3 API

Ports most of the integrated tests to the V3 API. The
test api samples test will be ported to the V3 API in a later
changeset

Partially implements blueprint v3-api-unittests

Change-Id: I00a93471d95760e6c97534808c5a93522710b20d
Adds infra for v3 API sample creation

Adds the required infrastructure for the v3 API sample creation.
- v3 API samples and the test cases are in their own v3 directory
- API samples from "core" are now put in their own (per plugin)
  directory rather than in the root directory
- Testcases to create api samples are now placed in individual
  files rather than one giant one. I think it makes it clearer what
  testcases we do have and avoids merge conflict pain

Adds API samples for basic servers interaction

Fix for bug in servers.py where if no extension was loaded which
extends create xml deserialization an exception would occur (fixed
here because it causes the api sample tests ported to fail).

Partially implements blueprint v3-api-unittests

Change-Id: I653af49dcc499c18f14b6e1764711a9922354069
Update mailmap

Change-Id: I7cc1c069aefca3f61328fa92d7366b5b755febaf
Handle InstanceInvalidState of soft_delete

Since commit 99c51e34230394cadf0b82e364ea10c38e193979, instance
is not able to be soft_deleted if instance has never been active.
But there are circumstances when instance fails on initial build.
Thus if we set reclaim_instance_interval in nova.conf, we cannot
delete such instances in any way.

This patch fixes this by handling InstanceInvalidState exception
when try to soft_delete instance. The delete() function is called
for instance which has never been active.

Bug 1202158

Change-Id: I7d0d9414d7436e56b6a3e5861ee3c2f02473df2b
Fix IVS vif to correctly delete interfaces on unplug

The IVS unplug method was incorrectly calling the OVS
specific interface removal methods. This corrects it
to call the IVS removal methods.

Fixes: bug #1214532
Change-Id: Ie718e167d5bdcfae0d915ef85976aeeb3449ad18
correct the name style issue of ExtendedServerAttributes in v3 api

correct the camel style issue of the attribute ExtendedServerAttributes:
namespace in v3 api

fix Bug #1214317

Change-Id: If58d8cd8a82a88a94302c3b0aa3d23f5414328cb
Set VM back to its original state if cold migration failed

If migration of a VM in the STOPPED state failed due to
NoValidHost, the VM was erroneously set to ACTIVE.

The fix sets the VM back to its original state instead.

Fix bug 1204905

Change-Id: I67ccac9ff4104fbd63c545b9f9399206a7febae7
Remove duplicate variable _host_state

* The variable _host_state is initialized twice in __init__() method of libvirt driver.
This patch removes the second occurrence.

Fixes bug #1214431

Change-Id: I13f175abcbce7752afb0d8c69ee209928afa1eb3
Use the common function is_neutron in servers.py

Remove duplicate code and use common utility function

Change-Id: Iff957a56cf0d43dcc9f7eba00a36530c485486ae
Implement hard reboot for powervm driver

Implements the OS reboot API in the powervm driver. Soft reboot is not
supported as it requires additional configuration on the LPAR when it's
spawned so this patch simply performs an immediate hard reboot.

Also adds tests for start_lpar and stop_lpar which didn't exist before.

Closes-Bug: #1205089

Change-Id: Iad64dda79f46d18c7aa5bee12ed41e7a01853d34
Fix instance metadata access in xenapi

In preparation for objects, use the helper method in utils to get instance
metadata.

Related to blueprint unified-object-model

Change-Id: I552369937854ec195d1f9abb1835b4e6afef7a70
Log exception details setting vm_state to error

This commit switches to LOG.exception() for exceptions that trigger
setting an instance into an error vm_state. Prior to this commit just
an error message was printed which provided no context for debugging
an actual failure. By switching to LOG.exception() instead of
LOG.error() a traceback will be printed to show where the exception
came from.

Fixes bug 1215068

Change-Id: If3aaf3d8ec61c3e902c299f3e5889dcafa144a9a