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:
parent
42192c36cc
commit
df6b5884e0
|
@ -29,12 +29,7 @@ from proboscis.asserts import assert_equal
|
|||
from proboscis.asserts import assert_false
|
||||
from proboscis.asserts import assert_true
|
||||
|
||||
# pylint: disable=import-error
|
||||
# noinspection PyUnresolvedReferences
|
||||
from six.moves.urllib.error import HTTPError
|
||||
# noinspection PyUnresolvedReferences
|
||||
from six.moves.urllib.error import URLError
|
||||
# pylint: enable=import-error
|
||||
from keystoneauth1 import exceptions
|
||||
# pylint: disable=redefined-builtin
|
||||
# noinspection PyUnresolvedReferences
|
||||
from six.moves import xrange
|
||||
|
@ -254,7 +249,7 @@ def enable_feature_group(env, group):
|
|||
try:
|
||||
return (group in
|
||||
env.fuel_web.client.get_api_version()["feature_groups"])
|
||||
except (HTTPError, URLError):
|
||||
except exceptions.HttpError:
|
||||
return False
|
||||
|
||||
wait(check_api_group_enabled, interval=10, timeout=60 * 20,
|
||||
|
|
|
@ -33,6 +33,7 @@ except ImportError:
|
|||
# pylint: enable=no-member
|
||||
from devops.helpers.helpers import wait_pass
|
||||
from devops.helpers.helpers import wait
|
||||
from keystoneauth1 import exceptions
|
||||
import netaddr
|
||||
from proboscis.asserts import assert_equal
|
||||
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_raises
|
||||
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
|
||||
|
||||
from fuelweb_test import logger
|
||||
|
@ -2160,8 +2157,9 @@ class FuelWebClient29(object):
|
|||
logger.info('Selected task: {}'.format(task))
|
||||
|
||||
# Task will be removed with the cluster, so we will get 404 error
|
||||
assert_raises(HTTPError,
|
||||
self.assert_task_success, task, timeout)
|
||||
assert_raises(
|
||||
exceptions.NotFound,
|
||||
self.assert_task_success, task, timeout)
|
||||
else:
|
||||
assert 'No cluster_deletion task found!'
|
||||
|
||||
|
|
|
@ -14,12 +14,9 @@
|
|||
|
||||
from copy import deepcopy
|
||||
|
||||
from keystoneauth1.exceptions import HttpError
|
||||
from proboscis.asserts import assert_equal
|
||||
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.helpers.decorators import log_snapshot_after_test
|
||||
|
@ -219,12 +216,14 @@ class BondingHAOneController(BondingTest):
|
|||
nailgun_nodes[0]['id'],
|
||||
interfaces_dict=interfaces_dict,
|
||||
raw_data=invalid_bond_conf)
|
||||
except HTTPError as exc:
|
||||
if exc.code != exp_code:
|
||||
except HttpError as exc:
|
||||
if exc.http_status != exp_code:
|
||||
logger.error(
|
||||
'Raised: {exc!s},\n'
|
||||
'Expected: {exp} with code={code}'.format(
|
||||
exc=exc, exp=HTTPError.__class__, code=exp_code))
|
||||
exc=exc,
|
||||
exp=HttpError,
|
||||
code=exp_code))
|
||||
raise
|
||||
|
||||
logger.info('Test PASS: expected exception raised: '
|
||||
|
@ -234,12 +233,15 @@ class BondingHAOneController(BondingTest):
|
|||
logger.error(
|
||||
'Raised: {exc!s},\n'
|
||||
'Expected: {exp} with code={code}'.format(
|
||||
exc=exc, exp=HTTPError.__class__, code=exp_code))
|
||||
exc=exc,
|
||||
exp=HttpError,
|
||||
code=exp_code))
|
||||
raise
|
||||
raise AssertionError(
|
||||
'Not raised any exception, while expected '
|
||||
'{exp} with code={code}'.format(
|
||||
exp=HTTPError.__class__, code=exp_code))
|
||||
exp=HttpError,
|
||||
code=exp_code))
|
||||
|
||||
|
||||
@test(groups=["bonding_neutron", "bonding_ha", "bonding"])
|
||||
|
|
|
@ -12,17 +12,16 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneauth1.exceptions import NotFound
|
||||
from keystoneauth1.exceptions import BadRequest
|
||||
from proboscis.asserts import assert_equal
|
||||
from proboscis.asserts import fail
|
||||
from proboscis import test
|
||||
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.tests.base_test_case import TestBasic
|
||||
from fuelweb_test import logger
|
||||
|
||||
|
||||
@test(groups=["clone_env_for_os_upgrade"],
|
||||
|
@ -138,8 +137,8 @@ class TestCloneEnv(TestBasic):
|
|||
}
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(1234567, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(404, e.code)
|
||||
except NotFound:
|
||||
logger.debug('exceptions.NotFound received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -168,8 +167,8 @@ class TestCloneEnv(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('exceptions.BadRequest received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -195,8 +194,8 @@ class TestCloneEnv(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('exceptions.BadRequest received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -218,8 +217,8 @@ class TestCloneEnv(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, None)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('exceptions.BadRequest received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -247,8 +246,8 @@ class TestCloneEnv(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(404, e.code)
|
||||
except NotFound:
|
||||
logger.debug('exceptions.NotFound received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -276,8 +275,8 @@ class TestCloneEnv(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('exceptions.BadRequest received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
||||
|
@ -310,7 +309,7 @@ class TestCloneEnv(TestBasic):
|
|||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
try:
|
||||
self.fuel_web.client.clone_environment(cluster_id, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('exceptions.BadRequest received as expected')
|
||||
else:
|
||||
fail("Doesn't raise needed error")
|
||||
|
|
|
@ -14,12 +14,9 @@
|
|||
|
||||
import random
|
||||
|
||||
from keystoneauth1.exceptions import BadRequest
|
||||
from proboscis import asserts
|
||||
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 import os_actions
|
||||
|
@ -562,8 +559,8 @@ class NumaCpuPinning(TestBasic):
|
|||
try:
|
||||
self.fuel_web.client.upload_node_attributes(
|
||||
compute_config, compute['id'])
|
||||
except HTTPError as e:
|
||||
asserts.assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('BadRequest received as expected')
|
||||
else:
|
||||
asserts.fail("Pinned all CPU on {0}, while expecting HTTP "
|
||||
"error on CPU value {1}"
|
||||
|
@ -574,8 +571,8 @@ class NumaCpuPinning(TestBasic):
|
|||
try:
|
||||
self.fuel_web.client.upload_node_attributes(
|
||||
compute_config, compute['id'])
|
||||
except HTTPError as e:
|
||||
asserts.assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('BadRequest received as expected')
|
||||
else:
|
||||
asserts.fail("Pinned all CPU on {0}, while expecting HTTP "
|
||||
"400 error on CPU value {1}"
|
||||
|
|
|
@ -14,14 +14,11 @@
|
|||
from random import randrange
|
||||
from re import match
|
||||
|
||||
from keystoneauth1.exceptions import BadRequest
|
||||
from proboscis.asserts import assert_equal
|
||||
from proboscis.asserts import assert_raises
|
||||
from proboscis.asserts import assert_true
|
||||
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.decorators import log_snapshot_after_test
|
||||
|
@ -209,7 +206,7 @@ class CustomHostname(TestBasic):
|
|||
"node-",
|
||||
):
|
||||
assert_raises(
|
||||
HTTPError,
|
||||
BadRequest,
|
||||
self.fuel_web.client.set_hostname,
|
||||
node['id'],
|
||||
invalid_hostname)
|
||||
|
@ -238,7 +235,7 @@ class CustomHostname(TestBasic):
|
|||
|
||||
# Try to change the hostname of the provisioned node
|
||||
assert_raises(
|
||||
HTTPError,
|
||||
BadRequest,
|
||||
self.fuel_web.client.set_hostname,
|
||||
node,
|
||||
custom_hostname)
|
||||
|
@ -281,7 +278,7 @@ class CustomHostname(TestBasic):
|
|||
# Try to change the hostname of the provisioned node
|
||||
# TODO(dkruglov): LP#1476722
|
||||
assert_raises(
|
||||
HTTPError,
|
||||
BadRequest,
|
||||
self.fuel_web.client.set_hostname,
|
||||
node['id'],
|
||||
'new-custom-hostname')
|
||||
|
|
|
@ -12,15 +12,14 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneauth1.exceptions import NotFound
|
||||
from keystoneauth1.exceptions import BadRequest
|
||||
from proboscis.asserts import assert_equal
|
||||
from proboscis.asserts import fail
|
||||
from proboscis import test
|
||||
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.tests.base_test_case import TestBasic
|
||||
|
||||
|
@ -136,8 +135,8 @@ class TestReassignNode(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.reassign_node(123456, data)
|
||||
except HTTPError as e:
|
||||
assert_equal(404, e.code)
|
||||
except NotFound:
|
||||
logger.debug('Got NotFound error as expected')
|
||||
else:
|
||||
fail("Doesn't rise HTTP 404 error"
|
||||
"while reassigning"
|
||||
|
@ -176,8 +175,8 @@ class TestReassignNode(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.reassign_node(cloned_cluster["id"], None)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('Got BadRequest error as expected')
|
||||
else:
|
||||
fail("Doesn't raise HTTP 400 error on request"
|
||||
"to reassigning node with empty body")
|
||||
|
@ -217,8 +216,8 @@ class TestReassignNode(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.reassign_node(cloned_cluster["id"], data)
|
||||
except HTTPError as e:
|
||||
assert_equal(400, e.code)
|
||||
except BadRequest:
|
||||
logger.debug('Got BadRequest error as expected')
|
||||
else:
|
||||
fail("Doesn't raise HTTP 400 error on request"
|
||||
"to reassigning node with incorrect node_id")
|
||||
|
@ -258,8 +257,8 @@ class TestReassignNode(TestBasic):
|
|||
|
||||
try:
|
||||
self.fuel_web.client.reassign_node(cloned_cluster["id"], data)
|
||||
except HTTPError as e:
|
||||
assert_equal(404, e.code)
|
||||
except NotFound:
|
||||
logger.debug('Got NotFound error as expected')
|
||||
else:
|
||||
fail("Doesn't raise HTTP 404 error on request"
|
||||
"to reassigning nonexistent node to cloned cluster")
|
||||
|
|
|
@ -17,13 +17,10 @@ import time
|
|||
import traceback
|
||||
|
||||
from devops.helpers import helpers
|
||||
from keystoneauth1.exceptions import HttpError
|
||||
import netaddr
|
||||
from proboscis import asserts
|
||||
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 import os_actions
|
||||
|
@ -87,8 +84,8 @@ class ServicesReconfiguration(TestBasic):
|
|||
func, *args, **kwargs):
|
||||
try:
|
||||
func(*args, **kwargs)
|
||||
except HTTPError as e:
|
||||
if e.code != expected_code:
|
||||
except HttpError as e:
|
||||
if e.http_status != expected_code:
|
||||
raise
|
||||
logger.warning('Ignoring exception: {!r}'.format(e))
|
||||
logger.debug(traceback.format_exc())
|
||||
|
|
|
@ -17,9 +17,7 @@ import yaml
|
|||
|
||||
from proboscis import SkipTest
|
||||
from proboscis import test
|
||||
# pylint: disable=import-error
|
||||
from six.moves.urllib.error import HTTPError
|
||||
# pylint: enable=import-error
|
||||
from keystoneauth1.exceptions import HttpError
|
||||
# pylint: disable=redefined-builtin
|
||||
from six.moves import xrange
|
||||
# pylint: enable=redefined-builtin
|
||||
|
@ -151,7 +149,7 @@ class UnlockSettingsTab(TestBasic):
|
|||
try:
|
||||
self.fuel_web.client.update_cluster_attributes(
|
||||
self.cluster_id, new_attrs)
|
||||
except HTTPError:
|
||||
except HttpError:
|
||||
logger.info(
|
||||
"Failed to update cluster attributes, please check logs")
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue