Merge "Move cfg to nova.openstack.common"
This commit is contained in:
@@ -40,11 +40,11 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'nova', '__init__.py')):
|
||||
gettext.install('nova', unicode=1)
|
||||
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
|
||||
@@ -38,9 +38,9 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import service
|
||||
from nova import utils
|
||||
|
||||
+1
-1
@@ -35,11 +35,11 @@ if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')):
|
||||
sys.path.insert(0, possible_topdir)
|
||||
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import compute
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import network
|
||||
from nova.openstack.common import cfg
|
||||
from nova import service
|
||||
from nova import utils
|
||||
from nova import volume
|
||||
|
||||
+1
-1
@@ -21,10 +21,10 @@ Common Auth Middleware.
|
||||
import webob.dec
|
||||
import webob.exc
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import wsgi
|
||||
|
||||
|
||||
|
||||
@@ -32,11 +32,11 @@ from nova.api.ec2 import ec2utils
|
||||
from nova.api.ec2 import faults
|
||||
from nova.api import validator
|
||||
from nova.auth import manager
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova import wsgi
|
||||
|
||||
|
||||
@@ -31,9 +31,9 @@ from nova.api.openstack.compute import limits
|
||||
from nova.api.openstack.compute import servers
|
||||
from nova.api.openstack.compute import server_metadata
|
||||
from nova.api.openstack.compute import versions
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger('nova.api.openstack.compute')
|
||||
|
||||
@@ -27,10 +27,10 @@ public methods.
|
||||
import functools
|
||||
import sys
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
ldap_opts = [
|
||||
|
||||
@@ -30,13 +30,13 @@ import tempfile
|
||||
import uuid
|
||||
import zipfile
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import crypto
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.auth import signer
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ import string
|
||||
import tempfile
|
||||
import zipfile
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import crypto
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
# TODO(eday): Eventually changes these to something not ec2-specific
|
||||
from nova.api.ec2 import cloud
|
||||
|
||||
+1
-1
@@ -28,7 +28,6 @@ import novaclient
|
||||
import webob.exc
|
||||
|
||||
from nova import block_device
|
||||
from nova.common import cfg
|
||||
from nova.compute import aggregate_states
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
@@ -40,6 +39,7 @@ from nova import flags
|
||||
import nova.image
|
||||
from nova import log as logging
|
||||
from nova import network
|
||||
from nova.openstack.common import cfg
|
||||
import nova.policy
|
||||
from nova import quota
|
||||
from nova import rpc
|
||||
|
||||
@@ -45,7 +45,6 @@ from eventlet import greenthread
|
||||
|
||||
from nova import block_device
|
||||
import nova.context
|
||||
from nova.common import cfg
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova.compute import task_states
|
||||
@@ -59,6 +58,7 @@ from nova import manager
|
||||
from nova import network
|
||||
from nova.network import model as network_model
|
||||
from nova.notifier import api as notifier
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
|
||||
import socket
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import manager
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
import base64
|
||||
import json
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.virt.vmwareapi import vim_util
|
||||
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
"""VMRC Console Manager."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova.virt import vmwareapi_conn
|
||||
|
||||
+1
-1
@@ -22,12 +22,12 @@ import signal
|
||||
|
||||
from Cheetah import Template
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
"""Module to authenticate Consoles."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
consoleauth_topic_opt = \
|
||||
|
||||
@@ -22,10 +22,10 @@ import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -33,12 +33,12 @@ import tempfile
|
||||
|
||||
import Crypto.Cipher.AES
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -43,9 +43,9 @@ these objects be simple dictionaries.
|
||||
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -18,9 +18,9 @@
|
||||
|
||||
"""Base class for classes that need modular database access."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import utils
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
db_driver_opt = \
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ import sys
|
||||
|
||||
import gflags
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
class FlagValues(object):
|
||||
|
||||
+1
-1
@@ -31,11 +31,11 @@ import eventlet
|
||||
|
||||
from nova import rpc
|
||||
import nova.db.api
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import image
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.api.ec2 import ec2utils
|
||||
|
||||
|
||||
+1
-1
@@ -14,8 +14,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -40,9 +40,9 @@ import sys
|
||||
import traceback
|
||||
|
||||
import nova
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import local
|
||||
from nova.openstack.common import cfg
|
||||
from nova import version
|
||||
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ import tempfile
|
||||
import time
|
||||
|
||||
from nova.auth import fakeldap
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger("nova.network.manager")
|
||||
|
||||
@@ -24,11 +24,11 @@ import inspect
|
||||
import netaddr
|
||||
import os
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,6 @@ import socket
|
||||
from eventlet import greenpool
|
||||
import netaddr
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import instance_types
|
||||
from nova import context
|
||||
@@ -68,6 +67,7 @@ from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.network import api as network_api
|
||||
from nova.network import model as network_model
|
||||
from nova.openstack.common import cfg
|
||||
import nova.policy
|
||||
from nova import quota
|
||||
from nova import utils
|
||||
|
||||
@@ -19,7 +19,6 @@ import time
|
||||
|
||||
from netaddr import IPNetwork, IPAddress
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.compute import instance_types
|
||||
from nova import context
|
||||
from nova import db
|
||||
@@ -29,6 +28,7 @@ from nova import log as logging
|
||||
from nova.network import manager
|
||||
from nova.network.quantum import melange_ipam_lib
|
||||
from nova.network.quantum import quantum_connection
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
LOG = logging.getLogger("nova.network.quantum.manager")
|
||||
|
||||
@@ -20,9 +20,9 @@ import socket
|
||||
import urllib
|
||||
import json
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
melange_opts = [
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.network.quantum import client as quantum_client
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger("nova.network.quantum.quantum_connection")
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
|
||||
import uuid
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import utils
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger('nova.exception')
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.exception import ClassNotFound
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
import nova.context
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
|
||||
|
||||
|
||||
@@ -44,9 +44,9 @@ import urllib
|
||||
import routes
|
||||
import webob
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova import wsgi
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
@@ -0,0 +1,15 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (c) 2011 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
+1
-1
@@ -17,10 +17,10 @@
|
||||
|
||||
"""Policy Engine For Nova"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.common import policy
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -18,8 +18,8 @@
|
||||
|
||||
"""Quotas for instances, volumes, and floating ips."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova.openstack.common import cfg
|
||||
from nova import flags
|
||||
|
||||
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.utils import import_object
|
||||
from nova.rpc.common import RemoteError, LOG
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.rpc.common import RemoteError, LOG
|
||||
from nova.utils import import_object
|
||||
|
||||
|
||||
rpc_backend_opt = \
|
||||
|
||||
+1
-1
@@ -19,10 +19,10 @@
|
||||
|
||||
import copy
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger('nova.rpc')
|
||||
|
||||
@@ -25,8 +25,8 @@ import greenlet
|
||||
import qpid.messaging
|
||||
import qpid.messaging.exceptions
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.rpc import amqp as rpc_amqp
|
||||
from nova.rpc import common as rpc_common
|
||||
from nova.rpc.common import LOG
|
||||
|
||||
@@ -22,11 +22,11 @@ import functools
|
||||
from novaclient import v1_1 as novaclient
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ Scheduler base class that all Schedulers should inherit from
|
||||
"""
|
||||
|
||||
from nova.api.ec2 import ec2utils
|
||||
from nova.common import cfg
|
||||
from nova.compute import api as compute_api
|
||||
from nova.compute import power_state
|
||||
from nova.compute import vm_states
|
||||
@@ -30,6 +29,7 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova.scheduler import host_manager
|
||||
from nova.scheduler import zone_manager
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.scheduler.filters import abstract_filter
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.scheduler.filters import abstract_filter
|
||||
|
||||
LOG = logging.getLogger('nova.scheduler.filter.ram_filter')
|
||||
|
||||
@@ -21,11 +21,11 @@ import datetime
|
||||
import types
|
||||
import UserDict
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ The cost-function and weights are tabulated, and the host with the least cost
|
||||
is then selected for provisioning.
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import log as logging
|
||||
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ Scheduler Service
|
||||
|
||||
import functools
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.compute import vm_states
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
Scheduler that allows routing some calls to one driver and others to another.
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.scheduler import driver
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ import datetime
|
||||
import json
|
||||
import os
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
scheduler_json_config_location_opt = \
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
Simple Scheduler
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import exception
|
||||
from nova.openstack.common import cfg
|
||||
from nova.scheduler import driver
|
||||
from nova.scheduler import chance
|
||||
from nova import utils
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
VSA Simple Scheduler
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova import exception
|
||||
|
||||
@@ -23,10 +23,10 @@ import traceback
|
||||
from eventlet import greenpool
|
||||
from novaclient import v1_1 as novaclient
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -25,12 +25,12 @@ import os
|
||||
import eventlet
|
||||
import greenlet
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova import version
|
||||
|
||||
+1
-1
@@ -33,10 +33,10 @@ import mox
|
||||
import nose.plugins.skip
|
||||
import stubout
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
import nova.image.fake
|
||||
from nova import log
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova import service
|
||||
from nova.testing.fake import rabbit
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.add_option(cfg.IntOpt('answer', default=42, help='test flag'))
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
FLAGS.add_option(cfg.IntOpt('runtime_answer', default=54, help='test flag'))
|
||||
|
||||
@@ -1,789 +0,0 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2011 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import StringIO
|
||||
import tempfile
|
||||
|
||||
import stubout
|
||||
|
||||
from nova import test
|
||||
from nova.common.cfg import *
|
||||
|
||||
|
||||
class BaseTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.conf = ConfigOpts(prog='test',
|
||||
version='1.0',
|
||||
usage='%prog FOO BAR',
|
||||
default_config_files=[])
|
||||
self.tempfiles = []
|
||||
self.stubs = stubout.StubOutForTesting()
|
||||
|
||||
def tearDown(self):
|
||||
self.remove_tempfiles()
|
||||
self.stubs.UnsetAll()
|
||||
|
||||
def create_tempfiles(self, files):
|
||||
for (basename, contents) in files:
|
||||
(fd, path) = tempfile.mkstemp(prefix=basename)
|
||||
self.tempfiles.append(path)
|
||||
try:
|
||||
os.write(fd, contents)
|
||||
finally:
|
||||
os.close(fd)
|
||||
return self.tempfiles[-len(files):]
|
||||
|
||||
def remove_tempfiles(self):
|
||||
for p in self.tempfiles:
|
||||
os.remove(p)
|
||||
|
||||
|
||||
class LeftoversTestCase(BaseTestCase):
|
||||
|
||||
def test_leftovers(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo'))
|
||||
self.conf.register_cli_opt(StrOpt('bar'))
|
||||
|
||||
leftovers = self.conf(['those', '--foo', 'this',
|
||||
'thems', '--bar', 'that', 'these'])
|
||||
|
||||
self.assertEquals(leftovers, ['those', 'thems', 'these'])
|
||||
|
||||
|
||||
class FindConfigFilesTestCase(BaseTestCase):
|
||||
|
||||
def test_find_config_files(self):
|
||||
config_files = \
|
||||
[os.path.expanduser('~/.blaa/blaa.conf'), '/etc/foo.conf']
|
||||
|
||||
self.stubs.Set(os.path, 'exists', lambda p: p in config_files)
|
||||
|
||||
self.assertEquals(find_config_files(project='blaa', prog='foo'),
|
||||
config_files)
|
||||
|
||||
|
||||
class CliOptsTestCase(BaseTestCase):
|
||||
|
||||
def _do_cli_test(self, opt_class, default, cli_args, value):
|
||||
self.conf.register_cli_opt(opt_class('foo', default=default))
|
||||
|
||||
self.conf(cli_args)
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, value)
|
||||
|
||||
def test_str_default(self):
|
||||
self._do_cli_test(StrOpt, None, [], None)
|
||||
|
||||
def test_str_arg(self):
|
||||
self._do_cli_test(StrOpt, None, ['--foo', 'bar'], 'bar')
|
||||
|
||||
def test_bool_default(self):
|
||||
self._do_cli_test(BoolOpt, False, [], False)
|
||||
|
||||
def test_bool_arg(self):
|
||||
self._do_cli_test(BoolOpt, None, ['--foo'], True)
|
||||
|
||||
def test_bool_arg_inverse(self):
|
||||
self._do_cli_test(BoolOpt, None, ['--foo', '--nofoo'], False)
|
||||
|
||||
def test_int_default(self):
|
||||
self._do_cli_test(IntOpt, 10, [], 10)
|
||||
|
||||
def test_int_arg(self):
|
||||
self._do_cli_test(IntOpt, None, ['--foo=20'], 20)
|
||||
|
||||
def test_float_default(self):
|
||||
self._do_cli_test(FloatOpt, 1.0, [], 1.0)
|
||||
|
||||
def test_float_arg(self):
|
||||
self._do_cli_test(FloatOpt, None, ['--foo', '2.0'], 2.0)
|
||||
|
||||
def test_list_default(self):
|
||||
self._do_cli_test(ListOpt, ['bar'], [], ['bar'])
|
||||
|
||||
def test_list_arg(self):
|
||||
self._do_cli_test(ListOpt, None,
|
||||
['--foo', 'blaa,bar'], ['blaa', 'bar'])
|
||||
|
||||
def test_multistr_default(self):
|
||||
self._do_cli_test(MultiStrOpt, ['bar'], [], ['bar'])
|
||||
|
||||
def test_multistr_arg(self):
|
||||
self._do_cli_test(MultiStrOpt, None,
|
||||
['--foo', 'blaa', '--foo', 'bar'], ['blaa', 'bar'])
|
||||
|
||||
def test_help(self):
|
||||
self.stubs.Set(sys, 'stdout', StringIO.StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, ['--help'])
|
||||
self.assertTrue('FOO BAR' in sys.stdout.getvalue())
|
||||
self.assertTrue('--version' in sys.stdout.getvalue())
|
||||
self.assertTrue('--help' in sys.stdout.getvalue())
|
||||
self.assertTrue('--config-file=PATH' in sys.stdout.getvalue())
|
||||
|
||||
def test_version(self):
|
||||
self.stubs.Set(sys, 'stdout', StringIO.StringIO())
|
||||
self.assertRaises(SystemExit, self.conf, ['--version'])
|
||||
self.assertTrue('1.0' in sys.stdout.getvalue())
|
||||
|
||||
def test_config_file(self):
|
||||
paths = self.create_tempfiles([('1.conf', '[DEFAULT]'),
|
||||
('2.conf', '[DEFAULT]')])
|
||||
|
||||
self.conf(['--config-file', paths[0], '--config-file', paths[1]])
|
||||
|
||||
self.assertEquals(self.conf.config_file, paths)
|
||||
|
||||
|
||||
class ConfigFileOptsTestCase(BaseTestCase):
|
||||
|
||||
def test_conf_file_str_default(self):
|
||||
self.conf.register_opt(StrOpt('foo', default='bar'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 'bar')
|
||||
|
||||
def test_conf_file_str_value(self):
|
||||
self.conf.register_opt(StrOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 'bar')
|
||||
|
||||
def test_conf_file_str_value_override(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('1.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = baar\n'),
|
||||
('2.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = baaar\n')])
|
||||
|
||||
self.conf(['--foo', 'bar',
|
||||
'--config-file', paths[0],
|
||||
'--config-file', paths[1]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 'baaar')
|
||||
|
||||
def test_conf_file_int_default(self):
|
||||
self.conf.register_opt(IntOpt('foo', default=666))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 666)
|
||||
|
||||
def test_conf_file_int_value(self):
|
||||
self.conf.register_opt(IntOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 666\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 666)
|
||||
|
||||
def test_conf_file_int_value_override(self):
|
||||
self.conf.register_cli_opt(IntOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('1.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 66\n'),
|
||||
('2.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 666\n')])
|
||||
|
||||
self.conf(['--foo', '6',
|
||||
'--config-file', paths[0],
|
||||
'--config-file', paths[1]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 666)
|
||||
|
||||
def test_conf_file_float_default(self):
|
||||
self.conf.register_opt(FloatOpt('foo', default=6.66))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 6.66)
|
||||
|
||||
def test_conf_file_float_value(self):
|
||||
self.conf.register_opt(FloatOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 6.66\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 6.66)
|
||||
|
||||
def test_conf_file_float_value_override(self):
|
||||
self.conf.register_cli_opt(FloatOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('1.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 6.6\n'),
|
||||
('2.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = 6.66\n')])
|
||||
|
||||
self.conf(['--foo', '6',
|
||||
'--config-file', paths[0],
|
||||
'--config-file', paths[1]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, 6.66)
|
||||
|
||||
def test_conf_file_list_default(self):
|
||||
self.conf.register_opt(ListOpt('foo', default=['bar']))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, ['bar'])
|
||||
|
||||
def test_conf_file_list_value(self):
|
||||
self.conf.register_opt(ListOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, ['bar'])
|
||||
|
||||
def test_conf_file_list_value_override(self):
|
||||
self.conf.register_cli_opt(ListOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('1.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar,bar\n'),
|
||||
('2.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = b,a,r\n')])
|
||||
|
||||
self.conf(['--foo', 'bar',
|
||||
'--config-file', paths[0],
|
||||
'--config-file', paths[1]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, ['b', 'a', 'r'])
|
||||
|
||||
def test_conf_file_multistr_default(self):
|
||||
self.conf.register_opt(MultiStrOpt('foo', default=['bar']))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, ['bar'])
|
||||
|
||||
def test_conf_file_multistr_value(self):
|
||||
self.conf.register_opt(MultiStrOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, ['bar'])
|
||||
|
||||
def test_conf_file_multistr_values_append(self):
|
||||
self.conf.register_cli_opt(ListOpt('foo'))
|
||||
|
||||
paths = self.create_tempfiles([('1.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n'),
|
||||
('2.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = bar\n')])
|
||||
|
||||
self.conf(['--foo', 'bar',
|
||||
'--config-file', paths[0],
|
||||
'--config-file', paths[1]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
|
||||
# FIXME(markmc): values spread across the CLI and multiple
|
||||
# config files should be appended
|
||||
# self.assertEquals(self.conf.foo, ['bar', 'bar', 'bar'])
|
||||
|
||||
|
||||
class OptGroupsTestCase(BaseTestCase):
|
||||
|
||||
def test_arg_group(self):
|
||||
blaa_group = OptGroup('blaa')
|
||||
self.conf.register_group(blaa_group)
|
||||
self.conf.register_cli_opt(StrOpt('foo'), group=blaa_group)
|
||||
|
||||
self.conf(['--blaa-foo', 'bar'])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
def test_arg_group_by_name(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_cli_opt(StrOpt('foo'), group='blaa')
|
||||
|
||||
self.conf(['--blaa-foo', 'bar'])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
def test_arg_group_with_default(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_cli_opt(StrOpt('foo', default='bar'), group='blaa')
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
def test_arg_group_in_config_file(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_opt(StrOpt('foo'), group='blaa')
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[blaa]\n'
|
||||
'foo = bar\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
|
||||
class TemplateSubstitutionTestCase(BaseTestCase):
|
||||
|
||||
def _prep_test_str_sub(self, foo_default=None, bar_default=None):
|
||||
self.conf.register_cli_opt(StrOpt('foo', default=foo_default))
|
||||
self.conf.register_cli_opt(StrOpt('bar', default=bar_default))
|
||||
|
||||
def _assert_str_sub(self):
|
||||
self.assertTrue(hasattr(self.conf, 'bar'))
|
||||
self.assertEquals(self.conf.bar, 'blaa')
|
||||
|
||||
def test_str_sub_default_from_default(self):
|
||||
self._prep_test_str_sub(foo_default='blaa', bar_default='$foo')
|
||||
|
||||
self.conf([])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_default_from_arg(self):
|
||||
self._prep_test_str_sub(bar_default='$foo')
|
||||
|
||||
self.conf(['--foo', 'blaa'])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_default_from_config_file(self):
|
||||
self._prep_test_str_sub(bar_default='$foo')
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = blaa\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_arg_from_default(self):
|
||||
self._prep_test_str_sub(foo_default='blaa')
|
||||
|
||||
self.conf(['--bar', '$foo'])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_arg_from_arg(self):
|
||||
self._prep_test_str_sub()
|
||||
|
||||
self.conf(['--foo', 'blaa', '--bar', '$foo'])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_arg_from_config_file(self):
|
||||
self._prep_test_str_sub()
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'foo = blaa\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0], '--bar=$foo'])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_config_file_from_default(self):
|
||||
self._prep_test_str_sub(foo_default='blaa')
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'bar = $foo\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_config_file_from_arg(self):
|
||||
self._prep_test_str_sub()
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'bar = $foo\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0], '--foo=blaa'])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_config_file_from_config_file(self):
|
||||
self._prep_test_str_sub()
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[DEFAULT]\n'
|
||||
'bar = $foo\n'
|
||||
'foo = blaa\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self._assert_str_sub()
|
||||
|
||||
def test_str_sub_group_from_default(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo', default='blaa'))
|
||||
self.conf.register_group(OptGroup('ba'))
|
||||
self.conf.register_cli_opt(StrOpt('r', default='$foo'), group='ba')
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'ba'))
|
||||
self.assertTrue(hasattr(self.conf.ba, 'r'))
|
||||
self.assertEquals(self.conf.ba.r, 'blaa')
|
||||
|
||||
|
||||
class ReparseTestCase(BaseTestCase):
|
||||
|
||||
def test_reparse(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_cli_opt(StrOpt('foo', default='r'), group='blaa')
|
||||
|
||||
paths = self.create_tempfiles([('test.conf',
|
||||
'[blaa]\n'
|
||||
'foo = b\n')])
|
||||
|
||||
self.conf(['--config-file', paths[0]])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'b')
|
||||
|
||||
self.conf(['--blaa-foo', 'a'])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'a')
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertTrue(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertEquals(self.conf.blaa.foo, 'r')
|
||||
|
||||
|
||||
class OverridesTestCase(BaseTestCase):
|
||||
|
||||
def test_no_default_override(self):
|
||||
self.conf.register_opt(StrOpt('foo'))
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.foo, None)
|
||||
self.conf.set_default('foo', 'bar')
|
||||
self.assertEquals(self.conf.foo, 'bar')
|
||||
|
||||
def test_default_override(self):
|
||||
self.conf.register_opt(StrOpt('foo', default='foo'))
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.foo, 'foo')
|
||||
self.conf.set_default('foo', 'bar')
|
||||
self.assertEquals(self.conf.foo, 'bar')
|
||||
self.conf.set_default('foo', None)
|
||||
self.assertEquals(self.conf.foo, 'foo')
|
||||
|
||||
def test_override(self):
|
||||
self.conf.register_opt(StrOpt('foo'))
|
||||
self.conf.set_override('foo', 'bar')
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.foo, 'bar')
|
||||
|
||||
def test_group_no_default_override(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_opt(StrOpt('foo'), group='blaa')
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.blaa.foo, None)
|
||||
self.conf.set_default('foo', 'bar', group='blaa')
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
def test_group_default_override(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_opt(StrOpt('foo', default='foo'), group='blaa')
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.blaa.foo, 'foo')
|
||||
self.conf.set_default('foo', 'bar', group='blaa')
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
self.conf.set_default('foo', None, group='blaa')
|
||||
self.assertEquals(self.conf.blaa.foo, 'foo')
|
||||
|
||||
def test_group_override(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_opt(StrOpt('foo'), group='blaa')
|
||||
self.conf.set_override('foo', 'bar', group='blaa')
|
||||
self.conf([])
|
||||
self.assertEquals(self.conf.blaa.foo, 'bar')
|
||||
|
||||
|
||||
class SadPathTestCase(BaseTestCase):
|
||||
|
||||
def test_unknown_attr(self):
|
||||
self.conf([])
|
||||
self.assertFalse(hasattr(self.conf, 'foo'))
|
||||
self.assertRaises(NoSuchOptError, getattr, self.conf, 'foo')
|
||||
|
||||
def test_unknown_attr_is_attr_error(self):
|
||||
self.conf([])
|
||||
self.assertFalse(hasattr(self.conf, 'foo'))
|
||||
self.assertRaises(AttributeError, getattr, self.conf, 'foo')
|
||||
|
||||
def test_unknown_group_attr(self):
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'blaa'))
|
||||
self.assertFalse(hasattr(self.conf.blaa, 'foo'))
|
||||
self.assertRaises(NoSuchOptError, getattr, self.conf.blaa, 'foo')
|
||||
|
||||
def test_ok_duplicate(self):
|
||||
opt = StrOpt('foo')
|
||||
self.conf.register_cli_opt(opt)
|
||||
self.conf.register_cli_opt(opt)
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(hasattr(self.conf, 'foo'))
|
||||
self.assertEquals(self.conf.foo, None)
|
||||
|
||||
def test_error_duplicate(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo'))
|
||||
self.assertRaises(DuplicateOptError,
|
||||
self.conf.register_cli_opt, StrOpt('foo'))
|
||||
|
||||
def test_error_duplicate_with_different_dest(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo', dest='f'))
|
||||
self.assertRaises(DuplicateOptError,
|
||||
self.conf.register_cli_opt, StrOpt('foo'))
|
||||
|
||||
def test_error_duplicate_short(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo', short='f'))
|
||||
self.assertRaises(DuplicateOptError,
|
||||
self.conf.register_cli_opt, StrOpt('bar', short='f'))
|
||||
|
||||
def test_no_such_group(self):
|
||||
self.assertRaises(NoSuchGroupError, self.conf.register_cli_opt,
|
||||
StrOpt('foo'), group='blaa')
|
||||
|
||||
def test_already_parsed(self):
|
||||
self.conf([])
|
||||
|
||||
self.assertRaises(ArgsAlreadyParsedError,
|
||||
self.conf.register_cli_opt, StrOpt('foo'))
|
||||
|
||||
def test_bad_cli_arg(self):
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
|
||||
self.assertRaises(SystemExit, self.conf, ['--foo'])
|
||||
|
||||
self.assertTrue('error' in sys.stderr.getvalue())
|
||||
self.assertTrue('--foo' in sys.stderr.getvalue())
|
||||
|
||||
def _do_test_bad_cli_value(self, opt_class):
|
||||
self.conf.register_cli_opt(opt_class('foo'))
|
||||
|
||||
self.stubs.Set(sys, 'stderr', StringIO.StringIO())
|
||||
|
||||
self.assertRaises(SystemExit, self.conf, ['--foo', 'bar'])
|
||||
|
||||
self.assertTrue('foo' in sys.stderr.getvalue())
|
||||
self.assertTrue('bar' in sys.stderr.getvalue())
|
||||
|
||||
def test_bad_int_arg(self):
|
||||
self._do_test_bad_cli_value(IntOpt)
|
||||
|
||||
def test_bad_float_arg(self):
|
||||
self._do_test_bad_cli_value(FloatOpt)
|
||||
|
||||
def test_conf_file_not_found(self):
|
||||
paths = self.create_tempfiles([('test.conf', '')])
|
||||
os.remove(paths[0])
|
||||
self.tempfiles.remove(paths[0])
|
||||
|
||||
self.assertRaises(ConfigFilesNotFoundError,
|
||||
self.conf, ['--config-file', paths[0]])
|
||||
|
||||
def test_conf_file_broken(self):
|
||||
paths = self.create_tempfiles([('test.conf', 'foo')])
|
||||
|
||||
self.assertRaises(ConfigFileParseError,
|
||||
self.conf, ['--config-file', paths[0]])
|
||||
|
||||
def _do_test_conf_file_bad_value(self, opt_class):
|
||||
self.conf.register_opt(opt_class('foo'))
|
||||
|
||||
def test_conf_file_bad_bool(self):
|
||||
self._do_test_conf_file_bad_value(BoolOpt)
|
||||
|
||||
def test_conf_file_bad_int(self):
|
||||
self._do_test_conf_file_bad_value(IntOpt)
|
||||
|
||||
def test_conf_file_bad_float(self):
|
||||
self._do_test_conf_file_bad_value(FloatOpt)
|
||||
|
||||
def test_str_sub_from_group(self):
|
||||
self.conf.register_group(OptGroup('f'))
|
||||
self.conf.register_cli_opt(StrOpt('oo', default='blaa'), group='f')
|
||||
self.conf.register_cli_opt(StrOpt('bar', default='$f.oo'))
|
||||
|
||||
self.conf([])
|
||||
|
||||
self.assertFalse(hasattr(self.conf, 'bar'))
|
||||
self.assertRaises(TemplateSubstitutionError, getattr, self.conf, 'bar')
|
||||
|
||||
def test_set_default_unknown_attr(self):
|
||||
self.conf([])
|
||||
self.assertRaises(NoSuchOptError, self.conf.set_default, 'foo', 'bar')
|
||||
|
||||
def test_set_default_unknown_group(self):
|
||||
self.conf([])
|
||||
self.assertRaises(NoSuchGroupError,
|
||||
self.conf.set_default, 'foo', 'bar', group='blaa')
|
||||
|
||||
def test_set_override_unknown_attr(self):
|
||||
self.conf([])
|
||||
self.assertRaises(NoSuchOptError, self.conf.set_override, 'foo', 'bar')
|
||||
|
||||
def test_set_override_unknown_group(self):
|
||||
self.conf([])
|
||||
self.assertRaises(NoSuchGroupError,
|
||||
self.conf.set_override, 'foo', 'bar', group='blaa')
|
||||
|
||||
|
||||
class OptDumpingTestCase(BaseTestCase):
|
||||
|
||||
class FakeLogger:
|
||||
|
||||
def __init__(self, test_case, expected_lvl):
|
||||
self.test_case = test_case
|
||||
self.expected_lvl = expected_lvl
|
||||
self.logged = []
|
||||
|
||||
def log(self, lvl, fmt, *args):
|
||||
self.test_case.assertEquals(lvl, self.expected_lvl)
|
||||
self.logged.append(fmt % args)
|
||||
|
||||
def test_log_opt_values(self):
|
||||
self.conf.register_cli_opt(StrOpt('foo'))
|
||||
self.conf.register_group(OptGroup('blaa'))
|
||||
self.conf.register_cli_opt(StrOpt('bar'), 'blaa')
|
||||
|
||||
self.conf(['--foo', 'this', '--blaa-bar', 'that'])
|
||||
|
||||
logger = self.FakeLogger(self, 666)
|
||||
|
||||
self.conf.log_opt_values(logger, 666)
|
||||
|
||||
self.assertEquals(logger.logged, [
|
||||
"*" * 80,
|
||||
"Configuration options gathered from:",
|
||||
"command line args: ['--foo', 'this', '--blaa-bar', 'that']",
|
||||
"config files: []",
|
||||
"=" * 80,
|
||||
"config_file = []",
|
||||
"foo = this",
|
||||
"blaa.bar = that",
|
||||
"*" * 80,
|
||||
])
|
||||
|
||||
|
||||
class CommonOptsTestCase(BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CommonOptsTestCase, self).setUp()
|
||||
self.conf = CommonConfigOpts()
|
||||
|
||||
def test_debug_verbose(self):
|
||||
self.conf(['--debug', '--verbose'])
|
||||
|
||||
self.assertEquals(self.conf.debug, True)
|
||||
self.assertEquals(self.conf.verbose, True)
|
||||
|
||||
def test_logging_opts(self):
|
||||
self.conf([])
|
||||
|
||||
self.assertTrue(self.conf.log_config is None)
|
||||
self.assertTrue(self.conf.log_file is None)
|
||||
self.assertTrue(self.conf.log_dir is None)
|
||||
|
||||
self.assertEquals(self.conf.log_format,
|
||||
CommonConfigOpts.DEFAULT_LOG_FORMAT)
|
||||
self.assertEquals(self.conf.log_date_format,
|
||||
CommonConfigOpts.DEFAULT_LOG_DATE_FORMAT)
|
||||
|
||||
self.assertEquals(self.conf.use_syslog, False)
|
||||
@@ -21,8 +21,8 @@ import exceptions
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import test
|
||||
|
||||
FLAGS = flags.FLAGS
|
||||
|
||||
@@ -22,11 +22,11 @@ Unit Tests for remote procedure calls using queue
|
||||
|
||||
import mox
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import test
|
||||
from nova import service
|
||||
from nova import manager
|
||||
|
||||
+1
-1
@@ -46,10 +46,10 @@ from eventlet import semaphore
|
||||
from eventlet.green import subprocess
|
||||
import netaddr
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
LOG = logging.getLogger("nova.utils")
|
||||
|
||||
@@ -29,10 +29,10 @@ import json
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.disk import guestfs
|
||||
from nova.virt.disk import loop
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.disk import mount
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt import netutils
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ from xml.etree import ElementTree
|
||||
|
||||
from nova.auth import manager
|
||||
from nova import block_device
|
||||
from nova.common import cfg
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
from nova import context as nova_context
|
||||
@@ -63,6 +62,7 @@ from nova import exception
|
||||
from nova import flags
|
||||
import nova.image
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.disk import api as disk
|
||||
from nova.virt import driver
|
||||
|
||||
@@ -29,13 +29,13 @@ import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import compute
|
||||
from nova import context as db_context
|
||||
from nova import db
|
||||
from nova import flags
|
||||
from nova import image
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.libvirt import utils as virtutils
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ import os
|
||||
import random
|
||||
import shutil
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.disk import api as disk
|
||||
from nova.virt import images
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
"""VIF drivers for libvirt."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.network import linux_net
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt import netutils
|
||||
from nova.virt.vif import VIFDriver
|
||||
|
||||
@@ -26,8 +26,8 @@ try:
|
||||
except ImportError:
|
||||
suds = None
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova.virt.vmwareapi import error_util
|
||||
|
||||
RESP_NOT_XML_ERROR = 'Response is "text/html", not "text/xml"'
|
||||
|
||||
@@ -26,11 +26,11 @@ import urllib
|
||||
import urllib2
|
||||
import uuid
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.compute import power_state
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt.vmwareapi import vim_util
|
||||
from nova.virt.vmwareapi import vm_util
|
||||
|
||||
@@ -36,12 +36,12 @@ import time
|
||||
|
||||
from eventlet import event
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
from nova.virt.vmwareapi import error_util
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
"""VIF drivers for XenAPI."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.virt.vif import VIFDriver
|
||||
from nova.virt.xenapi.network_utils import NetworkHelper
|
||||
from nova.virt.xenapi.vm_utils import VMHelper
|
||||
|
||||
@@ -33,11 +33,11 @@ import uuid
|
||||
from decimal import Decimal, InvalidOperation
|
||||
from xml.dom import minidom
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova.image import glance
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.compute import instance_types
|
||||
from nova.compute import power_state
|
||||
|
||||
@@ -31,7 +31,6 @@ import uuid
|
||||
|
||||
from eventlet import greenthread
|
||||
|
||||
from nova.common import cfg
|
||||
from nova.compute import api as compute
|
||||
from nova.compute import power_state
|
||||
from nova import context as nova_context
|
||||
@@ -39,6 +38,7 @@ from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.virt import driver
|
||||
from nova.virt.xenapi import volume_utils
|
||||
|
||||
@@ -70,13 +70,13 @@ from eventlet import queue
|
||||
from eventlet import tpool
|
||||
from eventlet import timeout
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import utils
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova.virt import driver
|
||||
from nova.virt.xenapi import vm_utils
|
||||
from nova.virt.xenapi.vmops import VMOps
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
"""Module for VNC Proxying."""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
|
||||
|
||||
vnc_opts = [
|
||||
|
||||
@@ -26,10 +26,10 @@ import eventlet.green
|
||||
import eventlet.greenio
|
||||
import eventlet.wsgi
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import version
|
||||
from nova import wsgi
|
||||
|
||||
@@ -24,10 +24,10 @@ import os
|
||||
import time
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.volume import iscsi
|
||||
from nova.volume import volume_types
|
||||
|
||||
@@ -20,8 +20,8 @@ Helper code for the iSCSI volume driver.
|
||||
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import flags
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
|
||||
|
||||
|
||||
@@ -38,12 +38,12 @@ intact.
|
||||
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import utils
|
||||
from nova.volume import volume_types
|
||||
|
||||
+1
-2
@@ -32,11 +32,10 @@ import string
|
||||
import uuid
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from nova.common import cfg
|
||||
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import utils
|
||||
from nova.utils import ssh_execute
|
||||
from nova.volume.driver import ISCSIDriver
|
||||
|
||||
+1
-1
@@ -25,11 +25,11 @@ For assistance and guidelines pls contact
|
||||
|
||||
import sys
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import compute
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova.openstack.common import cfg
|
||||
from nova import rpc
|
||||
from nova import volume
|
||||
from nova.compute import instance_types
|
||||
|
||||
+1
-1
@@ -22,12 +22,12 @@ Handles all processes relating to Virtual Storage Arrays (VSA).
|
||||
|
||||
"""
|
||||
|
||||
from nova.common import cfg
|
||||
from nova import compute
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import log as logging
|
||||
from nova import manager
|
||||
from nova.openstack.common import cfg
|
||||
from nova import volume
|
||||
from nova import vsa
|
||||
from nova import utils
|
||||
|
||||
Reference in New Issue
Block a user