Import only modules and update tox.ini

As stated in the OpenStack Hacking Guidelines, it is prefered
that only modules should be imported.

Also updated tox.ini to ignore opestack/common among others.

Change-Id: I2f0a603c31052eadee581c11880c0ec6bd392829
This commit is contained in:
Cindy Pallares 2015-05-19 19:59:06 -05:00
parent 71d8528364
commit 997c12d3ab
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
import requests
try:
from requests.packages.urllib3.exceptions import ProtocolError
ProtocolError = requests.packages.urllib3.exceptions.ProtocolError
except ImportError:
ProtocolError = requests.exceptions.ConnectionError
import six
@ -42,7 +42,7 @@ if not hasattr(parse, 'parse_qsl'):
from oslo_utils import encodeutils
from glanceclient.common import https
from glanceclient.common.utils import safe_header
from glanceclient.common import utils
from glanceclient import exc
osprofiler_web = importutils.try_import("osprofiler.web")
@ -167,7 +167,7 @@ class HTTPClient(_BaseHTTPClient):
headers.update(self.session.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)
if not self.session.verify:
@ -193,7 +193,7 @@ class HTTPClient(_BaseHTTPClient):
status = (resp.raw.version / 10.0, resp.status_code, resp.reason)
dump = ['\nHTTP/%.1f %s %s' % status]
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('')
content_type = resp.headers.get('Content-Type')

View File

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

View File

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

View File

@ -16,8 +16,8 @@
import testtools
from glanceclient import client
from glanceclient.v1 import client as v1
from glanceclient.v2 import client as v2
from glanceclient import v1
from glanceclient import v2
class ClientTest(testtools.TestCase):
@ -28,19 +28,19 @@ class ClientTest(testtools.TestCase):
def test_endpoint(self):
gc = client.Client(1, "http://example.com")
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):
gc = client.Client(1, "http://example.com/v2")
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):
gc = client.Client(endpoint="http://example.com/v2")
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):
gc = client.Client(2.2, "http://example.com/v2.1")
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 https
from glanceclient import Client
from glanceclient import exc
from glanceclient import v1
from glanceclient import v2
if six.PY3 is True:
import socketserver
@ -90,9 +91,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port
try:
client = Client('1', url,
insecure=False,
ssl_compression=True)
client = v1.client.Client(url,
insecure=False,
ssl_compression=True)
client.images.get('image123')
self.fail('No SSL exception raised')
except exc.CommunicationError as e:
@ -107,9 +108,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port
try:
client = Client('1', url,
insecure=False,
ssl_compression=False)
client = v1.client.Client(url,
insecure=False,
ssl_compression=False)
client.images.get('image123')
self.fail('No SSL exception raised')
except SSL.Error as e:
@ -124,9 +125,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port
try:
gc = Client('2', url,
insecure=False,
ssl_compression=True)
gc = v2.client.Client(url,
insecure=False,
ssl_compression=True)
gc.images.get('image123')
self.fail('No SSL exception raised')
except exc.CommunicationError as e:
@ -141,9 +142,9 @@ class TestHTTPSVerifyCert(testtools.TestCase):
url = 'https://0.0.0.0:%d' % port
try:
gc = Client('2', url,
insecure=False,
ssl_compression=False)
gc = v2.client.Client(url,
insecure=False,
ssl_compression=False)
gc.images.get('image123')
self.fail('No SSL exception raised')
except SSL.Error as e:

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from jsonpatch import JsonPatch
import jsonpatch
import testtools
import warlock
@ -61,7 +61,8 @@ _SCHEMA = schemas.Schema({
def compare_json_patches(a, b):
"""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):

View File

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

View File

@ -15,8 +15,8 @@
from glanceclient.common import http
from glanceclient.common import utils
from glanceclient.v1.image_members import ImageMemberManager
from glanceclient.v1.images import ImageManager
from glanceclient.v1 import image_members
from glanceclient.v1 import images
class Client(object):
@ -33,5 +33,5 @@ class Client(object):
"""Initialize a new client for the Images v1 API."""
endpoint, self.version = utils.endpoint_version_from_url(endpoint, 1.0)
self.http_client = http.get_http_client(endpoint=endpoint, **kwargs)
self.images = ImageManager(self.http_client)
self.image_members = ImageMemberManager(self.http_client)
self.images = images.ImageManager(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 utils
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 tasks
import json
import os
from os.path import expanduser
MEMBER_STATUS_VALUES = image_members.MEMBER_STATUS_VALUES
IMAGE_SCHEMA = None
def get_image_schema():
global IMAGE_SCHEMA
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):
with open(schema_path, "r") as f:
schema_raw = f.read()
@ -394,7 +394,8 @@ NAMESPACE_SCHEMA = None
def get_namespace_schema():
global NAMESPACE_SCHEMA
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):
with open(schema_path, "r") as f:
schema_raw = f.read()
@ -533,7 +534,8 @@ RESOURCE_TYPE_SCHEMA = None
def get_resource_type_schema():
global RESOURCE_TYPE_SCHEMA
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):
with open(schema_path, "r") as f:
schema_raw = f.read()

View File

@ -37,7 +37,6 @@ downloadcache = ~/cache/pip
[flake8]
# H233 Python 3.x incompatible use of print operator
# H302 import only modules
# H303 no wildcard import
# 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`)
# 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
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