Browse Source

Merge "Raise hacking to latest 2.0.0 release"

tags/20.0.0.0b3
Zuul 3 months ago
committed by Gerrit Code Review
parent
commit
2143060833
33 changed files with 94 additions and 60 deletions
  1. +3
    -3
      glance/api/v1/upload_utils.py
  2. +6
    -6
      glance/api/v2/image_data.py
  3. +7
    -9
      glance/api/v2/images.py
  4. +1
    -1
      glance/api/v2/metadef_resource_types.py
  5. +1
    -0
      glance/cmd/cache_manage.py
  6. +1
    -1
      glance/cmd/replicator.py
  7. +1
    -1
      glance/common/swift_store_utils.py
  8. +1
    -0
      glance/common/timeutils.py
  9. +1
    -1
      glance/common/wsgi.py
  10. +1
    -0
      glance/common/wsgi_app.py
  11. +5
    -2
      glance/db/simple/api.py
  12. +1
    -0
      glance/db/sqlalchemy/alembic_migrations/env.py
  13. +1
    -1
      glance/db/sqlalchemy/metadef_api/namespace.py
  14. +20
    -12
      glance/db/sqlalchemy/migrate_repo/schema.py
  15. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py
  16. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py
  17. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py
  18. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py
  19. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py
  20. +2
    -1
      glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py
  21. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py
  22. +1
    -1
      glance/db/sqlalchemy/migrate_repo/versions/010_default_update_at.py
  23. +16
    -2
      glance/i18n.py
  24. +3
    -1
      glance/tests/functional/db/base.py
  25. +1
    -1
      glance/tests/functional/v2/test_metadef_resourcetypes.py
  26. +3
    -3
      glance/tests/unit/common/test_wsgi.py
  27. +1
    -0
      glance/tests/unit/test_db.py
  28. +3
    -4
      glance/tests/unit/test_scrubber.py
  29. +1
    -1
      glance/tests/unit/utils.py
  30. +1
    -0
      glance/tests/unit/v2/test_tasks_resource.py
  31. +1
    -1
      lower-constraints.txt
  32. +1
    -1
      test-requirements.txt
  33. +4
    -1
      tox.ini

+ 3
- 3
glance/api/v1/upload_utils.py View File

@@ -242,7 +242,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
request=req,
content_type='text/plain')

except exception.ImageSizeLimitExceeded as e:
except exception.ImageSizeLimitExceeded:
msg = (_("Denying attempt to upload image larger than %d bytes.")
% CONF.image_size_cap)
LOG.warn(msg)
@@ -273,7 +273,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
LOG.exception(msg)
safe_kill(req, image_id, 'saving')

except (ValueError, IOError) as e:
except (ValueError, IOError):
msg = _("Client disconnected before sending all data to backend")
LOG.warn(msg)
safe_kill(req, image_id, 'saving')
@@ -281,7 +281,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
content_type="text/plain",
request=req)

except Exception as e:
except Exception:
msg = _("Failed to upload image %s") % image_id
LOG.exception(msg)
safe_kill(req, image_id, 'saving')


+ 6
- 6
glance/api/v2/image_data.py View File

@@ -234,7 +234,7 @@ class ImageDataController(object):
LOG.exception(msg)
raise webob.exc.HTTPConflict(explanation=e.msg, request=req)

except exception.Forbidden as e:
except exception.Forbidden:
msg = ("Not allowed to upload image data for image %s" %
image_id)
LOG.debug(msg)
@@ -283,16 +283,16 @@ class ImageDataController(object):
self._delete(image_repo, image)
raise webob.exc.HTTPBadRequest(explanation=msg)

except webob.exc.HTTPGone as e:
except webob.exc.HTTPGone:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Failed to upload image data due to HTTP error"))

except webob.exc.HTTPError as e:
except webob.exc.HTTPError:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Failed to upload image data due to HTTP error"))
self._restore(image_repo, image)

except Exception as e:
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE("Failed to upload image data due to "
"internal error"))
@@ -346,7 +346,7 @@ class ImageDataController(object):
staging_store.add(
image_id, utils.LimitingReader(
utils.CooperativeReader(data), CONF.image_size_cap), 0)
except glance_store.Duplicate as e:
except glance_store.Duplicate:
msg = _("The image %s has data on staging") % image_id
raise webob.exc.HTTPConflict(explanation=msg)

@@ -390,7 +390,7 @@ class ImageDataController(object):
LOG.debug(msg)
raise webob.exc.HTTPConflict(explanation=e.msg, request=req)

except Exception as e:
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(_LE("Failed to stage image data due to "
"internal error"))


+ 7
- 9
glance/api/v2/images.py View File

@@ -182,12 +182,10 @@ class ImagesController(object):
'backend': stores}

if (import_method == 'web-download' and
not utils.validate_import_uri(uri)):
LOG.debug("URI for web-download does not pass filtering: %s",
uri)
msg = (_("URI for web-download does not pass filtering: %s") %
uri)
raise webob.exc.HTTPBadRequest(explanation=msg)
not utils.validate_import_uri(uri)):
LOG.debug("URI for web-download does not pass filtering: %s", uri)
msg = (_("URI for web-download does not pass filtering: %s") % uri)
raise webob.exc.HTTPBadRequest(explanation=msg)

try:
import_task = task_factory.new_task(task_type='api_image_import',
@@ -506,7 +504,7 @@ class ImagesController(object):
except (glance_store.Forbidden, exception.Forbidden) as e:
LOG.debug("User not permitted to delete image '%s'", image_id)
raise webob.exc.HTTPForbidden(explanation=e.msg)
except (glance_store.NotFound, exception.NotFound) as e:
except (glance_store.NotFound, exception.NotFound):
msg = (_("Failed to find image %(image_id)s to delete") %
{'image_id': image_id})
LOG.warn(msg)
@@ -1176,8 +1174,8 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
locations = _get_image_locations(image)
if locations:
# Choose best location configured strategy
l = location_strategy.choose_best_location(locations)
image_view['direct_url'] = l['url']
loc = location_strategy.choose_best_location(locations)
image_view['direct_url'] = loc['url']
else:
LOG.debug("The 'locations' list of image %s is empty, "
"not including 'direct_url' in response",


+ 1
- 1
glance/api/v2/metadef_resource_types.py View File

@@ -128,7 +128,7 @@ class ResourceTypeController(object):
LOG.debug("User not permitted to delete metadata resource type "
"'%s' within '%s' namespace", resource_type, namespace)
raise webob.exc.HTTPForbidden(explanation=e.msg)
except exception.NotFound as e:
except exception.NotFound:
msg = (_("Failed to find resource type %(resourcetype)s to "
"delete") % {'resourcetype': resource_type})
LOG.error(msg)


+ 1
- 0
glance/cmd/cache_manage.py View File

@@ -524,5 +524,6 @@ def main():
except (RuntimeError, NotImplementedError) as e:
sys.exit("ERROR: %s" % e)


if __name__ == '__main__':
main()

+ 1
- 1
glance/cmd/replicator.py View File

@@ -757,7 +757,7 @@ def main():
config.parse_args()
except RuntimeError as e:
sys.exit("ERROR: %s" % encodeutils.exception_to_unicode(e))
except SystemExit as e:
except SystemExit:
sys.exit("Please specify one command")

# Setup logging


+ 1
- 1
glance/common/swift_store_utils.py View File

@@ -136,7 +136,7 @@ class SwiftParams(object):
reference['user'] = CONFIG.get(ref, 'user')
reference['key'] = CONFIG.get(ref, 'key')
account_params[ref] = reference
except (ValueError, SyntaxError, configparser.NoOptionError) as e:
except (ValueError, SyntaxError, configparser.NoOptionError):
LOG.exception(_LE("Invalid format of swift store config "
"cfg"))
return account_params

+ 1
- 0
glance/common/timeutils.py View File

@@ -76,6 +76,7 @@ def iso8601_from_timestamp(timestamp, microsecond=False):
"""Returns an iso8601 formatted date from timestamp."""
return isotime(datetime.datetime.utcfromtimestamp(timestamp), microsecond)


utcnow.override_time = None




+ 1
- 1
glance/common/wsgi.py View File

@@ -970,7 +970,7 @@ class APIMapper(routes.Mapper):
"""

def routematch(self, url=None, environ=None):
if url is "":
if url == "":
result = self._match("", environ)
return result[0], result[1]
return routes.Mapper.routematch(self, url, environ)


+ 1
- 0
glance/common/wsgi_app.py View File

@@ -19,6 +19,7 @@ import osprofiler.initializer

from glance.common import config
from glance.common import store_utils
from glance.i18n import _
from glance import notifier

CONF = cfg.CONF


+ 5
- 2
glance/db/simple/api.py View File

@@ -1056,8 +1056,11 @@ def _sort_tasks(tasks, sort_key, sort_dir):
reverse = False
if tasks and not (sort_key in tasks[0]):
raise exception.InvalidSortKey()
keyfn = lambda x: (x[sort_key] if x[sort_key] is not None else '',
x['created_at'], x['id'])

def keyfn(x):
return (x[sort_key] if x[sort_key] is not None else '',
x['created_at'], x['id'])

reverse = sort_dir == 'desc'
tasks.sort(key=keyfn, reverse=reverse)
return tasks


+ 1
- 0
glance/db/sqlalchemy/alembic_migrations/env.py View File

@@ -82,6 +82,7 @@ def run_migrations_online():
with context.begin_transaction():
context.run_migrations()


if context.is_offline_mode():
run_migrations_offline()
else:


+ 1
- 1
glance/db/sqlalchemy/metadef_api/namespace.py View File

@@ -182,7 +182,7 @@ def _get_all_by_resource_types(context, session, filters, marker=None,
for name, namespace_id in db_recs:
namespace_id_list.append(namespace_id)

if len(namespace_id_list) is 0:
if len(namespace_id_list) == 0:
return []

filters2 = filters


+ 20
- 12
glance/db/sqlalchemy/migrate_repo/schema.py View File

@@ -26,32 +26,40 @@ from glance.i18n import _LI
LOG = logging.getLogger(__name__)


String = lambda length: sqlalchemy.types.String(
length=length, convert_unicode=False,
unicode_error=None, _warn_on_bytestring=False)
def String(length):
return sqlalchemy.types.String(
length=length, convert_unicode=False,
unicode_error=None, _warn_on_bytestring=False)


Text = lambda: sqlalchemy.types.Text(
length=None, convert_unicode=False,
unicode_error=None, _warn_on_bytestring=False)
def Text():
return sqlalchemy.types.Text(
length=None, convert_unicode=False,
unicode_error=None, _warn_on_bytestring=False)


Boolean = lambda: sqlalchemy.types.Boolean(create_constraint=True, name=None)
def Boolean():
return sqlalchemy.types.Boolean(create_constraint=True, name=None)


DateTime = lambda: sqlalchemy.types.DateTime(timezone=False)
def DateTime():
return sqlalchemy.types.DateTime(timezone=False)


Integer = lambda: sqlalchemy.types.Integer()
def Integer():
return sqlalchemy.types.Integer()


BigInteger = lambda: sqlalchemy.types.BigInteger()
def BigInteger():
return sqlalchemy.types.BigInteger()


PickleType = lambda: sqlalchemy.types.PickleType()
def PickleType():
return sqlalchemy.types.PickleType()


Numeric = lambda: sqlalchemy.types.Numeric()
def Numeric():
return sqlalchemy.types.Numeric()


def from_migration_import(module_name, fromlist):


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/003_add_disk_format.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, MetaData, Table, and_, select

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text, from_migration_import) # noqa


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/004_add_checksum.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, MetaData, Table

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text, from_migration_import) # noqa


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/005_size_big_integer.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, MetaData, Table

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, BigInteger, Integer, String,


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/006_key_to_name.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Index, MetaData

from glance.db.sqlalchemy.migrate_repo.schema import from_migration_import



+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/007_add_owner.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, MetaData, Table

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, BigInteger, Integer, String,


+ 2
- 1
glance/db/sqlalchemy/migrate_repo/versions/008_add_image_members_table.py View File

@@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, ForeignKey, Index, MetaData, Table
from sqlalchemy import UniqueConstraint

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, create_tables,


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/009_add_mindisk_and_minram.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import Column, MetaData, Table

from glance.db.sqlalchemy.migrate_repo.schema import (
Boolean, DateTime, Integer, String, Text) # noqa


+ 1
- 1
glance/db/sqlalchemy/migrate_repo/versions/010_default_update_at.py View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import * # noqa
from sqlalchemy import MetaData

from glance.db.sqlalchemy.migrate_repo.schema import from_migration_import



+ 16
- 2
glance/i18n.py View File

@@ -13,14 +13,28 @@
# License for the specific language governing permissions and limitations
# under the License.

from oslo_i18n import * # noqa
import oslo_i18n as i18n

_translators = TranslatorFactory(domain='glance')
DOMAIN = 'glance'

_translators = i18n.TranslatorFactory(domain=DOMAIN)

# The primary translation function using the well-known name "_"
_ = _translators.primary


def enable_lazy(enable=True):
return i18n.enable_lazy(enable)


def translate(value, user_locale=None):
return i18n.translate(value, user_locale)


def get_available_languages(domain=DOMAIN):
return i18n.get_available_languages(domain)


# i18n log translation functions are deprecated. While removing the invocations
# requires a lot of reviewing effort, we decide to make it as no-op functions.
def _LI(msg):


+ 3
- 1
glance/tests/functional/db/base.py View File

@@ -1383,7 +1383,9 @@ class DriverTests(object):
return

def _assertMemberListMatch(list1, list2):
_simple = lambda x: set([(o['member'], o['image_id']) for o in x])
def _simple(x):
return set([(o['member'], o['image_id']) for o in x])

self.assertEqual(_simple(list1), _simple(list2))

# NOTE(flaper87): Update auth token, otherwise


+ 1
- 1
glance/tests/functional/v2/test_metadef_resourcetypes.py View File

@@ -122,7 +122,7 @@ class ResourceTypeController(object):
raise exception.NotFound()
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.msg)
except exception.NotFound as e:
except exception.NotFound:
msg = (_("Failed to find resource type %(resourcetype)s to "
"delete") % {'resourcetype': resource_type})
LOG.error(msg)


+ 3
- 3
glance/tests/unit/common/test_wsgi.py View File

@@ -394,9 +394,9 @@ class ResourceTest(test_utils.BaseTestCase):

def test_response_headers_encoded(self):
# prepare environment
for_openstack_comrades = \
u'\u0417\u0430 \u043e\u043f\u0435\u043d\u0441\u0442\u0435\u043a, ' \
u'\u0442\u043e\u0432\u0430\u0440\u0438\u0449\u0438'
for_openstack_comrades = (
u'\u0417\u0430 \u043e\u043f\u0435\u043d\u0441\u0442\u0435\u043a, '
u'\u0442\u043e\u0432\u0430\u0440\u0438\u0449\u0438')

class FakeController(object):
def index(self, shirt, pants=None):


+ 1
- 0
glance/tests/unit/test_db.py View File

@@ -61,6 +61,7 @@ class TestDbUtilities(test_utils.BaseTestCase):
import_module.assert_called_once_with('glance.db.sqlalchemy.api')
api.configure.assert_called_once_with()


UUID1 = 'c80a1a6c-bd1f-41c5-90ee-81afedb1d58d'
UUID2 = 'a85abd86-55b3-4d5b-b0b4-5d0a6e6042fc'
UUID3 = '971ec09a-8067-4bc8-a91f-ae3557f1c4c7'


+ 3
- 4
glance/tests/unit/test_scrubber.py View File

@@ -178,12 +178,11 @@ class ImagePager(object):
page_size = image_count
self.image_batches = []
start = 0
l = len(images)
while start < l:
while start < image_count:
self.image_batches.append(images[start: start + page_size])
start += page_size
if (l - start) < page_size:
page_size = l - start
if (image_count - start) < page_size:
page_size = image_count - start

def __call__(self):
if len(self.image_batches) == 0:


+ 1
- 1
glance/tests/unit/utils.py View File

@@ -65,7 +65,7 @@ def sort_url_by_qs_keys(url):
def get_fake_request(path='', method='POST', is_admin=False, user=USER1,
roles=None, tenant=TENANT1):
if roles is None:
roles = ['member']
roles = ['member']

req = wsgi.Request.blank(path)
req.method = method


+ 1
- 0
glance/tests/unit/v2/test_tasks_resource.py View File

@@ -84,6 +84,7 @@ def _domain_fixture(task_id, **kwargs):
task = glance.domain.Task(**task_properties)
return task


CONF = cfg.CONF
CONF.import_opt('task_time_to_live', 'glance.common.config', group='task')



+ 1
- 1
lower-constraints.txt View File

@@ -36,7 +36,7 @@ gitdb2==2.0.3
GitPython==2.1.8
glance-store==1.0.0
greenlet==0.4.13
hacking==0.12.0
hacking==2.0.0
httplib2==0.9.1
idna==2.6
imagesize==1.0.0


+ 1
- 1
test-requirements.txt View File

@@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.

# Hacking already pins down pep8, pyflakes and flake8
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
hacking>=2.0.0 # Apache-2.0

# For translations processing
Babel!=2.4.0,>=2.3.4 # BSD


+ 4
- 1
tox.ini View File

@@ -118,11 +118,14 @@ ignore-path = .venv,.git,.tox,*glance/locale*,*lib/python*,glance.egg*,api-ref/b

[flake8]
# TODO(dmllr): Analyze or fix the warnings blacklisted below
# E402 module level import not at top of file
# E711 comparison to None should be 'if cond is not None:'
# E712 comparison to True should be 'if cond is True:' or 'if cond:'
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
ignore = E711,E712,H404,H405
# W503 line break before binary operator - conflicting guidance
# W504 line break after binary operator - conflicting guidance
ignore = E402,E711,E712,H404,H405,W503,W504
exclude = .venv,.git,.tox,dist,doc,etc,*glance/locale*,*lib/python*,*egg,build

[hacking]


Loading…
Cancel
Save