From 055446b060d0b6a4b5e0a33bd6b4fd0d9bdada9a Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Tue, 18 Apr 2017 16:07:32 +0200 Subject: [PATCH] Make openrc deployment file work with keystone v3 When using a deployment with keystone v3 the env variable OS_IDENTITY_API_VERSION=3 is not written to ~/.rally/openrc. This causes requests by the openstack cli to fail unless the user sets that variable manually. This patch fixes this issue by writing OS_IDENTITY_API_VERSION to the openrc file when using a deployment. Closes-Bug: #1683820 Change-Id: I591eeacdd96e71d13561a7edade297223da86f73 --- rally/cli/commands/deployment.py | 6 ++++-- tests/ci/rally_gate_functions.sh | 6 ------ tests/unit/cli/commands/test_deployment.py | 7 +++++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rally/cli/commands/deployment.py b/rally/cli/commands/deployment.py index fb0349e9c9..a2ceccc7c3 100644 --- a/rally/cli/commands/deployment.py +++ b/rally/cli/commands/deployment.py @@ -290,6 +290,7 @@ class DeploymentCommands(object): "export OS_USERNAME='%(username)s'\n" "export OS_PASSWORD='%(password)s'\n" "export OS_TENANT_NAME='%(tenant_name)s'\n" + "export OS_PROJECT_NAME='%(tenant_name)s'\n" % credential) if credential.get("region_name"): env_file.write("export OS_REGION_NAME='%s'\n" % @@ -305,9 +306,10 @@ class DeploymentCommands(object): if credential.get("https_cacert"): env_file.write("export OS_CACERT='%s'\n" % credential["https_cacert"]) - if re.match(r"^/v3/?$", parse.urlparse( + if re.match(r"^[a-zA-Z0-9/\-_]*/v3/?$", parse.urlparse( credential["auth_url"]).path) is not None: - env_file.write("export OS_USER_DOMAIN_NAME='%s'\n" + env_file.write("export OS_IDENTITY_API_VERSION=3\n" + "export OS_USER_DOMAIN_NAME='%s'\n" "export OS_PROJECT_DOMAIN_NAME='%s'\n" % (credential["user_domain_name"], credential["project_domain_name"])) diff --git a/tests/ci/rally_gate_functions.sh b/tests/ci/rally_gate_functions.sh index edbaba5f31..98b749db58 100644 --- a/tests/ci/rally_gate_functions.sh +++ b/tests/ci/rally_gate_functions.sh @@ -34,12 +34,6 @@ function setUp () { source ~/.rally/openrc admin admin - if [[ $(rally deployment config) == *"project_name"* ]]; then - export OS_IDENTITY_API_VERSION=3 - else - export OS_IDENTITY_API_VERSION="2.0" - fi - OPENSTACK_SERVICES=$(openstack service list) if [[ $OPENSTACK_SERVICES == *"glance"* ]]; then openstack image list diff --git a/tests/unit/cli/commands/test_deployment.py b/tests/unit/cli/commands/test_deployment.py index b26c46f33c..cfd59c39ec 100644 --- a/tests/unit/cli/commands/test_deployment.py +++ b/tests/unit/cli/commands/test_deployment.py @@ -296,7 +296,8 @@ class DeploymentCommandsTestCase(test.TestCase): "export OS_AUTH_URL='fake_auth_url'\n" "export OS_USERNAME='fake_username'\n" "export OS_PASSWORD='fake_password'\n" - "export OS_TENANT_NAME='fake_tenant_name'\n") + "export OS_TENANT_NAME='fake_tenant_name'\n" + "export OS_PROJECT_NAME='fake_tenant_name'\n") mock_symlink.assert_called_once_with( os.path.expanduser("~/.rally/openrc-%s" % deployment_id), os.path.expanduser("~/.rally/openrc")) @@ -337,8 +338,10 @@ class DeploymentCommandsTestCase(test.TestCase): "export OS_AUTH_URL='http://localhost:5000/v3'\n" "export OS_USERNAME='fake_username'\n" "export OS_PASSWORD='fake_password'\n" - "export OS_TENANT_NAME='fake_tenant_name'\n") + "export OS_TENANT_NAME='fake_tenant_name'\n" + "export OS_PROJECT_NAME='fake_tenant_name'\n") mock_file.return_value.write.assert_any_call( + "export OS_IDENTITY_API_VERSION=3\n" "export OS_USER_DOMAIN_NAME='fake_user_domain'\n" "export OS_PROJECT_DOMAIN_NAME='fake_project_domain'\n") mock_symlink.assert_called_once_with(