From 14b4cdbb5138ea3ab6fb7166de3f70ae85820176 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 19 Aug 2014 10:19:23 +0200 Subject: [PATCH] Switch to oslo.utils Change-Id: Iacfcbf49864198915f8c229bc552afb412b83b79 --- ceilometer/alarm/evaluator/__init__.py | 2 +- ceilometer/alarm/evaluator/threshold.py | 3 +- ceilometer/alarm/partition/coordination.py | 3 +- ceilometer/alarm/service.py | 4 +- ceilometer/alarm/storage/impl_hbase.py | 4 +- ceilometer/api/controllers/v2.py | 4 +- ceilometer/cli.py | 2 +- ceilometer/cmd/alarm.py | 2 +- ceilometer/collector.py | 2 +- ceilometer/compute/notifications/cpu.py | 2 +- ceilometer/compute/plugin.py | 3 +- ceilometer/compute/pollsters/net.py | 3 +- ceilometer/compute/pollsters/util.py | 2 +- ceilometer/compute/virt/hyperv/inspector.py | 2 +- ceilometer/compute/virt/vmware/inspector.py | 2 +- ceilometer/dispatcher/database.py | 2 +- ceilometer/event/converter.py | 2 +- ceilometer/hardware/plugin.py | 4 +- ceilometer/hardware/pollsters/util.py | 2 +- ceilometer/image/glance.py | 2 +- ceilometer/network/floatingip.py | 2 +- ceilometer/network/services/fwaas.py | 2 +- ceilometer/network/services/lbaas.py | 3 +- ceilometer/network/services/vpnaas.py | 2 +- ceilometer/network/statistics/__init__.py | 4 +- .../network/statistics/opencontrail/driver.py | 3 +- .../network/statistics/opendaylight/driver.py | 3 +- ceilometer/objectstore/swift.py | 2 +- ceilometer/objectstore/swift_middleware.py | 3 +- ceilometer/openstack/common/network_utils.py | 163 ------------------ ceilometer/openstack/common/units.py | 38 ---- ceilometer/publisher/__init__.py | 7 +- ceilometer/publisher/udp.py | 4 +- ceilometer/storage/base.py | 3 +- ceilometer/storage/impl_db2.py | 2 +- ceilometer/storage/impl_hbase.py | 6 +- ceilometer/storage/impl_mongodb.py | 2 +- ceilometer/storage/impl_sqlalchemy.py | 2 +- ceilometer/storage/models.py | 2 +- ceilometer/storage/mongo/utils.py | 4 +- .../versions/005_remove_resource_timestamp.py | 4 +- .../versions/029_sample_recorded_at.py | 3 +- ceilometer/storage/sqlalchemy/models.py | 2 +- ceilometer/tests/alarm/evaluator/test_base.py | 3 +- .../tests/alarm/evaluator/test_combination.py | 3 +- .../tests/alarm/evaluator/test_threshold.py | 2 +- .../alarm/partition/test_coordination.py | 2 +- ceilometer/tests/alarm/test_notifier.py | 2 +- ceilometer/tests/alarm/test_rpc.py | 2 +- ceilometer/tests/api/v2/test_acl_scenarios.py | 2 +- .../api/v2/test_complex_query_scenarios.py | 3 +- ..._compute_duration_by_resource_scenarios.py | 2 +- .../tests/api/v2/test_event_scenarios.py | 3 +- .../api/v2/test_list_events_scenarios.py | 2 +- .../api/v2/test_list_resources_scenarios.py | 2 +- .../api/v2/test_post_samples_scenarios.py | 2 +- ceilometer/tests/api/v2/test_query.py | 2 +- ceilometer/tests/base.py | 2 +- .../compute/virt/hyperv/test_inspector.py | 2 +- ceilometer/tests/event/test_converter.py | 4 +- .../hardware/inspector/test_inspector.py | 6 +- .../tests/hardware/inspector/test_snmp.py | 4 +- .../network/statistics/test_statistics.py | 2 +- ceilometer/tests/pipeline_base.py | 2 +- ceilometer/tests/publisher/test_file.py | 12 +- .../tests/publisher/test_rpc_publisher.py | 26 +-- ceilometer/tests/publisher/test_udp.py | 8 +- .../tests/storage/test_impl_sqlalchemy.py | 2 +- .../tests/storage/test_storage_scenarios.py | 2 +- ceilometer/tests/test_collector.py | 2 +- ceilometer/tests/test_notification.py | 2 +- ceilometer/transformer/conversions.py | 2 +- ceilometer/utils.py | 5 +- nova_tests/test_notifier.py | 3 +- openstack-common.conf | 6 - requirements-py3.txt | 1 + requirements.txt | 1 + tools/make_test_data.py | 3 +- 78 files changed, 123 insertions(+), 324 deletions(-) delete mode 100644 ceilometer/openstack/common/network_utils.py delete mode 100644 ceilometer/openstack/common/units.py diff --git a/ceilometer/alarm/evaluator/__init__.py b/ceilometer/alarm/evaluator/__init__.py index f09f478f3..f1059f552 100644 --- a/ceilometer/alarm/evaluator/__init__.py +++ b/ceilometer/alarm/evaluator/__init__.py @@ -22,12 +22,12 @@ import datetime from ceilometerclient import client as ceiloclient from oslo.config import cfg +from oslo.utils import timeutils import pytz import six from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils LOG = log.getLogger(__name__) diff --git a/ceilometer/alarm/evaluator/threshold.py b/ceilometer/alarm/evaluator/threshold.py index 7a328231c..a15f9370f 100644 --- a/ceilometer/alarm/evaluator/threshold.py +++ b/ceilometer/alarm/evaluator/threshold.py @@ -19,11 +19,12 @@ import datetime import operator +from oslo.utils import timeutils + from ceilometer.alarm import evaluator from ceilometer.alarm.evaluator import utils from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils LOG = log.getLogger(__name__) diff --git a/ceilometer/alarm/partition/coordination.py b/ceilometer/alarm/partition/coordination.py index c0bbeb06a..e86358957 100644 --- a/ceilometer/alarm/partition/coordination.py +++ b/ceilometer/alarm/partition/coordination.py @@ -19,10 +19,11 @@ import math import random import uuid +from oslo.utils import timeutils + from ceilometer.alarm import rpc as rpc_alarm from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils LOG = log.getLogger(__name__) diff --git a/ceilometer/alarm/service.py b/ceilometer/alarm/service.py index 9bc989676..614d03f88 100644 --- a/ceilometer/alarm/service.py +++ b/ceilometer/alarm/service.py @@ -21,6 +21,7 @@ import abc from ceilometerclient import client as ceiloclient from oslo.config import cfg +from oslo.utils import netutils import six from stevedore import extension @@ -29,7 +30,6 @@ from ceilometer.alarm import rpc as rpc_alarm from ceilometer import messaging from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils from ceilometer.openstack.common import service as os_service @@ -210,7 +210,7 @@ class AlarmNotifierService(os_service.Service): def _handle_action(self, action, alarm_id, previous, current, reason, reason_data): try: - action = network_utils.urlsplit(action) + action = netutils.urlsplit(action) except Exception: LOG.error( _("Unable to parse action %(action)s for alarm %(alarm_id)s"), diff --git a/ceilometer/alarm/storage/impl_hbase.py b/ceilometer/alarm/storage/impl_hbase.py index efdcb4722..d64409575 100644 --- a/ceilometer/alarm/storage/impl_hbase.py +++ b/ceilometer/alarm/storage/impl_hbase.py @@ -16,13 +16,13 @@ import datetime import os import happybase +from oslo.utils import netutils from six.moves.urllib import parse as urlparse from ceilometer.alarm.storage import base from ceilometer.alarm.storage import models from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils from ceilometer.storage.hbase import inmemory as hbase_inmemory from ceilometer.storage.hbase import utils as hbase_utils from ceilometer import utils @@ -140,7 +140,7 @@ class Connection(base.Connection): database name, so we are not looking for these in the url. """ opts = {} - result = network_utils.urlsplit(url) + result = netutils.urlsplit(url) opts['table_prefix'] = urlparse.parse_qs( result.query).get('table_prefix', [None])[0] opts['dbtype'] = result.scheme diff --git a/ceilometer/api/controllers/v2.py b/ceilometer/api/controllers/v2.py index be5900fef..b4592abd4 100644 --- a/ceilometer/api/controllers/v2.py +++ b/ceilometer/api/controllers/v2.py @@ -37,6 +37,8 @@ import pytz import uuid from oslo.config import cfg +from oslo.utils import strutils +from oslo.utils import timeutils import pecan from pecan import rest import six @@ -50,8 +52,6 @@ from ceilometer import messaging from ceilometer.openstack.common import context from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import strutils -from ceilometer.openstack.common import timeutils from ceilometer import sample from ceilometer import storage from ceilometer import utils diff --git a/ceilometer/cli.py b/ceilometer/cli.py index 541bebb6e..b66f3af0d 100644 --- a/ceilometer/cli.py +++ b/ceilometer/cli.py @@ -29,9 +29,9 @@ import eventlet # oslo.messaging use threading.local eventlet.monkey_patch(socket=True, select=True, thread=True) from oslo.config import cfg +from oslo.utils import timeutils from ceilometer.openstack.common import context -from ceilometer.openstack.common import timeutils from ceilometer import pipeline from ceilometer import sample from ceilometer import service diff --git a/ceilometer/cmd/alarm.py b/ceilometer/cmd/alarm.py index 63def1c7f..37ef1f34f 100644 --- a/ceilometer/cmd/alarm.py +++ b/ceilometer/cmd/alarm.py @@ -15,9 +15,9 @@ # under the License. from oslo.config import cfg +from oslo.utils import importutils from ceilometer.alarm import service as alarm_service -from ceilometer.openstack.common import importutils from ceilometer.openstack.common import service as os_service from ceilometer import service diff --git a/ceilometer/collector.py b/ceilometer/collector.py index 18bae2451..6da4371ae 100644 --- a/ceilometer/collector.py +++ b/ceilometer/collector.py @@ -19,13 +19,13 @@ import socket import msgpack from oslo.config import cfg +from oslo.utils import units from ceilometer import dispatcher from ceilometer import messaging from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log from ceilometer.openstack.common import service as os_service -from ceilometer.openstack.common import units OPTS = [ cfg.StrOpt('udp_address', diff --git a/ceilometer/compute/notifications/cpu.py b/ceilometer/compute/notifications/cpu.py index 7af186da3..f4cd2c07d 100644 --- a/ceilometer/compute/notifications/cpu.py +++ b/ceilometer/compute/notifications/cpu.py @@ -17,11 +17,11 @@ """Converters for producing compute CPU sample messages from notification events. """ +from oslo.utils import timeutils from ceilometer.compute import notifications from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/compute/plugin.py b/ceilometer/compute/plugin.py index a6b6942b2..a4995c325 100644 --- a/ceilometer/compute/plugin.py +++ b/ceilometer/compute/plugin.py @@ -18,9 +18,10 @@ """ import abc + +from oslo.utils import timeutils import six -from ceilometer.openstack.common import timeutils from ceilometer import plugin diff --git a/ceilometer/compute/pollsters/net.py b/ceilometer/compute/pollsters/net.py index c95c23f53..ba56ad923 100644 --- a/ceilometer/compute/pollsters/net.py +++ b/ceilometer/compute/pollsters/net.py @@ -19,12 +19,13 @@ import copy +from oslo.utils import timeutils + from ceilometer.compute import plugin from ceilometer.compute.pollsters import util from ceilometer.compute.virt import inspector as virt_inspector from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/compute/pollsters/util.py b/ceilometer/compute/pollsters/util.py index f979f7157..0492c19ab 100644 --- a/ceilometer/compute/pollsters/util.py +++ b/ceilometer/compute/pollsters/util.py @@ -16,9 +16,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import timeutils from ceilometer.compute import util as compute_util -from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/compute/virt/hyperv/inspector.py b/ceilometer/compute/virt/hyperv/inspector.py index 6cb2a6966..183b0ca2b 100644 --- a/ceilometer/compute/virt/hyperv/inspector.py +++ b/ceilometer/compute/virt/hyperv/inspector.py @@ -17,11 +17,11 @@ """Implementation of Inspector abstraction for Hyper-V""" from oslo.config import cfg +from oslo.utils import units from ceilometer.compute.virt.hyperv import utilsv2 from ceilometer.compute.virt import inspector as virt_inspector from ceilometer.openstack.common import log -from ceilometer.openstack.common import units CONF = cfg.CONF LOG = log.getLogger(__name__) diff --git a/ceilometer/compute/virt/vmware/inspector.py b/ceilometer/compute/virt/vmware/inspector.py index f08cbf632..22fab9a85 100644 --- a/ceilometer/compute/virt/vmware/inspector.py +++ b/ceilometer/compute/virt/vmware/inspector.py @@ -16,12 +16,12 @@ """Implementation of Inspector abstraction for VMware vSphere""" from oslo.config import cfg +from oslo.utils import units from oslo.vmware import api from ceilometer.compute.virt import inspector as virt_inspector from ceilometer.compute.virt.vmware import vsphere_operations from ceilometer.openstack.common.gettextutils import _ -from ceilometer.openstack.common import units opt_group = cfg.OptGroup(name='vmware', diff --git a/ceilometer/dispatcher/database.py b/ceilometer/dispatcher/database.py index 7bb13c523..0093b1ba1 100644 --- a/ceilometer/dispatcher/database.py +++ b/ceilometer/dispatcher/database.py @@ -14,11 +14,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import timeutils from ceilometer import dispatcher from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils as publisher_utils from ceilometer import storage diff --git a/ceilometer/event/converter.py b/ceilometer/event/converter.py index d6c9466c6..89a0d00e5 100644 --- a/ceilometer/event/converter.py +++ b/ceilometer/event/converter.py @@ -20,12 +20,12 @@ import os import jsonpath_rw from oslo.config import cfg +from oslo.utils import timeutils import six import yaml from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer.storage import models OPTS = [ diff --git a/ceilometer/hardware/plugin.py b/ceilometer/hardware/plugin.py index 363ffb04f..83c5e4a31 100644 --- a/ceilometer/hardware/plugin.py +++ b/ceilometer/hardware/plugin.py @@ -21,13 +21,13 @@ import abc import itertools +from oslo.utils import netutils import six from ceilometer.central import plugin from ceilometer.hardware import inspector as insloader from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils LOG = log.getLogger(__name__) @@ -54,7 +54,7 @@ class HardwarePollster(plugin.CentralPollster): h_cache = cache.setdefault(self.CACHE_KEY, {}) sample_iters = [] for res in resources: - parsed_url = network_utils.urlsplit(res) + parsed_url = netutils.urlsplit(res) inspector = self._get_inspector(parsed_url) func = getattr(inspector, self.INSPECT_METHOD) diff --git a/ceilometer/hardware/pollsters/util.py b/ceilometer/hardware/pollsters/util.py index ac1b40dc2..37f77a3f7 100644 --- a/ceilometer/hardware/pollsters/util.py +++ b/ceilometer/hardware/pollsters/util.py @@ -20,9 +20,9 @@ import copy +from oslo.utils import timeutils from six.moves.urllib import parse as urlparse -from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/image/glance.py b/ceilometer/image/glance.py index 85bf6851b..0d2d619b9 100644 --- a/ceilometer/image/glance.py +++ b/ceilometer/image/glance.py @@ -22,9 +22,9 @@ import itertools import glanceclient from oslo.config import cfg +from oslo.utils import timeutils from ceilometer.central import plugin -from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py index 5228fa804..46536d6ea 100644 --- a/ceilometer/network/floatingip.py +++ b/ceilometer/network/floatingip.py @@ -17,12 +17,12 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import timeutils from ceilometer.central import plugin from ceilometer import nova_client from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/network/services/fwaas.py b/ceilometer/network/services/fwaas.py index 74967b7a2..0d093c10c 100644 --- a/ceilometer/network/services/fwaas.py +++ b/ceilometer/network/services/fwaas.py @@ -14,11 +14,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import timeutils from ceilometer.network.services import base from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/network/services/lbaas.py b/ceilometer/network/services/lbaas.py index 278262260..da7435953 100644 --- a/ceilometer/network/services/lbaas.py +++ b/ceilometer/network/services/lbaas.py @@ -17,12 +17,13 @@ import abc import collections + +from oslo.utils import timeutils import six from ceilometer.network.services import base from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/network/services/vpnaas.py b/ceilometer/network/services/vpnaas.py index a7a3891c7..0696dd121 100644 --- a/ceilometer/network/services/vpnaas.py +++ b/ceilometer/network/services/vpnaas.py @@ -14,11 +14,11 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import timeutils from ceilometer.network.services import base from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample LOG = log.getLogger(__name__) diff --git a/ceilometer/network/statistics/__init__.py b/ceilometer/network/statistics/__init__.py index 76d2dd221..9a0d0d6f7 100644 --- a/ceilometer/network/statistics/__init__.py +++ b/ceilometer/network/statistics/__init__.py @@ -15,12 +15,12 @@ import abc +from oslo.utils import netutils import six from six.moves.urllib import parse as urlparse from stevedore import driver as _driver from ceilometer.central import plugin -from ceilometer.openstack.common import network_utils from ceilometer import sample @@ -45,7 +45,7 @@ class _Base(plugin.CentralPollster): @staticmethod def _parse_my_resource(resource): - parse_url = network_utils.urlsplit(resource) + parse_url = netutils.urlsplit(resource) params = urlparse.parse_qs(parse_url.query) parts = urlparse.ParseResult(parse_url.scheme, diff --git a/ceilometer/network/statistics/opencontrail/driver.py b/ceilometer/network/statistics/opencontrail/driver.py index 56552f917..a64cabb24 100644 --- a/ceilometer/network/statistics/opencontrail/driver.py +++ b/ceilometer/network/statistics/opencontrail/driver.py @@ -13,13 +13,12 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from oslo.utils import timeutils from six.moves.urllib import parse as urlparse from ceilometer.network.statistics import driver from ceilometer.network.statistics.opencontrail import client from ceilometer import neutron_client -from ceilometer.openstack.common import timeutils class OpencontrailDriver(driver.Driver): diff --git a/ceilometer/network/statistics/opendaylight/driver.py b/ceilometer/network/statistics/opendaylight/driver.py index 999c385c4..492ab58c6 100644 --- a/ceilometer/network/statistics/opendaylight/driver.py +++ b/ceilometer/network/statistics/opendaylight/driver.py @@ -12,7 +12,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from oslo.utils import timeutils import six from six import moves from six.moves.urllib import parse as urlparse @@ -21,7 +21,6 @@ from ceilometer.network.statistics import driver from ceilometer.network.statistics.opendaylight import client from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import utils diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index 972c67935..7053b2e63 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -21,13 +21,13 @@ from __future__ import absolute_import from keystoneclient import exceptions from oslo.config import cfg +from oslo.utils import timeutils import six.moves.urllib.parse as urlparse from swiftclient import client as swift from ceilometer.central import plugin from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/objectstore/swift_middleware.py b/ceilometer/objectstore/swift_middleware.py index f7b8a016d..ce41711ad 100644 --- a/ceilometer/objectstore/swift_middleware.py +++ b/ceilometer/objectstore/swift_middleware.py @@ -41,9 +41,10 @@ before "proxy-server" and add the following filter in the file: from __future__ import absolute_import +from oslo.utils import timeutils + from ceilometer.openstack.common import context from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import pipeline from ceilometer import sample from ceilometer import service diff --git a/ceilometer/openstack/common/network_utils.py b/ceilometer/openstack/common/network_utils.py deleted file mode 100644 index 1c422499a..000000000 --- a/ceilometer/openstack/common/network_utils.py +++ /dev/null @@ -1,163 +0,0 @@ -# Copyright 2012 OpenStack Foundation. -# All Rights Reserved. -# -# 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. - -""" -Network-related utilities and helper functions. -""" - -import logging -import socket - -from six.moves.urllib import parse - -from ceilometer.openstack.common.gettextutils import _LW - -LOG = logging.getLogger(__name__) - - -def parse_host_port(address, default_port=None): - """Interpret a string as a host:port pair. - - An IPv6 address MUST be escaped if accompanied by a port, - because otherwise ambiguity ensues: 2001:db8:85a3::8a2e:370:7334 - means both [2001:db8:85a3::8a2e:370:7334] and - [2001:db8:85a3::8a2e:370]:7334. - - >>> parse_host_port('server01:80') - ('server01', 80) - >>> parse_host_port('server01') - ('server01', None) - >>> parse_host_port('server01', default_port=1234) - ('server01', 1234) - >>> parse_host_port('[::1]:80') - ('::1', 80) - >>> parse_host_port('[::1]') - ('::1', None) - >>> parse_host_port('[::1]', default_port=1234) - ('::1', 1234) - >>> parse_host_port('2001:db8:85a3::8a2e:370:7334', default_port=1234) - ('2001:db8:85a3::8a2e:370:7334', 1234) - >>> parse_host_port(None) - (None, None) - """ - if not address: - return (None, None) - - if address[0] == '[': - # Escaped ipv6 - _host, _port = address[1:].split(']') - host = _host - if ':' in _port: - port = _port.split(':')[1] - else: - port = default_port - else: - if address.count(':') == 1: - host, port = address.split(':') - else: - # 0 means ipv4, >1 means ipv6. - # We prohibit unescaped ipv6 addresses with port. - host = address - port = default_port - - return (host, None if port is None else int(port)) - - -class ModifiedSplitResult(parse.SplitResult): - """Split results class for urlsplit.""" - - # NOTE(dims): The functions below are needed for Python 2.6.x. - # We can remove these when we drop support for 2.6.x. - @property - def hostname(self): - netloc = self.netloc.split('@', 1)[-1] - host, port = parse_host_port(netloc) - return host - - @property - def port(self): - netloc = self.netloc.split('@', 1)[-1] - host, port = parse_host_port(netloc) - return port - - -def urlsplit(url, scheme='', allow_fragments=True): - """Parse a URL using urlparse.urlsplit(), splitting query and fragments. - This function papers over Python issue9374 when needed. - - The parameters are the same as urlparse.urlsplit. - """ - scheme, netloc, path, query, fragment = parse.urlsplit( - url, scheme, allow_fragments) - if allow_fragments and '#' in path: - path, fragment = path.split('#', 1) - if '?' in path: - path, query = path.split('?', 1) - return ModifiedSplitResult(scheme, netloc, - path, query, fragment) - - -def set_tcp_keepalive(sock, tcp_keepalive=True, - tcp_keepidle=None, - tcp_keepalive_interval=None, - tcp_keepalive_count=None): - """Set values for tcp keepalive parameters - - This function configures tcp keepalive parameters if users wish to do - so. - - :param tcp_keepalive: Boolean, turn on or off tcp_keepalive. If users are - not sure, this should be True, and default values will be used. - - :param tcp_keepidle: time to wait before starting to send keepalive probes - :param tcp_keepalive_interval: time between successive probes, once the - initial wait time is over - :param tcp_keepalive_count: number of probes to send before the connection - is killed - """ - - # NOTE(praneshp): Despite keepalive being a tcp concept, the level is - # still SOL_SOCKET. This is a quirk. - if isinstance(tcp_keepalive, bool): - sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, tcp_keepalive) - else: - raise TypeError("tcp_keepalive must be a boolean") - - if not tcp_keepalive: - return - - # These options aren't available in the OS X version of eventlet, - # Idle + Count * Interval effectively gives you the total timeout. - if tcp_keepidle is not None: - if hasattr(socket, 'TCP_KEEPIDLE'): - sock.setsockopt(socket.IPPROTO_TCP, - socket.TCP_KEEPIDLE, - tcp_keepidle) - else: - LOG.warning(_LW('tcp_keepidle not available on your system')) - if tcp_keepalive_interval is not None: - if hasattr(socket, 'TCP_KEEPINTVL'): - sock.setsockopt(socket.IPPROTO_TCP, - socket.TCP_KEEPINTVL, - tcp_keepalive_interval) - else: - LOG.warning(_LW('tcp_keepintvl not available on your system')) - if tcp_keepalive_count is not None: - if hasattr(socket, 'TCP_KEEPCNT'): - sock.setsockopt(socket.IPPROTO_TCP, - socket.TCP_KEEPCNT, - tcp_keepalive_count) - else: - LOG.warning(_LW('tcp_keepknt not available on your system')) diff --git a/ceilometer/openstack/common/units.py b/ceilometer/openstack/common/units.py deleted file mode 100644 index 4817da509..000000000 --- a/ceilometer/openstack/common/units.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright 2013 IBM Corp -# All Rights Reserved. -# -# 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. - -""" -Unit constants -""" - -# Binary unit constants. -Ki = 1024 -Mi = 1024 ** 2 -Gi = 1024 ** 3 -Ti = 1024 ** 4 -Pi = 1024 ** 5 -Ei = 1024 ** 6 -Zi = 1024 ** 7 -Yi = 1024 ** 8 - -# Decimal unit constants. -k = 1000 -M = 1000 ** 2 -G = 1000 ** 3 -T = 1000 ** 4 -P = 1000 ** 5 -E = 1000 ** 6 -Z = 1000 ** 7 -Y = 1000 ** 8 diff --git a/ceilometer/publisher/__init__.py b/ceilometer/publisher/__init__.py index 8fdeaa059..acee885f1 100644 --- a/ceilometer/publisher/__init__.py +++ b/ceilometer/publisher/__init__.py @@ -1,6 +1,6 @@ # # Copyright 2013 Intel Corp. -# Copyright 2013 eNovance +# Copyright 2013-2014 eNovance # # Author: Yunhong Jiang # Julien Danjou @@ -19,11 +19,10 @@ import abc +from oslo.utils import netutils import six from stevedore import driver -from ceilometer.openstack.common import network_utils - def get_publisher(url, namespace='ceilometer.publisher'): """Get publisher driver and load it. @@ -31,7 +30,7 @@ def get_publisher(url, namespace='ceilometer.publisher'): :param URL: URL for the publisher :param namespace: Namespace to use to look for drivers. """ - parse_result = network_utils.urlsplit(url) + parse_result = netutils.urlsplit(url) loaded_driver = driver.DriverManager(namespace, parse_result.scheme) return loaded_driver.driver(parse_result) diff --git a/ceilometer/publisher/udp.py b/ceilometer/publisher/udp.py index 6baac0740..46797a1a0 100644 --- a/ceilometer/publisher/udp.py +++ b/ceilometer/publisher/udp.py @@ -22,10 +22,10 @@ import socket import msgpack from oslo.config import cfg +from oslo.utils import netutils from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils from ceilometer import publisher from ceilometer.publisher import utils @@ -37,7 +37,7 @@ LOG = log.getLogger(__name__) class UDPPublisher(publisher.PublisherBase): def __init__(self, parsed_url): - self.host, self.port = network_utils.parse_host_port( + self.host, self.port = netutils.parse_host_port( parsed_url.netloc, default_port=cfg.CONF.collector.udp_port) self.socket = socket.socket(socket.AF_INET, diff --git a/ceilometer/storage/base.py b/ceilometer/storage/base.py index 769e3a44b..fd0f072e4 100644 --- a/ceilometer/storage/base.py +++ b/ceilometer/storage/base.py @@ -21,11 +21,10 @@ import datetime import inspect import math +from oslo.utils import timeutils import six from six import moves -from ceilometer.openstack.common import timeutils - def iter_period(start, end, period): """Split a time from start to end in periods of a number of seconds. diff --git a/ceilometer/storage/impl_db2.py b/ceilometer/storage/impl_db2.py index 4f21f1953..899b5df05 100644 --- a/ceilometer/storage/impl_db2.py +++ b/ceilometer/storage/impl_db2.py @@ -28,11 +28,11 @@ import sys import bson.code import bson.objectid +from oslo.utils import timeutils import pymongo import six from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import storage from ceilometer.storage import base from ceilometer.storage import models diff --git a/ceilometer/storage/impl_hbase.py b/ceilometer/storage/impl_hbase.py index 5da907205..24b12bf4a 100644 --- a/ceilometer/storage/impl_hbase.py +++ b/ceilometer/storage/impl_hbase.py @@ -18,12 +18,12 @@ import os import time import happybase +from oslo.utils import netutils +from oslo.utils import timeutils from six.moves.urllib import parse as urlparse from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils -from ceilometer.openstack.common import timeutils from ceilometer.storage import base from ceilometer.storage.hbase import inmemory as hbase_inmemory from ceilometer.storage.hbase import utils as hbase_utils @@ -205,7 +205,7 @@ class Connection(base.Connection): database name, so we are not looking for these in the url. """ opts = {} - result = network_utils.urlsplit(url) + result = netutils.urlsplit(url) opts['table_prefix'] = urlparse.parse_qs( result.query).get('table_prefix', [None])[0] opts['dbtype'] = result.scheme diff --git a/ceilometer/storage/impl_mongodb.py b/ceilometer/storage/impl_mongodb.py index 3110850f8..2b432767e 100644 --- a/ceilometer/storage/impl_mongodb.py +++ b/ceilometer/storage/impl_mongodb.py @@ -30,11 +30,11 @@ import uuid import bson.code import bson.objectid from oslo.config import cfg +from oslo.utils import timeutils import pymongo import six from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import storage from ceilometer.storage import base from ceilometer.storage import models diff --git a/ceilometer/storage/impl_sqlalchemy.py b/ceilometer/storage/impl_sqlalchemy.py index 94feb5ffa..53ac5a8d4 100644 --- a/ceilometer/storage/impl_sqlalchemy.py +++ b/ceilometer/storage/impl_sqlalchemy.py @@ -22,6 +22,7 @@ import operator import os from oslo.config import cfg +from oslo.utils import timeutils import six from sqlalchemy import and_ from sqlalchemy import distinct @@ -33,7 +34,6 @@ from ceilometer.openstack.common.db.sqlalchemy import migration import ceilometer.openstack.common.db.sqlalchemy.session as sqlalchemy_session from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import storage from ceilometer.storage import base from ceilometer.storage import models as api_models diff --git a/ceilometer/storage/models.py b/ceilometer/storage/models.py index fe874fb9d..9f707c52e 100644 --- a/ceilometer/storage/models.py +++ b/ceilometer/storage/models.py @@ -16,8 +16,8 @@ # under the License. """Model classes for use in the storage API. """ +from oslo.utils import timeutils -from ceilometer.openstack.common import timeutils from ceilometer.storage import base diff --git a/ceilometer/storage/mongo/utils.py b/ceilometer/storage/mongo/utils.py index fe337651e..5f2ad07b0 100644 --- a/ceilometer/storage/mongo/utils.py +++ b/ceilometer/storage/mongo/utils.py @@ -22,13 +22,13 @@ import time from oslo.config import cfg +from oslo.utils import netutils import pymongo import six import weakref from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import network_utils LOG = log.getLogger(__name__) @@ -171,7 +171,7 @@ class ConnectionPool(object): client = self._pool.get(pool_key)() if client: return client - splitted_url = network_utils.urlsplit(url) + splitted_url = netutils.urlsplit(url) log_data = {'db': splitted_url.scheme, 'nodelist': connection_options['nodelist']} LOG.info(_('Connecting to %(db)s on %(nodelist)s') % log_data) diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/005_remove_resource_timestamp.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/005_remove_resource_timestamp.py index 0dd422c30..0659fd84d 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/005_remove_resource_timestamp.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/005_remove_resource_timestamp.py @@ -14,11 +14,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from oslo.utils import timeutils from sqlalchemy import MetaData, Table, Column, DateTime -from ceilometer.openstack.common import timeutils - def upgrade(migrate_engine): meta = MetaData(bind=migrate_engine) diff --git a/ceilometer/storage/sqlalchemy/migrate_repo/versions/029_sample_recorded_at.py b/ceilometer/storage/sqlalchemy/migrate_repo/versions/029_sample_recorded_at.py index ee9f2dc7b..722d7107f 100644 --- a/ceilometer/storage/sqlalchemy/migrate_repo/versions/029_sample_recorded_at.py +++ b/ceilometer/storage/sqlalchemy/migrate_repo/versions/029_sample_recorded_at.py @@ -10,10 +10,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from oslo.utils import timeutils import sqlalchemy -from ceilometer.openstack.common import timeutils from ceilometer.storage.sqlalchemy import models diff --git a/ceilometer/storage/sqlalchemy/models.py b/ceilometer/storage/sqlalchemy/models.py index 97374b4bc..a494a8bcc 100644 --- a/ceilometer/storage/sqlalchemy/models.py +++ b/ceilometer/storage/sqlalchemy/models.py @@ -19,6 +19,7 @@ SQLAlchemy models for Ceilometer data. import json +from oslo.utils import timeutils import six from sqlalchemy import (Column, Integer, String, ForeignKey, Index, UniqueConstraint, BigInteger, join) @@ -30,7 +31,6 @@ from sqlalchemy.orm import column_property from sqlalchemy.orm import relationship from sqlalchemy.types import TypeDecorator -from ceilometer.openstack.common import timeutils from ceilometer.storage import models as api_models from ceilometer import utils diff --git a/ceilometer/tests/alarm/evaluator/test_base.py b/ceilometer/tests/alarm/evaluator/test_base.py index 634997981..0f4239c1b 100644 --- a/ceilometer/tests/alarm/evaluator/test_base.py +++ b/ceilometer/tests/alarm/evaluator/test_base.py @@ -17,11 +17,12 @@ """class for tests in ceilometer/alarm/evaluator/__init__.py """ import datetime + import mock +from oslo.utils import timeutils from oslotest import base from ceilometer.alarm import evaluator -from ceilometer.openstack.common import timeutils class TestEvaluatorBaseClass(base.BaseTestCase): diff --git a/ceilometer/tests/alarm/evaluator/test_combination.py b/ceilometer/tests/alarm/evaluator/test_combination.py index 504caa038..c59ba3a16 100644 --- a/ceilometer/tests/alarm/evaluator/test_combination.py +++ b/ceilometer/tests/alarm/evaluator/test_combination.py @@ -21,9 +21,10 @@ import mock import pytz import uuid +from oslo.utils import timeutils + from ceilometer.alarm.evaluator import combination from ceilometer.alarm.storage import models -from ceilometer.openstack.common import timeutils from ceilometer.tests.alarm.evaluator import base from ceilometerclient import exc from ceilometerclient.v2 import alarms diff --git a/ceilometer/tests/alarm/evaluator/test_threshold.py b/ceilometer/tests/alarm/evaluator/test_threshold.py index 6a4ca1975..d02b7b551 100644 --- a/ceilometer/tests/alarm/evaluator/test_threshold.py +++ b/ceilometer/tests/alarm/evaluator/test_threshold.py @@ -21,11 +21,11 @@ import mock import pytz import uuid +from oslo.utils import timeutils from six import moves from ceilometer.alarm.evaluator import threshold from ceilometer.alarm.storage import models -from ceilometer.openstack.common import timeutils from ceilometer.tests.alarm.evaluator import base from ceilometerclient import exc from ceilometerclient.v2 import statistics diff --git a/ceilometer/tests/alarm/partition/test_coordination.py b/ceilometer/tests/alarm/partition/test_coordination.py index 242855a7d..c9dbcd74c 100644 --- a/ceilometer/tests/alarm/partition/test_coordination.py +++ b/ceilometer/tests/alarm/partition/test_coordination.py @@ -22,11 +22,11 @@ import uuid import mock from oslo.config import fixture as fixture_config +from oslo.utils import timeutils from six import moves from ceilometer.alarm.partition import coordination from ceilometer.alarm.storage import models -from ceilometer.openstack.common import timeutils from ceilometer.tests import base as tests_base diff --git a/ceilometer/tests/alarm/test_notifier.py b/ceilometer/tests/alarm/test_notifier.py index e5f668470..f4cbd0b8f 100644 --- a/ceilometer/tests/alarm/test_notifier.py +++ b/ceilometer/tests/alarm/test_notifier.py @@ -211,7 +211,7 @@ class TestAlarmNotifier(tests_base.BaseTestCase): raise Exception("Evil urlsplit!") def test_notify_alarm_invalid_url(self): - with mock.patch('ceilometer.openstack.common.network_utils.urlsplit', + with mock.patch('oslo.utils.netutils.urlsplit', self._fake_urlsplit): LOG = mock.MagicMock() with mock.patch('ceilometer.alarm.service.LOG', LOG): diff --git a/ceilometer/tests/alarm/test_rpc.py b/ceilometer/tests/alarm/test_rpc.py index 0e73000de..1a54b02fb 100644 --- a/ceilometer/tests/alarm/test_rpc.py +++ b/ceilometer/tests/alarm/test_rpc.py @@ -20,12 +20,12 @@ import uuid from ceilometerclient.v2 import alarms import eventlet from oslo.config import fixture as fixture_config +from oslo.utils import timeutils import six from ceilometer.alarm import rpc as rpc_alarm from ceilometer.alarm.storage import models from ceilometer import messaging -from ceilometer.openstack.common import timeutils from ceilometer.tests import base as tests_base diff --git a/ceilometer/tests/api/v2/test_acl_scenarios.py b/ceilometer/tests/api/v2/test_acl_scenarios.py index 3b95ef260..feb307197 100644 --- a/ceilometer/tests/api/v2/test_acl_scenarios.py +++ b/ceilometer/tests/api/v2/test_acl_scenarios.py @@ -19,11 +19,11 @@ import datetime import json +from oslo.utils import timeutils import webtest from ceilometer.api import app from ceilometer.api.controllers import v2 as v2_api -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer.tests import api as acl diff --git a/ceilometer/tests/api/v2/test_complex_query_scenarios.py b/ceilometer/tests/api/v2/test_complex_query_scenarios.py index 70c346e12..0040d173b 100644 --- a/ceilometer/tests/api/v2/test_complex_query_scenarios.py +++ b/ceilometer/tests/api/v2/test_complex_query_scenarios.py @@ -20,8 +20,9 @@ import datetime +from oslo.utils import timeutils + from ceilometer.alarm.storage import models -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer.tests.api import v2 as tests_api diff --git a/ceilometer/tests/api/v2/test_compute_duration_by_resource_scenarios.py b/ceilometer/tests/api/v2/test_compute_duration_by_resource_scenarios.py index dce587c3b..e962f7ff1 100644 --- a/ceilometer/tests/api/v2/test_compute_duration_by_resource_scenarios.py +++ b/ceilometer/tests/api/v2/test_compute_duration_by_resource_scenarios.py @@ -20,8 +20,8 @@ import datetime import mock +from oslo.utils import timeutils -from ceilometer.openstack.common import timeutils from ceilometer.storage import models from ceilometer.tests.api import v2 from ceilometer.tests import db as tests_db diff --git a/ceilometer/tests/api/v2/test_event_scenarios.py b/ceilometer/tests/api/v2/test_event_scenarios.py index 0e8c50c9b..a07e2dd02 100644 --- a/ceilometer/tests/api/v2/test_event_scenarios.py +++ b/ceilometer/tests/api/v2/test_event_scenarios.py @@ -16,7 +16,8 @@ import datetime -from ceilometer.openstack.common import timeutils +from oslo.utils import timeutils + from ceilometer.storage import models from ceilometer.tests.api import v2 from ceilometer.tests import db as tests_db diff --git a/ceilometer/tests/api/v2/test_list_events_scenarios.py b/ceilometer/tests/api/v2/test_list_events_scenarios.py index da1c05a04..6a6e60ab5 100644 --- a/ceilometer/tests/api/v2/test_list_events_scenarios.py +++ b/ceilometer/tests/api/v2/test_list_events_scenarios.py @@ -20,10 +20,10 @@ import datetime import mock +from oslo.utils import timeutils import six import webtest.app -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer.tests.api import v2 diff --git a/ceilometer/tests/api/v2/test_list_resources_scenarios.py b/ceilometer/tests/api/v2/test_list_resources_scenarios.py index 2a43135e6..6789d0b69 100644 --- a/ceilometer/tests/api/v2/test_list_resources_scenarios.py +++ b/ceilometer/tests/api/v2/test_list_resources_scenarios.py @@ -20,9 +20,9 @@ import datetime import json +from oslo.utils import timeutils import six -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer.tests.api import v2 diff --git a/ceilometer/tests/api/v2/test_post_samples_scenarios.py b/ceilometer/tests/api/v2/test_post_samples_scenarios.py index 05be04208..1f3ceab71 100644 --- a/ceilometer/tests/api/v2/test_post_samples_scenarios.py +++ b/ceilometer/tests/api/v2/test_post_samples_scenarios.py @@ -21,9 +21,9 @@ import copy import datetime import mock +from oslo.utils import timeutils from oslotest import mockpatch -from ceilometer.openstack.common import timeutils from ceilometer.tests.api import v2 from ceilometer.tests import db as tests_db diff --git a/ceilometer/tests/api/v2/test_query.py b/ceilometer/tests/api/v2/test_query.py index 6d428e8f1..c23f5d384 100644 --- a/ceilometer/tests/api/v2/test_query.py +++ b/ceilometer/tests/api/v2/test_query.py @@ -18,12 +18,12 @@ import datetime import fixtures import mock +from oslo.utils import timeutils from oslotest import base from oslotest import mockpatch import wsme from ceilometer.api.controllers import v2 as api -from ceilometer.openstack.common import timeutils from ceilometer import storage from ceilometer.tests import base as tests_base diff --git a/ceilometer/tests/base.py b/ceilometer/tests/base.py index 9fe7f3d39..a43d85669 100644 --- a/ceilometer/tests/base.py +++ b/ceilometer/tests/base.py @@ -22,13 +22,13 @@ import os.path import eventlet import oslo.messaging.conffixture +from oslo.utils import timeutils from oslotest import base from oslotest import mockpatch import six from testtools import testcase from ceilometer import messaging -from ceilometer.openstack.common import timeutils class BaseTestCase(base.BaseTestCase): diff --git a/ceilometer/tests/compute/virt/hyperv/test_inspector.py b/ceilometer/tests/compute/virt/hyperv/test_inspector.py index 6402cd59a..0f2424c66 100644 --- a/ceilometer/tests/compute/virt/hyperv/test_inspector.py +++ b/ceilometer/tests/compute/virt/hyperv/test_inspector.py @@ -18,10 +18,10 @@ Tests for Hyper-V inspector. """ import mock +from oslo.utils import units from oslotest import base from ceilometer.compute.virt.hyperv import inspector as hyperv_inspector -from ceilometer.openstack.common import units class TestHyperVInspection(base.BaseTestCase): diff --git a/ceilometer/tests/event/test_converter.py b/ceilometer/tests/event/test_converter.py index 30cdf9611..22504445c 100644 --- a/ceilometer/tests/event/test_converter.py +++ b/ceilometer/tests/event/test_converter.py @@ -546,7 +546,7 @@ class TestEventDefinition(ConverterBase): edef = converter.EventDefinition(cfg, self.fake_plugin_mgr) self.assertTrue(edef.is_catchall) - @mock.patch('ceilometer.openstack.common.timeutils.utcnow') + @mock.patch('oslo.utils.timeutils.utcnow') def test_extract_when(self, mock_utcnow): now = datetime.datetime.utcnow() modified = now + datetime.timedelta(minutes=1) @@ -623,7 +623,7 @@ class TestNotificationConverter(ConverterBase): host='cydonia') self.fake_plugin_mgr = {} - @mock.patch('ceilometer.openstack.common.timeutils.utcnow') + @mock.patch('oslo.utils.timeutils.utcnow') def test_converter_missing_keys(self, mock_utcnow): # test a malformed notification now = datetime.datetime.utcnow() diff --git a/ceilometer/tests/hardware/inspector/test_inspector.py b/ceilometer/tests/hardware/inspector/test_inspector.py index b4bf20f11..75c0debaa 100644 --- a/ceilometer/tests/hardware/inspector/test_inspector.py +++ b/ceilometer/tests/hardware/inspector/test_inspector.py @@ -14,20 +14,20 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +from oslo.utils import netutils from ceilometer.hardware import inspector -from ceilometer.openstack.common import network_utils from ceilometer.tests import base class TestHardwareInspector(base.BaseTestCase): def test_get_inspector(self): - url = network_utils.urlsplit("snmp://") + url = netutils.urlsplit("snmp://") driver = inspector.get_inspector(url) self.assertTrue(driver) def test_get_inspector_illegal(self): - url = network_utils.urlsplit("illegal://") + url = netutils.urlsplit("illegal://") self.assertRaises(RuntimeError, inspector.get_inspector, url) diff --git a/ceilometer/tests/hardware/inspector/test_snmp.py b/ceilometer/tests/hardware/inspector/test_snmp.py index 1d2b052e1..617d74f17 100644 --- a/ceilometer/tests/hardware/inspector/test_snmp.py +++ b/ceilometer/tests/hardware/inspector/test_snmp.py @@ -16,10 +16,10 @@ # under the License. """Tests for ceilometer/hardware/inspector/snmp/inspector.py """ +from oslo.utils import netutils from oslotest import mockpatch from ceilometer.hardware.inspector import snmp -from ceilometer.openstack.common import network_utils from ceilometer.tests import base as test_base from ceilometer.tests.hardware.inspector import base @@ -250,7 +250,7 @@ class TestSNMPInspector(Base, test_base.BaseTestCase): def setUp(self): super(TestSNMPInspector, self).setUp() self.inspector = snmp.SNMPInspector() - self.host = network_utils.urlsplit("snmp://localhost") + self.host = netutils.urlsplit("snmp://localhost") self.inspector.MAPPING = self.mapping self.useFixture(mockpatch.PatchObject( self.inspector._cmdGen, 'getCmd', new=faux_getCmd)) diff --git a/ceilometer/tests/network/statistics/test_statistics.py b/ceilometer/tests/network/statistics/test_statistics.py index fd55d3365..3493a8756 100644 --- a/ceilometer/tests/network/statistics/test_statistics.py +++ b/ceilometer/tests/network/statistics/test_statistics.py @@ -15,11 +15,11 @@ import datetime +from oslo.utils import timeutils from oslotest import base from ceilometer.network import statistics from ceilometer.network.statistics import driver -from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/tests/pipeline_base.py b/ceilometer/tests/pipeline_base.py index 16acfa12d..aa72c432b 100644 --- a/ceilometer/tests/pipeline_base.py +++ b/ceilometer/tests/pipeline_base.py @@ -22,12 +22,12 @@ import datetime import traceback import mock +from oslo.utils import timeutils from oslotest import base from oslotest import mockpatch import six from stevedore import extension -from ceilometer.openstack.common import timeutils from ceilometer import pipeline from ceilometer import publisher from ceilometer.publisher import test as test_publisher diff --git a/ceilometer/tests/publisher/test_file.py b/ceilometer/tests/publisher/test_file.py index 19c6ea72d..b924d20cf 100644 --- a/ceilometer/tests/publisher/test_file.py +++ b/ceilometer/tests/publisher/test_file.py @@ -1,5 +1,5 @@ # -# Copyright 2013 eNovance +# Copyright 2013-2014 eNovance # # Author: Julien Danjou # @@ -22,9 +22,9 @@ import logging.handlers import os import tempfile +from oslo.utils import netutils from oslotest import base -from ceilometer.openstack.common import network_utils as utils from ceilometer.publisher import file from ceilometer import sample @@ -71,8 +71,8 @@ class TestFilePublisher(base.BaseTestCase): # Test valid configurations tempdir = tempfile.mkdtemp() name = '%s/log_file' % tempdir - parsed_url = utils.urlsplit('file://%s?max_bytes=50&backup_count=3' - % name) + parsed_url = netutils.urlsplit('file://%s?max_bytes=50&backup_count=3' + % name) publisher = file.FilePublisher(parsed_url) publisher.publish_samples(None, self.test_data) @@ -90,7 +90,7 @@ class TestFilePublisher(base.BaseTestCase): # Test missing max bytes, backup count configurations tempdir = tempfile.mkdtemp() name = '%s/log_file_plain' % tempdir - parsed_url = utils.urlsplit('file://%s' % name) + parsed_url = netutils.urlsplit('file://%s' % name) publisher = file.FilePublisher(parsed_url) publisher.publish_samples(None, self.test_data) @@ -112,7 +112,7 @@ class TestFilePublisher(base.BaseTestCase): def test_file_publisher_invalid(self): # Test invalid max bytes, backup count configurations tempdir = tempfile.mkdtemp() - parsed_url = utils.urlsplit( + parsed_url = netutils.urlsplit( 'file://%s/log_file_bad' '?max_bytes=yus&backup_count=5y' % tempdir) publisher = file.FilePublisher(parsed_url) diff --git a/ceilometer/tests/publisher/test_rpc_publisher.py b/ceilometer/tests/publisher/test_rpc_publisher.py index 6a2b55cfa..427be665c 100644 --- a/ceilometer/tests/publisher/test_rpc_publisher.py +++ b/ceilometer/tests/publisher/test_rpc_publisher.py @@ -24,10 +24,10 @@ import mock from oslo.config import fixture as fixture_config import oslo.messaging import oslo.messaging._drivers.common +from oslo.utils import netutils from ceilometer import messaging from ceilometer.openstack.common import context -from ceilometer.openstack.common import network_utils from ceilometer.publisher import rpc from ceilometer import sample from ceilometer.tests import base as tests_base @@ -100,7 +100,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_no_mock(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://')) + netutils.urlsplit('rpc://')) endpoint = mock.MagicMock(['record_metering_data']) collector = messaging.get_rpc_server( @@ -127,7 +127,7 @@ class TestPublish(tests_base.BaseTestCase): def test_publish_target(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?target=custom_procedure_call')) + netutils.urlsplit('rpc://?target=custom_procedure_call')) cast_context = mock.MagicMock() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.return_value = cast_context @@ -141,7 +141,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_per_meter_topic(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?per_meter_topic=1')) + netutils.urlsplit('rpc://?per_meter_topic=1')) with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: publisher.publish_samples(mock.MagicMock(), self.test_data) @@ -169,7 +169,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_concurrency(self): """Test concurrent access to the local queue of the rpc publisher.""" - publisher = rpc.RPCPublisher(network_utils.urlsplit('rpc://')) + publisher = rpc.RPCPublisher(netutils.urlsplit('rpc://')) cast_context = mock.MagicMock() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: @@ -199,7 +199,7 @@ class TestPublish(tests_base.BaseTestCase): @mock.patch('ceilometer.publisher.rpc.LOG') def test_published_with_no_policy(self, mylog): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://')) + netutils.urlsplit('rpc://')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.side_effect = side_effect @@ -217,7 +217,7 @@ class TestPublish(tests_base.BaseTestCase): @mock.patch('ceilometer.publisher.rpc.LOG') def test_published_with_policy_block(self, mylog): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=default')) + netutils.urlsplit('rpc://?policy=default')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.side_effect = side_effect @@ -233,7 +233,7 @@ class TestPublish(tests_base.BaseTestCase): @mock.patch('ceilometer.publisher.rpc.LOG') def test_published_with_policy_incorrect(self, mylog): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=notexist')) + netutils.urlsplit('rpc://?policy=notexist')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.side_effect = side_effect @@ -249,7 +249,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_policy_drop_and_rpc_down(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=drop')) + netutils.urlsplit('rpc://?policy=drop')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.side_effect = side_effect @@ -261,7 +261,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_policy_queue_and_rpc_down(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=queue')) + netutils.urlsplit('rpc://?policy=queue')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: prepare.side_effect = side_effect @@ -275,7 +275,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_policy_queue_and_rpc_down_up(self): self.rpc_unreachable = True publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=queue')) + netutils.urlsplit('rpc://?policy=queue')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: @@ -299,7 +299,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_policy_sized_queue_and_rpc_down(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=queue&max_queue_length=3')) + netutils.urlsplit('rpc://?policy=queue&max_queue_length=3')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: @@ -326,7 +326,7 @@ class TestPublish(tests_base.BaseTestCase): def test_published_with_policy_default_sized_queue_and_rpc_down(self): publisher = rpc.RPCPublisher( - network_utils.urlsplit('rpc://?policy=queue')) + netutils.urlsplit('rpc://?policy=queue')) side_effect = oslo.messaging._drivers.common.RPCException() with mock.patch.object(publisher.rpc_client, 'prepare') as prepare: diff --git a/ceilometer/tests/publisher/test_udp.py b/ceilometer/tests/publisher/test_udp.py index 751b517d9..bc3b297f3 100644 --- a/ceilometer/tests/publisher/test_udp.py +++ b/ceilometer/tests/publisher/test_udp.py @@ -1,5 +1,5 @@ # -# Copyright 2013 eNovance +# Copyright 2013-2014 eNovance # # Author: Julien Danjou # @@ -22,9 +22,9 @@ import datetime import mock import msgpack from oslo.config import fixture as fixture_config +from oslo.utils import netutils from oslotest import base -from ceilometer.openstack.common import network_utils from ceilometer.publisher import udp from ceilometer.publisher import utils from ceilometer import sample @@ -118,7 +118,7 @@ class TestUDPPublisher(base.BaseTestCase): with mock.patch('socket.socket', self._make_fake_socket(self.data_sent)): publisher = udp.UDPPublisher( - network_utils.urlsplit('udp://somehost')) + netutils.urlsplit('udp://somehost')) publisher.publish_samples(None, self.test_data) @@ -152,6 +152,6 @@ class TestUDPPublisher(base.BaseTestCase): with mock.patch('socket.socket', self._make_broken_socket): publisher = udp.UDPPublisher( - network_utils.urlsplit('udp://localhost')) + netutils.urlsplit('udp://localhost')) publisher.publish_samples(None, self.test_data) diff --git a/ceilometer/tests/storage/test_impl_sqlalchemy.py b/ceilometer/tests/storage/test_impl_sqlalchemy.py index 7d5ba9314..b58fd22c9 100644 --- a/ceilometer/tests/storage/test_impl_sqlalchemy.py +++ b/ceilometer/tests/storage/test_impl_sqlalchemy.py @@ -26,9 +26,9 @@ import datetime import repr import mock +from oslo.utils import timeutils from ceilometer.alarm.storage import impl_sqlalchemy as impl_sqla_alarm -from ceilometer.openstack.common import timeutils from ceilometer.storage import impl_sqlalchemy from ceilometer.storage import models from ceilometer.storage.sqlalchemy import models as sql_models diff --git a/ceilometer/tests/storage/test_storage_scenarios.py b/ceilometer/tests/storage/test_storage_scenarios.py index 2a929ec10..af014bf05 100644 --- a/ceilometer/tests/storage/test_storage_scenarios.py +++ b/ceilometer/tests/storage/test_storage_scenarios.py @@ -23,9 +23,9 @@ import datetime import operator import mock +from oslo.utils import timeutils from ceilometer.alarm.storage import models as alarm_models -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer import storage diff --git a/ceilometer/tests/test_collector.py b/ceilometer/tests/test_collector.py index 64a32ba99..ea4d067a0 100644 --- a/ceilometer/tests/test_collector.py +++ b/ceilometer/tests/test_collector.py @@ -21,6 +21,7 @@ import mock import msgpack from oslo.config import fixture as fixture_config import oslo.messaging +from oslo.utils import timeutils from oslotest import mockpatch from stevedore import extension @@ -28,7 +29,6 @@ from ceilometer import collector from ceilometer import dispatcher from ceilometer import messaging from ceilometer.openstack.common import context -from ceilometer.openstack.common import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer.tests import base as tests_base diff --git a/ceilometer/tests/test_notification.py b/ceilometer/tests/test_notification.py index 6d4ed2a9b..c105d9a0c 100644 --- a/ceilometer/tests/test_notification.py +++ b/ceilometer/tests/test_notification.py @@ -21,6 +21,7 @@ import mock from oslo.config import fixture as fixture_config import oslo.messaging import oslo.messaging.conffixture +from oslo.utils import timeutils from stevedore import extension import yaml @@ -29,7 +30,6 @@ from ceilometer import messaging from ceilometer import notification from ceilometer.openstack.common import context from ceilometer.openstack.common import fileutils -from ceilometer.openstack.common import timeutils from ceilometer.publisher import test as test_publisher from ceilometer.tests import base as tests_base diff --git a/ceilometer/transformer/conversions.py b/ceilometer/transformer/conversions.py index 0d4c185df..ec9946772 100644 --- a/ceilometer/transformer/conversions.py +++ b/ceilometer/transformer/conversions.py @@ -18,11 +18,11 @@ import collections import re +from oslo.utils import timeutils import six from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log -from ceilometer.openstack.common import timeutils from ceilometer import sample from ceilometer import transformer diff --git a/ceilometer/utils.py b/ceilometer/utils.py index b26d99f5f..674c8a2fb 100644 --- a/ceilometer/utils.py +++ b/ceilometer/utils.py @@ -24,11 +24,10 @@ import datetime import decimal import multiprocessing +from oslo.utils import timeutils +from oslo.utils import units import six -from ceilometer.openstack.common import timeutils -from ceilometer.openstack.common import units - def recursive_keypairs(d, separator=':'): """Generator that produces sequence of keypairs for nested dictionaries.""" diff --git a/nova_tests/test_notifier.py b/nova_tests/test_notifier.py index ec16c2322..1e466f746 100644 --- a/nova_tests/test_notifier.py +++ b/nova_tests/test_notifier.py @@ -22,8 +22,10 @@ import contextlib import datetime import mock +from oslo.utils import importutils from oslotest import base from oslotest import moxstubout + from stevedore import extension ## NOTE(dhellmann): These imports are not in the generally approved @@ -40,7 +42,6 @@ from nova.objects import instance as nova_instance from nova import config from nova import context from nova import db -from nova.openstack.common import importutils from nova.openstack.common import log as logging # This option is used in the nova_notifier module, so make diff --git a/openstack-common.conf b/openstack-common.conf index 4817472a4..ff4442fa4 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -6,9 +6,7 @@ module=context module=db module=db.sqlalchemy module=eventlet_backdoor -module=excutils module=gettextutils -module=importutils module=jsonutils module=local module=log @@ -20,13 +18,9 @@ module=middleware.correlation_id module=middleware.debug module=middleware.request_id module=middleware.sizelimit -module=network_utils module=policy module=service -module=strutils module=threadgroup -module=timeutils -module=units # The base module to hold the copy of openstack.common base=ceilometer diff --git a/requirements-py3.txt b/requirements-py3.txt index 411560d84..0706d6fa1 100644 --- a/requirements-py3.txt +++ b/requirements-py3.txt @@ -16,6 +16,7 @@ pbr>=0.6,!=0.7,<1.0 pecan>=0.5.0 posix_ipc oslo.messaging>=1.3.0 +oslo.utils>=0.2.0 pysnmp>=4.2.1,<5.0.0 python-ceilometerclient>=1.0.6 python-glanceclient>=0.13.1 diff --git a/requirements.txt b/requirements.txt index 689c16c91..c4b0ebf7d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ pbr>=0.6,!=0.7,<1.0 pecan>=0.5.0 posix_ipc oslo.messaging>=1.3.0 +oslo.utils>=0.2.0 pysnmp>=4.2.1,<5.0.0 python-ceilometerclient>=1.0.6 python-glanceclient>=0.13.1 diff --git a/tools/make_test_data.py b/tools/make_test_data.py index c1918cbac..9f3b069ed 100755 --- a/tools/make_test_data.py +++ b/tools/make_test_data.py @@ -34,11 +34,12 @@ import random import sys from oslo.config import cfg +from oslo.utils import timeutils from ceilometer.publisher import utils from ceilometer import sample from ceilometer import storage -from ceilometer.openstack.common import timeutils + def make_test_data(conn, name, meter_type, unit, volume, random_min, random_max, user_id, project_id, resource_id, start,