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
Support building wheels (PEP-427)

Universal is used to identify pure-Python module(by bdist_wheel). For
these, it is sufficient to build a wheel with _any_ Python ABI version
and publish that to PyPI (by whatever means).

Change-Id: Ic22b78ef6434ebf888c92c0a162caeabb70edf88
Make sure "volumeId" in req body on volume actions

We should check whether the parameter "volumeId" is in request body while
attaching a volume to an instance and while swapping volume.

Change-Id: I0be2ae4c80615c0304cd1a0d8ca0a4282a0867c7
Closes-Bug: #1257135
Rename Openstack to OpenStack

Change-Id: Iacc51d8ad071c3b22b7bb6b21cff972599b59a7b
Catch InstanceNotFound exceptions for V2 API virtual interfaces

Use the common.get_instance method to get the instance object
in the V2 API virtual interfaces extension rather than call
the compute api directly. The utility function
handes InstanceNotFound exceptions and tranlsates them to HTTPNotFound
rather than letting them propagate up causing a traceback.

Co-Authored-By: Michael Still <mikal@stillhq.com>

Change-Id: I8abee22c53195926e3d2af1da9b14cd9d3608e63
Closes-Bug: 1270804
Fix the calls of webob exception classes

The webob exception classes has "explanation" arguments but some
methods calls the classes with invalid arguments. This patch fixes
them.
In addition, this patch changes the error handling of agent_build
_create() because the method raises AgentBuildExists exception only.
The API of v3 has already done it.

Change-Id: I2af5aae297c09ed34fadf6520f1a06228624a5a9
Fix HTTP methods for test_attach_interfaces

delete() method of attach_interfaces API is routed when specifying
"DELETE" as HTTP method, but some tests specify "POST". This bug
does not affect the test behaviors because the tests do not check
API router behaviors and just checks delete() method behaviors.

However, this patch fixes this bug because the bug confuses the
API router behaviors.

Change-Id: I8e862cbd58da820eb336d3ef41185e16f63bb6be
Fix the explanations of HTTPNotFound response

Nova wsgi framework gets "explanation" from HTTPNotFound exception and
outputs it into a response body as "message" attribute. Now some error
explanations are passed to HTTPNotFound exception without explanation
argument and they are not output to a response body. As the result,
the default message "The resource could not be found." of wsgi library
are output to a response body instead.

This patch fixes them to output right message to a response body.

Change-Id: I80d3a2da6258e94c485ce024eb310a63bcf39773
Closes-Bug: #1285437
libvirt: raises exception when attempt to resize disk down

Raises an exception when trying to resize an instance that needs to
resize the disk down.

Change-Id: Ic0a0bede744a1aacd057c5db9de3307b61c525b4
Related-Bug: #1270238
Added os-security-groups prefix

Added os-security-groups prefix to the security_groups attribute in json response.

Change-Id: Id2a4a92da0c9751abc5c37f06fc2484ba80a8a09
Closes-Bug: #1223309
Raise exception if volume snapshot id not found instead of return

In V2 API, if show or delete a snapshot with an unknown id, exception
will be returned instead of raised. Even though correct error
will be returned to client, it's not aligned to other API layer
code, this patch modify it by raise exception instead of return.

Change-Id: I22d4565ca08e1c0ed5041ce903bf6ba918c14cfd
Closes-Bug: #1279189
Port libvirt copy_image tests to mock

Rather than using temporary files, monkey patching and only checking a
subset of utils.execute() arguments, let's use mock.

Change-Id: Ifd1d35d5f44fba16293263bc3b11c405a86aafd4
VMware ESX: Boot from volume must not relocate vol

ESX does not support relocate API. Moreover when working with ESX the boot
from volume logic need not perform relocation since the volume's datastore
is always visible to the ESX host.

The fix is to ignore relocation when working with ESX.

Change-Id: I227cf2ea5b6f681150ede0bf6257eb238f1452d2
Closes-bug: #1244918
Fix log messages typos in rebuild_instance function

One log message typos in rebuild_instance function.

Change-Id: I0c86a40b6683f3a8a091134b6f37c82a4562370e
Closes-Bug: #1288661
VMware: Ensure test VM is running in rescue tests

Code was calling get_info() on test VM, but not using it. There are 2
options to fix this:

1. Use it
2. Don't call get_info()

I have chosen option 1.

This change adds a test on the data returned by get_info() which
ensures that the vm just created is in state power_state.RUNNING. The
code later tests that the vm is in state power_state.SHUTDOWN, so the
additional test that it was previously running reinforces that
rescue() caused the shutdown to happen.

Change-Id: Iec58b0dd40702d3bcebf339e9ada8b90a2229d5c
Rescue API handle NotImplementedError

There are several nova virt drivers that don't implement the rescue API,
but the os compute API doesn't handle NotImplementedError,
it returns a 400 instead of a 501.

The patch add the proper logic to return a 501 instead.

Change-Id: Ia649c4dadd50985efed631ce8f3e4b212646766e
Closes-Bug: #1287367
Add conversion type to LOG.exception's string

Add conversion type for 'String Formatting Operations' to
LOG.exception's string in _get_floating_ips_by_fixed_and_port().

Change-Id: Iec97a354176e3044064bf190735257080be7ae70
Closes-Bug: #1289230
Volume operations should be blocked for non-null task state

Currently volume attach, detach, and swap check on vm_state but
not task_state.  This means that, for example, volume attach is
allowed even when other operations such as migration are in
progress.  As with other operations the check should be against
a task state of "None"

This change also refactors the volume_attach() method a little
so that the cells api can include the state decorator checks.

Change-Id: I0c4d697cf9d9e431a050c3c1b03e46b8629d182a
Closes-Bug: #1274627
Fixup debug log statements in the nova compute manager

We were mishandling instance logging in a few places.

Change-Id: Ie1ec44fb5092ca9229e037328def52cb6aa81c33
Noted that tox is the preferred unit tester.

This bug and fix is not about deleting run_tests.sh.
The change to delete run_tests.sh has been abandoned.
Thus the documentation of run_tests.sh remains.

Change-Id: Ia0a883260affc56c148dbebc5e3a49acb36b067e
Closes-Bug: #1282393