Correct the state for PAUSED instances on reboot

If an instance is in the PAUSED state before the compute node is
restarted, it will be left in an inconsistent state (impossible to
delete and/or restart it) after the node boots again.

This patch adds a check in the periodic task sync_power_state so when
this situation is detected the instance is stopped and left in a state
from where it can be started again or deleted.

Closes-Bug: #1265494
Change-Id: I7266ace596598522c28a3839091ef50faf4463c2
correct the bugs reference url in man documents

All the bugs reference in nova man documents are incorrect.
Nova bugs are managed at launchpad, not the nova.openstack.org

Change-Id: Id5bbf09ad8ba079d4de959314123437031ded3ab
Fix run_tests.sh lockutils when run with -d

Change I007bd39e4d9aad7539b4b7389eb5189b5d1f10e2 fixed how the test
runner was called, but did not take into account that a different
command line is used when -d flag is passed to the script. We fix that but
accounting for the lockuitls change even when -d is passed.

Change-Id: I7462b70a707fff281fabe9d9f20cbb7bf8d037ef
Explicity teardown on error in libguestfs setup()

Previously, in the setup method of the libguestfs driver
for Nova's VFS, on an error the handle object was simply
dereferenced (set to None), and then an new error was thrown.
This relied on an implicit close() on the handle being called
by GC.  However, in some cases the setup progresses far enough
that the implicit close is not enough, and leaves an "orphaned"
libguestfs VM.

Now, the teardown() method is called explicitly, which ensures that
no "orphaned" VMs are left around in case of an error.

Change-Id: I7fbe470046ce6c76bc13d77d8df360351a3ef715
Fixes: bug #1270304
changed quantum to neutron in vif-openstack

Change-Id: I50c14066584527a6fbc25c59b0bf03a321a5f1f5
Fix upper bound checking for flavor create parameters

Fix flavor-create upper bound checking so it uses platform-independent
32-bit max signed integer value instead of sys.maxint, which causes
problems on 64-bit platforms.  The DB int type is a 32-bit signed
integer, regardless of platform.

Change-Id: I82624121a45f6385d3ea9ae9c032109834584fac
Closes-bug: 1278939
Fixes the Hyper-V VolumeOpsTestCase base class

The VolumeOpsTestCase base class inherits incorrectly from
HyperVAPITestCase, with the unwanted side effect of executing all
base class tests as well.

This patch generalizes a common base class from HyperVAPITestCase
and fixes the inheritance issue.

Closes-Bug: #1280379

Change-Id: Ic81beb8397138c16c8d2d88a9c9d05d2b76e0e83
Ensure parent dir exists while injecting files

Currently, if we inject a file to a not existing path,
the injecting will be failed with error 'No such file
or directory'.
Nova will firstly execute `mkdir -p` in folsom before injecting,
but this operation is lost from commit
72918415f2b6a241d6097a563aba55a849936591

This patch fix this bug by adding the `mkdir -p` operation as folsom.

Closes-bug: #1272829

Change-Id: If33a79c538e07cb25300db64ac7a9dee3d3b19c2
Fix incorrect kwargs 'reason' for HTTPBadRequest

webob.exc.HTTPBadRequest doesn't have attribute 'reason', and its
__init__ method doesn't have such parameter too, so if we use such
kwargs, it will not be accepted by constructor of base class
WSGIHTTPException, then the http response body will format message
using default explanation instead of what we expected.

We should use kwargs 'explanation' instead of wrong 'reason'.

Change-Id: I02619164176a723e313ae274e527948d45fa6cad
Closes-Bug: #1264223
compute: format_message is a method not an attribute

The method format_message used to convert an exception to a string
it uses as an attribute. This patch fix the problem.

Change-Id: Ia1af1644f64d9d12edc905d2ec613aef1927e644
Removing redundant validation for rebuild request.

Any method decorated with wsgi.action will need to have
the said key, in this case 'rebuild', before it
reaches the relevant code block. If not, a key
error is raised when the wsgi.action code kicks in. This
code is at openstack/wsgi.py in the  _process_stack
method and subsequently the self.get_method method.
A KeyError is raised and caught. Removing the redundant
check for rebuild api.

Change-Id: I4baf920c7e1b3d51a91323f12d0802cedec77fe2
VMware: add instance detail to detach log message

Provide extra details when detaching a volume from an instance.

Change-Id: I043bce041f82d18379ffc052ad8868ac425167fe
Replaces exception re-raising in Hyper-V

In a few cases in the Hyper-V driver classes, generic exceptions
are getting caught, logged and a domain specific exception is raised.

This creates issues in identifying the exception cause programmatically
(e.g. in unit tests).

This patch enforces the usage of excutils.save_and_reraise_exception()

Closes-Bug: #1280363

Change-Id: I27cc54941c5f592ea567ccaa8fa369362da1427f
Unmount the NFS and GlusterFS shares on detach

When attaching an NFS or GlusterFS volume, nova mounts the share so it
can be reused by other instances but it is not unmounted when detaching.

This patch adds the disconnect_volume method to both drivers, which will
try to unmount the share. If a volume in that share is still being used
by another instance, the umount command will fail with the error 'target
is busy' and we will ignore it. Any other error while unmounting will be
properly logged. In any case the detach will fail because nova hasn't
been able to unmount the share.

Closes-Bug: #1285209
Change-Id: I79289524541a88ad359b3465719055cd402b4e3d
Move the metrics update to get_metrics

It is not necessary to update the metrics when get every metric in
one compute monitor plugin, just update once when get metrics for
the monitor plugin.

Change-Id: Ib665188964de8318f6d94343891666c674111c8c
Prevent caller from specifying id during Aggregate.create()

The patch is to remove id when it was set before creating an aggregate
in objects, and check if the aggregate exists before it is created.

Related to blueprint icehouse-objects.

Change-Id: I0d7c5c5da9a93e52c7fee9eee7df80d2f460593e
Remove and recreate interface if already exists

If a nova-compute machine restarts when openvswitch comes up it logs the
following warning messages for all tap interfaces that do not exist:

bridge|WARN|could not open network device tap2cf7dbad-9d (No such device)

Once the compute-node starts it recreates the interfaces and re-adds them
to the ovs-bridge. Unfortunately, ovs does not reinitialize the interfaces
as they are already in ovsdb and does not assign them a ofport number.

This situation corrects itself though the next time a port is added to the
ovs-bridge which is why no one has probably noticed this issue till now.

In order to correct this we should first remove interface that exist and
then readd them.

Change-Id: I1dc01604c5857941d9f35eb1e0c4d5103a56d57b
Closes-bug: #1270973
Related-bug: #1268762
VMware: support instance objects

Over the course of Icehouse the instance dictionary has been changed
to an instance object. The patch ensures that the driver functions
receive an instance object as input.

Change-Id: I502ab7708f9b3c992ca80d442d794fdd4f5db6d5
Sync latest config file generator from oslo-incubator

The fix to the config file generator to support lazy messages
is the main addition of interest because it is needed before
lazy messages can be enabled in Nova.

Commits included:

  1a6dfb956 Sanitize FQDN in config generator
  e839886cc Config generator fails with lazy messages
  763eedff6 Fix DictOpt support in config sample generator

Note that these commits do not touch any other files (beyond
oslo testcases).

Partially implements blueprint i18n-messages
Closes-Bug: #1280826

Change-Id: I2174139ba3767d05924747cbefa377ba8780103d
xenapi: stop destroy_vdi errors masking real error

We frequently call destroy_vdi in an exception block where we plan to
re-raise the exception.

Should an error occur while destroying the vdi this hides the real error
that caused the problem. To stop this, I have moved those calls to
safe_destroy_vdis and added unit tests to ensure the error from
destroy_vdi does not mask the real issue.

Closes-Bug: #1246276
Change-Id: Ib02f93ab1086f077d3d00e5ca915a26f90552c85