renamed rbd_iscsi_client to client

This fixes the py27 build failures.
Cleaned up pep8 violations
This commit is contained in:
Walter A. Boring IV 2019-06-13 16:34:12 +00:00
parent d74953c1b8
commit d26ee89df6
8 changed files with 145 additions and 146 deletions

View File

@ -1,3 +1,5 @@
CHANGES
=======
* Added basic unit tests
* Initial commit

View File

@ -1,5 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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.
#
# rbd_iscsi_client documentation build configuration file, created by
# sphinx-quickstart on Fri Jun 9 13:47:02 2017.
@ -18,11 +28,6 @@
# relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import rbd_iscsi_client
# -- General configuration ---------------------------------------------
@ -59,9 +64,6 @@ author = u"Walter A. Boring IV"
# the built documents.
#
# The short X.Y version.
version = rbd_iscsi_client.__version__
# The full version, including alpha/beta/rc tags.
release = rbd_iscsi_client.__version__
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -101,7 +103,7 @@ html_theme = 'openstackdocs'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#html_static_path = ['_static']
# -- Options for HTMLHelp output ---------------------------------------

View File

@ -8,7 +8,7 @@
# 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."""
# under the License.
"""
Exceptions for the client
@ -30,9 +30,7 @@ LOG = logging.getLogger(__name__)
class UnsupportedVersion(Exception):
"""
Indicates that the user is trying to use an unsupported version of the API
"""
"""unsupported version of the API."""
pass
@ -49,8 +47,7 @@ class NoUniqueMatch(Exception):
class ClientException(Exception):
"""
The base exception class for all exceptions this library raises.
"""The base exception class for all exceptions this library raises.
:param error: The error array
:type error: array
@ -117,9 +114,7 @@ class ClientException(Exception):
class SSLCertFailed(ClientException):
"""
The SSL certificate from the server could not be verified
"""
"""The SSL certificate from the server could not be verified."""
http_status = ""
message = "SSL Certificate Verification Failed"
@ -128,44 +123,32 @@ class SSLCertFailed(ClientException):
class RequestException(ClientException):
"""
There was an ambiguous exception that occurred in Requests
"""
"""There was an ambiguous exception that occurred in Requests."""
pass
class ConnectionError(ClientException):
"""
There was an error connecting to the server
"""
"""There was an error connecting to the server."""
pass
class HTTPError(ClientException):
"""
An HTTP error occurred
"""
"""An HTTP error occurred."""
pass
class URLRequired(ClientException):
"""
A valid URL is required to make a request
"""
"""A valid URL is required to make a request."""
pass
class TooManyRedirects(ClientException):
"""
Too many redirects
"""
"""Too many redirects."""
pass
class Timeout(ClientException):
"""
The request timed out
"""
"""The request timed out."""
pass
@ -173,81 +156,63 @@ class Timeout(ClientException):
class HTTPBadRequest(ClientException):
"""
HTTP 400 - Bad request: you sent some malformed data.
"""
"""HTTP 400 - Bad request: you sent some malformed data."""
http_status = 400
message = "Bad request"
class HTTPUnauthorized(ClientException):
"""
HTTP 401 - Unauthorized: bad credentials.
"""
"""HTTP 401 - Unauthorized: bad credentials."""
http_status = 401
message = "Unauthorized"
class HTTPForbidden(ClientException):
"""
HTTP 403 - Forbidden: your credentials don't give you access to this
resource.
"""
"""HTTP 403 - Forbidden: credentials don't give access to this resource."""
http_status = 403
message = "Forbidden"
class HTTPNotFound(ClientException):
"""
HTTP 404 - Not found
"""
"""HTTP 404 - Not found """
http_status = 404
message = "Not found"
class HTTPMethodNotAllowed(ClientException):
"""
HTTP 405 - Method not Allowed
"""
"""HTTP 405 - Method not Allowed """
http_status = 405
message = "Method Not Allowed"
class HTTPNotAcceptable(ClientException):
"""
HTTP 406 - Method not Acceptable
"""
"""HTTP 406 - Method not Acceptable """
http_status = 406
message = "Method Not Acceptable"
class HTTPProxyAuthRequired(ClientException):
"""
HTTP 407 - The client must first authenticate itself with the proxy.
"""
"""HTTP 407 - The client must first authenticate itself with the proxy."""
http_status = 407
message = "Proxy Authentication Required"
class HTTPRequestTimeout(ClientException):
"""
HTTP 408 - The server timed out waiting for the request.
"""
"""HTTP 408 - The server timed out waiting for the request."""
http_status = 408
message = "Request Timeout"
class HTTPConflict(ClientException):
"""
HTTP 409 - Conflict: A Conflict happened on the server
"""
"""HTTP 409 - Conflict: A Conflict happened on the server."""
http_status = 409
message = "Conflict"
class HTTPGone(ClientException):
"""
HTTP 410 - Indicates that the resource requested is no longer available and
"""HTTP 410
Indicates that the resource requested is no longer available and
will not be available again.
"""
http_status = 410
@ -255,17 +220,20 @@ class HTTPGone(ClientException):
class HTTPLengthRequired(ClientException):
"""
HTTP 411 - The request did not specify the length of its content, which is
"""HTTP 411
The request did not specify the length of its content, which is
required by the requested resource.
"""
http_status = 411
message = "Length Required"
class HTTPPreconditionFailed(ClientException):
"""
HTTP 412 - The server does not meet one of the preconditions that the
"""HTTP 412
The server does not meet one of the preconditions that the
requester put on the request.
"""
http_status = 412
@ -273,53 +241,54 @@ class HTTPPreconditionFailed(ClientException):
class HTTPRequestEntityTooLarge(ClientException):
"""
HTTP 413 - The request is larger than the server is willing or able to
process
"""HTTP 413
The request is larger than the server is willing or able to process
"""
http_status = 413
message = "Request Entity Too Large"
class HTTPRequestURITooLong(ClientException):
"""
HTTP 414 - The URI provided was too long for the server to process.
"""
"""HTTP 414 - The URI provided was too long for the server to process."""
http_status = 414
message = "Request URI Too Large"
class HTTPUnsupportedMediaType(ClientException):
"""
HTTP 415 - The request entity has a media type which the server or resource
"""HTTP 415
The request entity has a media type which the server or resource
does not support.
"""
http_status = 415
message = "Unsupported Media Type"
class HTTPRequestedRangeNotSatisfiable(ClientException):
"""
HTTP 416 - The client has asked for a portion of the file, but the server
cannot supply that portion.
"""HTTP 416
The client has asked for a portion of the file, but the server cannot
supply that portion.
"""
http_status = 416
message = "Requested Range Not Satisfiable"
class HTTPExpectationFailed(ClientException):
"""
HTTP 417 - The server cannot meet the requirements of the Expect
"""HTTP 417
The server cannot meet the requirements of the Expect
request-header field.
"""
http_status = 417
message = "Expectation Failed"
class HTTPTeaPot(ClientException):
"""
HTTP 418 - I'm a Tea Pot
"""
"""HTTP 418 - I'm a Tea Pot."""
http_status = 418
message = "I'm A Teapot. (RFC 2324)"
@ -328,24 +297,21 @@ class HTTPTeaPot(ClientException):
class HTTPInternalServerError(ClientException):
"""
HTTP 500 - Internal Server Error: an internal error occured.
"""
"""HTTP 500 - Internal Server Error: an internal error occured."""
http_status = 500
message = "Internal Server Error"
class HTTPNotImplemented(ClientException):
"""
HTTP 501 - Not Implemented: the server does not support this operation.
"""
"""HTTP 501 - Not Implemented: server does not support the operation."""
http_status = 501
message = "Not Implemented"
class HTTPBadGateway(ClientException):
"""
HTTP 502 - The server was acting as a gateway or proxy and received an
"""HTTP 502
The server was acting as a gateway or proxy and received an
invalid response from the upstream server.
"""
http_status = 502
@ -353,16 +319,15 @@ class HTTPBadGateway(ClientException):
class HTTPServiceUnavailable(ClientException):
"""
HTTP 503 - The server is currently unavailable
"""
"""HTTP 503 - The server is currently unavailable."""
http_status = 503
message = "Service Unavailable"
class HTTPGatewayTimeout(ClientException):
"""
HTTP 504 - The server was acting as a gateway or proxy and did
"""HTTP 504
The server was acting as a gateway or proxy and did
not receive a timely response from the upstream server.
"""
http_status = 504
@ -370,9 +335,9 @@ class HTTPGatewayTimeout(ClientException):
class HTTPVersionNotSupported(ClientException):
"""
HTTP 505 - The server does not support the HTTP protocol version used
in the request.
"""HTTP 505
The server does not support the HTTP protocol version used in the request.
"""
http_status = 505
message = "Version Not Supported"
@ -399,8 +364,8 @@ _code_map = dict((c.http_status, c) for c in
def from_response(response, body):
"""
Return an instance of an ClientException or subclass
"""Return an instance of an ClientException or subclass.
based on a Python Requests response.
Usage::

View File

@ -0,0 +1,38 @@
# 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.
"""Tests for `rbd_iscsi_client` package."""
import unittest
from rbd_iscsi_client import client
class TestRbd_iscsi_client(unittest.TestCase):
"""Tests for `rbd_iscsi_client` package."""
def setUp(self):
"""Set up test fixtures, if any."""
fake_url = 'client://fake-url:0000'
fake_user = 'user'
fake_password = 'password'
self.client = client.RBDISCSIClient(fake_user, fake_password,
fake_url, secure=False,
http_log_debug=True,
suppress_ssl_warnings=False,
timeout=10)
def tearDown(self):
"""Tear down test fixtures, if any."""
def test_000_something(self):
"""Test something."""

View File

@ -1,13 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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.
"""Tests for `rbd_iscsi_client` package."""
import mock
import requests
import unittest
from rbd_iscsi_client import rbd_iscsi_client as client
from rbd_iscsi_client import client
from rbd_iscsi_client import exceptions
@ -30,7 +38,6 @@ class TestRbd_iscsi_client(unittest.TestCase):
def tearDown(self):
self.client = None
def test_request_timeout(self):
self.client._http_log_req = mock.Mock()
self.client.timeout = 10

View File

@ -1,9 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 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.
"""Tests for `rbd_iscsi_client` package."""
import unittest
from rbd_iscsi_client import exceptions
@ -25,7 +32,7 @@ class Test_exceptions(unittest.TestCase):
fake_response = FakeResponse()
output = exceptions.from_response(fake_response, {}).__str__()
self.assertEquals('Internal Server Error (HTTP 500)', output)
self.assertEqual('Internal Server Error (HTTP 500)', output)
def test_001_client_exception_string_format(self):
fake_error = {'code': 999,
@ -38,6 +45,6 @@ class Test_exceptions(unittest.TestCase):
client_ex.http_status = 500
output = client_ex.__str__()
self.assertEquals("Fake Error (HTTP 500) 999 - Fake Description - "
self.assertEqual("Fake Error (HTTP 500) 999 - Fake Description - "
"Fake Ref (1: 'Fake Debug 1') (2: 'Fake Debug 2')",
output)

View File

@ -1,22 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Tests for `rbd_iscsi_client` package."""
import unittest
from rbd_iscsi_client import rbd_iscsi_client
class TestRbd_iscsi_client(unittest.TestCase):
"""Tests for `rbd_iscsi_client` package."""
def setUp(self):
"""Set up test fixtures, if any."""
def tearDown(self):
"""Tear down test fixtures, if any."""
def test_000_something(self):
"""Test something."""