From 6fc8e58bab5ac710a9b54928f396f54a175602f6 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Mon, 5 May 2014 12:58:22 -0500 Subject: [PATCH] openrc search failure The old openrc code handled when identity role was not converged yet by looking at attributes. Add this support back in. Change-Id: I738c0f619b364548b5fff1f06cc48dce2c8f7e84 Closes-Bug: #1316236 --- CHANGELOG.md | 3 +++ README.md | 4 +++- metadata.rb | 2 +- recipes/openrc.rb | 19 ++++++++++++++----- spec/openrc_spec.rb | 11 +++++++++++ spec/spec_helper.rb | 3 +++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a2e142..b3e735e6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # CHANGELOG for cookbook-openstack-common This file is used to list changes made in each version of cookbook-openstack-common. +## 9.2.2 +* Fixed openrc failure on role search + ## 9.2.1 * Fix package action to allow updates diff --git a/README.md b/README.md index 9a9de2dc..bb6de36f 100755 --- a/README.md +++ b/README.md @@ -80,7 +80,9 @@ example, overriding `node['openstack']['endpoints']['identity']['host']`). If openrc ---- -Creates an /root/openrc file +Creates an /root/openrc file. This requires the identity attributes for +admin_user and admin_tenant_name, or for the identity_service_chef_role +to be used on the identity server node. sysctl diff --git a/metadata.rb b/metadata.rb index b57fa31c..2447c677 100755 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email 'cookbooks@lists.tfoundry.com' license 'Apache 2.0' description 'Common OpenStack attributes, libraries and recipes.' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '9.2.1' +version '9.2.2' recipe 'openstack-common', 'Installs/Configures common recipes' recipe 'openstack-common::set_endpoints_by_interface', 'Set endpoints by interface' diff --git a/recipes/openrc.rb b/recipes/openrc.rb index c59780a2..e2a26eab 100644 --- a/recipes/openrc.rb +++ b/recipes/openrc.rb @@ -22,13 +22,22 @@ class ::Chef::Recipe # rubocop:disable Documentation include ::Openstack end -identity_service_role = node['openstack']['identity_service_chef_role'] -keystone = search_for(identity_service_role).first +# check attributes before searching +if node['openstack']['identity'] && node['openstack']['identity']['admin_tenant_name'] && node['openstack']['identity']['admin_user'] + ksadmin_tenant_name = node['openstack']['identity']['admin_tenant_name'] + ksadmin_user = node['openstack']['identity']['admin_user'] +else + identity_service_role = node['openstack']['identity_service_chef_role'] + keystone = search_for(identity_service_role).first -return if keystone.nil? + if keystone.nil? + Chef::Log.warn("openrc not created, identity role node not found: #{identity_service_role}") + return + end -ksadmin_tenant_name = keystone['openstack']['identity']['admin_tenant_name'] -ksadmin_user = keystone['openstack']['identity']['admin_user'] + ksadmin_tenant_name = keystone['openstack']['identity']['admin_tenant_name'] + ksadmin_user = keystone['openstack']['identity']['admin_user'] +end ksadmin_pass = get_password 'user', ksadmin_user identity_endpoint = endpoint 'identity-api' diff --git a/spec/openrc_spec.rb b/spec/openrc_spec.rb index 0908b2ca..c533a20e 100644 --- a/spec/openrc_spec.rb +++ b/spec/openrc_spec.rb @@ -42,6 +42,17 @@ describe 'openstack-common::openrc' do expect(chef_run).to render_file(file.name).with_content( /^export MISC2=OPTION2$/) end + + it 'contains overridden auth environment variables' do + node.set['openstack']['identity']['admin_tenant_name'] = 'admin-tenant-name-override' + node.set['openstack']['identity']['admin_user'] = 'admin-user-override' + [ + /^export OS_USERNAME=admin-user-override$/, + /^export OS_TENANT_NAME=admin-tenant-name-override$/ + ].each do |line| + expect(chef_run).to render_file(file.name).with_content(line) + end + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a6853716..690135d7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -45,5 +45,8 @@ shared_context 'common-stubs' do Chef::Recipe.any_instance.stub(:get_password) .with('user', 'admin') .and_return('admin') + Chef::Recipe.any_instance.stub(:get_password) + .with('user', 'admin-user-override') + .and_return('admin-user-override') end end