Merge "Import only modules and update tox.ini"

This commit is contained in:
Jenkins 2015-06-18 19:52:43 +00:00 committed by Gerrit Code Review
commit dc3dd87de9
10 changed files with 50 additions and 46 deletions

View File

@ -23,7 +23,7 @@ from oslo_utils import importutils
from oslo_utils import netutils from oslo_utils import netutils
import requests import requests
try: try:
from requests.packages.urllib3.exceptions import ProtocolError ProtocolError = requests.packages.urllib3.exceptions.ProtocolError
except ImportError: except ImportError:
ProtocolError = requests.exceptions.ConnectionError ProtocolError = requests.exceptions.ConnectionError
import six import six
@ -42,7 +42,7 @@ if not hasattr(parse, 'parse_qsl'):
from oslo_utils import encodeutils from oslo_utils import encodeutils
from glanceclient.common import https from glanceclient.common import https
from glanceclient.common.utils import safe_header from glanceclient.common import utils
from glanceclient import exc from glanceclient import exc
osprofiler_web = importutils.try_import("osprofiler.web") osprofiler_web = importutils.try_import("osprofiler.web")
@ -167,7 +167,7 @@ class HTTPClient(_BaseHTTPClient):
headers.update(self.session.headers) headers.update(self.session.headers)
for (key, value) in six.iteritems(headers): for (key, value) in six.iteritems(headers):
header = '-H \'%s: %s\'' % safe_header(key, value) header = '-H \'%s: %s\'' % utils.safe_header(key, value)
curl.append(header) curl.append(header)
if not self.session.verify: if not self.session.verify:
@ -193,7 +193,7 @@ class HTTPClient(_BaseHTTPClient):
status = (resp.raw.version / 10.0, resp.status_code, resp.reason) status = (resp.raw.version / 10.0, resp.status_code, resp.reason)
dump = ['\nHTTP/%.1f %s %s' % status] dump = ['\nHTTP/%.1f %s %s' % status]
headers = resp.headers.items() headers = resp.headers.items()
dump.extend(['%s: %s' % safe_header(k, v) for k, v in headers]) dump.extend(['%s: %s' % utils.safe_header(k, v) for k, v in headers])
dump.append('') dump.append('')
content_type = resp.headers.get('Content-Type') content_type = resp.headers.get('Content-Type')

View File

@ -47,11 +47,10 @@ try:
else: else:
raise ImportError raise ImportError
except ImportError: except ImportError:
try: from OpenSSL import SSL
from httplib import HTTPSConnection from six.moves import http_client
except ImportError: HTTPSConnection = http_client.HTTPSConnection
from http.client import HTTPSConnection Connection = SSL.Connection
from OpenSSL.SSL import Connection as Connection
from glanceclient import exc from glanceclient import exc

View File

@ -25,7 +25,6 @@ import getpass
import json import json
import logging import logging
import os import os
from os.path import expanduser
import sys import sys
import traceback import traceback
@ -551,7 +550,7 @@ class OpenStackImagesShell(object):
return client return client
def _cache_schemas(self, options, home_dir='~/.glanceclient'): def _cache_schemas(self, options, home_dir='~/.glanceclient'):
homedir = expanduser(home_dir) homedir = os.path.expanduser(home_dir)
if not os.path.exists(homedir): if not os.path.exists(homedir):
try: try:
os.makedirs(homedir) os.makedirs(homedir)

View File

@ -16,8 +16,8 @@
import testtools import testtools
from glanceclient import client from glanceclient import client
from glanceclient.v1 import client as v1 from glanceclient import v1
from glanceclient.v2 import client as v2 from glanceclient import v2
class ClientTest(testtools.TestCase): class ClientTest(testtools.TestCase):
@ -28,19 +28,19 @@ class ClientTest(testtools.TestCase):
def test_endpoint(self): def test_endpoint(self):
gc = client.Client(1, "http://example.com") gc = client.Client(1, "http://example.com")
self.assertEqual("http://example.com", gc.http_client.endpoint) self.assertEqual("http://example.com", gc.http_client.endpoint)
self.assertIsInstance(gc, v1.Client) self.assertIsInstance(gc, v1.client.Client)
def test_versioned_endpoint(self): def test_versioned_endpoint(self):
gc = client.Client(1, "http://example.com/v2") gc = client.Client(1, "http://example.com/v2")
self.assertEqual("http://example.com", gc.http_client.endpoint) self.assertEqual("http://example.com", gc.http_client.endpoint)
self.assertIsInstance(gc, v1.Client) self.assertIsInstance(gc, v1.client.Client)
def test_versioned_endpoint_no_version(self): def test_versioned_endpoint_no_version(self):
gc = client.Client(endpoint="http://example.com/v2") gc = client.Client(endpoint="http://example.com/v2")
self.assertEqual("http://example.com", gc.http_client.endpoint) self.assertEqual("http://example.com", gc.http_client.endpoint)
self.assertIsInstance(gc, v2.Client) self.assertIsInstance(gc, v2.client.Client)
def test_versioned_endpoint_with_minor_revision(self): def test_versioned_endpoint_with_minor_revision(self):
gc = client.Client(2.2, "http://example.com/v2.1") gc = client.Client(2.2, "http://example.com/v2.1")
self.assertEqual("http://example.com", gc.http_client.endpoint) self.assertEqual("http://example.com", gc.http_client.endpoint)
self.assertIsInstance(gc, v2.Client) self.assertIsInstance(gc, v2.client.Client)

View File

@ -29,8 +29,9 @@ import threading
from glanceclient.common import http from glanceclient.common import http
from glanceclient.common import https from glanceclient.common import https
from glanceclient import Client
from glanceclient import exc from glanceclient import exc
from glanceclient import v1
from glanceclient import v2
if six.PY3 is True: if six.PY3 is True:
import socketserver import socketserver
@ -90,9 +91,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port url = 'https://0.0.0.0:%d' % port
try: try:
client = Client('1', url, client = v1.client.Client(url,
insecure=False, insecure=False,
ssl_compression=True) ssl_compression=True)
client.images.get('image123') client.images.get('image123')
self.fail('No SSL exception raised') self.fail('No SSL exception raised')
except exc.CommunicationError as e: except exc.CommunicationError as e:
@ -107,9 +108,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port url = 'https://0.0.0.0:%d' % port
try: try:
client = Client('1', url, client = v1.client.Client(url,
insecure=False, insecure=False,
ssl_compression=False) ssl_compression=False)
client.images.get('image123') client.images.get('image123')
self.fail('No SSL exception raised') self.fail('No SSL exception raised')
except SSL.Error as e: except SSL.Error as e:
@ -124,9 +125,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port url = 'https://0.0.0.0:%d' % port
try: try:
gc = Client('2', url, gc = v2.client.Client(url,
insecure=False, insecure=False,
ssl_compression=True) ssl_compression=True)
gc.images.get('image123') gc.images.get('image123')
self.fail('No SSL exception raised') self.fail('No SSL exception raised')
except exc.CommunicationError as e: except exc.CommunicationError as e:
@ -141,9 +142,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port url = 'https://0.0.0.0:%d' % port
try: try:
gc = Client('2', url, gc = v2.client.Client(url,
insecure=False, insecure=False,
ssl_compression=False) ssl_compression=False)
gc.images.get('image123') gc.images.get('image123')
self.fail('No SSL exception raised') self.fail('No SSL exception raised')
except SSL.Error as e: except SSL.Error as e:

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from jsonpatch import JsonPatch import jsonpatch
import testtools import testtools
import warlock import warlock
@ -61,7 +61,8 @@ _SCHEMA = schemas.Schema({
def compare_json_patches(a, b): def compare_json_patches(a, b):
"""Return 0 if a and b describe the same JSON patch.""" """Return 0 if a and b describe the same JSON patch."""
return JsonPatch.from_string(a) == JsonPatch.from_string(b) return(jsonpatch.JsonPatch.from_string(a) ==
jsonpatch.JsonPatch.from_string(b))
class TestSchemaProperty(testtools.TestCase): class TestSchemaProperty(testtools.TestCase):

View File

@ -19,7 +19,7 @@ import six
import six.moves.urllib.parse as urlparse import six.moves.urllib.parse as urlparse
import testtools import testtools
from glanceclient.v2.schemas import Schema from glanceclient.v2 import schemas
class FakeAPI(object): class FakeAPI(object):
@ -68,7 +68,7 @@ class FakeAPI(object):
class FakeSchemaAPI(FakeAPI): class FakeSchemaAPI(FakeAPI):
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
_, raw_schema = self._request('GET', *args, **kwargs) _, raw_schema = self._request('GET', *args, **kwargs)
return Schema(raw_schema) return schemas.Schema(raw_schema)
class RawRequest(object): class RawRequest(object):

View File

@ -15,8 +15,8 @@
from glanceclient.common import http from glanceclient.common import http
from glanceclient.common import utils from glanceclient.common import utils
from glanceclient.v1.image_members import ImageMemberManager from glanceclient.v1 import image_members
from glanceclient.v1.images import ImageManager from glanceclient.v1 import images
class Client(object): class Client(object):
@ -33,5 +33,5 @@ class Client(object):
"""Initialize a new client for the Images v1 API.""" """Initialize a new client for the Images v1 API."""
endpoint, self.version = utils.endpoint_version_from_url(endpoint, 1.0) endpoint, self.version = utils.endpoint_version_from_url(endpoint, 1.0)
self.http_client = http.get_http_client(endpoint=endpoint, **kwargs) self.http_client = http.get_http_client(endpoint=endpoint, **kwargs)
self.images = ImageManager(self.http_client) self.images = images.ImageManager(self.http_client)
self.image_members = ImageMemberManager(self.http_client) self.image_members = image_members.ImageMemberManager(self.http_client)

View File

@ -18,20 +18,20 @@ import sys
from glanceclient.common import progressbar from glanceclient.common import progressbar
from glanceclient.common import utils from glanceclient.common import utils
from glanceclient import exc from glanceclient import exc
from glanceclient.v2.image_members import MEMBER_STATUS_VALUES from glanceclient.v2 import image_members
from glanceclient.v2 import images from glanceclient.v2 import images
from glanceclient.v2 import tasks from glanceclient.v2 import tasks
import json import json
import os import os
from os.path import expanduser
MEMBER_STATUS_VALUES = image_members.MEMBER_STATUS_VALUES
IMAGE_SCHEMA = None IMAGE_SCHEMA = None
def get_image_schema(): def get_image_schema():
global IMAGE_SCHEMA global IMAGE_SCHEMA
if IMAGE_SCHEMA is None: if IMAGE_SCHEMA is None:
schema_path = expanduser("~/.glanceclient/image_schema.json") schema_path = os.path.expanduser("~/.glanceclient/image_schema.json")
if os.path.isfile(schema_path): if os.path.isfile(schema_path):
with open(schema_path, "r") as f: with open(schema_path, "r") as f:
schema_raw = f.read() schema_raw = f.read()
@ -394,7 +394,8 @@ NAMESPACE_SCHEMA = None
def get_namespace_schema(): def get_namespace_schema():
global NAMESPACE_SCHEMA global NAMESPACE_SCHEMA
if NAMESPACE_SCHEMA is None: if NAMESPACE_SCHEMA is None:
schema_path = expanduser("~/.glanceclient/namespace_schema.json") schema_path = os.path.expanduser("~/.glanceclient/"
"namespace_schema.json")
if os.path.isfile(schema_path): if os.path.isfile(schema_path):
with open(schema_path, "r") as f: with open(schema_path, "r") as f:
schema_raw = f.read() schema_raw = f.read()
@ -533,7 +534,8 @@ RESOURCE_TYPE_SCHEMA = None
def get_resource_type_schema(): def get_resource_type_schema():
global RESOURCE_TYPE_SCHEMA global RESOURCE_TYPE_SCHEMA
if RESOURCE_TYPE_SCHEMA is None: if RESOURCE_TYPE_SCHEMA is None:
schema_path = expanduser("~/.glanceclient/resource_type_schema.json") schema_path = os.path.expanduser("~/.glanceclient/"
"resource_type_schema.json")
if os.path.isfile(schema_path): if os.path.isfile(schema_path):
with open(schema_path, "r") as f: with open(schema_path, "r") as f:
schema_raw = f.read() schema_raw = f.read()

View File

@ -37,7 +37,6 @@ downloadcache = ~/cache/pip
[flake8] [flake8]
# H233 Python 3.x incompatible use of print operator # H233 Python 3.x incompatible use of print operator
# H302 import only modules
# H303 no wildcard import # H303 no wildcard import
# H404 multi line docstring should start with a summary # H404 multi line docstring should start with a summary
@ -49,6 +48,9 @@ downloadcache = ~/cache/pip
# H238 old style class declaration, use new style (inherit from `object`) # H238 old style class declaration, use new style (inherit from `object`)
# E128 continuation line under-indented for visual indent # E128 continuation line under-indented for visual indent
ignore = F403,F812,F821,H233,H302,H303,H404,E265,H405,E123,H238,E128 ignore = F403,F812,F821,H233,H303,H404,E265,H405,E123,H238,E128
show-source = True show-source = True
exclude = .venv,.tox,dist,*egg,build exclude = .venv*,.tox,dist,*egg,build,.git,doc,*openstack/common*,*lib/python*,.update-venv
[hacking]
import_exceptions = six.moves