tests: Enable SQLAlchemy 2.0 deprecation warnings
Well, sort of. We enable them but immediately filter out the ones we're actually seeing, the rationale being that we can address these in a piecemeal fashion without the risk of introducing new issues. There's a lot more to be done here. However, the work done in oslo.db [1], nova [2], cinder [2] etc. should provide a guide for how to resolve the outstanding issues. [1] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/oslo.db [2] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/nova [3] https://review.opendev.org/q/topic:sqlalchemy-20+project:openstack/cinder Change-Id: If13c14f1d968f1ef968ae440087227691cf966b0 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -726,6 +726,8 @@ def vmove_delete(context, vmove_uuid):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteFromSelect(sa_sql.expression.UpdateBase):
|
class DeleteFromSelect(sa_sql.expression.UpdateBase):
|
||||||
|
inherit_cache = False
|
||||||
|
|
||||||
def __init__(self, table, select, column):
|
def __init__(self, table, select, column):
|
||||||
self.table = table
|
self.table = table
|
||||||
self.select = select
|
self.select = select
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ class TestCase(testtools.TestCase):
|
|||||||
else:
|
else:
|
||||||
self.useFixture(masakari_fixtures.DatabasePoisonFixture())
|
self.useFixture(masakari_fixtures.DatabasePoisonFixture())
|
||||||
|
|
||||||
|
self.useFixture(masakari_fixtures.WarningsFixture())
|
||||||
|
|
||||||
def stub_out(self, old, new):
|
def stub_out(self, old, new):
|
||||||
"""Replace a function for the duration of the test.
|
"""Replace a function for the duration of the test.
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Copyright (c) 2016 NTT Data.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
from oslotest import base
|
|
||||||
|
|
||||||
|
|
||||||
class TestCase(base.BaseTestCase):
|
|
||||||
|
|
||||||
"""Test case base class for all unit tests."""
|
|
||||||
@@ -14,8 +14,11 @@
|
|||||||
|
|
||||||
"""Fixtures for Masakari tests."""
|
"""Fixtures for Masakari tests."""
|
||||||
|
|
||||||
|
import warnings
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
from sqlalchemy import exc as sqla_exc
|
||||||
|
|
||||||
from masakari.db import migration
|
from masakari.db import migration
|
||||||
from masakari.db.sqlalchemy import api as session
|
from masakari.db.sqlalchemy import api as session
|
||||||
@@ -139,3 +142,77 @@ class Database(fixtures.Fixture):
|
|||||||
super(Database, self).setUp()
|
super(Database, self).setUp()
|
||||||
self.reset()
|
self.reset()
|
||||||
self.addCleanup(self.cleanup)
|
self.addCleanup(self.cleanup)
|
||||||
|
|
||||||
|
|
||||||
|
class WarningsFixture(fixtures.Fixture):
|
||||||
|
"""Filters out warnings during test runs."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
|
||||||
|
self._original_warning_filters = warnings.filters[:]
|
||||||
|
|
||||||
|
warnings.simplefilter('once', DeprecationWarning)
|
||||||
|
|
||||||
|
# The UUIDFields emits a warning if the value is not a valid UUID.
|
||||||
|
# Let's escalate that to an exception in the test to prevent adding
|
||||||
|
# violations.
|
||||||
|
|
||||||
|
# warnings.filterwarnings('error', message='.*invalid UUID.*')
|
||||||
|
|
||||||
|
# Enable deprecation warnings for nova itself to capture upcoming
|
||||||
|
# SQLAlchemy changes
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'error',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
message='The current statement is being autocommitted',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
message='Using strings to indicate column or relationship paths',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
message=r'Passing a string to Connection.execute\(\)',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'ignore',
|
||||||
|
message=r'The legacy calling style of select\(\)',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SADeprecationWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Enable general SQLAlchemy warnings also to ensure we're not doing
|
||||||
|
# silly stuff. It's possible that we'll need to filter things out here
|
||||||
|
# with future SQLAlchemy versions, but that's a good thing
|
||||||
|
|
||||||
|
warnings.filterwarnings(
|
||||||
|
'error',
|
||||||
|
module='masakari',
|
||||||
|
category=sqla_exc.SAWarning,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.addCleanup(self._reset_warning_filters)
|
||||||
|
|
||||||
|
def _reset_warning_filters(self):
|
||||||
|
warnings.filters[:] = self._original_warning_filters
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ import sys
|
|||||||
|
|
||||||
import openstack.config
|
import openstack.config
|
||||||
from openstack import connection
|
from openstack import connection
|
||||||
|
from oslotest import base
|
||||||
from masakari.tests import base
|
|
||||||
|
|
||||||
|
|
||||||
#: Defines the OpenStack Client Config (OCC) cloud key in your OCC config
|
#: Defines the OpenStack Client Config (OCC) cloud key in your OCC config
|
||||||
#: file, typically in /etc/openstack/clouds.yaml. That configuration
|
#: file, typically in /etc/openstack/clouds.yaml. That configuration
|
||||||
@@ -30,7 +28,7 @@ from masakari.tests import base
|
|||||||
TEST_CLOUD_NAME = os.getenv('OS_CLOUD', 'devstack-admin')
|
TEST_CLOUD_NAME = os.getenv('OS_CLOUD', 'devstack-admin')
|
||||||
|
|
||||||
|
|
||||||
class BaseFunctionalTest(base.TestCase):
|
class BaseFunctionalTest(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self, ha_api_version="1.0"):
|
def setUp(self, ha_api_version="1.0"):
|
||||||
super(BaseFunctionalTest, self).setUp()
|
super(BaseFunctionalTest, self).setUp()
|
||||||
|
|||||||
36
tox.ini
36
tox.ini
@@ -1,32 +1,40 @@
|
|||||||
[tox]
|
[tox]
|
||||||
minversion = 3.1.1
|
minversion = 3.18.0
|
||||||
envlist = pep8,py3
|
envlist = pep8,py3
|
||||||
ignore_basepython_conflict = True
|
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
basepython = python3
|
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
setenv = VIRTUAL_ENV={envdir}
|
setenv =
|
||||||
|
VIRTUAL_ENV={envdir}
|
||||||
LANGUAGE=en_US
|
LANGUAGE=en_US
|
||||||
LC_ALL=en_US.utf-8
|
LC_ALL=en_US.utf-8
|
||||||
|
# TODO(stephenfin): Remove once we bump our upper-constraint to SQLAlchemy 2.0
|
||||||
|
SQLALCHEMY_WARN_20=1
|
||||||
deps =
|
deps =
|
||||||
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
commands =
|
commands =
|
||||||
stestr run {posargs}
|
stestr run {posargs}
|
||||||
passenv = HTTP_PROXY, HTTPS_PROXY, NO_PROXY, OS_DEBUG, GENERATE_HASHES
|
passenv =
|
||||||
|
HTTP_PROXY
|
||||||
|
HTTPS_PROXY
|
||||||
|
NO_PROXY
|
||||||
|
OS_DEBUG
|
||||||
|
GENERATE_HASHES
|
||||||
|
|
||||||
[testenv:functional]
|
[testenv:functional]
|
||||||
commands =
|
commands =
|
||||||
stestr --test-path=./masakari/tests/functional run --concurrency=1 --slowest {posargs}
|
stestr --test-path=./masakari/tests/functional run --concurrency=1 --slowest {posargs}
|
||||||
|
|
||||||
[testenv:genconfig]
|
[testenv:genconfig]
|
||||||
commands = oslo-config-generator --config-file=etc/masakari/masakari-config-generator.conf
|
commands =
|
||||||
|
oslo-config-generator --config-file=etc/masakari/masakari-config-generator.conf
|
||||||
oslo-config-generator --config-file=etc/masakari/masakari-customized-recovery-flow-config-generator.conf
|
oslo-config-generator --config-file=etc/masakari/masakari-customized-recovery-flow-config-generator.conf
|
||||||
|
|
||||||
[testenv:genpolicy]
|
[testenv:genpolicy]
|
||||||
commands = oslopolicy-sample-generator --config-file=etc/masakari/masakari-policy-generator.conf
|
commands =
|
||||||
|
oslopolicy-sample-generator --config-file=etc/masakari/masakari-policy-generator.conf
|
||||||
|
|
||||||
[testenv:linters]
|
[testenv:linters]
|
||||||
skip_install = True
|
skip_install = True
|
||||||
@@ -84,7 +92,8 @@ commands =
|
|||||||
# NOTE(elod.illes): requirements.txt is needed because otherwise
|
# NOTE(elod.illes): requirements.txt is needed because otherwise
|
||||||
# dependencies are installed during 'develop-inst' tox phase without
|
# dependencies are installed during 'develop-inst' tox phase without
|
||||||
# constraints which could cause failures in stable branches.
|
# constraints which could cause failures in stable branches.
|
||||||
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
deps =
|
||||||
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
-r{toxinidir}/doc/requirements.txt
|
-r{toxinidir}/doc/requirements.txt
|
||||||
commands =
|
commands =
|
||||||
@@ -100,12 +109,13 @@ commands =
|
|||||||
|
|
||||||
[testenv:releasenotes]
|
[testenv:releasenotes]
|
||||||
skip_install = True
|
skip_install = True
|
||||||
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
deps =
|
||||||
|
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master}
|
||||||
-r{toxinidir}/doc/requirements.txt
|
-r{toxinidir}/doc/requirements.txt
|
||||||
allowlist_externals =
|
allowlist_externals =
|
||||||
rm
|
rm
|
||||||
commands =
|
commands =
|
||||||
rm -fr releasenotes/build
|
rm -rf releasenotes/build
|
||||||
sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
|
sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
|
||||||
|
|
||||||
[testenv:debug]
|
[testenv:debug]
|
||||||
@@ -122,10 +132,8 @@ commands =
|
|||||||
sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html
|
sphinx-build -W -b html -d api-ref/build/doctrees api-ref/source api-ref/build/html
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# E123, E125 skipped as they are invalid PEP-8.
|
|
||||||
|
|
||||||
show-source = True
|
show-source = True
|
||||||
|
# E123, E125 skipped as they are invalid PEP-8.
|
||||||
# The below hacking rules by default are disabled should be enabled:
|
# The below hacking rules by default are disabled should be enabled:
|
||||||
# [H106] Don't put vim configuration in source files.
|
# [H106] Don't put vim configuration in source files.
|
||||||
# [H203] Use assertIs(Not)None to check for None.
|
# [H203] Use assertIs(Not)None to check for None.
|
||||||
@@ -134,7 +142,7 @@ enable-extensions = H106,H203,H904
|
|||||||
# [W504] line break after binary operator (use W503 instead)
|
# [W504] line break after binary operator (use W503 instead)
|
||||||
ignore = E123,E125,E128,E731,H405,W504
|
ignore = E123,E125,E128,E731,H405,W504
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build
|
||||||
|
|
||||||
[hacking]
|
[hacking]
|
||||||
import_exceptions = masakari.i18n
|
import_exceptions = masakari.i18n
|
||||||
|
|||||||
Reference in New Issue
Block a user