diff --git a/glanceclient/__init__.py b/glanceclient/__init__.py index f9670312..a5600e7e 100644 --- a/glanceclient/__init__.py +++ b/glanceclient/__init__.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -#NOTE(bcwaldon): this try/except block is needed to run setup.py due to +# NOTE(bcwaldon): this try/except block is needed to run setup.py due to # its need to import local code before installing required dependencies try: import glanceclient.client diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index b8328f7e..a9df2157 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -218,6 +218,7 @@ class HTTPClient(_BaseHTTPClient): def _request(self, method, url, **kwargs): """Send an http request with the specified characteristics. + Wrapper around httplib.HTTP(S)Connection.request to handle tasks such as setting headers and error handling. """ diff --git a/glanceclient/common/https.py b/glanceclient/common/https.py index 30896e0b..79f6d6da 100644 --- a/glanceclient/common/https.py +++ b/glanceclient/common/https.py @@ -58,6 +58,7 @@ from glanceclient import exc def verify_callback(host=None): """ + We use a partial around the 'real' verify_callback function so that we can stash the host value without holding a reference on the VerifiedHTTPSConnection. @@ -71,8 +72,7 @@ def verify_callback(host=None): def do_verify_callback(connection, x509, errnum, depth, preverify_ok, host=None): - """ - Verify the server's SSL certificate. + """Verify the server's SSL certificate. This is a standalone function rather than a method to avoid issues around closing sockets if a reference is held on @@ -93,6 +93,7 @@ def do_verify_callback(connection, x509, errnum, def host_matches_cert(host, x509): """ + Verify that the x509 certificate we have received from 'host' correctly identifies the server we are connecting to, ie that the certificate's Common Name @@ -140,13 +141,10 @@ def to_bytes(s): class HTTPSAdapter(adapters.HTTPAdapter): - """ - This adapter will be used just when - ssl compression should be disabled. + """This adapter will be used just when ssl compression should be disabled. - The init method overwrites the default - https pool by setting glanceclient's - one. + The init method overwrites the default https pool by setting + glanceclient's one. """ def __init__(self, *args, **kwargs): classes_by_scheme = poolmanager.pool_classes_by_scheme @@ -194,8 +192,9 @@ class HTTPSAdapter(adapters.HTTPAdapter): class HTTPSConnectionPool(connectionpool.HTTPSConnectionPool): """ + HTTPSConnectionPool will be instantiated when a new - connection is requested to the HTTPSAdapter.This + connection is requested to the HTTPSAdapter. This implementation overwrites the _new_conn method and returns an instances of glanceclient's VerifiedHTTPSConnection which handles no compression. @@ -218,8 +217,7 @@ class HTTPSConnectionPool(connectionpool.HTTPSConnectionPool): class OpenSSLConnectionDelegator(object): - """ - An OpenSSL.SSL.Connection delegator. + """An OpenSSL.SSL.Connection delegator. Supplies an additional 'makefile' method which httplib requires and is not present in OpenSSL.SSL.Connection. @@ -239,6 +237,7 @@ class OpenSSLConnectionDelegator(object): class VerifiedHTTPSConnection(HTTPSConnection): """ + Extended HTTPSConnection which uses the OpenSSL library for enhanced SSL support. Note: Much of this functionality can eventually be replaced @@ -284,9 +283,7 @@ class VerifiedHTTPSConnection(HTTPSConnection): raise exc.SSLConfigurationError(str(e)) def set_context(self): - """ - Set up the OpenSSL context. - """ + """Set up the OpenSSL context.""" self.context = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) self.context.set_cipher_list(self.CIPHERS) @@ -333,8 +330,9 @@ class VerifiedHTTPSConnection(HTTPSConnection): def connect(self): """ - Connect to an SSL port using the OpenSSL library and apply - per-connection parameters. + + Connect to an SSL port using the OpenSSL library + and apply per-connection parameters. """ result = socket.getaddrinfo(self.host, self.port, 0, socket.SOCK_STREAM) diff --git a/glanceclient/common/progressbar.py b/glanceclient/common/progressbar.py index cd4ffe50..d372e5c1 100644 --- a/glanceclient/common/progressbar.py +++ b/glanceclient/common/progressbar.py @@ -20,8 +20,9 @@ import six class _ProgressBarBase(object): """ - Base abstract class used by specific class wrapper to show a progress bar - when the wrapped object are consumed. + + Base abstract class used by specific class wrapper to show + a progress bar when the wrapped object are consumed. :param wrapped: Object to wrap that hold data to be consumed. :param totalsize: The total size of the data in the wrapped object. @@ -51,8 +52,9 @@ class _ProgressBarBase(object): class VerboseFileWrapper(_ProgressBarBase): """ - A file wrapper that show and advance a progress bar whenever file's read - method is called. + + A file wrapper that show and advance a progress bar + whenever file's read method is called. """ def read(self, *args, **kwargs): @@ -69,9 +71,9 @@ class VerboseFileWrapper(_ProgressBarBase): class VerboseIteratorWrapper(_ProgressBarBase): """ + An iterator wrapper that show and advance a progress bar whenever data is consumed from the iterator. - :note: Use only with iterator that yield strings. """ diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 7410b3bf..18059bb1 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -215,7 +215,7 @@ def is_authentication_required(f): def env(*vars, **kwargs): - """Search for the first defined of possibly many env vars + """Search for the first defined of possibly many env vars. Returns the first environment variable defined in vars, or returns the default defined in kwargs. @@ -241,8 +241,7 @@ def exit(msg='', exit_code=1): def save_image(data, path): - """ - Save an image to the specified path. + """Save an image to the specified path. :param data: binary data of the image :param path: path to save the image to @@ -276,6 +275,7 @@ def make_size_human_readable(size): def getsockopt(self, *args, **kwargs): """ + A function which allows us to monkey patch eventlet's GreenSocket, adding a required 'getsockopt' method. TODO: (mclaren) we can remove this once the eventlet fix @@ -298,8 +298,7 @@ def exception_to_str(exc): def get_file_size(file_obj): - """ - Analyze file-like object and attempt to determine its size. + """Analyze file-like object and attempt to determine its size. :param file_obj: file-like object. :retval The file's size or None if it cannot be determined. @@ -385,8 +384,7 @@ def print_image(image_obj, human_readable=False, max_col_width=None): def integrity_iter(iter, checksum): - """ - Check image data integrity. + """Check image data integrity. :raises: IOError """ diff --git a/glanceclient/openstack/common/apiclient/base.py b/glanceclient/openstack/common/apiclient/base.py index 3fc69dd8..6f7c64a0 100644 --- a/glanceclient/openstack/common/apiclient/base.py +++ b/glanceclient/openstack/common/apiclient/base.py @@ -467,8 +467,7 @@ class Resource(object): @property def human_id(self): - """Human-readable ID which can be used for bash completion. - """ + """Human-readable ID which can be used for bash completion.""" if self.HUMAN_ID: name = getattr(self, self.NAME_ATTR, None) if name is not None: diff --git a/glanceclient/openstack/common/apiclient/client.py b/glanceclient/openstack/common/apiclient/client.py index ec2150ee..241fc4c7 100644 --- a/glanceclient/openstack/common/apiclient/client.py +++ b/glanceclient/openstack/common/apiclient/client.py @@ -368,7 +368,7 @@ class BaseClient(object): @staticmethod def get_class(api_name, version, version_map): - """Returns the client class for the requested API version + """Returns the client class for the requested API version. :param api_name: the name of the API, e.g. 'compute', 'image', etc :param version: the requested API version diff --git a/glanceclient/openstack/common/apiclient/exceptions.py b/glanceclient/openstack/common/apiclient/exceptions.py index c8669f70..85550085 100644 --- a/glanceclient/openstack/common/apiclient/exceptions.py +++ b/glanceclient/openstack/common/apiclient/exceptions.py @@ -42,8 +42,7 @@ from glanceclient.openstack.common._i18n import _ class ClientException(Exception): - """The base exception class for all exceptions this library raises. - """ + """The base exception class for all exceptions this library raises.""" pass @@ -118,8 +117,7 @@ class AmbiguousEndpoints(EndpointException): class HttpError(ClientException): - """The base exception class for all HTTP exceptions. - """ + """The base exception class for all HTTP exceptions.""" http_status = 0 message = _("HTTP Error") diff --git a/glanceclient/openstack/common/apiclient/fake_client.py b/glanceclient/openstack/common/apiclient/fake_client.py index a6a736a0..b1529336 100644 --- a/glanceclient/openstack/common/apiclient/fake_client.py +++ b/glanceclient/openstack/common/apiclient/fake_client.py @@ -59,8 +59,7 @@ def assert_has_keys(dct, required=None, optional=None): class TestResponse(requests.Response): - """Wrap requests.Response and provide a convenient initialization. - """ + """Wrap requests.Response and provide a convenient initialization.""" def __init__(self, data): super(TestResponse, self).__init__() @@ -99,8 +98,7 @@ class FakeHTTPClient(client.HTTPClient): super(FakeHTTPClient, self).__init__(*args, **kwargs) def assert_called(self, method, url, body=None, pos=-1): - """Assert than an API method was just called. - """ + """Assert than an API method was just called.""" expected = (method, url) called = self.callstack[pos][0:2] assert self.callstack, \ @@ -115,8 +113,7 @@ class FakeHTTPClient(client.HTTPClient): (self.callstack[pos][3], body)) def assert_called_anytime(self, method, url, body=None): - """Assert than an API method was called anytime in the test. - """ + """Assert than an API method was called anytime in the test.""" expected = (method, url) assert self.callstack, \ diff --git a/glanceclient/shell.py b/glanceclient/shell.py old mode 100644 new mode 100755 index 74496314..82195c8c --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -682,9 +682,7 @@ class OpenStackImagesShell(object): @utils.arg('command', metavar='', nargs='?', help='Display help for .') def do_help(self, args): - """ - Display help about this program or one of its subcommands. - """ + """Display help about this program or one of its subcommands.""" if getattr(args, 'command', None): if args.command in self.subcommands: self.subcommands[args.command].print_help() diff --git a/glanceclient/tests/functional/base.py b/glanceclient/tests/functional/base.py index a39e77d0..9488595a 100644 --- a/glanceclient/tests/functional/base.py +++ b/glanceclient/tests/functional/base.py @@ -17,10 +17,9 @@ from tempest_lib.cli import base class ClientTestBase(base.ClientTestBase): - """ - This is a first pass at a simple read only python-glanceclient test. This - only exercises client commands that are read only. + """This is a first pass at a simple read only python-glanceclient test. + This only exercises client commands that are read only. This should test commands: * as a regular user * as an admin user diff --git a/glanceclient/tests/functional/test_readonly_glance.py b/glanceclient/tests/functional/test_readonly_glance.py index 0082f292..e3f09666 100644 --- a/glanceclient/tests/functional/test_readonly_glance.py +++ b/glanceclient/tests/functional/test_readonly_glance.py @@ -19,8 +19,7 @@ from glanceclient.tests.functional import base class SimpleReadOnlyGlanceClientTest(base.ClientTestBase): - """ - read only functional python-glanceclient tests. + """Read only functional python-glanceclient tests. This only exercises client commands that are read only. """ diff --git a/glanceclient/tests/unit/test_http.py b/glanceclient/tests/unit/test_http.py index f83a5147..c7a16f30 100644 --- a/glanceclient/tests/unit/test_http.py +++ b/glanceclient/tests/unit/test_http.py @@ -77,7 +77,7 @@ class TestClient(testtools.TestCase): 'X-Identity-Status': 'Confirmed', 'X-Service-Catalog': 'service_catalog', } - #with token + # with token kwargs = {'token': u'fake-token', 'identity_headers': identity_headers} http_client_object = http.HTTPClient(self.endpoint, **kwargs) @@ -93,7 +93,7 @@ class TestClient(testtools.TestCase): 'X-Identity-Status': 'Confirmed', 'X-Service-Catalog': 'service_catalog', } - #without X-Auth-Token in identity headers + # without X-Auth-Token in identity headers kwargs = {'token': u'fake-token', 'identity_headers': identity_headers} http_client_object = http.HTTPClient(self.endpoint, **kwargs) @@ -140,9 +140,7 @@ class TestClient(testtools.TestCase): self.assertEqual(v, headers[k]) def test_connection_timeout(self): - """ - Should receive an InvalidEndpoint if connection timeout. - """ + """Should receive an InvalidEndpoint if connection timeout.""" def cb(request, context): raise requests.exceptions.Timeout @@ -155,6 +153,7 @@ class TestClient(testtools.TestCase): def test_connection_refused(self): """ + Should receive a CommunicationError if connection refused. And the error should list the host and port that refused the connection @@ -192,7 +191,7 @@ class TestClient(testtools.TestCase): self.assertNotIn("none-val", encoded) def test_raw_request(self): - " Verify the path being used for HTTP requests reflects accurately. " + """Verify the path being used for HTTP requests reflects accurately.""" headers = {"Content-Type": "text/plain"} text = 'Ok' path = '/v1/images/detail' diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py index c3d258dd..4a0f6291 100644 --- a/glanceclient/tests/unit/test_shell.py +++ b/glanceclient/tests/unit/test_shell.py @@ -36,7 +36,7 @@ from glanceclient import exc from glanceclient import shell as openstack_shell from glanceclient.tests import utils as testutils -#NOTE (esheffield) Used for the schema caching tests +# NOTE (esheffield) Used for the schema caching tests from glanceclient.v2 import schemas as schemas import json @@ -507,7 +507,7 @@ class ShellCacheSchemaTest(testutils.TestCase): self.shell._get_versioned_client = mocked_get_client def _make_args(self, args): - class Args(): + class Args(object): def __init__(self, entries): self.__dict__.update(entries) diff --git a/glanceclient/tests/unit/test_ssl.py b/glanceclient/tests/unit/test_ssl.py index b6ae083f..bf533134 100644 --- a/glanceclient/tests/unit/test_ssl.py +++ b/glanceclient/tests/unit/test_ssl.py @@ -66,7 +66,7 @@ class ThreadedTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer): class TestHTTPSVerifyCert(testtools.TestCase): - """Check 'requests' based ssl verification occurs + """Check 'requests' based ssl verification occurs. The requests library performs SSL certificate validation, however there is still a need to check that the glance @@ -156,9 +156,7 @@ class TestHTTPSVerifyCert(testtools.TestCase): class TestVerifiedHTTPSConnection(testtools.TestCase): def test_ssl_init_ok(self): - """ - Test VerifiedHTTPSConnection class init - """ + """Test VerifiedHTTPSConnection class init.""" key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key') cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') @@ -171,9 +169,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Failed to init VerifiedHTTPSConnection.') def test_ssl_init_cert_no_key(self): - """ - Test VerifiedHTTPSConnection: absence of SSL key file. - """ + """Test VerifiedHTTPSConnection: absence of SSL key file.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') try: @@ -185,9 +181,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): pass def test_ssl_init_key_no_cert(self): - """ - Test VerifiedHTTPSConnection: absence of SSL cert file. - """ + """Test VerifiedHTTPSConnection: absence of SSL cert file.""" key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') try: @@ -200,9 +194,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Failed to init VerifiedHTTPSConnection.') def test_ssl_init_bad_key(self): - """ - Test VerifiedHTTPSConnection: bad key. - """ + """Test VerifiedHTTPSConnection: bad key.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') key_file = os.path.join(TEST_VAR_DIR, 'badkey.key') @@ -216,9 +208,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): pass def test_ssl_init_bad_cert(self): - """ - Test VerifiedHTTPSConnection: bad cert. - """ + """Test VerifiedHTTPSConnection: bad cert.""" cert_file = os.path.join(TEST_VAR_DIR, 'badcert.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') try: @@ -230,9 +220,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): pass def test_ssl_init_bad_ca(self): - """ - Test VerifiedHTTPSConnection: bad CA. - """ + """Test VerifiedHTTPSConnection: bad CA.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'badca.crt') try: @@ -244,9 +232,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): pass def test_ssl_cert_cname(self): - """ - Test certificate: CN match - """ + """Test certificate: CN match.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -259,9 +245,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Unexpected exception.') def test_ssl_cert_cname_wildcard(self): - """ - Test certificate: wildcard CN match - """ + """Test certificate: wildcard CN match.""" cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -274,9 +258,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Unexpected exception.') def test_ssl_cert_subject_alt_name(self): - """ - Test certificate: SAN match - """ + """Test certificate: SAN match.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -295,9 +277,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Unexpected exception.') def test_ssl_cert_subject_alt_name_wildcard(self): - """ - Test certificate: wildcard SAN match - """ + """Test certificate: wildcard SAN match.""" cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -323,9 +303,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): pass def test_ssl_cert_mismatch(self): - """ - Test certificate: bogus host - """ + """Test certificate: bogus host.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -341,9 +319,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): host=conn.host) def test_ssl_expired_cert(self): - """ - Test certificate: out of date cert - """ + """Test certificate: out of date cert.""" cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt') cert = crypto.load_certificate(crypto.FILETYPE_PEM, open(cert_file).read()) @@ -360,9 +336,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): host=conn.host) def test_ssl_broken_key_file(self): - """ - Test verify exception is raised. - """ + """Test verify exception is raised.""" cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') key_file = 'fake.key' @@ -373,9 +347,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): cert_file=cert_file, cacert=cacert) def test_ssl_init_ok_with_insecure_true(self): - """ - Test VerifiedHTTPSConnection class init - """ + """Test VerifiedHTTPSConnection class init.""" key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key') cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') @@ -389,9 +361,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Failed to init VerifiedHTTPSConnection.') def test_ssl_init_ok_with_ssl_compression_false(self): - """ - Test VerifiedHTTPSConnection class init - """ + """Test VerifiedHTTPSConnection class init.""" key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key') cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt') cacert = os.path.join(TEST_VAR_DIR, 'ca.crt') @@ -405,8 +375,7 @@ class TestVerifiedHTTPSConnection(testtools.TestCase): self.fail('Failed to init VerifiedHTTPSConnection.') def test_ssl_init_non_byte_string(self): - """ - Test VerifiedHTTPSConnection class non byte string + """Test VerifiedHTTPSConnection class non byte string. Reproduces bug #1301849 """ diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py index e2c17807..c991f3ce 100644 --- a/glanceclient/tests/unit/test_utils.py +++ b/glanceclient/tests/unit/test_utils.py @@ -55,7 +55,7 @@ class TestUtils(testtools.TestCase): file_obj.close() def test_prettytable(self): - class Struct: + class Struct(object): def __init__(self, **entries): self.__dict__.update(entries) diff --git a/glanceclient/tests/unit/v1/test_shell.py b/glanceclient/tests/unit/v1/test_shell.py index 963c560d..a3a41c24 100644 --- a/glanceclient/tests/unit/v1/test_shell.py +++ b/glanceclient/tests/unit/v1/test_shell.py @@ -236,11 +236,11 @@ class ShellInvalidEndpointandParameterTest(utils.TestCase): self.gc = self._mock_glance_client() def _make_args(self, args): - #NOTE(venkatesh): this conversion from a dict to an object + # NOTE(venkatesh): this conversion from a dict to an object # is required because the test_shell.do_xxx(gc, args) methods # expects the args to be attributes of an object. If passed as # dict directly, it throws an AttributeError. - class Args(): + class Args(object): def __init__(self, entries): self.__dict__.update(entries) @@ -396,10 +396,12 @@ class ShellInvalidEndpointandParameterTest(utils.TestCase): class ShellStdinHandlingTests(testtools.TestCase): def _fake_update_func(self, *args, **kwargs): - '''Function to replace glanceclient.images.update, + """ + + Function to replace glanceclient.images.update, to determine the parameters that would be supplied with the update request - ''' + """ # Store passed in args self.collected_args = (args, kwargs) @@ -477,7 +479,9 @@ class ShellStdinHandlingTests(testtools.TestCase): ) def test_image_update_closed_stdin(self): - """Supply glanceclient with a closed stdin, and perform an image + """ + + Supply glanceclient with a closed stdin, and perform an image update to an active image. Glanceclient should not attempt to read stdin. """ @@ -494,7 +498,9 @@ class ShellStdinHandlingTests(testtools.TestCase): ) def test_image_update_opened_stdin(self): - """Supply glanceclient with a stdin, and perform an image + """ + + Supply glanceclient with a stdin, and perform an image update to an active image. Glanceclient should not allow it. """ diff --git a/glanceclient/tests/unit/v2/test_members.py b/glanceclient/tests/unit/v2/test_members.py index cf56a36d..be378f91 100644 --- a/glanceclient/tests/unit/v2/test_members.py +++ b/glanceclient/tests/unit/v2/test_members.py @@ -84,7 +84,7 @@ class TestController(testtools.TestCase): def test_list_image_members(self): image_id = IMAGE - #NOTE(iccha): cast to list since the controller returns a generator + # NOTE(iccha): cast to list since the controller returns a generator image_members = list(self.controller.list(image_id)) self.assertEqual(IMAGE, image_members[0].image_id) self.assertEqual(MEMBER, image_members[0].member_id) diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index 5967b004..d5868055 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -30,11 +30,11 @@ class ShellV2Test(testtools.TestCase): self.gc = self._mock_glance_client() def _make_args(self, args): - #NOTE(venkatesh): this conversion from a dict to an object + # NOTE(venkatesh): this conversion from a dict to an object # is required because the test_shell.do_xxx(gc, args) methods # expects the args to be attributes of an object. If passed as # dict directly, it throws an AttributeError. - class Args(): + class Args(object): def __init__(self, entries): self.__dict__.update(entries) diff --git a/glanceclient/tests/unit/v2/test_tasks.py b/glanceclient/tests/unit/v2/test_tasks.py index d1dd1ef1..349a880f 100644 --- a/glanceclient/tests/unit/v2/test_tasks.py +++ b/glanceclient/tests/unit/v2/test_tasks.py @@ -255,7 +255,7 @@ class TestController(testtools.TestCase): self.controller = tasks.Controller(self.api, self.schema_api) def test_list_tasks(self): - #NOTE(flwang): cast to list since the controller returns a generator + # NOTE(flwang): cast to list since the controller returns a generator tasks = list(self.controller.list()) self.assertEqual(tasks[0].id, _PENDING_ID) self.assertEqual(tasks[0].type, 'import') @@ -265,7 +265,7 @@ class TestController(testtools.TestCase): self.assertEqual(tasks[1].status, 'processing') def test_list_tasks_paginated(self): - #NOTE(flwang): cast to list since the controller returns a generator + # NOTE(flwang): cast to list since the controller returns a generator tasks = list(self.controller.list(page_size=1)) self.assertEqual(tasks[0].id, _PENDING_ID) self.assertEqual(tasks[0].type, 'import') diff --git a/glanceclient/tests/utils.py b/glanceclient/tests/utils.py index f7f3452d..2dc510c7 100644 --- a/glanceclient/tests/utils.py +++ b/glanceclient/tests/utils.py @@ -75,6 +75,7 @@ class RawRequest(object): def __init__(self, headers, body=None, version=1.0, status=200, reason="Ok"): """ + :param headers: dict representing HTTP response headers :param body: file-like object :param version: HTTP Version @@ -101,6 +102,7 @@ class FakeResponse(object): def __init__(self, headers=None, body=None, version=1.0, status_code=200, reason="Ok"): """ + :param headers: dict representing HTTP response headers :param body: file-like object :param version: HTTP Version @@ -179,6 +181,7 @@ class FakeNoTTYStdout(FakeTTYStdout): def sort_url_by_query_keys(url): """A helper function which sorts the keys of the query string of a url. + For example, an input of '/v2/tasks?sort_key=id&sort_dir=asc&limit=10' returns '/v2/tasks?limit=10&sort_dir=asc&sort_key=id'. This is to prevent non-deterministic ordering of the query string causing @@ -200,8 +203,7 @@ def sort_url_by_query_keys(url): def build_call_record(method, url, headers, data): - """Key the request body be ordered if it's a dict type. - """ + """Key the request body be ordered if it's a dict type.""" if isinstance(data, dict): data = sorted(data.items()) if isinstance(data, six.string_types): diff --git a/glanceclient/v1/image_members.py b/glanceclient/v1/image_members.py index d940a5f8..79242b56 100644 --- a/glanceclient/v1/image_members.py +++ b/glanceclient/v1/image_members.py @@ -44,7 +44,7 @@ class ImageMemberManager(base.ManagerWithFind): if image and member: try: out.append(self.get(image, member)) - #TODO(bcwaldon): narrow this down to 404 + # TODO(bcwaldon): narrow this down to 404 except Exception: pass elif image: @@ -52,7 +52,7 @@ class ImageMemberManager(base.ManagerWithFind): elif member: out.extend(self._list_by_member(member)) else: - #TODO(bcwaldon): figure out what is appropriate to do here as we + # TODO(bcwaldon): figure out what is appropriate to do here as we # are unable to provide the requested response pass return out diff --git a/glanceclient/v1/images.py b/glanceclient/v1/images.py index 11a56ba9..4e26c515 100644 --- a/glanceclient/v1/images.py +++ b/glanceclient/v1/images.py @@ -26,7 +26,7 @@ from glanceclient.openstack.common.apiclient import base UPDATE_PARAMS = ('name', 'disk_format', 'container_format', 'min_disk', 'min_ram', 'owner', 'size', 'is_public', 'protected', 'location', 'checksum', 'copy_from', 'properties', - #NOTE(bcwaldon: an attempt to update 'deleted' will be + # NOTE(bcwaldon: an attempt to update 'deleted' will be # ignored, but we need to support it for backwards- # compatibility with the legacy client library 'deleted') @@ -289,7 +289,7 @@ class ImageManager(base.ManagerWithFind): return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None)) def create(self, **kwargs): - """Create an image + """Create an image. TODO(bcwaldon): document accepted params """ @@ -324,7 +324,7 @@ class ImageManager(base.ManagerWithFind): return Image(self, self._format_image_meta_for_user(body['image'])) def update(self, image, **kwargs): - """Update an image + """Update an image. TODO(bcwaldon): document accepted params """ diff --git a/glanceclient/v2/image_tags.py b/glanceclient/v2/image_tags.py index 0f2f1bb4..bcecd013 100644 --- a/glanceclient/v2/image_tags.py +++ b/glanceclient/v2/image_tags.py @@ -30,8 +30,7 @@ class Controller(object): return warlock.model_factory(schema.raw(), schemas.SchemaBasedModel) def update(self, image_id, tag_value): - """ - Update an image with the given tag. + """Update an image with the given tag. :param image_id: image to be updated with the given tag. :param tag_value: value of the tag. @@ -40,8 +39,7 @@ class Controller(object): self.http_client.put(url) def delete(self, image_id, tag_value): - """ - Delete the tag associated with the given image. + """Delete the tag associated with the given image. :param image_id: Image whose tag to be deleted. :param tag_value: tag value to be deleted. diff --git a/glanceclient/v2/images.py b/glanceclient/v2/images.py index 0cbd0d52..e704428f 100644 --- a/glanceclient/v2/images.py +++ b/glanceclient/v2/images.py @@ -177,14 +177,13 @@ class Controller(object): def get(self, image_id): url = '/v2/images/%s' % image_id resp, body = self.http_client.get(url) - #NOTE(bcwaldon): remove 'self' for now until we have an elegant + # NOTE(bcwaldon): remove 'self' for now until we have an elegant # way to pass it into the model constructor without conflict body.pop('self', None) return self.model(**body) def data(self, image_id, do_checksum=True): - """ - Retrieve data of an image. + """Retrieve data of an image. :param image_id: ID of the image to download. :param do_checksum: Enable/disable checksum validation. @@ -200,8 +199,7 @@ class Controller(object): return utils.IterableWithLength(body, content_length) def upload(self, image_id, image_data, image_size=None): - """ - Upload the data for an image. + """Upload the data for an image. :param image_id: ID of the image to upload data for. :param image_data: File-like object supplying the data to upload. @@ -233,14 +231,13 @@ class Controller(object): raise TypeError(utils.exception_to_str(e)) resp, body = self.http_client.post(url, data=image) - #NOTE(esheffield): remove 'self' for now until we have an elegant + # NOTE(esheffield): remove 'self' for now until we have an elegant # way to pass it into the model constructor without conflict body.pop('self', None) return self.model(**body) def update(self, image_id, remove_props=None, **kwargs): - """ - Update attributes of an image. + """Update attributes of an image. :param image_id: ID of the image to modify. :param remove_props: List of property names to remove @@ -256,7 +253,7 @@ class Controller(object): if remove_props is not None: cur_props = image.keys() new_props = kwargs.keys() - #NOTE(esheffield): Only remove props that currently exist on the + # NOTE(esheffield): Only remove props that currently exist on the # image and are NOT in the properties being updated / added props_to_remove = set(cur_props).intersection( set(remove_props).difference(new_props)) @@ -268,7 +265,7 @@ class Controller(object): hdrs = {'Content-Type': 'application/openstack-images-v2.1-json-patch'} self.http_client.patch(url, headers=hdrs, data=image.patch) - #NOTE(bcwaldon): calling image.patch doesn't clear the changes, so + # NOTE(bcwaldon): calling image.patch doesn't clear the changes, so # we need to fetch the image again to get a clean history. This is # an obvious optimization for warlock return self.get(image_id) diff --git a/glanceclient/v2/metadefs.py b/glanceclient/v2/metadefs.py index 84d83df7..5886563e 100644 --- a/glanceclient/v2/metadefs.py +++ b/glanceclient/v2/metadefs.py @@ -89,7 +89,8 @@ class NamespaceController(object): return self.model(**body) def list(self, **kwargs): - """Retrieve a listing of Namespace objects + """Retrieve a listing of Namespace objects. + :param page_size: Number of items to request in each paginated request :param limit: Use to request a specific page size. Expect a response to a limited request to return between zero and limit @@ -206,7 +207,7 @@ class ResourceTypeController(object): self.http_client.delete(url) def list(self): - """Retrieve a listing of available resource types + """Retrieve a listing of available resource types. :returns generator over list of resource_types """ @@ -280,7 +281,7 @@ class PropertyController(object): return self.model(**body) def list(self, namespace, **kwargs): - """Retrieve a listing of metadata properties + """Retrieve a listing of metadata properties. :returns generator over list of objects """ @@ -365,7 +366,7 @@ class ObjectController(object): return self.model(**body) def list(self, namespace, **kwargs): - """Retrieve a listing of metadata objects + """Retrieve a listing of metadata objects. :returns generator over list of objects """ diff --git a/glanceclient/v2/schemas.py b/glanceclient/v2/schemas.py index 94d1bb62..9ba72c35 100644 --- a/glanceclient/v2/schemas.py +++ b/glanceclient/v2/schemas.py @@ -21,7 +21,7 @@ import warlock.model as warlock class SchemaBasedModel(warlock.Model): - """Glance specific subclass of the warlock Model + """Glance specific subclass of the warlock Model. This implementation alters the function of the patch property to take into account the schema's core properties. With this version @@ -35,8 +35,8 @@ class SchemaBasedModel(warlock.Model): tags_patch = [] else: tags_patch = [{"path": "/tags", - "value": self.get('tags'), - "op": "replace"}] + "value": self.get('tags'), + "op": "replace"}] patch_string = jsonpatch.make_patch(original, new).to_string() patch = json.loads(patch_string) @@ -69,7 +69,7 @@ class SchemaProperty(object): def translate_schema_properties(schema_properties): - """Parse the properties dictionary of a schema document + """Parse the properties dictionary of a schema document. :returns list of SchemaProperty objects """ @@ -87,7 +87,9 @@ class Schema(object): self.properties = translate_schema_properties(raw_properties) def is_core_property(self, property_name): - """Checks if a property with a given name is known to the schema, + """ + + Checks if a property with a given name is known to the schema, i.e. is either a base property or a custom one registered in schema-image.json file @@ -97,7 +99,7 @@ class Schema(object): return self._check_property(property_name, True) def is_base_property(self, property_name): - """Checks if a property with a given name is a base property + """Checks if a property with a given name is a base property. :param property_name: name of the property :returns: True if the property is base, False otherwise diff --git a/glanceclient/v2/tasks.py b/glanceclient/v2/tasks.py index 8ad039f3..2f4aca5e 100644 --- a/glanceclient/v2/tasks.py +++ b/glanceclient/v2/tasks.py @@ -38,7 +38,7 @@ class Controller(object): return warlock.model_factory(schema.raw(), schemas.SchemaBasedModel) def list(self, **kwargs): - """Retrieve a listing of Task objects + """Retrieve a listing of Task objects. :param page_size: Number of tasks to request in each paginated request :returns generator over list of Tasks @@ -87,7 +87,7 @@ class Controller(object): url = '/v2/tasks?%s' % six.moves.urllib.parse.urlencode(filters) for task in paginate(url): - #NOTE(flwang): remove 'self' for now until we have an elegant + # NOTE(flwang): remove 'self' for now until we have an elegant # way to pass it into the model constructor without conflict task.pop('self', None) yield self.model(**task) @@ -96,7 +96,7 @@ class Controller(object): """Get a task based on given task id.""" url = '/v2/tasks/%s' % task_id resp, body = self.http_client.get(url) - #NOTE(flwang): remove 'self' for now until we have an elegant + # NOTE(flwang): remove 'self' for now until we have an elegant # way to pass it into the model constructor without conflict body.pop('self', None) return self.model(**body) @@ -113,7 +113,7 @@ class Controller(object): raise TypeError(utils.exception_to_str(e)) resp, body = self.http_client.post(url, data=task) - #NOTE(flwang): remove 'self' for now until we have an elegant + # NOTE(flwang): remove 'self' for now until we have an elegant # way to pass it into the model constructor without conflict body.pop('self', None) return self.model(**body) diff --git a/test-requirements.txt b/test-requirements.txt index ebf9fc06..dcdd38ee 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking<0.11,>=0.10.0 +hacking>=0.10.0,<0.11 coverage>=3.6 discover diff --git a/tox.ini b/tox.ini index 74cf84ca..4065c137 100644 --- a/tox.ini +++ b/tox.ini @@ -40,15 +40,7 @@ downloadcache = ~/cache/pip # H303 no wildcard import # H404 multi line docstring should start with a summary -# TODO(kragniz) fix these and remove from the ignore list - -# E265 block comment should start with '# ' -# H405 multi line docstring summary not separated with an empty line -# E123 closing bracket does not match indentation of opening bracket's line -# H238 old style class declaration, use new style (inherit from `object`) -# E128 continuation line under-indented for visual indent - -ignore = F403,F812,F821,H233,H303,H404,E265,H405,E123,H238,E128 +ignore = F403,F812,F821,H233,H303,H404 show-source = True exclude = .venv*,.tox,dist,*egg,build,.git,doc,*openstack/common*,*lib/python*,.update-venv