Switch to latest Rally release

* adopt osclients.Clients.create_from_env method. It re-used code from
  rally framework repo which was recently deleted.
* adopt error handling of new ks errors

Change-Id: I9e20c0e69426d07dd682f596f7b75b2f284d141c
This commit is contained in:
Andrey Kurilin 2019-05-13 17:18:15 -07:00
parent a539f306c1
commit 65031b1a46
4 changed files with 65 additions and 23 deletions

View File

@ -16,7 +16,6 @@
import abc import abc
import os import os
from rally.cli import envutils
from rally.common import cfg from rally.common import cfg
from rally.common import logging from rally.common import logging
from rally.common.plugin import plugin from rally.common.plugin import plugin
@ -49,14 +48,15 @@ class AuthenticationFailed(exceptions.AuthenticationFailed):
from keystoneauth1 import exceptions as ks_exc from keystoneauth1 import exceptions as ks_exc
if isinstance(error, ks_exc.ConnectionError): if isinstance(error, (ks_exc.ConnectionError,
ks_exc.DiscoveryFailure)):
# this type of errors is general for all users no need to include # this type of errors is general for all users no need to include
# username, project name. The original error message should be # username, project name. The original error message should be
# self-sufficient # self-sufficient
self.msg_fmt = self.msg_fmt_2 self.msg_fmt = self.msg_fmt_2
message = error.message message = error.message
if message.startswith("Unable to establish connection to"): if (message.startswith("Unable to establish connection to") or
# this message contains too much info. isinstance(error, ks_exc.DiscoveryFailure)):
if "Max retries exceeded with url" in message: if "Max retries exceeded with url" in message:
if "HTTPConnectionPool" in message: if "HTTPConnectionPool" in message:
splitter = ": HTTPConnectionPool" splitter = ": HTTPConnectionPool"
@ -900,17 +900,23 @@ class Clients(object):
@classmethod @classmethod
def create_from_env(cls): def create_from_env(cls):
creds = envutils.get_creds_from_env_vars()
from rally_openstack import credential from rally_openstack import credential
from rally_openstack.platforms import existing
spec = existing.OpenStack.create_spec_from_sys_environ(os.environ)
if not spec["available"]:
raise ValueError(spec["message"])
creds = spec["spec"]
oscred = credential.OpenStackCredential( oscred = credential.OpenStackCredential(
auth_url=creds["auth_url"], auth_url=creds["auth_url"],
username=creds["admin"]["username"], username=creds["admin"]["username"],
password=creds["admin"]["password"], password=creds["admin"]["password"],
tenant_name=creds["admin"]["tenant_name"], tenant_name=creds["admin"].get(
"tenant_name", creds["admin"].get("project_name")),
endpoint_type=creds["endpoint_type"], endpoint_type=creds["endpoint_type"],
user_domain_name=creds["admin"].get("user_domain_name"), user_domain_name=creds["admin"].get("user_domain_name"),
project_domain_name=creds["admin"].get("project_domain_name"), project_domain_name=creds["admin"].get("project_domain_name"),
endpoint=creds["endpoint"],
region_name=creds["region_name"], region_name=creds["region_name"],
https_cacert=creds["https_cacert"], https_cacert=creds["https_cacert"],
https_insecure=creds["https_insecure"]) https_insecure=creds["https_insecure"])

View File

@ -14,7 +14,8 @@
# under the License. # under the License.
import re import re
import unittest
import testtools
from tests.functional import utils from tests.functional import utils
@ -27,7 +28,7 @@ TEST_ENV = {
} }
class DeploymentTestCase(unittest.TestCase): class DeploymentTestCase(testtools.TestCase):
def test_create_fromenv_list_show(self): def test_create_fromenv_list_show(self):
# NOTE(andreykurilin): `rally deployment create --fromenv` is # NOTE(andreykurilin): `rally deployment create --fromenv` is
@ -80,18 +81,12 @@ class DeploymentTestCase(unittest.TestCase):
"--filename %s" % file.filename) "--filename %s" % file.filename)
self.assertIn("t_create_file_debug", rally("deployment list")) self.assertIn("t_create_file_debug", rally("deployment list"))
self.assertEqual(config, rally("deployment config", getjson=True)) self.assertEqual(config, rally("deployment config", getjson=True))
self.assertRaises(utils.RallyCliError, rally, "deployment check") e = self.assertRaises(utils.RallyCliError, rally,
"--debug deployment check")
try: self.assertIn(
rally("--debug deployment check") "AuthenticationFailed: Could not find versioned identity "
except utils.RallyCliError as e: "endpoints when attempting to authenticate.",
self.assertIn( e.output)
"AuthenticationFailed: Unable to establish connection to "
"%s" % TEST_ENV["OS_AUTH_URL"],
str(e))
else:
self.fail("rally deployment fails to raise error for wrong"
" authentication info")
def test_use(self): def test_use(self):
rally = utils.Rally() rally = utils.Rally()

View File

@ -1063,3 +1063,44 @@ class OSClientsTestCase(test.TestCase):
} }
mock_barbican.client.Client.assert_called_once_with(**kw) mock_barbican.client.Client.assert_called_once_with(**kw)
self.assertEqual(fake_barbican, self.clients.cache["barbican"]) self.assertEqual(fake_barbican, self.clients.cache["barbican"])
class AuthenticationFailedTestCase(test.TestCase):
def test_init(self):
from keystoneauth1 import exceptions as ks_exc
actual_exc = ks_exc.ConnectionError("Something")
exc = osclients.AuthenticationFailed(
error=actual_exc, url="https://example.com", username="user",
project="project")
# only original exc should be used
self.assertEqual("Something", exc.format_message())
actual_exc = Exception("Something")
exc = osclients.AuthenticationFailed(
error=actual_exc, url="https://example.com", username="user",
project="project")
# additional info should be added
self.assertEqual("Failed to authenticate to https://example.com for "
"user 'user' in project 'project': "
"[Exception] Something", exc.format_message())
# check cutting message
actual_exc = ks_exc.DiscoveryFailure(
"Could not find versioned identity endpoints when attempting to "
"authenticate. Please check that your auth_url is correct. "
"Unable to establish connection to https://example.com: "
"HTTPConnectionPool(host='example.com', port=80): Max retries "
"exceeded with url: / (Caused by NewConnectionError('"
"<urllib3.connection.HTTPConnection object at 0x7f32ab9809d0>: "
"Failed to establish a new connection: [Errno -2] Name or service"
" not known',))")
exc = osclients.AuthenticationFailed(
error=actual_exc, url="https://example.com", username="user",
project="project")
# original message should be simplified
self.assertEqual(
"Could not find versioned identity endpoints when attempting to "
"authenticate. Please check that your auth_url is correct. "
"Unable to establish connection to https://example.com",
exc.format_message())

View File

@ -86,7 +86,7 @@ pyOpenSSL===18.0.0
pyparsing===2.2.2 pyparsing===2.2.2
pyperclip===1.7.0 pyperclip===1.7.0
Python===2.7.15rc1 Python===2.7.15rc1
python-barbicanclient===4.5.2 python-barbicanclient===4.5.2
python-ceilometerclient===2.9.0 python-ceilometerclient===2.9.0
python-cinderclient===4.0.1 python-cinderclient===4.0.1
python-dateutil===2.7.3 python-dateutil===2.7.3
@ -115,7 +115,7 @@ python-watcherclient===2.1.0
python-zaqarclient===1.10.0 python-zaqarclient===1.10.0
pytz===2018.5 pytz===2018.5
PyYAML===3.13 PyYAML===3.13
rally===1.4.1 rally===1.5.1
requests===2.21.0 requests===2.21.0
requests-oauthlib===1.0.0 requests-oauthlib===1.0.0
requestsexceptions===1.4.0 requestsexceptions===1.4.0