Partially revert "Remove unused scheduler functions"

This partially reverts commit 2aaa3d2860eed7574c5df64a8ceeb8a6adf23460.

The problem pointed out by this bug is that these changes introduce a
non-backwards compatibile change to the schedulre rpc API.  There are a
couple of acceptable ways to deal with this:

1) Leave most of the code and only remove the client side.  This means
   that a message sent from an earlier version will still work.  This is
   the ideal situation for almost *all* changes to rpc APIs.  We have to
   make a habit of this to eventually be able to support rolling
   upgrades.

2) Leave the manager methods, but simply have them raise an exception.
   This is a bit better than removing the method because the error
   can be made more explicit and obvious.  Otherwise, the operator will
   get "no such method" rpc exceptions, which will seem a bit more
   bizzare.

   An example of when this option makes sense is commit
   cac332c39645286a11c009094a86f62d02752183.  This patch refactored the
   live migration code is such a significant way that making it
   backwards compatibile seemed rather difficult to do.  The old rpc
   methods stuck around but just raise an exception.  The potential
   failure is just that live migration would fail, but the exception
   makes it obvious that an upgrade must be completed for live migration
   to work.

The current patch implements #2 in the case of get_service_capabilities,
since it hasn't been used since pre-essex.  Approach #2 is taken for
get_host_list() as well.  It was used until fairly recently, but was
broken, including being broken in Essex.  The fix that went into Essex
for this makes it no longer use RPC.

Fix bug 1029262.

Change-Id: I74c7d2a3e88b3a4f114e7da62c56f0481ee64a64
Clarify TooManyInstances exception message.

Fixes LP 1031737.

Previously the message indicated the number of instances requested
and an incorrect indication of the headroom, in the case where ram
or cores was the resource gone over-quota (as opposed to the number
of raw instances).

Change-Id: I9f7f3203f0e644ba533940a87e496bfd09da0460
Deprecate root_helper in favor of rootwrap_config

Mark the root_helper option deprecated and introduce usage of
the rootwrap_config option instead. The root_helper option will
still fully be supported in Folsom, but will be removed in Grizzly.

Transition notes: you should replace:
root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf

by:
rootwrap_config=/etc/nova/rootwrap.conf

Implements bp deprecate-root-helper

Change-Id: I8dfc94e9b91f7ffc82d393b345f09409da347e78
Move tests.test_compute_utils into tests.compute.

Move the test_compute_utils module into nova.tests.compute to be with
other compute related unit tests.

Change-Id: I0956a18279caa15504448ddca7ffe7f4113f1f65
Remove agent_update from the compute manager.

It appears that this method of the compute method has never been used
since it was added in fa0b64b500f3a196044459ba4bf8ed0dea214e92, so just
remove it.

It was also added to the virt driver API, but the only use is internally
to the xenapi driver, so leave it as an internal thing to that driver
only.

Part of blueprint no-db-messaging.

Change-Id: Idb2c823421e714fa364affbbb80d28175b9b5b4e
Pass a full instance to rotate_backups().

This patch renames rotate_backups() to _rotate_backups(), as this method
has never been used over rpc since it was first introduced in
75a87df739effe840e6cb39c976002e99b49c796.  The name change makes it more
clear that it's a private method.

The change also makes it so this method takes an instance dict instead
of just the instance_uuid as an argument.  This is mainly for
consistency with the rest of this file, where things are moving toward
passing the full instance dict around instead to avoid any potential
need for db access.

In passing, this also fixes up some uses of instance_uuid in
snapshot_instance() where instance_uuid is most likely None.

Part of blueprint no-db-messaging.

Change-Id: I275f71384e77eb038aa1140bbfde108b91cd2f83
Sync w/ latest openstack common log.py.

Includes the following updates for openstack-common's log.py:

    Remove code to clear basicConfig root log handlers

    Removes some old Nova specific code to clear out the log handlers
    from Nova's logging basicConfig. This code is arguably Nova specific
    and doesn't really belong in openstack-common's generic logging
    configuration.

    Additionally, This code was actually removing the root logger used
by
    some command line tools and binaries and hiding log messages that
should
    have otherwise gone to the console.

    Fixes LP Bug #1029577.

Change-Id: Ic6a6862e5bc357846bf3202186c7e24622d3bb87
Audit log messages in nova/compute/manager.py

To include instance whereever possible. This resolves bug 977978.

Change-Id: Ic113489c464458f9b1859a21942b1bbe203698bd
Merge "Move tests.test_compute_utils into tests.compute."
Merge "Remove agent_update from the compute manager."
Merge "Pass a full instance to rotate_backups()."
Fix a comment typo in db api

Fix the comment for instance_type_get_by_flavor_id().

Change-Id: I6160c6d8e7a0160c01362f9a34550740600f8bc9
Signed-off-by: Shane Wang <shane.wang@intel.com>
Merge "Clarify TooManyInstances exception message."
Merge "Deprecate root_helper in favor of rootwrap_config"
Check instance lock in compute/api

This adds a check for the instance lock in compute/api.py, which:
1. Helps avoid the need to call into the manager just to be stopped
   by the lock there
2. Returns a failure to the user right away when an operation cannot
   be completed due to the lock
3. Avoids the potential for task_state to get into an unhappy state
   because a user unknowingly attempts an action whilst an instance
   is locked
4. Avoids the manager from having to re-do the lock check by
   stuffing a flag into RequestContext when the check has already
   been done by api.py

Various tests needed to be fixed up in order to pass fake instances
with the locked attribute. We could make the decorator ignore
instances without it, but I think it's more explicit to push that
requirement into the tests.

This fixes bug 872541

Change-Id: I1127e31d86a061a93a64ee1eb4a4d900d8bf49b5
Use function registration for policy checks

The original policy framework allowed new policy checks to be created
through inheritance.  This is somewhat clunky and unnecessary in
Python.  This change refactors policy.py to allow new policy checks
to be registered using an @register() decorator.  One consequence is
that HttpBrain is deprecated.

Care has been taken to ensure backwards compatibility; deprecation
warnings will be emitted for uses of HttpBrain or the inheritance-
based checks.

(Pull-up from openstack-common, with deprecation of HttpBrain.)

Change-Id: Ia9a6039a82fe4ebfa9b18e5eb93c21fffee90f09
Update usage of 'ip' to handle more return codes

Make sure that ip raises an exception.ProcessExecutionError unless
'ip' exits with a 0, 2, or 254.

0 = command executed correctly
2/254 = command has already been executed.

Change-Id: I55dd63ca7fc22bc133ab5fe722df4141c332a819
Signed-off-by: Chuck Short <chuck.short@canonical.com>
fix unmounting of LXC containers

There were two issues here.

1. There was a global object stored for all instances,
thus the last mounted instance was always unmounted.

2. Even if there was only a single LXC instance in use,
the global object would be lost on restart of Nova.

Therefore we reset the internal state for the mount object,
by passing in the mount point to destroy_container(),
and querying the device in use for that mount point.

Fixes bug: 971621
Change-Id: I5442442f00d93f5e8b82f492d62918419db5cd3b
Simple refactor of some db api tests.

A few tests were using context.elevated instead of just passing the correct
project id to the instance_create function.

Change-Id: Ib54d079cbad823abd85dcca9e5cd813887169fb0
Remove unused imports

Change-Id: I9e307cd5bab2542f43948c96767811a769814341