]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/ext/keystone_test_v3.rb
Update to Kilo
[dsa-puppet.git] / 3rdparty / modules / keystone / ext / keystone_test_v3.rb
1 #!/usr/bin/env ruby
2 # this script verifies that keystone has
3 # been successfully installed using the instructions
4 # found here: http://keystone.openstack.org/configuration.html
5 # and can use the v3 api http://developer.openstack.org/api-ref-identity-v3.html
6
7 begin
8   require 'rubygems'
9 rescue
10   puts 'Could not require rubygems. This assumes puppet is not installed as a gem'
11 end
12 require 'open3'
13 require 'fileutils'
14 require 'puppet'
15 require 'pp'
16
17 username='admin'
18 password='a_big_secret'
19 # required to get a real services catalog
20 project='openstack'
21 user_domain='admin'
22 project_domain='admin'
23
24 # shared secret
25 service_token='admin_token'
26
27 def run_command(cmd)
28   Open3.popen3(cmd) do |stdin, stdout, stderr|
29     begin
30       stdout = stdout.read
31       puts "Response from token request:#{stdout}"
32       return stdout
33     rescue Exception => e
34       puts "Request failed, this sh*t is borked :( : details: #{e}"
35       exit 1
36     end
37   end
38 end
39
40 puts `puppet apply -e "package {curl: ensure => present }"`
41 get_token = %(curl -D - -d '{"auth":{"identity":{"methods":["password"],"password":{"user":{"domain":{"name":"#{user_domain}"},"name":"#{username}","password": "#{password}"}}},"scope":{"project":{"domain":{"name":"#{project_domain}"},"name": "#{project}"}}}}' -H "Content-type: application/json" http://localhost:35357/v3/auth/tokens)
42 token = nil
43
44 puts "Running auth command: #{get_token}"
45 rawoutput = run_command(get_token)
46 if rawoutput =~ /X-Subject-Token: ([\w]+)/
47   token = $1
48 else
49   puts "No token in output! #{rawoutput}"
50   exit 1
51 end
52
53 if token
54   puts "We were able to retrieve a token"
55   puts token
56   verify_token = "curl -H 'X-Auth-Token: #{service_token}' 'X-Subject-Token: #{token}' http://localhost:35357/v3/auth/tokens"
57   puts 'verifying token'
58   run_command(verify_token)
59   ['endpoints', 'projects', 'users'].each do |x|
60     puts "getting #{x}"
61     get_keystone_data = "curl -H 'X-Auth-Token: #{token}' http://localhost:35357/v3/#{x}"
62     pp PSON.load(run_command(get_keystone_data))
63   end
64 end