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
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
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
Fix regression with nova-manage floating list

Fixes bug #1032177

If a floating IP is not associated with an instance, nova-manage fails
with:

  local variable 'instance_uuid' referenced before assignment

This is a regression introduced by commit fc82c6d. Simply rename
the local variable to instance_uuid.

Change-Id: Ia6df23c945f0815c65bcfd2f49e8ba3225d03d7f
Merge "Update usage of 'ip' to handle more return codes"
Merge "Check instance lock in compute/api"
Merge "Simple refactor of some db api tests."
Merge "Fix regression with nova-manage floating list"
Migrate a logging change from common:

commit 58404a1a9461900367dbb7a8b3f2f98441e12959
Author: Mate Lakat <mate.lakat@citrix.com>
Date:   Tue Jul 31 17:53:57 2012 +0100

    Install a qualified except hook.

    Fixes bug 1031351.

    As an Exception is raised, it was not visible in the log, because
    it wasn't qualified. The fix sets up the exception hook to be
    qualified as the product_name.

Change-Id: I38c48d0dd2ac885fcb226310b6039be667af9e0d
Update reset_db to call setup if _DB is None.

This resolves issues when running individual tests that require
a database. With this fix I can once again run individual test
modules that make use of the database. For example:

  ./run_tests.sh test_libvirt

Previously this would fail with database errors.

Fixes LP Bug #1032738.

Change-Id: Icce7ac9414f0e19eece44819a217634947de7f73