From 6283970aa4de3fb4103f09af19fbec181fc6b2b1 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 19 Oct 2015 19:21:48 +0200 Subject: [PATCH] Port script utils to Python 3 * Replace StandardError with exception.BadStoreUri: StandardError was removed in Python 3. * tox.ini: add script util tests to Python 3.4 Change-Id: I26a723d3b5712fede9ad8ca67187fd5fbe31fc2a --- glance/common/scripts/utils.py | 6 +++--- glance/tests/unit/common/scripts/test_scripts_utils.py | 7 ++++--- tox.ini | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/glance/common/scripts/utils.py b/glance/common/scripts/utils.py index 6310de1b7d..a4787a9805 100644 --- a/glance/common/scripts/utils.py +++ b/glance/common/scripts/utils.py @@ -97,9 +97,9 @@ def validate_location_uri(location): elif location.startswith(("file:///", "filesystem:///")): msg = _("File based imports are not allowed. Please use a non-local " "source of image data.") - # NOTE: raise Exception and let the encompassing block save - # the error msg in the task.message. - raise StandardError(msg) + # NOTE: raise BadStoreUri and let the encompassing block save the error + # msg in the task.message. + raise exception.BadStoreUri(msg) else: # TODO(nikhil): add other supported uris diff --git a/glance/tests/unit/common/scripts/test_scripts_utils.py b/glance/tests/unit/common/scripts/test_scripts_utils.py index a2dac4c41a..8d79dbeb6b 100644 --- a/glance/tests/unit/common/scripts/test_scripts_utils.py +++ b/glance/tests/unit/common/scripts/test_scripts_utils.py @@ -89,9 +89,10 @@ class TestScriptsUtils(test_utils.BaseTestCase): script_utils.validate_location_uri, '') def test_validate_location_file_location_error(self): - self.assertRaises(StandardError, script_utils.validate_location_uri, - "file:///tmp") - self.assertRaises(StandardError, script_utils.validate_location_uri, + self.assertRaises(exception.BadStoreUri, + script_utils.validate_location_uri, "file:///tmp") + self.assertRaises(exception.BadStoreUri, + script_utils.validate_location_uri, "filesystem:///tmp") def test_validate_location_unsupported_error(self): diff --git a/tox.ini b/tox.ini index c5e43444d9..0801f266ee 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,8 @@ commands = glance.tests.unit.async.flows.test_introspect \ glance.tests.unit.async.test_async \ glance.tests.unit.async.test_taskflow_executor \ + glance.tests.unit.common.scripts.image_import.test_main \ + glance.tests.unit.common.scripts.test_scripts_utils \ glance.tests.unit.common.test_client \ glance.tests.unit.common.test_config \ glance.tests.unit.common.test_exception \