From 5418ee4f01588ed9aa86d05b91b0464047520801 Mon Sep 17 00:00:00 2001 From: Gordon Chung Date: Mon, 16 Jun 2014 16:35:59 -0400 Subject: [PATCH] use urlparse from six - six provides compatibility support for urlparse. lets use it. - cleanup import lines to be consistent. Change-Id: I655b64888a29dc1f34e51216f06b83e84fe25970 --- ceilometer/agent.py | 2 +- ceilometer/alarm/notifier/rest.py | 5 ++-- ceilometer/hardware/inspector/snmp.py | 4 +-- ceilometer/hardware/pollsters/util.py | 3 ++- ceilometer/network/statistics/__init__.py | 16 ++++++------ .../network/statistics/opencontrail/client.py | 6 ++--- .../network/statistics/opencontrail/driver.py | 16 ++++++------ .../network/statistics/opendaylight/driver.py | 16 ++++++------ ceilometer/objectstore/swift.py | 2 +- ceilometer/publisher/file.py | 3 ++- ceilometer/publisher/rpc.py | 2 +- ceilometer/storage/__init__.py | 3 +-- ceilometer/storage/impl_hbase.py | 2 +- ceilometer/tests/alarm/test_notifier.py | 2 +- ceilometer/tests/db.py | 2 +- .../statistics/opencontrail/test_driver.py | 8 +++--- .../statistics/opendaylight/test_client.py | 17 ++++++------ .../statistics/opendaylight/test_driver.py | 26 +++++++++---------- 18 files changed, 67 insertions(+), 68 deletions(-) diff --git a/ceilometer/agent.py b/ceilometer/agent.py index 0427a5b62..daa63b727 100644 --- a/ceilometer/agent.py +++ b/ceilometer/agent.py @@ -19,8 +19,8 @@ import collections import itertools -import urlparse +from six.moves.urllib import parse as urlparse from stevedore import extension from ceilometer.openstack.common import context diff --git a/ceilometer/alarm/notifier/rest.py b/ceilometer/alarm/notifier/rest.py index 6cd345fe6..0526a9a1b 100644 --- a/ceilometer/alarm/notifier/rest.py +++ b/ceilometer/alarm/notifier/rest.py @@ -17,10 +17,9 @@ """Rest alarm notifier.""" import eventlet -import requests -import six.moves.urllib.parse as urlparse - from oslo.config import cfg +import requests +from six.moves.urllib import parse as urlparse from ceilometer.alarm import notifier from ceilometer.openstack.common.gettextutils import _ diff --git a/ceilometer/hardware/inspector/snmp.py b/ceilometer/hardware/inspector/snmp.py index a408695a2..d98c8deda 100644 --- a/ceilometer/hardware/inspector/snmp.py +++ b/ceilometer/hardware/inspector/snmp.py @@ -17,10 +17,10 @@ # under the License. """Inspector for collecting data over SNMP""" -import urlparse +from pysnmp.entity.rfc3413.oneliner import cmdgen +from six.moves.urllib import parse as urlparse from ceilometer.hardware.inspector import base -from pysnmp.entity.rfc3413.oneliner import cmdgen class SNMPException(Exception): diff --git a/ceilometer/hardware/pollsters/util.py b/ceilometer/hardware/pollsters/util.py index addcab393..532302334 100644 --- a/ceilometer/hardware/pollsters/util.py +++ b/ceilometer/hardware/pollsters/util.py @@ -19,7 +19,8 @@ # under the License. import copy -import urlparse + +from six.moves.urllib import parse as urlparse from ceilometer.openstack.common import timeutils from ceilometer import sample diff --git a/ceilometer/network/statistics/__init__.py b/ceilometer/network/statistics/__init__.py index cbbcf28d3..53ef251d5 100644 --- a/ceilometer/network/statistics/__init__.py +++ b/ceilometer/network/statistics/__init__.py @@ -16,7 +16,7 @@ import abc import six -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from stevedore import driver as _driver from ceilometer.central import plugin @@ -47,13 +47,13 @@ class _Base(plugin.CentralPollster): parse_url = network_utils.urlsplit(resource) - params = url_parse.parse_qs(parse_url.query) - parts = url_parse.ParseResult(parse_url.scheme, - parse_url.netloc, - parse_url.path, - None, - None, - None) + params = urlparse.parse_qs(parse_url.query) + parts = urlparse.ParseResult(parse_url.scheme, + parse_url.netloc, + parse_url.path, + None, + None, + None) return parts, params @staticmethod diff --git a/ceilometer/network/statistics/opencontrail/client.py b/ceilometer/network/statistics/opencontrail/client.py index 2e6e6bdee..af0d3a391 100644 --- a/ceilometer/network/statistics/opencontrail/client.py +++ b/ceilometer/network/statistics/opencontrail/client.py @@ -17,7 +17,7 @@ from oslo.config import cfg import requests import six -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log @@ -51,7 +51,7 @@ class AnalyticsAPIBaseClient(object): 'domain': self.domain} req_params = self._get_req_params(data=data) - url = url_parse.urljoin(self.endpoint, path) + url = urlparse.urljoin(self.endpoint, path) resp = requests.post(url, **req_params) if resp.status_code != 302: raise OpencontrailAPIFailed( @@ -71,7 +71,7 @@ class AnalyticsAPIBaseClient(object): req_params = self._get_req_params(data=data, cookies={'connect.sid': self.sid}) - url = url_parse.urljoin(self.endpoint, path) + url = urlparse.urljoin(self.endpoint, path) self._log_req(url, req_params) resp = requests.get(url, **req_params) self._log_res(resp) diff --git a/ceilometer/network/statistics/opencontrail/driver.py b/ceilometer/network/statistics/opencontrail/driver.py index 105f36ad7..56552f917 100644 --- a/ceilometer/network/statistics/opencontrail/driver.py +++ b/ceilometer/network/statistics/opencontrail/driver.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.network.statistics import driver from ceilometer.network.statistics.opencontrail import client @@ -73,13 +73,13 @@ class OpencontrailDriver(driver.Driver): def get_sample_data(self, meter_name, parse_url, params, cache): - parts = url_parse.ParseResult(params.get('scheme', ['http'])[0], - parse_url.netloc, - parse_url.path, - None, - None, - None) - endpoint = url_parse.urlunparse(parts) + parts = urlparse.ParseResult(params.get('scheme', ['http'])[0], + parse_url.netloc, + parse_url.path, + None, + None, + None) + endpoint = urlparse.urlunparse(parts) iter = self._get_iter(meter_name) if iter is None: diff --git a/ceilometer/network/statistics/opendaylight/driver.py b/ceilometer/network/statistics/opendaylight/driver.py index 91c945022..5c000dadf 100644 --- a/ceilometer/network/statistics/opendaylight/driver.py +++ b/ceilometer/network/statistics/opendaylight/driver.py @@ -15,7 +15,7 @@ import six from six import moves -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.network.statistics import driver from ceilometer.network.statistics.opendaylight import client @@ -187,13 +187,13 @@ class OpenDayLightDriver(driver.Driver): # OpenDaylight REST API has not api to getting meter. return None - parts = url_parse.ParseResult(params.get('scheme', ['http'])[0], - parse_url.netloc, - parse_url.path, - None, - None, - None) - endpoint = url_parse.urlunparse(parts) + parts = urlparse.ParseResult(params.get('scheme', ['http'])[0], + parse_url.netloc, + parse_url.path, + None, + None, + None) + endpoint = urlparse.urlunparse(parts) data = self._prepare_cache(endpoint, params, cache) diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index c4a3cb469..cb2fd03f6 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -18,10 +18,10 @@ """ from __future__ import absolute_import -import six.moves.urllib.parse as urlparse from keystoneclient import exceptions from oslo.config import cfg +from six.moves.urllib import parse as urlparse from swiftclient import client as swift from ceilometer.central import plugin diff --git a/ceilometer/publisher/file.py b/ceilometer/publisher/file.py index 7b8baf270..2d1169a10 100644 --- a/ceilometer/publisher/file.py +++ b/ceilometer/publisher/file.py @@ -17,7 +17,8 @@ import logging import logging.handlers -import six.moves.urllib.parse as urlparse + +from six.moves.urllib import parse as urlparse from ceilometer.openstack.common.gettextutils import _ from ceilometer.openstack.common import log diff --git a/ceilometer/publisher/rpc.py b/ceilometer/publisher/rpc.py index 16d403750..e189d9117 100644 --- a/ceilometer/publisher/rpc.py +++ b/ceilometer/publisher/rpc.py @@ -20,11 +20,11 @@ import itertools import operator -import six.moves.urllib.parse as urlparse from oslo.config import cfg import oslo.messaging import oslo.messaging._drivers.common +from six.moves.urllib import parse as urlparse from ceilometer import messaging from ceilometer.openstack.common.gettextutils import _ diff --git a/ceilometer/storage/__init__.py b/ceilometer/storage/__init__.py index c7d40c788..93050c942 100644 --- a/ceilometer/storage/__init__.py +++ b/ceilometer/storage/__init__.py @@ -17,10 +17,9 @@ """Storage backend management """ -import six.moves.urllib.parse as urlparse - from oslo.config import cfg import six +from six.moves.urllib import parse as urlparse from stevedore import driver from ceilometer.openstack.common.gettextutils import _ diff --git a/ceilometer/storage/impl_hbase.py b/ceilometer/storage/impl_hbase.py index d620630a3..1bd5fcfcb 100644 --- a/ceilometer/storage/impl_hbase.py +++ b/ceilometer/storage/impl_hbase.py @@ -16,10 +16,10 @@ import datetime import hashlib import operator import os -import six.moves.urllib.parse as urlparse import time import happybase +from six.moves.urllib import parse as urlparse from ceilometer.alarm.storage import models as alarm_models from ceilometer.openstack.common.gettextutils import _ diff --git a/ceilometer/tests/alarm/test_notifier.py b/ceilometer/tests/alarm/test_notifier.py index 6774214f8..1cd2889bd 100644 --- a/ceilometer/tests/alarm/test_notifier.py +++ b/ceilometer/tests/alarm/test_notifier.py @@ -14,10 +14,10 @@ # 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 six.moves.urllib.parse as urlparse import mock import requests +from six.moves.urllib import parse as urlparse from ceilometer.alarm import service from ceilometer.openstack.common import context diff --git a/ceilometer/tests/db.py b/ceilometer/tests/db.py index 2f3c2d27e..9801bb2ba 100644 --- a/ceilometer/tests/db.py +++ b/ceilometer/tests/db.py @@ -20,11 +20,11 @@ """Base classes for API tests.""" import fixtures import os -import urlparse import uuid import warnings import six +from six.moves.urllib import parse as urlparse import testscenarios.testcase from testtools import testcase diff --git a/ceilometer/tests/network/statistics/opencontrail/test_driver.py b/ceilometer/tests/network/statistics/opencontrail/test_driver.py index 940e99897..c2114c559 100644 --- a/ceilometer/tests/network/statistics/opencontrail/test_driver.py +++ b/ceilometer/tests/network/statistics/opencontrail/test_driver.py @@ -15,7 +15,7 @@ # under the License. import mock -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.network.statistics.opencontrail import driver from ceilometer.openstack.common import test @@ -37,9 +37,9 @@ class TestOpencontrailDriver(test.BaseTestCase): self.nc_networks.start() self.driver = driver.OpencontrailDriver() - self.parse_url = url_parse.ParseResult('opencontrail', - '127.0.0.1:8143', - '/', None, None, None) + self.parse_url = urlparse.ParseResult('opencontrail', + '127.0.0.1:8143', + '/', None, None, None) self.params = {'password': ['admin'], 'scheme': ['http'], 'username': ['admin'], diff --git a/ceilometer/tests/network/statistics/opendaylight/test_client.py b/ceilometer/tests/network/statistics/opendaylight/test_client.py index 751730a28..aedfc1de7 100644 --- a/ceilometer/tests/network/statistics/opendaylight/test_client.py +++ b/ceilometer/tests/network/statistics/opendaylight/test_client.py @@ -13,10 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. import mock - from requests import auth as req_auth import six -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.network.statistics.opendaylight import client from ceilometer.openstack.common.gettextutils import _ @@ -30,16 +29,16 @@ class TestClientHTTPBasicAuth(test.BaseTestCase): def setUp(self): super(TestClientHTTPBasicAuth, self).setUp() - self.parsed_url = url_parse.urlparse( + self.parsed_url = urlparse.urlparse( 'http://127.0.0.1:8080/controller/nb/v2?container_name=default&' 'container_name=egg&auth=%s&user=admin&password=admin_pass&' 'scheme=%s' % (self.auth_way, self.scheme)) - self.params = url_parse.parse_qs(self.parsed_url.query) - self.endpoint = url_parse.urlunparse( - url_parse.ParseResult(self.scheme, - self.parsed_url.netloc, - self.parsed_url.path, - None, None, None)) + self.params = urlparse.parse_qs(self.parsed_url.query) + self.endpoint = urlparse.urlunparse( + urlparse.ParseResult(self.scheme, + self.parsed_url.netloc, + self.parsed_url.path, + None, None, None)) odl_params = {} odl_params['auth'] = self.params.get('auth')[0] odl_params['user'] = self.params.get('user')[0] diff --git a/ceilometer/tests/network/statistics/opendaylight/test_driver.py b/ceilometer/tests/network/statistics/opendaylight/test_driver.py index 521486b22..59bef11f6 100644 --- a/ceilometer/tests/network/statistics/opendaylight/test_driver.py +++ b/ceilometer/tests/network/statistics/opendaylight/test_driver.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. import abc -import mock +import mock import six from six import moves -from six.moves.urllib import parse as url_parse +from six.moves.urllib import parse as urlparse from ceilometer.network.statistics.opendaylight import driver from ceilometer.openstack.common import test @@ -58,20 +58,20 @@ class _Base(test.BaseTestCase): def inactive_hosts_data(self): pass - fake_odl_url = url_parse.ParseResult('opendaylight', - 'localhost:8080', - 'controller/nb/v2', - None, - None, - None) + fake_odl_url = urlparse.ParseResult('opendaylight', + 'localhost:8080', + 'controller/nb/v2', + None, + None, + None) - fake_params = url_parse.parse_qs('user=admin&password=admin&scheme=http&' - 'container_name=default&auth=basic') + fake_params = urlparse.parse_qs('user=admin&password=admin&scheme=http&' + 'container_name=default&auth=basic') fake_params_multi_container = \ - url_parse.parse_qs('user=admin&password=admin&scheme=http&' - 'container_name=first&container_name=second&' - 'auth=basic') + urlparse.parse_qs('user=admin&password=admin&scheme=http&' + 'container_name=first&container_name=second&' + 'auth=basic') def setUp(self): super(_Base, self).setUp()