diff --git a/spec/classes/openstack_auth_file_spec.rb b/spec/classes/openstack_auth_file_spec.rb index 4820fd0ff..33c421c34 100644 --- a/spec/classes/openstack_auth_file_spec.rb +++ b/spec/classes/openstack_auth_file_spec.rb @@ -10,18 +10,18 @@ it 'should create a openrc file' do verify_contents(subject, '/root/openrc', [ - 'export OS_NO_CACHE=true', - 'export OS_TENANT_NAME=openstack', - 'export OS_USERNAME=admin', - 'export OS_PASSWORD=admin', - 'export OS_AUTH_URL=http://127.0.0.1:5000/v2.0/', - 'export OS_AUTH_STRATEGY=keystone', - 'export OS_REGION_NAME=RegionOne', - 'export CINDER_ENDPOINT_TYPE=publicURL', - 'export GLANCE_ENDPOINT_TYPE=publicURL', - 'export KEYSTONE_ENDPOINT_TYPE=publicURL', - 'export NOVA_ENDPOINT_TYPE=publicURL', - 'export NEUTRON_ENDPOINT_TYPE=publicURL' + 'export OS_NO_CACHE=\'true\'', + 'export OS_TENANT_NAME=\'openstack\'', + 'export OS_USERNAME=\'admin\'', + 'export OS_PASSWORD=\'admin\'', + 'export OS_AUTH_URL=\'http://127.0.0.1:5000/v2.0/\'', + 'export OS_AUTH_STRATEGY=\'keystone\'', + 'export OS_REGION_NAME=\'RegionOne\'', + 'export CINDER_ENDPOINT_TYPE=\'publicURL\'', + 'export GLANCE_ENDPOINT_TYPE=\'publicURL\'', + 'export KEYSTONE_ENDPOINT_TYPE=\'publicURL\'', + 'export NOVA_ENDPOINT_TYPE=\'publicURL\'', + 'export NEUTRON_ENDPOINT_TYPE=\'publicURL\'' ]) end end @@ -44,21 +44,39 @@ it 'should create a openrc file' do verify_contents(subject, '/root/openrc', [ - 'export OS_SERVICE_TOKEN=keystone', - 'export OS_SERVICE_ENDPOINT=http://127.0.0.2:35357/v2.0/', - 'export OS_NO_CACHE=true', - 'export OS_TENANT_NAME=admin', - 'export OS_USERNAME=admin', - 'export OS_PASSWORD=admin', - 'export OS_AUTH_URL=http://127.0.0.2:5000/v2.0/', - 'export OS_AUTH_STRATEGY=keystone', - 'export OS_REGION_NAME=RegionOne', - 'export CINDER_ENDPOINT_TYPE=privateURL', - 'export GLANCE_ENDPOINT_TYPE=privateURL', - 'export KEYSTONE_ENDPOINT_TYPE=privateURL', - 'export NOVA_ENDPOINT_TYPE=privateURL', - 'export NEUTRON_ENDPOINT_TYPE=privateURL' + 'export OS_SERVICE_TOKEN=\'keystone\'', + 'export OS_SERVICE_ENDPOINT=\'http://127.0.0.2:35357/v2.0/\'', + 'export OS_NO_CACHE=\'true\'', + 'export OS_TENANT_NAME=\'admin\'', + 'export OS_USERNAME=\'admin\'', + 'export OS_PASSWORD=\'admin\'', + 'export OS_AUTH_URL=\'http://127.0.0.2:5000/v2.0/\'', + 'export OS_AUTH_STRATEGY=\'keystone\'', + 'export OS_REGION_NAME=\'RegionOne\'', + 'export CINDER_ENDPOINT_TYPE=\'privateURL\'', + 'export GLANCE_ENDPOINT_TYPE=\'privateURL\'', + 'export KEYSTONE_ENDPOINT_TYPE=\'privateURL\'', + 'export NOVA_ENDPOINT_TYPE=\'privateURL\'', + 'export NEUTRON_ENDPOINT_TYPE=\'privateURL\'' ]) end end + + describe "handle password and token with single quotes" do + + let :params do + { + :admin_password => 'singlequote\'', + :keystone_admin_token => 'key\'stone' + } + end + + it 'should create a openrc file' do + verify_contents(subject, '/root/openrc', [ + 'export OS_SERVICE_TOKEN=\'key\\\'stone\'', + 'export OS_PASSWORD=\'singlequote\\\'\'', + ]) + end + end + end diff --git a/templates/openrc.erb b/templates/openrc.erb index 4110260a7..6bf063be0 100644 --- a/templates/openrc.erb +++ b/templates/openrc.erb @@ -1,17 +1,17 @@ #!/bin/sh <% if @keystone_admin_token -%> -export OS_SERVICE_TOKEN=<%= @keystone_admin_token %> -export OS_SERVICE_ENDPOINT=http://<%= @controller_node %>:35357/v2.0/ +export OS_SERVICE_TOKEN='<%= @keystone_admin_token.gsub(/'/){ %q(\') } %>' +export OS_SERVICE_ENDPOINT='http://<%= @controller_node %>:35357/v2.0/' <% end -%> -export OS_NO_CACHE=<%= @use_no_cache %> -export OS_TENANT_NAME=<%= @admin_tenant %> -export OS_USERNAME=<%= @admin_user %> -export OS_PASSWORD=<%= @admin_password %> -export OS_AUTH_URL=http://<%= @controller_node %>:5000/v2.0/ -export OS_AUTH_STRATEGY=keystone -export OS_REGION_NAME=<%= @region_name %> -export CINDER_ENDPOINT_TYPE=<%= @cinder_endpoint_type %> -export GLANCE_ENDPOINT_TYPE=<%= @glance_endpoint_type %> -export KEYSTONE_ENDPOINT_TYPE=<%= @keystone_endpoint_type %> -export NOVA_ENDPOINT_TYPE=<%= @nova_endpoint_type %> -export NEUTRON_ENDPOINT_TYPE=<%= @neutron_endpoint_type %> +export OS_NO_CACHE='<%= @use_no_cache %>' +export OS_TENANT_NAME='<%= @admin_tenant %>' +export OS_USERNAME='<%= @admin_user %>' +export OS_PASSWORD='<%= @admin_password.gsub(/'/){ %q(\') } %>' +export OS_AUTH_URL='http://<%= @controller_node %>:5000/v2.0/' +export OS_AUTH_STRATEGY='keystone' +export OS_REGION_NAME='<%= @region_name %>' +export CINDER_ENDPOINT_TYPE='<%= @cinder_endpoint_type %>' +export GLANCE_ENDPOINT_TYPE='<%= @glance_endpoint_type %>' +export KEYSTONE_ENDPOINT_TYPE='<%= @keystone_endpoint_type %>' +export NOVA_ENDPOINT_TYPE='<%= @nova_endpoint_type %>' +export NEUTRON_ENDPOINT_TYPE='<%= @neutron_endpoint_type %>'