From 81941188436ccf717657e864612531730bdaa11f Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Wed, 6 Jan 2016 19:45:25 +0800 Subject: [PATCH] Fix bugs in load config options The config options in DEFAULT section are not registered before use. This patch also fixed the order of import to avoid pep8 failure. Change-Id: Iadde365d5bac235423bbe9b3d9f72df11f32e30d Implements: blueprint refactoring-terracotta-as-per-requires-of-openstack-project --- terracotta/cmd/api.py | 20 +++++++++----------- terracotta/cmd/collector.py | 20 +++++++++----------- terracotta/cmd/global_manager.py | 21 ++++++++++----------- terracotta/cmd/launch.py | 29 ++++++++++++++--------------- terracotta/cmd/local_manager.py | 20 ++++++++++---------- terracotta/globals/manager.py | 12 ++++++------ terracotta/locals/collector.py | 27 +++++++++++++++++++++++++++ terracotta/locals/manager.py | 23 +++++++++++++++++++++++ 8 files changed, 108 insertions(+), 64 deletions(-) diff --git a/terracotta/cmd/api.py b/terracotta/cmd/api.py index f7c3bc4..0dfb544 100644 --- a/terracotta/cmd/api.py +++ b/terracotta/cmd/api.py @@ -12,9 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import eventlet +import os +from oslo_config import cfg +from oslo_log import log as logging +from wsgiref import simple_server +import sys +from terracotta.api import app +from terracotta import config +from terracotta import rpc +from terracotta import version eventlet.monkey_patch( os=True, @@ -23,7 +31,6 @@ eventlet.monkey_patch( thread=False if '--use-debugger' in sys.argv else True, time=True) -import os POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, @@ -31,15 +38,6 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -from oslo_config import cfg -from oslo_log import log as logging -from wsgiref import simple_server - -from terracotta.api import app -from terracotta import config -from terracotta import rpc -from terracotta import version - CONF = cfg.CONF LOG = logging.getLogger(__name__) diff --git a/terracotta/cmd/collector.py b/terracotta/cmd/collector.py index 282c6cc..5cbf6fd 100644 --- a/terracotta/cmd/collector.py +++ b/terracotta/cmd/collector.py @@ -12,9 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import eventlet +from oslo_config import cfg +from oslo_log import log as logging +import oslo_messaging as messaging +import sys +from terracotta import config +from terracotta import rpc +from terracotta.locals import collector +from terracotta.openstack.common import threadgroup +from terracotta import version eventlet.monkey_patch( os=True, @@ -31,16 +39,6 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -from oslo_config import cfg -from oslo_log import log as logging -import oslo_messaging as messaging - -from terracotta import config -from terracotta import rpc -from terracotta.locals import collector -from terracotta.openstack.common import threadgroup -from terracotta import version - CONF = cfg.CONF LOG = logging.getLogger(__name__) diff --git a/terracotta/cmd/global_manager.py b/terracotta/cmd/global_manager.py index 621cdd2..e5ace72 100644 --- a/terracotta/cmd/global_manager.py +++ b/terracotta/cmd/global_manager.py @@ -12,9 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import eventlet +import os +from oslo_config import cfg +from oslo_log import log as logging +import oslo_messaging as messaging +import sys +from terracotta import config +from terracotta import rpc +from terracotta.globals import manager as global_mgr +from terracotta import version + eventlet.monkey_patch( os=True, @@ -23,7 +32,6 @@ eventlet.monkey_patch( thread=False if '--use-debugger' in sys.argv else True, time=True) -import os POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, @@ -31,15 +39,6 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -from oslo_config import cfg -from oslo_log import log as logging -import oslo_messaging as messaging - -from terracotta import config -from terracotta import rpc -from terracotta.globals import manager as global_mgr -from terracotta import version - CONF = cfg.CONF LOG = logging.getLogger(__name__) diff --git a/terracotta/cmd/launch.py b/terracotta/cmd/launch.py index 6e38735..f496448 100644 --- a/terracotta/cmd/launch.py +++ b/terracotta/cmd/launch.py @@ -12,9 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import eventlet +from oslo_config import cfg +from oslo_log import log as logging +import oslo_messaging as messaging +from wsgiref import simple_server +import sys +from terracotta.api import app +from terracotta import config +from terracotta import rpc +from terracotta.locals import collector +from terracotta.locals import manager as local_mgr +from terracotta.globals import manager as global_mgr +from terracotta.openstack.common import threadgroup +from terracotta import version + eventlet.monkey_patch( os=True, @@ -31,20 +44,6 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -from oslo_config import cfg -from oslo_log import log as logging -import oslo_messaging as messaging -from wsgiref import simple_server - -from terracotta.api import app -from terracotta import config -from terracotta import rpc -from terracotta.locals import collector -from terracotta.locals import manager as local_mgr -from terracotta.globals import manager as global_mgr -from terracotta.openstack.common import threadgroup -from terracotta import version - CONF = cfg.CONF LOG = logging.getLogger(__name__) diff --git a/terracotta/cmd/local_manager.py b/terracotta/cmd/local_manager.py index b6ff311..8246f43 100644 --- a/terracotta/cmd/local_manager.py +++ b/terracotta/cmd/local_manager.py @@ -12,9 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys import eventlet +from oslo_config import cfg +from oslo_log import log as logging +import oslo_messaging as messaging +import sys +from terracotta import config +from terracotta import rpc +from terracotta.locals import manager as local_mgr +from terracotta.openstack.common import threadgroup +from terracotta import version +import os eventlet.monkey_patch( os=True, @@ -23,7 +32,6 @@ eventlet.monkey_patch( thread=False if '--use-debugger' in sys.argv else True, time=True) -import os POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, @@ -31,15 +39,7 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'terracotta', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -from oslo_config import cfg -from oslo_log import log as logging -import oslo_messaging as messaging -from terracotta import config -from terracotta import rpc -from terracotta.locals import manager as local_mgr -from terracotta.openstack.common import threadgroup -from terracotta import version CONF = cfg.CONF diff --git a/terracotta/globals/manager.py b/terracotta/globals/manager.py index de0b8ab..f12915c 100644 --- a/terracotta/globals/manager.py +++ b/terracotta/globals/manager.py @@ -69,12 +69,6 @@ the beginning of the global manager's execution. from hashlib import sha1 import platform - -dist = platform.linux_distribution(full_distribution_name=0)[0] -if dist in ['redhat', 'centos']: - etherwake = 'ether-wake' -else: - etherwake = 'etherwake' import subprocess import time @@ -86,6 +80,12 @@ from oslo_log import log as logging from terracotta import common from terracotta.utils import db_utils +dist = platform.linux_distribution(full_distribution_name=0)[0] +if dist in ['redhat', 'centos']: + etherwake = 'ether-wake' +else: + etherwake = 'etherwake' + global_mgr_ops = [ cfg.StrOpt('os_admin_user', diff --git a/terracotta/locals/collector.py b/terracotta/locals/collector.py index 2335548..ff74e7d 100644 --- a/terracotta/locals/collector.py +++ b/terracotta/locals/collector.py @@ -103,8 +103,35 @@ from terracotta import common from terracotta.openstack.common import periodic_task from terracotta.utils import db_utils +collector_opts = [ + cfg.StrOpt('local_data_directory', + default='/var/lib/terracotta', + help='he directory used by the data collector to store ' + 'the data on the resource usage by the VMs running ' + 'on the host.'), + cfg.FloatOpt('host_cpu_usable_by_vms', + default=1.0, + help='The threshold on the overall (all cores) ' + 'utilization of the physical CPU of a host ' + 'that can be allocated to VMs.'), + cfg.StrOpt('os_admin_user', + default='admin', + help='The admin user name for authentication ' + 'with Nova using Keystone.'), + cfg.StrOpt('os_admin_password', + default='admin', + help='The admin user password for authentication ' + 'with Nova using Keystone.'), + cfg.IntOpt('data_collector_data_length', + default=100, + help='The number of the latest data values stored ' + 'locally by the data collector and passed to ' + 'the underload / overload detection and VM ' + 'placement algorithms.'), +] CONF = cfg.CONF +CONF.register_opts(collector_opts) LOG = logging.getLogger(__name__) diff --git a/terracotta/locals/manager.py b/terracotta/locals/manager.py index 75e7c98..6a6ce70 100644 --- a/terracotta/locals/manager.py +++ b/terracotta/locals/manager.py @@ -113,7 +113,30 @@ from terracotta.openstack.common import periodic_task from terracotta.utils import db_utils +local_manager_opts = [ + cfg.FloatOpt('host_cpu_usable_by_vms', + default=1.0, + help='The threshold on the overall (all cores) ' + 'utilization of the physical CPU of a host ' + 'that can be allocated to VMs.'), + cfg.StrOpt('os_admin_user', + default='admin', + help='The admin user name for authentication ' + 'with Nova using Keystone.'), + cfg.StrOpt('os_admin_password', + default='admin', + help='The admin user password for authentication ' + 'with Nova using Keystone.'), + cfg.StrOpt('local_data_directory', + default='/var/lib/terracotta', + help='he directory used by the data collector to store ' + 'the data on the resource usage by the VMs running ' + 'on the host.'), +] + + CONF = cfg.CONF +CONF.register_opts(local_manager_opts) LOG = logging.getLogger(__name__)