level up keystone testing script

This fixes some issues with the previous keystone
test script.

1. conditionally requires rubygems in case that is how
puppet is installed
2. installs curl if not installed
3. performs way more queries. so that this can serve as
a reminder to me about how to play with the keystone apis.
This commit is contained in:
Dan Bode 2013-01-11 16:01:48 -08:00
parent f23e55d088
commit 85639708a6

View File

@ -3,27 +3,53 @@
# been successfully installed using the instructions # been successfully installed using the instructions
# found here: http://keystone.openstack.org/configuration.html # found here: http://keystone.openstack.org/configuration.html
begin
require 'rubygems'
rescue
puts 'Could not require rubygems. This assumes puppet is not installed as a gem'
end
require 'open3' require 'open3'
require 'fileutils' require 'fileutils'
require 'puppet' require 'puppet'
get_token = %(curl -d '{"auth":{"passwordCredentials":{"username": "admin", "password": "ChangeMe"}}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens) username='admin'
token = nil password='admin_password'
Open3.popen3(get_token) do |stdin, stdout, stderr| # required to get a real services catalog
begin tenant='openstack'
stdout = stdout.read
puts "Response from token request:#{stdout}" # shared secret
token = PSON.load(stdout)["access"]["token"]["id"] service_token='service_token'
rescue Exception => e
puts "Could not retrieve token from response, this sh*t is borked :( : details: #{e}" def run_command(cmd)
exit 1 Open3.popen3(cmd) do |stdin, stdout, stderr|
begin
stdout = stdout.read
puts "Response from token request:#{stdout}"
return stdout
rescue Exception => e
puts "Request failed, this sh*t is borked :( : details: #{e}"
exit 1
end
end end
end end
puts `puppet apply -e "package {curl: ensure => present }"`
get_token = %(curl -d '{"auth":{"passwordCredentials":{"username": "#{username}", "password": "#{password}"}}}' -H "Content-type: application/json" http://localhost:35357/v2.0/tokens)
token = nil
puts "Running auth command: #{get_token}"
token = PSON.load(run_command(get_token))["access"]["token"]["id"]
if token if token
puts "We were able to retrieve a token" puts "We were able to retrieve a token"
puts token
verify_token = "curl -H 'X-Auth-Token: #{service_token}' http://localhost:35357/v2.0/tokens/#{token}"
puts 'verifying token'
run_command(verify_token)
['endpoints', 'tenants', 'users'].each do |x|
puts "getting #{x}"
get_keystone_data = "curl -H 'X-Auth-Token: #{service_token}' http://localhost:35357/v2.0/#{x}"
run_command(get_keystone_data)
end
end end