Merge "python3: Fix imports for py2/py3"

This commit is contained in:
Jenkins 2013-08-29 01:17:12 +00:00 committed by Gerrit Code Review
commit c970dc3dd4
14 changed files with 37 additions and 45 deletions

@ -10,7 +10,6 @@ OpenStack Client interface. Handles the REST calls and responses.
import logging
import os
import time
import urlparse
import requests
@ -22,6 +21,7 @@ except ImportError:
from novaclient import exceptions
from novaclient import service_catalog
from novaclient import utils
from novaclient.openstack.common.py3kcompat import urlutils
class HTTPClient(object):
@ -298,7 +298,7 @@ class HTTPClient(object):
extract_token=False)
def authenticate(self):
magic_tuple = urlparse.urlsplit(self.auth_url)
magic_tuple = urlutils.urlsplit(self.auth_url)
scheme, netloc, path, query, frag = magic_tuple
port = magic_tuple.port
if port is None:
@ -312,7 +312,7 @@ class HTTPClient(object):
# TODO(sandy): Assume admin endpoint is 35357 for now.
# Ideally this is going to have to be provided by the service catalog.
new_netloc = netloc.replace(':%d' % port, ':%d' % (35357,))
admin_url = urlparse.urlunsplit(
admin_url = urlutils.urlunsplit(
(scheme, new_netloc, path, query, frag))
# FIXME(chmouel): This is to handle backward compatibiliy when

@ -1,4 +1,4 @@
import cStringIO
import io
import prettytable
import re
import sys
@ -43,8 +43,8 @@ class ShellTest(utils.TestCase):
orig = sys.stdout
orig_stderr = sys.stderr
try:
sys.stdout = cStringIO.StringIO()
sys.stderr = cStringIO.StringIO()
sys.stdout = io.BytesIO()
sys.stderr = io.BytesIO()
_shell = novaclient.shell.OpenStackComputeShell()
_shell.main(argstr.split())
except SystemExit:

@ -1,4 +1,4 @@
import StringIO
import io
import sys
import mock
@ -112,7 +112,7 @@ class _FakeResult(object):
class PrintResultTestCase(test_utils.TestCase):
@mock.patch('sys.stdout', StringIO.StringIO())
@mock.patch('sys.stdout', io.BytesIO())
def test_print_list_sort_by_str(self):
objs = [_FakeResult("k1", 1),
_FakeResult("k3", 2),
@ -129,7 +129,7 @@ class PrintResultTestCase(test_utils.TestCase):
'| k3 | 2 |\n'
'+------+-------+\n')
@mock.patch('sys.stdout', StringIO.StringIO())
@mock.patch('sys.stdout', io.BytesIO())
def test_print_list_sort_by_integer(self):
objs = [_FakeResult("k1", 1),
_FakeResult("k3", 2),
@ -147,7 +147,7 @@ class PrintResultTestCase(test_utils.TestCase):
'+------+-------+\n')
# without sorting
@mock.patch('sys.stdout', StringIO.StringIO())
@mock.patch('sys.stdout', io.BytesIO())
def test_print_list_sort_by_none(self):
objs = [_FakeResult("k1", 1),
_FakeResult("k3", 3),

@ -15,13 +15,13 @@
# limitations under the License.
from datetime import datetime
import urlparse
import six
from novaclient import client as base_client
from novaclient import exceptions
from novaclient.openstack.common import strutils
from novaclient.openstack.common.py3kcompat import urlutils
from novaclient.tests import fakes
from novaclient.tests import utils
from novaclient.v1_1 import client
@ -64,7 +64,7 @@ class FakeHTTPClient(base_client.HTTPClient):
assert 'body' in kwargs
# Call the method
args = urlparse.parse_qsl(urlparse.urlparse(url)[4])
args = urlutils.parse_qsl(urlutils.urlparse(url)[4])
kwargs.update(args)
munged_url = url.rsplit('?', 1)[0]
munged_url = munged_url.strip('/').replace('/', '_').replace('.', '_')

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import StringIO
import io
import mock
import six
@ -50,7 +50,7 @@ class ServersTest(utils.TestCase):
key_name="fakekey",
files={
'/etc/passwd': 'some data', # a file
'/tmp/foo.txt': StringIO.StringIO('data'), # a stream
'/tmp/foo.txt': io.BytesIO('data'), # a stream
}
)
cs.assert_called('POST', '/servers')
@ -94,10 +94,10 @@ class ServersTest(utils.TestCase):
image=1,
flavor=1,
meta={'foo': 'bar'},
userdata=StringIO.StringIO('hello moto'),
userdata=io.BytesIO('hello moto'),
files={
'/etc/passwd': 'some data', # a file
'/tmp/foo.txt': StringIO.StringIO('data'), # a stream
'/tmp/foo.txt': io.BytesIO('data'), # a stream
},
)
cs.assert_called('POST', '/servers')
@ -113,7 +113,7 @@ class ServersTest(utils.TestCase):
key_name="fakekey",
files={
'/etc/passwd': 'some data', # a file
'/tmp/foo.txt': StringIO.StringIO('data'), # a stream
'/tmp/foo.txt': io.BytesIO('data'), # a stream
},
)
cs.assert_called('POST', '/servers')
@ -129,7 +129,7 @@ class ServersTest(utils.TestCase):
key_name="fakekey",
files={
'/etc/passwd': 'some data', # a file
'/tmp/foo.txt': StringIO.StringIO('data'), # a stream
'/tmp/foo.txt': io.BytesIO('data'), # a stream
},
)
cs.assert_called('POST', '/servers')

@ -17,9 +17,9 @@
# under the License.
import datetime
import io
import os
import mock
import StringIO
import sys
import tempfile
@ -71,7 +71,7 @@ class ShellTest(utils.TestCase):
lambda *_: fakes.FakeClient))
self.addCleanup(timeutils.clear_time_override)
@mock.patch('sys.stdout', StringIO.StringIO())
@mock.patch('sys.stdout', io.BytesIO())
def run_command(self, cmd):
if isinstance(cmd, list):
self.shell.main(cmd)

@ -2,11 +2,10 @@
"""
Flavor interface.
"""
import urllib
from novaclient import base
from novaclient import exceptions
from novaclient import utils
from novaclient.openstack.common.py3kcompat import urlutils
class Flavor(base.Resource):
@ -89,7 +88,7 @@ class FlavorManager(base.ManagerWithFind):
# and flavors from their own projects only.
if not is_public:
qparams['is_public'] = is_public
query_string = "?%s" % urllib.urlencode(qparams) if qparams else ""
query_string = "?%s" % urlutils.urlencode(qparams) if qparams else ""
detail = ""
if detailed:

@ -13,9 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
def _quote_domain(domain):
@ -25,7 +24,7 @@ def _quote_domain(domain):
but Routes tends to choke on them, so we need an extra level of
by-hand quoting here.
"""
return urllib.quote(domain.replace('.', '%2E'))
return urlutils.quote(domain.replace('.', '%2E'))
class FloatingIPDNSDomain(base.Resource):
@ -102,7 +101,7 @@ class FloatingIPDNSEntryManager(base.Manager):
def get_for_ip(self, domain, ip):
"""Return a list of entries for the given domain and ip or name."""
qparams = {'ip': ip}
params = "?%s" % urllib.urlencode(qparams)
params = "?%s" % urlutils.urlencode(qparams)
return self._list("/os-floating-ip-dns/%s/entries%s" %
(_quote_domain(domain), params),

@ -17,9 +17,8 @@
Hypervisors interface (1.1 extension).
"""
import urllib
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
class Hypervisor(base.Resource):
@ -49,7 +48,7 @@ class HypervisorManager(base.ManagerWithFind):
"""
target = 'servers' if servers else 'search'
url = ('/os-hypervisors/%s/%s' %
(urllib.quote(hypervisor_match, safe=''), target))
(urlutils.quote(hypervisor_match, safe=''), target))
return self._list(url, 'hypervisors')
def get(self, hypervisor):

@ -2,9 +2,8 @@
"""
Image interface.
"""
import urllib
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
class Image(base.Resource):
@ -51,7 +50,7 @@ class ImageManager(base.ManagerWithFind):
detail = '/detail'
if limit:
params['limit'] = int(limit)
query = '?%s' % urllib.urlencode(params) if params else ''
query = '?%s' % urlutils.urlencode(params) if params else ''
return self._list('/images%s%s' % (detail, query), 'images')
def delete(self, image):

@ -1,8 +1,7 @@
# Copyright 2011 OpenStack Foundation
import urllib
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
class Limits(base.Resource):
@ -83,6 +82,6 @@ class LimitsManager(base.Manager):
opts['reserved'] = 1
if tenant_id:
opts['tenant_id'] = tenant_id
query_string = "?%s" % urllib.urlencode(opts) if opts else ""
query_string = "?%s" % urlutils.urlencode(opts) if opts else ""
return self._get("/limits%s" % query_string, "limits")

@ -17,11 +17,10 @@
Security group interface (1.1 extension).
"""
import urllib
import six
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
class SecurityGroup(base.Resource):
@ -91,7 +90,7 @@ class SecurityGroupManager(base.ManagerWithFind):
qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
query_string = '?%s' % urlutils.urlencode(qparams) if qparams else ''
return self._list('/os-security-groups%s' % query_string,
'security_groups')

@ -19,12 +19,11 @@
Server interface.
"""
import urllib
import six
from novaclient import base
from novaclient import crypto
from novaclient.openstack.common.py3kcompat import urlutils
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
@ -382,7 +381,7 @@ class ServerManager(base.BootingManagerWithFind):
if val:
qparams[opt] = val
query_string = "?%s" % urllib.urlencode(qparams) if qparams else ""
query_string = "?%s" % urlutils.urlencode(qparams) if qparams else ""
detail = ""
if detailed:

@ -17,11 +17,10 @@
Volume interface (1.1 extension).
"""
import urllib
import six
from novaclient import base
from novaclient.openstack.common.py3kcompat import urlutils
class Volume(base.Resource):
@ -90,7 +89,7 @@ class VolumeManager(base.ManagerWithFind):
qparams = dict((k, v) for (k, v) in six.iteritems(search_opts) if v)
query_string = '?%s' % urllib.urlencode(qparams) if qparams else ''
query_string = '?%s' % urlutils.urlencode(qparams) if qparams else ''
if detailed is True:
return self._list("/volumes/detail%s" % query_string, "volumes")