Fix exception handling in tests

HTTP client was replaced by keystoneauth1 session -> update test code
Related-bug: #1609705

Change-Id: I1b3881e7c75fd0163347d4d6605dd979087393eb
This commit is contained in:
Alexey Stepanov 2016-08-08 13:07:46 +03:00
parent 42192c36cc
commit df6b5884e0
9 changed files with 59 additions and 77 deletions

View File

@ -29,12 +29,7 @@ from proboscis.asserts import assert_equal
from proboscis.asserts import assert_false from proboscis.asserts import assert_false
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
# pylint: disable=import-error from keystoneauth1 import exceptions
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import URLError
# pylint: enable=import-error
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
from six.moves import xrange from six.moves import xrange
@ -254,7 +249,7 @@ def enable_feature_group(env, group):
try: try:
return (group in return (group in
env.fuel_web.client.get_api_version()["feature_groups"]) env.fuel_web.client.get_api_version()["feature_groups"])
except (HTTPError, URLError): except exceptions.HttpError:
return False return False
wait(check_api_group_enabled, interval=10, timeout=60 * 20, wait(check_api_group_enabled, interval=10, timeout=60 * 20,

View File

@ -33,6 +33,7 @@ except ImportError:
# pylint: enable=no-member # pylint: enable=no-member
from devops.helpers.helpers import wait_pass from devops.helpers.helpers import wait_pass
from devops.helpers.helpers import wait from devops.helpers.helpers import wait
from keystoneauth1 import exceptions
import netaddr import netaddr
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import assert_false from proboscis.asserts import assert_false
@ -40,10 +41,6 @@ from proboscis.asserts import assert_is_not_none
from proboscis.asserts import assert_not_equal from proboscis.asserts import assert_not_equal
from proboscis.asserts import assert_raises from proboscis.asserts import assert_raises
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
import yaml import yaml
from fuelweb_test import logger from fuelweb_test import logger
@ -2160,8 +2157,9 @@ class FuelWebClient29(object):
logger.info('Selected task: {}'.format(task)) logger.info('Selected task: {}'.format(task))
# Task will be removed with the cluster, so we will get 404 error # Task will be removed with the cluster, so we will get 404 error
assert_raises(HTTPError, assert_raises(
self.assert_task_success, task, timeout) exceptions.NotFound,
self.assert_task_success, task, timeout)
else: else:
assert 'No cluster_deletion task found!' assert 'No cluster_deletion task found!'

View File

@ -14,12 +14,9 @@
from copy import deepcopy from copy import deepcopy
from keystoneauth1.exceptions import HttpError
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis import test from proboscis import test
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test import logger from fuelweb_test import logger
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
@ -219,12 +216,14 @@ class BondingHAOneController(BondingTest):
nailgun_nodes[0]['id'], nailgun_nodes[0]['id'],
interfaces_dict=interfaces_dict, interfaces_dict=interfaces_dict,
raw_data=invalid_bond_conf) raw_data=invalid_bond_conf)
except HTTPError as exc: except HttpError as exc:
if exc.code != exp_code: if exc.http_status != exp_code:
logger.error( logger.error(
'Raised: {exc!s},\n' 'Raised: {exc!s},\n'
'Expected: {exp} with code={code}'.format( 'Expected: {exp} with code={code}'.format(
exc=exc, exp=HTTPError.__class__, code=exp_code)) exc=exc,
exp=HttpError,
code=exp_code))
raise raise
logger.info('Test PASS: expected exception raised: ' logger.info('Test PASS: expected exception raised: '
@ -234,12 +233,15 @@ class BondingHAOneController(BondingTest):
logger.error( logger.error(
'Raised: {exc!s},\n' 'Raised: {exc!s},\n'
'Expected: {exp} with code={code}'.format( 'Expected: {exp} with code={code}'.format(
exc=exc, exp=HTTPError.__class__, code=exp_code)) exc=exc,
exp=HttpError,
code=exp_code))
raise raise
raise AssertionError( raise AssertionError(
'Not raised any exception, while expected ' 'Not raised any exception, while expected '
'{exp} with code={code}'.format( '{exp} with code={code}'.format(
exp=HTTPError.__class__, code=exp_code)) exp=HttpError,
code=exp_code))
@test(groups=["bonding_neutron", "bonding_ha", "bonding"]) @test(groups=["bonding_neutron", "bonding_ha", "bonding"])

View File

@ -12,17 +12,16 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from keystoneauth1.exceptions import NotFound
from keystoneauth1.exceptions import BadRequest
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import fail from proboscis.asserts import fail
from proboscis import test from proboscis import test
from proboscis import SkipTest from proboscis import SkipTest
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test.tests.base_test_case import TestBasic from fuelweb_test.tests.base_test_case import TestBasic
from fuelweb_test import logger
@test(groups=["clone_env_for_os_upgrade"], @test(groups=["clone_env_for_os_upgrade"],
@ -138,8 +137,8 @@ class TestCloneEnv(TestBasic):
} }
try: try:
self.fuel_web.client.clone_environment(1234567, data) self.fuel_web.client.clone_environment(1234567, data)
except HTTPError as e: except NotFound:
assert_equal(404, e.code) logger.debug('exceptions.NotFound received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -168,8 +167,8 @@ class TestCloneEnv(TestBasic):
try: try:
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('exceptions.BadRequest received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -195,8 +194,8 @@ class TestCloneEnv(TestBasic):
try: try:
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('exceptions.BadRequest received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -218,8 +217,8 @@ class TestCloneEnv(TestBasic):
try: try:
self.fuel_web.client.clone_environment(cluster_id, None) self.fuel_web.client.clone_environment(cluster_id, None)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('exceptions.BadRequest received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -247,8 +246,8 @@ class TestCloneEnv(TestBasic):
try: try:
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
except HTTPError as e: except NotFound:
assert_equal(404, e.code) logger.debug('exceptions.NotFound received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -276,8 +275,8 @@ class TestCloneEnv(TestBasic):
try: try:
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('exceptions.BadRequest received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")
@ -310,7 +309,7 @@ class TestCloneEnv(TestBasic):
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
try: try:
self.fuel_web.client.clone_environment(cluster_id, data) self.fuel_web.client.clone_environment(cluster_id, data)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('exceptions.BadRequest received as expected')
else: else:
fail("Doesn't raise needed error") fail("Doesn't raise needed error")

View File

@ -14,12 +14,9 @@
import random import random
from keystoneauth1.exceptions import BadRequest
from proboscis import asserts from proboscis import asserts
from proboscis import test from proboscis import test
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test.helpers import os_actions from fuelweb_test.helpers import os_actions
@ -562,8 +559,8 @@ class NumaCpuPinning(TestBasic):
try: try:
self.fuel_web.client.upload_node_attributes( self.fuel_web.client.upload_node_attributes(
compute_config, compute['id']) compute_config, compute['id'])
except HTTPError as e: except BadRequest:
asserts.assert_equal(400, e.code) logger.debug('BadRequest received as expected')
else: else:
asserts.fail("Pinned all CPU on {0}, while expecting HTTP " asserts.fail("Pinned all CPU on {0}, while expecting HTTP "
"error on CPU value {1}" "error on CPU value {1}"
@ -574,8 +571,8 @@ class NumaCpuPinning(TestBasic):
try: try:
self.fuel_web.client.upload_node_attributes( self.fuel_web.client.upload_node_attributes(
compute_config, compute['id']) compute_config, compute['id'])
except HTTPError as e: except BadRequest:
asserts.assert_equal(400, e.code) logger.debug('BadRequest received as expected')
else: else:
asserts.fail("Pinned all CPU on {0}, while expecting HTTP " asserts.fail("Pinned all CPU on {0}, while expecting HTTP "
"400 error on CPU value {1}" "400 error on CPU value {1}"

View File

@ -14,14 +14,11 @@
from random import randrange from random import randrange
from re import match from re import match
from keystoneauth1.exceptions import BadRequest
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import assert_raises from proboscis.asserts import assert_raises
from proboscis.asserts import assert_true from proboscis.asserts import assert_true
from proboscis import test from proboscis import test
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test.helpers.checkers import check_ping from fuelweb_test.helpers.checkers import check_ping
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
@ -209,7 +206,7 @@ class CustomHostname(TestBasic):
"node-", "node-",
): ):
assert_raises( assert_raises(
HTTPError, BadRequest,
self.fuel_web.client.set_hostname, self.fuel_web.client.set_hostname,
node['id'], node['id'],
invalid_hostname) invalid_hostname)
@ -238,7 +235,7 @@ class CustomHostname(TestBasic):
# Try to change the hostname of the provisioned node # Try to change the hostname of the provisioned node
assert_raises( assert_raises(
HTTPError, BadRequest,
self.fuel_web.client.set_hostname, self.fuel_web.client.set_hostname,
node, node,
custom_hostname) custom_hostname)
@ -281,7 +278,7 @@ class CustomHostname(TestBasic):
# Try to change the hostname of the provisioned node # Try to change the hostname of the provisioned node
# TODO(dkruglov): LP#1476722 # TODO(dkruglov): LP#1476722
assert_raises( assert_raises(
HTTPError, BadRequest,
self.fuel_web.client.set_hostname, self.fuel_web.client.set_hostname,
node['id'], node['id'],
'new-custom-hostname') 'new-custom-hostname')

View File

@ -12,15 +12,14 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from keystoneauth1.exceptions import NotFound
from keystoneauth1.exceptions import BadRequest
from proboscis.asserts import assert_equal from proboscis.asserts import assert_equal
from proboscis.asserts import fail from proboscis.asserts import fail
from proboscis import test from proboscis import test
from proboscis import SkipTest from proboscis import SkipTest
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test import logger
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test.tests.base_test_case import TestBasic from fuelweb_test.tests.base_test_case import TestBasic
@ -136,8 +135,8 @@ class TestReassignNode(TestBasic):
try: try:
self.fuel_web.client.reassign_node(123456, data) self.fuel_web.client.reassign_node(123456, data)
except HTTPError as e: except NotFound:
assert_equal(404, e.code) logger.debug('Got NotFound error as expected')
else: else:
fail("Doesn't rise HTTP 404 error" fail("Doesn't rise HTTP 404 error"
"while reassigning" "while reassigning"
@ -176,8 +175,8 @@ class TestReassignNode(TestBasic):
try: try:
self.fuel_web.client.reassign_node(cloned_cluster["id"], None) self.fuel_web.client.reassign_node(cloned_cluster["id"], None)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('Got BadRequest error as expected')
else: else:
fail("Doesn't raise HTTP 400 error on request" fail("Doesn't raise HTTP 400 error on request"
"to reassigning node with empty body") "to reassigning node with empty body")
@ -217,8 +216,8 @@ class TestReassignNode(TestBasic):
try: try:
self.fuel_web.client.reassign_node(cloned_cluster["id"], data) self.fuel_web.client.reassign_node(cloned_cluster["id"], data)
except HTTPError as e: except BadRequest:
assert_equal(400, e.code) logger.debug('Got BadRequest error as expected')
else: else:
fail("Doesn't raise HTTP 400 error on request" fail("Doesn't raise HTTP 400 error on request"
"to reassigning node with incorrect node_id") "to reassigning node with incorrect node_id")
@ -258,8 +257,8 @@ class TestReassignNode(TestBasic):
try: try:
self.fuel_web.client.reassign_node(cloned_cluster["id"], data) self.fuel_web.client.reassign_node(cloned_cluster["id"], data)
except HTTPError as e: except NotFound:
assert_equal(404, e.code) logger.debug('Got NotFound error as expected')
else: else:
fail("Doesn't raise HTTP 404 error on request" fail("Doesn't raise HTTP 404 error on request"
"to reassigning nonexistent node to cloned cluster") "to reassigning nonexistent node to cloned cluster")

View File

@ -17,13 +17,10 @@ import time
import traceback import traceback
from devops.helpers import helpers from devops.helpers import helpers
from keystoneauth1.exceptions import HttpError
import netaddr import netaddr
from proboscis import asserts from proboscis import asserts
from proboscis import test from proboscis import test
# pylint: disable=import-error
# noinspection PyUnresolvedReferences
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
from fuelweb_test.helpers.decorators import log_snapshot_after_test from fuelweb_test.helpers.decorators import log_snapshot_after_test
from fuelweb_test.helpers import os_actions from fuelweb_test.helpers import os_actions
@ -87,8 +84,8 @@ class ServicesReconfiguration(TestBasic):
func, *args, **kwargs): func, *args, **kwargs):
try: try:
func(*args, **kwargs) func(*args, **kwargs)
except HTTPError as e: except HttpError as e:
if e.code != expected_code: if e.http_status != expected_code:
raise raise
logger.warning('Ignoring exception: {!r}'.format(e)) logger.warning('Ignoring exception: {!r}'.format(e))
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())

View File

@ -17,9 +17,7 @@ import yaml
from proboscis import SkipTest from proboscis import SkipTest
from proboscis import test from proboscis import test
# pylint: disable=import-error from keystoneauth1.exceptions import HttpError
from six.moves.urllib.error import HTTPError
# pylint: enable=import-error
# pylint: disable=redefined-builtin # pylint: disable=redefined-builtin
from six.moves import xrange from six.moves import xrange
# pylint: enable=redefined-builtin # pylint: enable=redefined-builtin
@ -151,7 +149,7 @@ class UnlockSettingsTab(TestBasic):
try: try:
self.fuel_web.client.update_cluster_attributes( self.fuel_web.client.update_cluster_attributes(
self.cluster_id, new_attrs) self.cluster_id, new_attrs)
except HTTPError: except HttpError:
logger.info( logger.info(
"Failed to update cluster attributes, please check logs") "Failed to update cluster attributes, please check logs")
return False return False