[ci] Turn treat warning as errors at tox

+ fix inner usage of deprecated imports
+ cover rally_openstack._compat module with unittests

Change-Id: I3b800826b7336ff82b2e7b258272b6116215a0e1
This commit is contained in:
Andrey Kurilin 2020-03-25 19:57:45 +02:00
parent e46de4521f
commit cfa3de2572
12 changed files with 78 additions and 16 deletions

View File

@ -315,6 +315,7 @@ class Keystone(OSClient):
version = str(discover.Discover(
temp_session,
password_args["auth_url"]).version_data()[0]["version"][0])
temp_session.session.close()
if "v2.0" not in password_args["auth_url"] and version != "2":
password_args.update({
@ -868,7 +869,7 @@ class Clients(object):
@classmethod
def create_from_env(cls):
from rally_openstack.common import credential
from rally_openstack.platforms import existing
from rally_openstack.environment.platforms import existing
spec = existing.OpenStack.create_spec_from_sys_environ(os.environ)
if not spec["available"]:

View File

@ -23,7 +23,7 @@ import shutil
import subprocess
import tempfile
from oslo_utils import encodeutils
from rally.utils import encodeutils
class RallyCliError(Exception):
@ -217,7 +217,7 @@ class Rally(object):
except subprocess.CalledProcessError as e:
output = e.output
raise RallyCliError(cmd, e.returncode, e.output)
raise RallyCliError(cmd, e.returncode, e.output) from None
finally:
if write_report:
if not report_path:

View File

@ -251,10 +251,12 @@ class TestCreateKeystoneClient(test.TestCase, OSClientTestCaseUtils):
tenant_name="tenant", username="user",
domain_name=None, project_domain_name=None,
user_domain_name=None)
self.ksa_session.Session.assert_has_calls(
self.assertEqual(
[mock.call(timeout=180.0, verify=True, cert=None),
mock.call(auth=self.ksa_identity_plugin, timeout=180.0,
verify=True, cert=None)])
verify=True, cert=None)],
self.ksa_session.Session.call_args_list
)
def test_keystone_property(self):
keystone = osclients.Keystone(self.credential, None)

View File

@ -21,7 +21,7 @@ from rally.env import env_mgr
from rally.env import platform
from rally import exceptions
from rally_openstack.platforms import existing
from rally_openstack.environment.platforms import existing
from tests.unit import test

View File

@ -19,7 +19,7 @@ from rally_openstack.task.cleanup import base
from tests.unit import test
BASE = "rally_openstack.cleanup.base"
BASE = "rally_openstack.task.cleanup.base"
class ResourceDecoratorTestCase(test.TestCase):

View File

@ -22,7 +22,7 @@ from rally_openstack.task.cleanup import manager
from tests.unit import test
BASE = "rally_openstack.cleanup.manager"
BASE = "rally_openstack.task.cleanup.manager"
class SeekAndDestroyTestCase(test.TestCase):

View File

@ -24,7 +24,7 @@ from watcherclient.common.apiclient import exceptions as watcher_exceptions
from rally_openstack.task.cleanup import resources
from tests.unit import test
BASE = "rally_openstack.cleanup.resources"
BASE = "rally_openstack.task.cleanup.resources"
GLANCE_V2_PATH = ("rally_openstack.common.services.image.glance_v2."
"GlanceV2Service")

View File

@ -182,7 +182,7 @@ class SharesTestCase(test.TestCase):
mock_calls, any_order=True)
@mock.patch(MANILA_UTILS_PATH + "_create_share")
@mock.patch("rally_openstack.cleanup.manager.cleanup")
@mock.patch("rally_openstack.task.cleanup.manager.cleanup")
def test_cleanup(
self,
mock_cleanup_manager_cleanup,

View File

@ -104,8 +104,8 @@ class OpenStackScenarioTestCase(test.TestCase):
([("admin", CREDENTIAL_WITHOUT_HMAC),
("user", CREDENTIAL_WITHOUT_HMAC)], 0))
@ddt.unpack
@mock.patch("rally_openstack.scenario.profiler.init")
@mock.patch("rally_openstack.scenario.profiler.get")
@mock.patch("rally_openstack.task.scenario.profiler.init")
@mock.patch("rally_openstack.task.scenario.profiler.get")
def test_profiler_init(self, users_credentials,
expected_call_count,
mock_profiler_get,

View File

@ -126,14 +126,14 @@ class ScenarioTestCase(TestCase):
return key in self._clients
def get_client_mocks(self):
base_path = "rally_openstack"
base_path = "rally_openstack.task"
return [
mock.patch(
"%s.scenario.OpenStackScenario.clients" % base_path,
f"{base_path}.scenario.OpenStackScenario.clients",
mock.Mock(side_effect=self.clients)),
mock.patch(
"%s.scenario.OpenStackScenario.admin_clients" % base_path,
f"{base_path}.scenario.OpenStackScenario.admin_clients",
mock.Mock(side_effect=self.admin_clients))
]

View File

@ -0,0 +1,43 @@
# 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.
import warnings
from tests.unit import test
class CompatibilityTestCase(test.TestCase):
def test_old_imports_work(self):
with warnings.catch_warnings(record=True) as ctx:
warnings.simplefilter("always")
from rally_openstack import osclients
if not ctx:
self.fail("`rally_openstack._compat` should raise a warning.")
self.assertEqual(1, len(ctx))
catched_warning = ctx[0]
self.assertEqual(
"Module rally_openstack.osclients is deprecated since "
"rally-openstack 2.0.0. Use rally_openstack.common.osclients "
"instead.",
# catched_warning.message is an instance of an exception
str(catched_warning.message))
from rally_openstack.common import osclients as right_osclients
expected = set(o for o in dir(right_osclients)
if not o.startswith("_"))
actual = set(o for o in dir(osclients) if not o.startswith("_"))
self.assertEqual(expected, actual)
self.assertEqual(right_osclients.Clients, osclients.Clients)

18
tox.ini
View File

@ -115,4 +115,20 @@ commands = bindep
commands = {toxinidir}/tests/ci/rally_self_job.sh {toxinidir}/rally-jobs/self-rally.yaml
[pytest]
addopts = -p no:warnings
filterwarnings =
error
ignore:.*EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade*:
# instead of ignoring all modules, let's list only libraries that are failing
ignore:invalid escape sequence:DeprecationWarning:.*netaddr.*
ignore:invalid escape sequence:DeprecationWarning:.*prettytable
ignore:invalid escape sequence:DeprecationWarning:.*subunit.*
ignore:invalid escape sequence:DeprecationWarning:.*testtools.*
# new to rally-openstack
ignore:Using or importing the ABCs:DeprecationWarning:.*oslo_context.*
ignore:the imp module is deprecated in favour of importlib.*:DeprecationWarning
# should be fixed soon
ignore:Module rally_openstack.credential is deprecated.*:
# python 3.7
ignore:Using or importing the ABCs:DeprecationWarning:unittest2.*
# python 3.8
ignore:::.*netaddr.strategy.*