Bad except clauses order causes wrong text in http response

InstanceInvalidState is an ancestor class of InstanceIsLocked, so
we need to catch InstanceIsLocked first. Fix the test case to
ensure we get the right http response back

Change-Id: Id22b284d9b7da8db4161ad8703bea1702cb0b82e
Fix power manager hangs while executing ipmitool

In nova/virt/baremetal, IPMI power manager uses ipmitool with '-F' option to
specify a file containing the remote server password.  When the passowrd was
empty, ipmitool ignores that file and asks user to set password in stdin.
This makes the thread stop.

This patch changes power manager to write '\0' to the password file in the
case of empty password, to force the password on impitool.

Closes-bug: #1237802

Change-Id: I44f56129a8ce2af4dda8dea35eb9c60d9518d54b
Include name/level in unit test log messages

Use a more informative format than just the raw message string in log
messages captured by fixtures.FakeLogger during unit testing.  For
example, this changes cryptic unit test output such as

    pythonlogging:'': {{{
    214 -> 215...
    done
    215 -> 216...
    done
    }}}

into:

    pythonlogging:'': {{{
    INFO [migrate.versioning.api] 214 -> 215...
    INFO [migrate.versioning.api] done
    INFO [migrate.versioning.api] 215 -> 216...
    INFO [migrate.versioning.api] done
    }}}

which instantly makes it clearer that these numbers come from database
migrations.

Change-Id: I56b6fa03892e6d865ccb036fdf75d2bb499b6c93
Stylistic improvement of models.ComputeNodeStat

The patch is aimed at improving the readability of models.ComputeNodeStat.

Here, we rename the 'stats' attribute of the class to 'compute_node' (due to
the fact that the corresponding relation actually maps to ComputeNode class,
not to ComputeNodeStat). We also rewrite the relationship() method call to
make it stylistically conforming with the analogous 'service' relationship
in the ComputeNode class: we add the 'foreign_keys' parameter, wrap the
'backref' parameter into a method call and remove the auxiliary 'primary_join'
variable.

Change-Id: I2b1f27b4c1d06f364af01fc82d3490fd3bbf4ac0
Closes-Bug: #1215390
tenant_id implies all_tenants for servers list in V3 API

Makes tenant_id imply all_tenants is also enabled unless
explicitly disabled when a request is made for a list of
servers. This only occurs if the requestor is an admin. The
change is only made for the V3 API as although this behavior is
more intuitive it is too late to change it for the V2 API.

Change-Id: Ia84e62c8dc80ac3a2f16aee3620af31987cce570
Partial-Bug: 1185290
Issue brctl/delif only if the bridge exists

Add a check for existence of the bridge before we try cleaning
up as we see a lot of spurious exceptions in the logs especially
when rebuild_instance is in progress and terminate_instance is
issued

Closes-Bug: #1243488

Change-Id: Ib0e2e4d9506e3a8f63201d28a3fc2c910c77d3bd
Add test for class InsertFromSelect

InsertFromSelect is used to generate SQL statement like
"INSERT INTO table1 SELECt * FROM table2".

Change-Id: I0fec93463be1e9930b24862724b7a6d1c8cc52af
Catch exception while building due to instance being deleted

In run_instance() a instance_update() call in _start_building() can
result in a UnexpectedDeletingTaskStateError if the instance gets
deleted while being built.Since this is an expected situation, we
don't want this exception written in the logs or worse, the instance
be set to error state. Instead catch this and raise a proper
BuildAbortException that gets handled above this call.

Change-Id: Ib9d3dd22b33b104f1593d534876a5387df81d11c
Closes-Bug: #1223843
Ensure deleted instances' status is always DELETED

Currently when deleting failed instances that were never assigned a
host, their vm_state is left in 'error' instead of 'deleted'. This is a
problem when invoking the Index Instances REST API with a Changes-Since
query parameter since that API returns both deleted and non-deleted
instances, but currently the failed deleted instances are incorrectly
marked as status:ERROR instead of status:DELETED.

This patch modifies the server ViewBuilder to ensure the status is
correctly set.

Change-Id: I614714676bab4986564b236d74f2c0d77400e48c
Closes-bug: #1243301
Rename _get_vm_state to _get_vm_status

The method is actually used to get the server's "status", so rename it
to better reflect function.

Change-Id: Ie4b0a1c76c81f6d08250a1cfd594429ef9eaf5ae
Remove unused local variables in test case

Non-functional change. Just remove the variables that had been assigned
but were never used for clarity of the code base.

Change-Id: I4c204067cff161a975df2277d6ef9d2081863bd1
Checking existence of index before dropping

Migrations modifying indexes drop and recreate the index.
If an index does not exist dropping would fail the migration.
As part of this fix, checking if index exists before dropping it.

Fixes bug 1243553

Change-Id: Ic75744bdccfbc516d36a9711ad6997fd86c7a722
Check return code of command instead of checking stderr

Command "ip link show" return a no 0 return code when passing
a no existing ip interface so we should use the return code
instead of checking stderr because stderr can contain messages
from the system even though the command succeeded.

Change-Id: Ic43e72dab3c5b6e266240b7ff7309ca3b44f8ed5
Closes-Bug: #1248699
Enable non-ascii characters in flavor names

The current implementation provided under commit e6b42d made it so that
flavor names did not have special characters (e.g. *&^%$ etc. except for
-._ and space) however it also limited names to only ascii letters.

This patch makes it so that special characters are still not allowed,
except the ones currently allowed, but it allows the use of non-ascii
characters so that flavor names can be created in locales other than
English.

Change-Id: I056451a5e8b7a49f86e0a11d0011393dc769db34
Closes-bug: #1241625
Update quota-class-set/quota-set throw 500 error

The server doesn't check whether the parameter "quota_class_set" is in request
body.So the 500 error has been thrown.

We should catch the KeyError and transfer the KeyError to
400(HTTPBadRequest) instead of 500.

Change-Id: I431a836bd35f846790497d6179515e8d559e2cd0
Closes-Bug: #1249222
Make baremetal_deploy_helper understand ephemeral disks

Teach baremetal_deploy_helper how to run sfdisk with ephemeral disks.
baremetal_deploy_helper calls default mkfs on the epheral disk.

Change-Id: I92d473c34e9a076f5dbcd54be538410b30b10204
Partial-Bug: #1238311
Co-Authored-By: Robert Collins <rbtcollins@hp.com>
Make baremetal support metadata for ephemeral block-device-mapping

Make baremetal driver set instance['default_ephemeral_device'] to
/dev/sda1 since we are using the same device for root(sda3) and
ephemeral(sda1)

Change-Id: Ib2076198eacb0ea61706043b42d673c35d26f5d1
Partial-Bug: #1239524
Add V3 API sample for server's actions

Adds api sample tests and api samples for server's actions

Partially implements blueprint v3-api-unittests

Change-Id: I4b420f09f9fc9a7f6fab8dbaeaa9b93631909255
libvirt: Allow delete to complete when a volume disconnect fails

If an instance which was booted from a volume fails to spawn, the
instance is left in an ERROR state.  If the failure is in the networking
stage Nova will not have attached the volume via the Cinder driver,
and so the volume remains in an available state.  In this state the
volume may be deleted or assigned to another instance.
During the subsequent delete an exception may be thrown from
the cinder driver which prevents the instance from completing the
deletion process leaving the instance stuck in Error and unable to
be deleted.

Volume exceptions should be logged and ignored when the instance
is being deleted.

Closes-Bug #1222979

Change-Id: Icb3796b0ddba25cf344953a649b2e762fab6d782
Users with admin role in Nova should not re-auth with Neutron

A recent change to the way Nova creates a Neutron clients
https://review.openstack.org/#/c/52954/4 changed the conditions
under which it re-authenticates using the neutron admin credentials
from "if admin" to "if admin or context.is_admin".

This means that any user with admin role in Nova now interacts
with Neutron as a different tenant.  Not only does this cause an
unnecessary re-authentication (The user may/should also have an admin
role in Neutron) it means that they can no longer allocate and assign
a floating IP to their instance via Nova (as the floating ip will now
always be allocated in the context of neutron_admin_tenant).

This change removes the context.is_admin check to revert to the
previous behaviour where the used of admin creds is determined just
on the explicit use of "admin=True" parameter to get_client().

Change-Id: Ib1720420c778960bc90c5b7d703de936ebb7d6b5
Closes-Bug: 1250763