fog 1.31.0 → 1.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +53 -0
  3. data/Rakefile +5 -5
  4. data/fog.gemspec +6 -5
  5. data/lib/fog/cloudstack/models/compute/network.rb +1 -0
  6. data/lib/fog/openstack/compute.rb +41 -98
  7. data/lib/fog/openstack/core.rb +257 -118
  8. data/lib/fog/openstack/identity.rb +4 -0
  9. data/lib/fog/openstack/identity_v3.rb +10 -41
  10. data/lib/fog/openstack/models/baremetal/chassis_collection.rb +10 -4
  11. data/lib/fog/openstack/models/baremetal/drivers.rb +4 -2
  12. data/lib/fog/openstack/models/baremetal/nodes.rb +10 -4
  13. data/lib/fog/openstack/models/baremetal/ports.rb +10 -4
  14. data/lib/fog/openstack/models/compute/addresses.rb +4 -2
  15. data/lib/fog/openstack/models/compute/aggregate.rb +64 -0
  16. data/lib/fog/openstack/models/compute/aggregates.rb +28 -0
  17. data/lib/fog/openstack/models/compute/flavors.rb +5 -0
  18. data/lib/fog/openstack/models/compute/hosts.rb +4 -2
  19. data/lib/fog/openstack/models/compute/images.rb +2 -0
  20. data/lib/fog/openstack/models/compute/key_pairs.rb +4 -2
  21. data/lib/fog/openstack/models/compute/security_groups.rb +4 -2
  22. data/lib/fog/openstack/models/compute/servers.rb +2 -0
  23. data/lib/fog/openstack/models/compute/services.rb +7 -4
  24. data/lib/fog/openstack/models/compute/snapshots.rb +15 -2
  25. data/lib/fog/openstack/models/compute/volumes.rb +15 -2
  26. data/lib/fog/openstack/models/identity_v2/ec2_credentials.rb +6 -3
  27. data/lib/fog/openstack/models/identity_v2/roles.rb +5 -3
  28. data/lib/fog/openstack/models/identity_v2/tenants.rb +5 -3
  29. data/lib/fog/openstack/models/identity_v2/users.rb +7 -3
  30. data/lib/fog/openstack/models/identity_v3/domains.rb +7 -6
  31. data/lib/fog/openstack/models/identity_v3/endpoints.rb +5 -4
  32. data/lib/fog/openstack/models/identity_v3/groups.rb +5 -3
  33. data/lib/fog/openstack/models/identity_v3/os_credentials.rb +5 -3
  34. data/lib/fog/openstack/models/identity_v3/policies.rb +5 -3
  35. data/lib/fog/openstack/models/identity_v3/project.rb +1 -0
  36. data/lib/fog/openstack/models/identity_v3/projects.rb +7 -5
  37. data/lib/fog/openstack/models/identity_v3/role_assignments.rb +10 -5
  38. data/lib/fog/openstack/models/identity_v3/roles.rb +11 -5
  39. data/lib/fog/openstack/models/identity_v3/services.rb +5 -3
  40. data/lib/fog/openstack/models/identity_v3/users.rb +4 -2
  41. data/lib/fog/openstack/models/image/images.rb +10 -4
  42. data/lib/fog/openstack/models/network/floating_ips.rb +2 -0
  43. data/lib/fog/openstack/models/network/lb_health_monitors.rb +2 -0
  44. data/lib/fog/openstack/models/network/lb_members.rb +2 -0
  45. data/lib/fog/openstack/models/network/lb_pools.rb +2 -0
  46. data/lib/fog/openstack/models/network/lb_vips.rb +2 -0
  47. data/lib/fog/openstack/models/network/networks.rb +2 -0
  48. data/lib/fog/openstack/models/network/port.rb +1 -0
  49. data/lib/fog/openstack/models/network/ports.rb +2 -0
  50. data/lib/fog/openstack/models/network/routers.rb +2 -0
  51. data/lib/fog/openstack/models/network/security_group_rules.rb +2 -0
  52. data/lib/fog/openstack/models/network/security_groups.rb +2 -0
  53. data/lib/fog/openstack/models/network/subnets.rb +2 -0
  54. data/lib/fog/openstack/models/orchestration/events.rb +10 -6
  55. data/lib/fog/openstack/models/orchestration/resources.rb +4 -2
  56. data/lib/fog/openstack/models/orchestration/stack.rb +1 -1
  57. data/lib/fog/openstack/models/orchestration/stacks.rb +9 -1
  58. data/lib/fog/openstack/models/planning/plans.rb +4 -2
  59. data/lib/fog/openstack/models/planning/roles.rb +5 -2
  60. data/lib/fog/openstack/models/storage/directories.rb +4 -2
  61. data/lib/fog/openstack/models/storage/files.rb +2 -0
  62. data/lib/fog/openstack/models/volume/volume.rb +1 -0
  63. data/lib/fog/openstack/models/volume/volume_types.rb +2 -0
  64. data/lib/fog/openstack/models/volume/volumes.rb +13 -2
  65. data/lib/fog/openstack/network.rb +18 -97
  66. data/lib/fog/openstack/orchestration.rb +2 -0
  67. data/lib/fog/openstack/requests/baremetal/list_chassis.rb +2 -8
  68. data/lib/fog/openstack/requests/baremetal/list_chassis_detailed.rb +3 -9
  69. data/lib/fog/openstack/requests/baremetal/list_drivers.rb +4 -3
  70. data/lib/fog/openstack/requests/baremetal/list_nodes.rb +3 -9
  71. data/lib/fog/openstack/requests/baremetal/list_nodes_detailed.rb +3 -9
  72. data/lib/fog/openstack/requests/baremetal/list_ports.rb +3 -9
  73. data/lib/fog/openstack/requests/baremetal/list_ports_detailed.rb +3 -9
  74. data/lib/fog/openstack/requests/compute/add_aggregate_host.rb +30 -0
  75. data/lib/fog/openstack/requests/compute/create_aggregate.rb +42 -0
  76. data/lib/fog/openstack/requests/compute/delete_aggregate.rb +28 -0
  77. data/lib/fog/openstack/requests/compute/get_aggregate.rb +26 -0
  78. data/lib/fog/openstack/requests/compute/list_aggregates.rb +36 -0
  79. data/lib/fog/openstack/requests/compute/list_all_addresses.rb +4 -3
  80. data/lib/fog/openstack/requests/compute/list_flavors.rb +6 -5
  81. data/lib/fog/openstack/requests/compute/list_hosts.rb +4 -3
  82. data/lib/fog/openstack/requests/compute/list_key_pairs.rb +4 -3
  83. data/lib/fog/openstack/requests/compute/list_security_groups.rb +15 -2
  84. data/lib/fog/openstack/requests/compute/list_snapshots.rb +18 -4
  85. data/lib/fog/openstack/requests/compute/list_snapshots_detail.rb +27 -0
  86. data/lib/fog/openstack/requests/compute/list_volumes.rb +18 -4
  87. data/lib/fog/openstack/requests/compute/list_volumes_detail.rb +25 -0
  88. data/lib/fog/openstack/requests/compute/remove_aggregate_host.rb +30 -0
  89. data/lib/fog/openstack/requests/compute/update_aggregate.rb +37 -0
  90. data/lib/fog/openstack/requests/compute/update_aggregate_metadata.rb +30 -0
  91. data/lib/fog/openstack/requests/identity_v2/list_ec2_credentials.rb +23 -7
  92. data/lib/fog/openstack/requests/identity_v2/list_roles.rb +5 -4
  93. data/lib/fog/openstack/requests/identity_v2/list_tenants.rb +14 -8
  94. data/lib/fog/openstack/requests/identity_v2/list_users.rb +16 -4
  95. data/lib/fog/openstack/requests/identity_v3/auth_domains.rb +2 -7
  96. data/lib/fog/openstack/requests/identity_v3/auth_projects.rb +6 -11
  97. data/lib/fog/openstack/requests/identity_v3/list_domains.rb +7 -14
  98. data/lib/fog/openstack/requests/identity_v3/list_endpoints.rb +7 -14
  99. data/lib/fog/openstack/requests/identity_v3/list_group_users.rb +5 -13
  100. data/lib/fog/openstack/requests/identity_v3/list_groups.rb +14 -24
  101. data/lib/fog/openstack/requests/identity_v3/list_os_credentials.rb +7 -12
  102. data/lib/fog/openstack/requests/identity_v3/list_policies.rb +7 -11
  103. data/lib/fog/openstack/requests/identity_v3/list_projects.rb +14 -25
  104. data/lib/fog/openstack/requests/identity_v3/list_role_assignments.rb +21 -17
  105. data/lib/fog/openstack/requests/identity_v3/list_roles.rb +7 -25
  106. data/lib/fog/openstack/requests/identity_v3/list_services.rb +7 -13
  107. data/lib/fog/openstack/requests/identity_v3/list_users.rb +7 -15
  108. data/lib/fog/openstack/requests/image/list_public_images.rb +4 -3
  109. data/lib/fog/openstack/requests/image/list_public_images_detailed.rb +9 -6
  110. data/lib/fog/openstack/requests/network/create_port.rb +12 -11
  111. data/lib/fog/openstack/requests/network/create_subnet.rb +7 -7
  112. data/lib/fog/openstack/requests/network/get_port.rb +1 -0
  113. data/lib/fog/openstack/requests/network/update_port.rb +7 -6
  114. data/lib/fog/openstack/requests/orchestration/list_events.rb +46 -0
  115. data/lib/fog/openstack/requests/orchestration/list_resource_events.rb +7 -2
  116. data/lib/fog/openstack/requests/orchestration/list_resource_types.rb +3 -2
  117. data/lib/fog/openstack/requests/orchestration/list_resources.rb +27 -4
  118. data/lib/fog/openstack/requests/orchestration/list_stack_data.rb +2 -2
  119. data/lib/fog/openstack/requests/orchestration/list_stack_data_detailed.rb +49 -0
  120. data/lib/fog/openstack/requests/orchestration/list_stack_events.rb +6 -2
  121. data/lib/fog/openstack/requests/planning/list_plans.rb +4 -3
  122. data/lib/fog/openstack/requests/planning/list_roles.rb +3 -9
  123. data/lib/fog/openstack/requests/volume/create_volume.rb +2 -1
  124. data/lib/fog/openstack/requests/volume/list_snapshots.rb +16 -3
  125. data/lib/fog/openstack/requests/volume/list_snapshots_detailed.rb +27 -0
  126. data/lib/fog/openstack/requests/volume/list_volume_types.rb +6 -6
  127. data/lib/fog/openstack/requests/volume/list_volumes.rb +20 -7
  128. data/lib/fog/openstack/requests/volume/list_volumes_detailed.rb +49 -0
  129. data/lib/fog/openstack/volume.rb +1 -0
  130. data/lib/fog/ovirt/models/compute/server.rb +1 -0
  131. data/lib/fog/ovirt/models/compute/template.rb +1 -0
  132. data/lib/fog/rackspace/docs/queues.md +2 -2
  133. data/lib/fog/rackspace/models/block_storage/snapshot.rb +5 -1
  134. data/lib/fog/version.rb +1 -1
  135. data/lib/fog/vsphere/requests/compute/vm_clone.rb +1 -1
  136. data/lib/tasks/changelog_task.rb +1 -0
  137. data/spec/fog/openstack/identity_v3/authv3_a.yml +55 -35
  138. data/spec/fog/openstack/identity_v3/authv3_b.yml +55 -35
  139. data/spec/fog/openstack/identity_v3/authv3_c.yml +159 -33
  140. data/spec/fog/openstack/identity_v3/authv3_project.yml +79 -35
  141. data/spec/fog/openstack/identity_v3/authv3_token.yml +377 -76
  142. data/spec/fog/openstack/identity_v3/authv3_unscoped.yml +298 -155
  143. data/spec/fog/openstack/identity_v3/authv3_unscoped_reauth.yml +371 -0
  144. data/spec/fog/openstack/identity_v3/idv3.yml +456 -41
  145. data/spec/fog/openstack/identity_v3/idv3_credential.yml +36 -30
  146. data/spec/fog/openstack/identity_v3/idv3_credential_crud.yml +223 -190
  147. data/spec/fog/openstack/identity_v3/idv3_domain.yml +64 -58
  148. data/spec/fog/openstack/identity_v3/idv3_domain_crud.yml +176 -393
  149. data/spec/fog/openstack/identity_v3/idv3_domain_group_roles_mutation.yml +277 -379
  150. data/spec/fog/openstack/identity_v3/idv3_domain_roles_mutation.yml +177 -204
  151. data/spec/fog/openstack/identity_v3/idv3_endpoint.yml +492 -174
  152. data/spec/fog/openstack/identity_v3/idv3_endpoints_crud.yml +669 -435
  153. data/spec/fog/openstack/identity_v3/idv3_group_crud_mutation.yml +378 -298
  154. data/spec/fog/openstack/identity_v3/idv3_other_region.yml +187 -0
  155. data/spec/fog/openstack/identity_v3/idv3_policy.yml +54 -46
  156. data/spec/fog/openstack/identity_v3/idv3_policy_crud.yml +137 -117
  157. data/spec/fog/openstack/identity_v3/idv3_project.yml +116 -86
  158. data/spec/fog/openstack/identity_v3/idv3_project_crud.yml +179 -387
  159. data/spec/fog/openstack/identity_v3/idv3_project_group_user_roles_mutation.yml +415 -556
  160. data/spec/fog/openstack/identity_v3/idv3_role.yml +108 -74
  161. data/spec/fog/openstack/identity_v3/idv3_role_crud.yml +160 -368
  162. data/spec/fog/openstack/identity_v3/idv3_service.yml +156 -94
  163. data/spec/fog/openstack/identity_v3/idv3_services_crud.yml +250 -306
  164. data/spec/fog/openstack/identity_v3/idv3_token.yml +195 -101
  165. data/spec/fog/openstack/identity_v3/idv3_user_crud.yml +276 -193
  166. data/spec/fog/openstack/identity_v3/idv3_users.yml +149 -219
  167. data/spec/fog/openstack/identity_v3_spec.rb +502 -474
  168. data/spec/fog/openstack/volume/volume_common_setup.yml +76 -0
  169. data/spec/fog/openstack/volume/volume_crud.yml +561 -0
  170. data/spec/fog/openstack/volume/volume_type_read.yml +120 -0
  171. data/spec/fog/openstack/volume_spec.rb +165 -0
  172. data/tests/openstack/requests/compute/aggregate_tests.rb +59 -0
  173. data/tests/openstack/requests/network/port_tests.rb +12 -11
  174. data/tests/openstack/requests/orchestration/stack_tests.rb +25 -0
  175. metadata +56 -14
  176. data/spec/fog/openstack/identity_v3/idv2_unscoped_token_v3.yml +0 -467
@@ -1,11 +1,12 @@
1
1
  require 'fog/openstack/identity'
2
2
  require 'fog/openstack/identity_v3'
3
3
  require 'rspec/core'
4
+ require 'rspec/expectations'
4
5
  require 'vcr'
5
6
 
6
7
  RSpec.describe Fog::Identity::OpenStack::V3 do
7
8
 
8
- before :each do |example|
9
+ before :all do |example|
9
10
  @os_auth_url = ENV['OS_AUTH_URL']
10
11
 
11
12
  # if OS_AUTH_URL is set but FOG_MOCK is not, don't record anything and just pass through the requests
@@ -23,130 +24,154 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
23
24
  config.hook_into :webmock
24
25
  config.cassette_library_dir = "spec/fog/openstack/identity_v3"
25
26
  config.default_cassette_options = {:record => :none}
27
+ config.default_cassette_options.merge! :match_requests_on => [:method, :uri, :body] unless RUBY_VERSION =~ /1.8/ # Ruby 1.8.7 encodes JSON differently, which screws up request matching
26
28
  end
27
29
 
28
- unless example.metadata[:skip_preauthentication]
29
- VCR.use_cassette('idv3') do
30
- @id_v3 = Fog::Identity::OpenStack::V3.new(
31
- :openstack_project_name => ENV['OS_TENANT_NAME'] || 'admin',
32
- :openstack_domain_name => 'Default',
33
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
34
- :openstack_username => ENV['OS_USERNAME'] || 'admin',
35
- :openstack_auth_url => "#{@os_auth_url}/auth/tokens") unless @id_v3
30
+ if ENV['DEBUG']
31
+ VCR.configure do |config|
32
+ config.ignore_request do |request|
33
+ false && !ENV['OS_AUTH_URL'].nil?
34
+ end
35
+ config.cassette_library_dir = "spec/debug"
36
+ config.default_cassette_options.merge! :record => :all
36
37
  end
37
38
  end
39
+
40
+ # Allow us to ignore dev certificates on servers
41
+ Excon.defaults[:ssl_verify_peer] = false if ENV['SSL_VERIFY_PEER'] == 'false'
42
+
43
+ VCR.use_cassette('idv3') do
44
+ @id_v3 = Fog::Identity::OpenStack::V3.new(
45
+ :openstack_project_name => ENV['OS_PROJECT_NAME'] || 'admin',
46
+ :openstack_domain_name => ENV['OS_USER_DOMAIN_NAME'] || 'Default',
47
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
48
+ :openstack_username => ENV['OS_USERNAME'] || 'admin',
49
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
50
+ :openstack_auth_url => "#{@os_auth_url}/auth/tokens") unless @id_v3
51
+ end
38
52
  end
39
53
 
40
- it 'authenticates with password, userid and domain_id', :skip_preauthentication do
54
+ it 'authenticates with password, userid and domain_id' do
41
55
  VCR.use_cassette('authv3_a') do
42
56
  Fog::Identity::OpenStack::V3.new(
43
- :openstack_project_name => ENV['OS_TENANT_NAME'] || 'admin',
44
- :openstack_domain_name => 'Default',
45
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
46
- :openstack_username => ENV['OS_USERNAME'] || 'admin',
57
+ :openstack_domain_id => ENV['OS_USER_DOMAIN_ID'] || 'default',
58
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
59
+ :openstack_userid => ENV['OS_USER_ID'] || 'aa9f25defa6d4cafb48466df83106065',
60
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
47
61
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
48
62
  end
49
63
  end
50
64
 
51
- it 'authenticates with password, username and domain_id', :skip_preauthentication do
65
+ it 'authenticates with password, username and domain_id' do
52
66
  VCR.use_cassette('authv3_b') do
53
67
  Fog::Identity::OpenStack::V3.new(
54
- :openstack_project_name => ENV['OS_TENANT_NAME'] || 'admin',
55
- :openstack_domain_name => 'Default',
56
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
68
+ :openstack_domain_id => ENV['OS_USER_DOMAIN_ID'] || 'default',
69
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
57
70
  :openstack_username => ENV['OS_USERNAME'] || 'admin',
71
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
58
72
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
59
73
  end
60
74
  end
61
75
 
62
- it 'authenticates with password, username and domain_name', :skip_preauthentication do
76
+ it 'authenticates with password, username and domain_name' do
63
77
  VCR.use_cassette('authv3_c') do
64
78
  Fog::Identity::OpenStack::V3.new(
65
- :openstack_project_name => ENV['OS_TENANT_NAME'] || 'admin',
66
- :openstack_domain_name => 'Default',
67
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
79
+ :openstack_user_domain => ENV['OS_USER_DOMAIN_NAME'] || 'Default',
80
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
68
81
  :openstack_username => ENV['OS_USERNAME'] || 'admin',
82
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
69
83
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
70
84
  end
71
85
  end
72
86
 
73
- it 'authenticates with project scope', :skip_preauthentication do
74
- VCR.use_cassette('authv3_project') do
75
- Fog::Identity::OpenStack::V3.new(
76
- :openstack_project_name => ENV['OS_TENANT_NAME'] || 'admin',
77
- :openstack_domain_name => 'Default',
78
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
79
- :openstack_username => ENV['OS_USERNAME'] || 'admin',
80
- :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
87
+ it 'authenticates in another region' do
88
+ VCR.use_cassette('idv3_endpoint') do
89
+ @endpoints_all = @id_v3.endpoints.all
81
90
  end
91
+ endpoints_in_region = @endpoints_all.select { |endpoint| endpoint.region == (ENV['OS_REGION_OTHER']||'europe') }
92
+
93
+ VCR.use_cassette('idv3_other_region') do
94
+ @fog = Fog::Identity::OpenStack::V3.new({
95
+ :openstack_region => ENV['OS_REGION_OTHER']||'europe',
96
+ :openstack_auth_url => "#{@os_auth_url}/auth/tokens",
97
+ :openstack_userid => ENV['OS_USER_ID'] || 'aa9f25defa6d4cafb48466df83106065',
98
+ :openstack_api_key => ENV['OS_PASSWORD'] || "password"
99
+ })
100
+ expect(@fog).to_not be_nil
101
+ end unless endpoints_in_region.empty?
82
102
  end
83
103
 
84
- it "get an unscoped token using v2, then use it to get a scoped token in v3", :skip_preauthentication do
85
- VCR.use_cassette('idv2_unscoped_token_v3') do
86
-
87
- # Juno Keystone
88
- # Get an initial unscoped token by authenticating with username & password
89
- openstack_auth_url = @os_auth_url.gsub(/v3/, 'v2.0')
90
- @id_v2 = Fog::Identity::OpenStack.new(
91
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
92
- :openstack_username => ENV['OS_USERNAME'] || 'admin',
93
- :openstack_auth_url => "#{openstack_auth_url}/tokens")
104
+ it 'get an unscoped token, then reauthenticate with it' do
105
+ VCR.use_cassette('authv3_unscoped_reauth') do
94
106
 
95
- # Exchange it for a project-scoped token
96
- auth = Fog::Identity::OpenStack::V3.new(
97
- :openstack_project_name => ENV['OS_USERNAME'] || 'admin',
98
- :openstack_domain_name => 'Default',
99
- :openstack_tenant => ENV['OS_USERNAME'] || 'admin',
100
- :openstack_auth_token => @id_v2.credentials[:openstack_auth_token],
107
+ @id_v3 = Fog::Identity::OpenStack::V3.new(
108
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
109
+ :openstack_userid => ENV['OS_USER_ID'] || 'aa9f25defa6d4cafb48466df83106065',
110
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
101
111
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
102
112
 
103
- token = auth.credentials[:openstack_auth_token]
113
+ auth_params = {:provider => "openstack",
114
+ :openstack_auth_token => @id_v3.credentials[:openstack_auth_token],
115
+ :openstack_auth_url => "#{@os_auth_url}/auth/tokens",
116
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne'}
117
+ @fog2 = Fog::Identity::OpenStack::V3.new(auth_params)
104
118
 
105
- # We can use the scoped token to validate the scoped token
106
- validated_token = @id_v2.validate_token(token)
107
- expect(validated_token).to_not be_nil
119
+ expect(@fog2).to_not be_nil
120
+ token = @fog2.credentials[:openstack_auth_token]
121
+ expect(token).to_not be_nil
108
122
 
109
- @id_v2.check_token(token)
110
- expect { @id_v2.check_token(token, 'random-tenant-id') }.to raise_error(Excon::Errors::Unauthorized)
111
123
  end
112
124
  end
113
125
 
114
- it 'get an unscoped token, then use it to get a scoped token', :skip_preauthentication do
126
+ it 'authenticates with project scope' do
127
+ VCR.use_cassette('authv3_project') do
128
+ Fog::Identity::OpenStack::V3.new(
129
+ :openstack_project_name => ENV['OS_PROJECT_NAME'] || 'admin',
130
+ :openstack_domain_name => ENV['OS_USER_DOMAIN_NAME'] || 'Default',
131
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
132
+ :openstack_username => ENV['OS_USERNAME'] || 'admin',
133
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
134
+ :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
135
+ end
136
+ end
137
+
138
+ it 'get an unscoped token, then use it to get a scoped token' do
115
139
  VCR.use_cassette('authv3_unscoped') do
116
140
 
117
- # Juno Keystone
118
- @id_v3 = Fog::Identity::OpenStack::V3.new(
119
- :openstack_api_key => ENV['OS_PASSWORD'] || 'openstack',
120
- :openstack_userid => '8d5732a0ebd9485396351d74e24c9647',
141
+ id_v3 = Fog::Identity::OpenStack::V3.new(
142
+ :openstack_api_key => ENV['OS_PASSWORD'] || 'password',
143
+ :openstack_userid => ENV['OS_USER_ID']||'aa9f25defa6d4cafb48466df83106065',
144
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
121
145
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
122
146
 
123
147
  # Exchange it for a project-scoped token
124
148
  auth = Fog::Identity::OpenStack::V3.new(
125
- :openstack_project_name => ENV['OS_USERNAME'] || 'admin',
126
- :openstack_domain_name => 'Default',
149
+ :openstack_project_name => ENV['OS_PROJECT_NAME'] || 'admin',
150
+ :openstack_domain_name => ENV['OS_USER_DOMAIN_NAME'] || 'Default',
127
151
  :openstack_tenant => ENV['OS_USERNAME'] || 'admin',
128
- :openstack_auth_token => @id_v3.credentials[:openstack_auth_token],
152
+ :openstack_auth_token => id_v3.credentials[:openstack_auth_token],
153
+ :openstack_region => ENV['OS_REGION_NAME'] || 'RegionOne',
129
154
  :openstack_auth_url => "#{@os_auth_url}/auth/tokens")
130
155
 
131
156
  token = auth.credentials[:openstack_auth_token]
132
157
 
133
158
  # We can use the unscoped token to validate the scoped token
134
- validated_token = @id_v3.tokens.validate(token)
159
+ validated_token = id_v3.tokens.validate(token)
135
160
  expect(validated_token).to_not be_nil
136
161
 
137
- @id_v3.tokens.check(token)
138
- expect { @id_v3.tokens.check('random-token') }.to raise_error(Fog::Identity::OpenStack::NotFound)
162
+ id_v3.tokens.check(token)
163
+ expect { id_v3.tokens.check('random-token') }.to raise_error(Fog::Identity::OpenStack::NotFound)
139
164
  end
140
165
  end
141
166
 
142
167
  it "find specific user, lists users" do
143
168
  VCR.use_cassette('idv3_users') do
144
169
 
145
- other_user = @id_v3.users.find_by_id '8d5732a0ebd9485396351d74e24c9647'
146
-
147
- expect(other_user).to_not be_nil
148
170
  expect { nonexistent_user = @id_v3.users.find_by_id 'u-random-blah' }.to raise_error(Fog::Identity::OpenStack::NotFound)
149
171
 
172
+ admin_user = @id_v3.users.find_by_name ENV['OS_USERNAME'] || 'admin'
173
+ expect(admin_user.length).to be 1
174
+
150
175
  users = @id_v3.users
151
176
  expect(users).to_not be_nil
152
177
  expect(users.length).to_not be 0
@@ -155,8 +180,8 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
155
180
  expect(users_all).to_not be_nil
156
181
  expect(users_all.length).to_not be 0
157
182
 
158
- admin_user = @id_v3.users.find_by_name 'admin'
159
- expect(admin_user.length).to be 1
183
+ admin_by_id = @id_v3.users.find_by_id admin_user.first.id
184
+ expect(admin_by_id).to_not be_nil
160
185
 
161
186
  expect(@id_v3.users.find_by_name('pimpernel').length).to be 0
162
187
  end
@@ -193,6 +218,11 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
193
218
  expect(baz_user.email).to eq 'foobar@example.com'
194
219
  expect(baz_user.enabled).to be false
195
220
 
221
+ # Try to create the user again
222
+ expect { @id_v3.users.create(:name => 'baz',
223
+ :email => 'foobar@example.com',
224
+ :password => 's3cret!') }.to raise_error(Excon::Errors::Conflict)
225
+
196
226
  # Delete the user
197
227
  baz_user.destroy
198
228
  # Check that the deletion worked
@@ -228,9 +258,13 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
228
258
  expect(baz_group.name).to eq 'baz'
229
259
 
230
260
  # Add users to the group
261
+ #foobar_user1 = @id_v3.users.find_by_name('foobar1').first
262
+ #foobar_user1.destroy if foobar_user1
231
263
  foobar_user1 = @id_v3.users.create(:name => 'foobar1',
232
264
  :email => 'foobar1@example.com',
233
265
  :password => 's3cret!1')
266
+ #foobar_user2 = @id_v3.users.find_by_name('foobar2').first
267
+ #foobar_user2.destroy if foobar_user2
234
268
  foobar_user2 = @id_v3.users.create(:name => 'foobar2',
235
269
  :email => 'foobar2@example.com',
236
270
  :password => 's3cret!2')
@@ -271,8 +305,10 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
271
305
  it "gets a token, checks it and then revokes it" do
272
306
  VCR.use_cassette('idv3_token') do
273
307
  auth = {:auth => {:identity => {:methods => %w{password},
274
- :password => {:user => {:id => '8d5732a0ebd9485396351d74e24c9647', :password => 'openstack'}}},
275
- :scope => {:project => {:domain => {:id => 'default'}, :name => 'admin'}}}}
308
+ :password => {:user => {:id => ENV['OS_USER_ID']||'aa9f25defa6d4cafb48466df83106065',
309
+ :password => ENV['OS_PASSWORD']||'password'}}},
310
+ :scope => {:project => {:domain => {:name => ENV['OS_USER_DOMAIN_NAME']||'Default'},
311
+ :name => ENV['OS_PROJECT_NAME']||'admin'}}}}
276
312
 
277
313
  token = @id_v3.tokens.authenticate(auth)
278
314
  expect(token).to_not be_nil
@@ -291,26 +327,44 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
291
327
  VCR.use_cassette('authv3_token') do
292
328
  # Setup - get a non-admin token to check by using username/password authentication to start with
293
329
  auth_url = "#{@os_auth_url}/auth/tokens"
294
- nonadmin_v3 = Fog::Identity::OpenStack::V3.new(
295
- :openstack_project_name => 'demo',
296
- :openstack_domain_id => 'default',
297
- :openstack_api_key => 'openstack',
298
- :openstack_username => 'demo',
299
- :openstack_region => 'europe',
300
- :openstack_auth_url => auth_url)
301
-
302
- # Test - check the token validity by using it to create a new Fog::Identity::OpenStack::V3 instance
303
- token_check = Fog::Identity::OpenStack::V3.new(
304
- :openstack_auth_token => nonadmin_v3.auth_token,
305
- :openstack_region => 'europe',
306
- :openstack_auth_url => auth_url)
307
-
308
- expect(token_check).to_not be_nil
309
-
310
- expect { Fog::Identity::OpenStack::V3.new(
311
- :openstack_auth_token => 'blahblahblah',
312
- :openstack_region => 'europe',
313
- :openstack_auth_url => auth_url) }.to raise_error(Excon::Errors::NotFound)
330
+
331
+ begin
332
+
333
+ foobar_user = @id_v3.users.create(:name => 'foobar_385',
334
+ :email => 'foobar_demo@example.com',
335
+ :domain_id => ENV['OS_USER_DOMAIN_ID'] || 'default',
336
+ :password => 's3cret!')
337
+
338
+ foobar_role = @id_v3.roles.create(:name => 'foobar_role390')
339
+ foobar_user.grant_role(foobar_role.id)
340
+
341
+ nonadmin_v3 = Fog::Identity::OpenStack::V3.new(
342
+ :openstack_domain_id => foobar_user.domain_id,
343
+ :openstack_api_key => 's3cret!',
344
+ :openstack_username => 'foobar_385',
345
+ :openstack_region => ENV['OS_REGION_NAME']||'europe',
346
+ :openstack_auth_url => auth_url)
347
+
348
+ # Test - check the token validity by using it to create a new Fog::Identity::OpenStack::V3 instance
349
+ token_check = Fog::Identity::OpenStack::V3.new(
350
+ :openstack_auth_token => nonadmin_v3.auth_token,
351
+ :openstack_region => ENV['OS_REGION_NAME']||'europe',
352
+ :openstack_auth_url => auth_url)
353
+
354
+ expect(token_check).to_not be_nil
355
+
356
+ expect { Fog::Identity::OpenStack::V3.new(
357
+ :openstack_auth_token => 'blahblahblah',
358
+ :openstack_region => ENV['OS_REGION_NAME']||'europe',
359
+ :openstack_auth_url => auth_url) }.to raise_error(Excon::Errors::NotFound)
360
+ ensure
361
+ # Clean up
362
+ foobar_user = @id_v3.users.find_by_name('foobar_385').first unless foobar_user
363
+ foobar_user.destroy if foobar_user
364
+ foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role390' }.first unless foobar_role
365
+ foobar_role.destroy if foobar_role
366
+ end
367
+
314
368
  end
315
369
  end
316
370
 
@@ -325,7 +379,7 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
325
379
  expect(domains_all).to_not be_nil
326
380
  expect(domains_all.length).to_not be 0
327
381
 
328
- default_domain = @id_v3.domains.find_by_id 'default'
382
+ default_domain = @id_v3.domains.find_by_id ENV['OS_USER_DOMAIN_ID']||'default'
329
383
  expect(default_domain).to_not be_nil
330
384
 
331
385
  expect { @id_v3.domains.find_by_id 'atlantis' }.to raise_error(Fog::Identity::OpenStack::NotFound)
@@ -335,37 +389,36 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
335
389
  it "CRUD domains" do
336
390
  VCR.use_cassette('idv3_domain_crud') do
337
391
 
338
- # Make sure there are no existing domains called foobar or baz
339
- ['foobar', 'baz'].each do |domain_name|
340
- @id_v3.domains.all(:name => domain_name).each do |domain|
341
- domain.update(:enabled => false) if domain
342
- domain.destroy if domain
392
+ begin
393
+ # Create a domain called foobar
394
+ foobar_domain = @id_v3.domains.create(:name => 'foobar')
395
+ foobar_id = foobar_domain.id
396
+ expect(@id_v3.domains.all(:name => 'foobar').length).to be 1
397
+
398
+ # Rename it to baz and disable it (required so we can delete it)
399
+ foobar_domain.update(:name => 'baz', :enabled => false)
400
+ expect(foobar_domain.name).to eq 'baz'
401
+
402
+ # Read the domain freshly and check the name & enabled state
403
+ expect(@id_v3.domains.all(:name => 'baz').length).to be 1
404
+ baz_domain = @id_v3.domains.find_by_id foobar_id
405
+ expect(baz_domain).to_not be_nil
406
+ expect(baz_domain.name).to eq 'baz'
407
+ expect(baz_domain.enabled).to be false
408
+ ensure
409
+ # Delete the domains
410
+ begin
411
+ baz_domain.update(:enabled => false) if baz_domain
412
+ baz_domain.destroy if baz_domain
413
+ foobar_domain.update(:enabled => false) if foobar_domain
414
+ foobar_domain.destroy if foobar_domain
415
+ rescue
416
+ end
417
+ # Check that the deletion worked
418
+ expect { @id_v3.domains.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound) if foobar_id
419
+ ['foobar', 'baz'].each do |domain_name|
420
+ expect(@id_v3.domains.all(:name => domain_name).length).to be 0
343
421
  end
344
- expect(@id_v3.domains.all(:name => domain_name).length).to be 0
345
- end
346
-
347
- # Create a domain called foobar
348
- foobar_domain = @id_v3.domains.create(:name => 'foobar')
349
- foobar_id = foobar_domain.id
350
- expect(@id_v3.domains.all(:name => 'foobar').length).to be 1
351
-
352
- # Rename it to baz and disable it (required so we can delete it)
353
- foobar_domain.update(:name => 'baz', :enabled => false)
354
- expect(foobar_domain.name).to eq 'baz'
355
-
356
- # Read the domain freshly and check the name & enabled state
357
- expect(@id_v3.domains.all(:name => 'baz').length).to be 1
358
- baz_domain = @id_v3.domains.find_by_id foobar_id
359
- expect(baz_domain).to_not be_nil
360
- expect(baz_domain.name).to eq 'baz'
361
- expect(baz_domain.enabled).to be false
362
-
363
- # Delete the domain
364
- baz_domain.destroy
365
- # Check that the deletion worked
366
- expect { @id_v3.domains.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
367
- ['foobar', 'baz'].each do |domain_name|
368
- expect(@id_v3.domains.all(:name => domain_name).length).to be 0
369
422
  end
370
423
  end
371
424
  end
@@ -374,119 +427,113 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
374
427
  # Note that the domain is implicit in the user operations here
375
428
 
376
429
  VCR.use_cassette('idv3_domain_roles_mutation') do
430
+ begin
431
+ foobar_user = @id_v3.users.create(:name => 'foobar_role_user',
432
+ :email => 'foobar@example.com',
433
+ :password => 's3cret!')
434
+
435
+ # User has no roles initially
436
+ expect(foobar_user.roles.length).to be 0
437
+
438
+ # Create a role and add it to the user in the user's domain
439
+ foobar_role = @id_v3.roles.create(:name => 'foobar_role')
440
+ foobar_user.grant_role(foobar_role.id)
441
+ expect(foobar_user.roles.length).to be 1
442
+ assignments = @id_v3.role_assignments.all(:user_id => foobar_user.id)
443
+ expect(assignments.length).to be 1
444
+ expect(assignments.first.role['id']).to eq foobar_role.id
445
+ expect(assignments.first.user['id']).to eq foobar_user.id
446
+ expect(assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
447
+ expect(assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_user.domain_id}/users/#{foobar_user.id}/roles/#{foobar_role.id}").to be true
448
+
449
+ # Quick test of @id_v3.role_assignments.all while we're at it
450
+ all_assignments = @id_v3.role_assignments.all
451
+ expect(all_assignments.length).to be >= 1
452
+
453
+ # Check that the user has the role
454
+ expect(foobar_user.check_role(foobar_role.id)).to be true
455
+
456
+ # Revoke the role from the user
457
+ foobar_user.revoke_role(foobar_role.id)
458
+ expect(foobar_user.check_role(foobar_role.id)).to be false
459
+ ensure
460
+ foobar_user = @id_v3.users.find_by_name('u-foobar_role_user').first unless foobar_user
461
+ foobar_user.destroy if foobar_user
462
+ foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role' }.first unless foobar_role
463
+ foobar_role.destroy if foobar_role
464
+ end
377
465
 
378
- foobar_user = @id_v3.users.find_by_name('foobar').first
379
- foobar_user.destroy if foobar_user
380
- foobar_user = @id_v3.users.create(:name => 'foobar',
381
- :email => 'foobar@example.com',
382
- :password => 's3cret!')
383
-
384
- # User has no roles initially
385
- expect(foobar_user.roles.length).to be 0
386
-
387
- # Create a role and add it to the user in the user's domain
388
- foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role' }.first
389
- foobar_role.destroy if foobar_role
390
- foobar_role = @id_v3.roles.create(:name => 'foobar_role')
391
- foobar_user.grant_role(foobar_role.id)
392
- expect(foobar_user.roles.length).to be 1
393
- assignments = @id_v3.role_assignments.filter_by(:user_id => foobar_user.id)
394
- expect(assignments.length).to be 1
395
- expect(assignments.first.role['id']).to eq foobar_role.id
396
- expect(assignments.first.user['id']).to eq foobar_user.id
397
- expect(assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
398
- expect(assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_user.domain_id}/users/#{foobar_user.id}/roles/#{foobar_role.id}").to be true
399
-
400
- # Quick test of @id_v3.role_assignments.all while we're at it
401
- all_assignments = @id_v3.role_assignments.all
402
- expect(assignments.length).to be >= 1
403
-
404
- # Check that the user has the role
405
- expect(foobar_user.check_role(foobar_role.id)).to be true
406
-
407
- # Revoke the role from the user
408
- foobar_user.revoke_role(foobar_role.id)
409
- expect(foobar_user.check_role(foobar_role.id)).to be false
410
-
411
- foobar_user.destroy
412
- foobar_role.destroy
413
466
  end
414
467
  end
415
468
 
416
469
  it "Manipulates roles on domain groups" do
417
470
  VCR.use_cassette('idv3_domain_group_roles_mutation') do
418
471
 
419
- # Make sure there is no existing domain called foobar
420
- @id_v3.domains.all.select { |domain| ['d-foobar'].include? domain.name }.each do |domain|
421
- domain.update(:enabled => false)
422
- domain.destroy
423
- end
424
- expect(@id_v3.domains.all.select { |domain| domain.name == 'd-foobar' }.length).to be 0
472
+ begin
473
+ # Create a domain called foobar
474
+ foobar_domain = @id_v3.domains.create(:name => 'd-foobar')
425
475
 
426
- # Create a domain called foobar
427
- foobar_domain = @id_v3.domains.create(:name => 'd-foobar')
476
+ # Create a group in this domain
477
+ foobar_group = @id_v3.groups.create(:name => 'g-foobar',
478
+ :description => "Group of Foobar users",
479
+ :domain_id => foobar_domain.id)
428
480
 
429
- # Create a group in this domain
430
- @id_v3.groups.all.select { |group| ['g-foobar'].include? group.name }.each do |group|
431
- group.destroy
432
- end
433
- foobar_group = @id_v3.groups.create(:name => 'g-foobar',
434
- :description => "Group of Foobar users",
481
+ # Create a user in the domain
482
+ foobar_user = @id_v3.users.create(:name => 'u-foobar_foobar',
483
+ :email => 'foobar@example.com',
484
+ :password => 's3cret!',
435
485
  :domain_id => foobar_domain.id)
436
486
 
437
- # Create a user in the domain
438
- foobar_user = @id_v3.users.find_by_name('u-foobar').first
439
- foobar_user.destroy if foobar_user
440
- foobar_user = @id_v3.users.create(:name => 'u-foobar',
441
- :email => 'foobar@example.com',
442
- :password => 's3cret!',
443
- :domain_id => foobar_domain.id)
444
-
445
- # User has no roles initially
446
- expect(foobar_user.roles.length).to be 0
447
-
448
- # Create a role and add it to the domain group
449
- foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role' }.first
450
- foobar_role.destroy if foobar_role
451
- foobar_role = @id_v3.roles.create(:name => 'foobar_role')
452
-
453
- foobar_group.grant_role foobar_role.id
454
- expect(foobar_group.roles.length).to be 1
455
-
456
- # Add user to the group and check that it inherits the role
457
- expect(foobar_user.check_role foobar_role.id).to be false
458
- expect(@id_v3.role_assignments.filter_by(:user_id => foobar_user.id, :effective => true).length).to be 0
459
- foobar_group.add_user foobar_user.id
460
- expect(foobar_user.check_role foobar_role.id).to be false # Still false in absolute assignment terms
461
- assignments = @id_v3.role_assignments.filter_by(:user_id => foobar_user.id, :effective => true)
462
- expect(assignments.length).to be 1
463
- expect(assignments.first.role['id']).to eq foobar_role.id
464
- expect(assignments.first.user['id']).to eq foobar_user.id
465
- expect(assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
466
- expect(assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_domain.id}/groups/#{foobar_group.id}/roles/#{foobar_role.id}").to be true
467
- expect(assignments.first.links['membership'].end_with? "/v3/groups/#{foobar_group.id}/users/#{foobar_user.id}").to be true
468
-
469
- group_assignments = @id_v3.role_assignments.filter_by(:group_id => foobar_group.id)
470
- expect(group_assignments.length).to be 1
471
- expect(group_assignments.first.role['id']).to eq foobar_role.id
472
- expect(group_assignments.first.group['id']).to eq foobar_group.id
473
- expect(group_assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
474
- expect(group_assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_domain.id}/groups/#{foobar_group.id}/roles/#{foobar_role.id}").to be true
475
-
476
- # Revoke the role from the group and check the user no longer has it
477
- foobar_group.revoke_role foobar_role.id
478
- expect(@id_v3.role_assignments.filter_by(:user_id => foobar_user.id, :effective => true).length).to be 0
479
-
480
- # Clean up
481
- foobar_user.destroy
482
- foobar_group.destroy
483
- foobar_role.destroy
484
- foobar_domain.update(:enabled => false)
485
- foobar_domain.destroy
487
+ # User has no roles initially
488
+ expect(foobar_user.roles.length).to be 0
489
+
490
+ # Create a role and add it to the domain group
491
+ foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role' }.first
492
+ foobar_role.destroy if foobar_role
493
+ foobar_role = @id_v3.roles.create(:name => 'foobar_role')
494
+
495
+ foobar_group.grant_role foobar_role.id
496
+ expect(foobar_group.roles.length).to be 1
497
+
498
+ # Add user to the group and check that it inherits the role
499
+ expect(foobar_user.check_role foobar_role.id).to be false
500
+ expect(@id_v3.role_assignments.all(:user_id => foobar_user.id, :effective => true).length).to be 0
501
+ foobar_group.add_user foobar_user.id
502
+ expect(foobar_user.check_role foobar_role.id).to be false # Still false in absolute assignment terms
503
+ assignments = @id_v3.role_assignments.all(:user_id => foobar_user.id, :effective => true)
504
+ expect(assignments.length).to be 1
505
+ expect(assignments.first.role['id']).to eq foobar_role.id
506
+ expect(assignments.first.user['id']).to eq foobar_user.id
507
+ expect(assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
508
+ expect(assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_domain.id}/groups/#{foobar_group.id}/roles/#{foobar_role.id}").to be true
509
+ expect(assignments.first.links['membership'].end_with? "/v3/groups/#{foobar_group.id}/users/#{foobar_user.id}").to be true
510
+
511
+ group_assignments = @id_v3.role_assignments.all(:group_id => foobar_group.id)
512
+ expect(group_assignments.length).to be 1
513
+ expect(group_assignments.first.role['id']).to eq foobar_role.id
514
+ expect(group_assignments.first.group['id']).to eq foobar_group.id
515
+ expect(group_assignments.first.scope['domain']['id']).to eq foobar_user.domain_id
516
+ expect(group_assignments.first.links['assignment'].end_with? "/v3/domains/#{foobar_domain.id}/groups/#{foobar_group.id}/roles/#{foobar_role.id}").to be true
517
+
518
+ # Revoke the role from the group and check the user no longer has it
519
+ foobar_group.revoke_role foobar_role.id
520
+ expect(@id_v3.role_assignments.all(:user_id => foobar_user.id, :effective => true).length).to be 0
521
+ ensure
522
+ # Clean up
523
+ foobar_user = @id_v3.users.find_by_name('u-foobar_foobar').first unless foobar_user
524
+ foobar_user.destroy if foobar_user
525
+ foobar_group = @id_v3.groups.all.select { |group| group.name == 'g-foobar' }.first unless foobar_group
526
+ foobar_group.destroy if foobar_group
527
+ foobar_role = @id_v3.roles.all.select { |role| role.name == 'foobar_role' }.first unless foobar_role
528
+ foobar_role.destroy if foobar_role
529
+ foobar_domain = @id_v3.domains.all.select { |domain| domain.name == 'd-foobar' }.first unless foobar_domain
530
+ foobar_domain.update(:enabled => false) if foobar_domain
531
+ foobar_domain.destroy if foobar_domain
532
+ end
486
533
  end
487
534
  end
488
535
 
489
- it "lists roles and assignments" do
536
+ it "lists roles" do
490
537
  VCR.use_cassette('idv3_role') do
491
538
 
492
539
  roles = @id_v3.roles
@@ -497,8 +544,8 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
497
544
  expect(roles_all).to_not be_nil
498
545
  expect(roles_all.length).to_not be 0
499
546
 
500
- default_role = @id_v3.roles.find_by_id '9fe2ff9ee4384b1894a90878d3e92bab'
501
- expect(default_role).to_not be_nil
547
+ role_by_id = @id_v3.roles.find_by_id roles_all.first.id
548
+ expect(role_by_id).to_not be_nil
502
549
 
503
550
  expect { @id_v3.roles.find_by_id 'atlantis' }.to raise_error(Fog::Identity::OpenStack::NotFound)
504
551
  end
@@ -507,36 +554,29 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
507
554
  it "CRUD roles" do
508
555
  VCR.use_cassette('idv3_role_crud') do
509
556
 
510
- # Make sure there are no existing roles called foobar or baz
511
- ['foobar', 'baz'].each do |role_name|
512
- @id_v3.roles.all(:name => role_name).each do |role|
513
- role.update(:enabled => false)
514
- role.destroy
557
+ begin
558
+ # Create a role called foobar
559
+ foobar_role = @id_v3.roles.create(:name => 'foobar23')
560
+ foobar_id = foobar_role.id
561
+ expect(@id_v3.roles.all(:name => 'foobar23').length).to be 1
562
+
563
+ # Rename it to baz
564
+ foobar_role.update(:name => 'baz23')
565
+ expect(foobar_role.name).to eq 'baz23'
566
+
567
+ # Read the role freshly and check the name & enabled state
568
+ expect(@id_v3.roles.all(:name => 'baz23').length).to be 1
569
+ baz_role = @id_v3.roles.find_by_id foobar_id
570
+ expect(baz_role).to_not be_nil
571
+ expect(baz_role.name).to eq 'baz23'
572
+ ensure
573
+ # Delete the role
574
+ baz_role.destroy if baz_role
575
+ # Check that the deletion worked
576
+ expect { @id_v3.roles.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound) if foobar_id
577
+ ['foobar23', 'baz23'].each do |role_name|
578
+ expect(@id_v3.roles.all(:name => role_name).length).to be 0
515
579
  end
516
- expect(@id_v3.roles.all(:name => role_name).length).to be 0
517
- end
518
-
519
- # Create a role called foobar
520
- foobar_role = @id_v3.roles.create(:name => 'foobar')
521
- foobar_id = foobar_role.id
522
- expect(@id_v3.roles.all(:name => 'foobar').length).to be 1
523
-
524
- # Rename it to baz
525
- foobar_role.update(:name => 'baz')
526
- expect(foobar_role.name).to eq 'baz'
527
-
528
- # Read the role freshly and check the name & enabled state
529
- expect(@id_v3.roles.all(:name => 'baz').length).to be 1
530
- baz_role = @id_v3.roles.find_by_id foobar_id
531
- expect(baz_role).to_not be_nil
532
- expect(baz_role.name).to eq 'baz'
533
-
534
- # Delete the role
535
- baz_role.destroy
536
- # Check that the deletion worked
537
- expect { @id_v3.roles.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
538
- ['foobar', 'baz'].each do |role_name|
539
- expect(@id_v3.roles.all(:name => role_name).length).to be 0
540
580
  end
541
581
  end
542
582
  end
@@ -551,9 +591,8 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
551
591
  projects_all = @id_v3.projects.all
552
592
  expect(projects_all).to_not be_nil
553
593
  expect(projects_all.length).to_not be 0
554
-
555
- default_project = @id_v3.projects.find_by_id 'c9f75b1200f64bf09ed079206a1a1b75'
556
- expect(default_project).to_not be_nil
594
+ project_byid = @id_v3.projects.find_by_id projects_all.first.id
595
+ expect(project_byid).to_not be_nil
557
596
 
558
597
  expect { @id_v3.projects.find_by_id 'atlantis' }.to raise_error(Fog::Identity::OpenStack::NotFound)
559
598
  end
@@ -562,41 +601,34 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
562
601
  it "CRUD projects" do
563
602
  VCR.use_cassette('idv3_project_crud') do
564
603
 
565
- default_domain = @id_v3.domains.find_by_id 'default'
566
-
567
- # Make sure there are no existing projects called foobar or baz
568
- ['p-foobar', 'p-baz'].each do |project_name|
569
- @id_v3.projects.all(:name => project_name).each do |project|
570
- project.update(:enabled => false) if project
571
- project.destroy if project
604
+ default_domain = @id_v3.domains.find_by_id ENV['OS_USER_DOMAIN_ID']||'default'
605
+
606
+ begin
607
+ # Create a project called foobar - should not work without domain id?
608
+ foobar_project = @id_v3.projects.create(:name => 'p-foobar46')
609
+ foobar_id = foobar_project.id
610
+ expect(@id_v3.projects.all(:name => 'p-foobar46').length).to be 1
611
+ expect(foobar_project.domain_id).to eq default_domain.id
612
+
613
+ # Rename it to baz and disable it (required so we can delete it)
614
+ foobar_project.update(:name => 'p-baz46', :enabled => false)
615
+ expect(foobar_project.name).to eq 'p-baz46'
616
+
617
+ # Read the project freshly and check the name & enabled state
618
+ expect(@id_v3.projects.all(:name => 'p-baz46').length).to be 1
619
+ baz_project = @id_v3.projects.find_by_id foobar_id
620
+ expect(baz_project).to_not be_nil
621
+ expect(baz_project.name).to eq 'p-baz46'
622
+ expect(baz_project.enabled).to be false
623
+ ensure
624
+ # Delete the project
625
+ baz_project.destroy
626
+
627
+ # Check that the deletion worked
628
+ expect { @id_v3.projects.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
629
+ ['p-foobar46', 'p-baz46'].each do |project_name|
630
+ expect(@id_v3.projects.all(:name => project_name).length).to be 0
572
631
  end
573
- expect(@id_v3.projects.all(:name => project_name).length).to be 0
574
- end
575
-
576
- # Create a project called foobar - should not work without domain id?
577
- foobar_project = @id_v3.projects.create(:name => 'p-foobar')
578
- foobar_id = foobar_project.id
579
- expect(@id_v3.projects.all(:name => 'p-foobar').length).to be 1
580
- expect(foobar_project.domain_id).to eq default_domain.id
581
-
582
- # Rename it to baz and disable it (required so we can delete it)
583
- foobar_project.update(:name => 'p-baz', :enabled => false)
584
- expect(foobar_project.name).to eq 'p-baz'
585
-
586
- # Read the project freshly and check the name & enabled state
587
- expect(@id_v3.projects.all(:name => 'p-baz').length).to be 1
588
- baz_project = @id_v3.projects.find_by_id foobar_id
589
- expect(baz_project).to_not be_nil
590
- expect(baz_project.name).to eq 'p-baz'
591
- expect(baz_project.enabled).to be false
592
-
593
- # Delete the project
594
- baz_project.destroy
595
-
596
- # Check that the deletion worked
597
- expect { @id_v3.projects.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
598
- ['p-foobar', 'p-baz'].each do |project_name|
599
- expect(@id_v3.projects.all(:name => project_name).length).to be 0
600
632
  end
601
633
  end
602
634
  end
@@ -605,92 +637,89 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
605
637
  VCR.use_cassette('idv3_project_group_user_roles_mutation') do
606
638
 
607
639
  # Make sure there is no existing project called foobar
608
- @id_v3.projects.all(:name => 'p-foobar').each do |project|
640
+ @id_v3.projects.all(:name => 'p-foobar69').each do |project|
609
641
  project.update(:enabled => false)
610
642
  project.destroy
611
643
  end
612
- expect(@id_v3.projects.all(:name => 'p-foobar').length).to be 0
613
-
614
- # Create a project called foobar
615
- foobar_project = @id_v3.projects.create(:name => 'p-foobar')
616
-
617
- # Create a role called baz
618
- @id_v3.roles.all(:name => 'baz').each do |role|
619
- role.update(:enabled => false)
620
- role.destroy
621
- end
622
- baz_role = @id_v3.roles.create(:name => 'baz')
644
+ expect(@id_v3.projects.all(:name => 'p-foobar69').length).to be 0
623
645
 
624
- # Create a user
625
- foobar_user = @id_v3.users.find_by_name('u-foobar').first
626
- foobar_user.destroy if foobar_user
627
- foobar_user = @id_v3.users.create(:name => 'u-foobar',
628
- :email => 'foobar@example.com',
629
- :password => 's3cret!')
630
-
631
- # Create a group and add the user to it
632
- @id_v3.groups.all.select { |group| ['g-foobar'].include? group.name }.each do |group|
633
- group.destroy
646
+ begin
647
+ # Create a project called foobar
648
+ foobar_project = @id_v3.projects.create(:name => 'p-foobar69')
649
+ # Create a role called baz
650
+ @id_v3.roles.all(:name => 'baz').each do |role|
651
+ role.update(:enabled => false)
652
+ role.destroy
653
+ end
654
+ baz_role = @id_v3.roles.create(:name => 'baz69')
655
+
656
+ # Create a user
657
+ foobar_user = @id_v3.users.create(:name => 'u-foobar69',
658
+ :email => 'foobar@example.com',
659
+ :password => 's3cret!')
660
+
661
+ # Create a group and add the user to it
662
+ foobar_group = @id_v3.groups.create(:name => 'g-foobar69',
663
+ :description => "Group of Foobar users")
664
+ foobar_group.add_user foobar_user.id
665
+
666
+ # User has no projects initially
667
+ expect(foobar_user.projects.length).to be 0
668
+ expect(@id_v3.role_assignments.all(:user_id => foobar_user.id,
669
+ :project_id => foobar_project.id,
670
+ :effective => true).length).to be 0
671
+ expect(foobar_project.user_roles(foobar_user.id).length).to be 0
672
+
673
+ # Grant role to the user in the new project - this assigns the project to the user
674
+ foobar_project.grant_role_to_user(baz_role.id, foobar_user.id)
675
+ expect(foobar_user.projects.length).to be 1
676
+ expect(foobar_project.check_user_role(foobar_user.id, baz_role.id)).to be true
677
+ expect(foobar_project.user_roles(foobar_user.id).length).to be 1
678
+
679
+ # Revoke role from the user in the new project - this removes the user from the project
680
+ foobar_project.revoke_role_from_user(baz_role.id, foobar_user.id)
681
+ expect(foobar_user.projects.length).to be 0
682
+ expect(foobar_project.check_user_role(foobar_user.id, baz_role.id)).to be false
683
+
684
+ # Group initially has no roles in project
685
+ expect(foobar_project.group_roles(foobar_group.id).length).to be 0
686
+
687
+ expect(@id_v3.role_assignments.all(:user_id => foobar_user.id,
688
+ :project_id => foobar_project.id,
689
+ :effective => true).length).to be 0
690
+
691
+ # Grant role to the group in the new project - this assigns the project to the group
692
+ foobar_project.grant_role_to_group(baz_role.id, foobar_group.id)
693
+ expect(foobar_project.check_group_role(foobar_group.id, baz_role.id)).to be true
694
+ expect(foobar_project.group_roles(foobar_group.id).length).to be 1
695
+
696
+ # Now we check that a user has the role in that project
697
+ assignments = @id_v3.role_assignments.all(:user_id => foobar_user.id,
698
+ :project_id => foobar_project.id,
699
+ :effective => true)
700
+ expect(assignments.length).to be 1
701
+ expect(assignments.first.role['id']).to eq baz_role.id
702
+ expect(assignments.first.user['id']).to eq foobar_user.id
703
+ expect(assignments.first.scope['project']['id']).to eq foobar_project.id
704
+ expect(assignments.first.links['assignment'].end_with? "/v3/projects/#{foobar_project.id}/groups/#{foobar_group.id}/roles/#{baz_role.id}").to be true
705
+ expect(assignments.first.links['membership'].end_with? "/v3/groups/#{foobar_group.id}/users/#{foobar_user.id}").to be true
706
+
707
+ # and we check that the user is in the project because of group membership
708
+ expect(foobar_user.projects.length).to be 1
709
+
710
+ # Revoke role from the group in the new project - this removes the group from the project
711
+ foobar_project.revoke_role_from_group(baz_role.id, foobar_group.id)
712
+ expect(foobar_user.projects.length).to be 0
713
+ expect(foobar_project.check_group_role(foobar_group.id, baz_role.id)).to be false
714
+
715
+ ensure
716
+ # Clean up
717
+ foobar_user.destroy if foobar_user
718
+ foobar_group.destroy if foobar_group
719
+ baz_role.destroy if baz_role
720
+ foobar_project.update(:enabled => false) if foobar_project
721
+ foobar_project.destroy if foobar_project
634
722
  end
635
- foobar_group = @id_v3.groups.create(:name => 'g-foobar',
636
- :description => "Group of Foobar users")
637
- foobar_group.add_user foobar_user.id
638
-
639
- # User has no projects initially
640
- expect(foobar_user.projects.length).to be 0
641
- expect(@id_v3.role_assignments.filter_by(:user_id => foobar_user.id,
642
- :project_id => foobar_project.id,
643
- :effective => true).length).to be 0
644
- expect(foobar_project.user_roles(foobar_user.id).length).to be 0
645
-
646
- # Grant role to the user in the new project - this assigns the project to the user
647
- foobar_project.grant_role_to_user(baz_role.id, foobar_user.id)
648
- expect(foobar_user.projects.length).to be 1
649
- expect(foobar_project.check_user_role(foobar_user.id, baz_role.id)).to be true
650
- expect(foobar_project.user_roles(foobar_user.id).length).to be 1
651
-
652
- # Revoke role from the user in the new project - this removes the user from the project
653
- foobar_project.revoke_role_from_user(baz_role.id, foobar_user.id)
654
- expect(foobar_user.projects.length).to be 0
655
- expect(foobar_project.check_user_role(foobar_user.id, baz_role.id)).to be false
656
-
657
- # Group initially has no roles in project
658
- expect(foobar_project.group_roles(foobar_group.id).length).to be 0
659
-
660
- expect(@id_v3.role_assignments.filter_by(:user_id => foobar_user.id,
661
- :project_id => foobar_project.id,
662
- :effective => true).length).to be 0
663
-
664
- # Grant role to the group in the new project - this assigns the project to the group
665
- foobar_project.grant_role_to_group(baz_role.id, foobar_group.id)
666
- expect(foobar_project.check_group_role(foobar_group.id, baz_role.id)).to be true
667
- expect(foobar_project.group_roles(foobar_group.id).length).to be 1
668
-
669
- # Now we check that a user has the role in that project
670
- assignments = @id_v3.role_assignments.filter_by(:user_id => foobar_user.id,
671
- :project_id => foobar_project.id,
672
- :effective => true)
673
- expect(assignments.length).to be 1
674
- expect(assignments.first.role['id']).to eq baz_role.id
675
- expect(assignments.first.user['id']).to eq foobar_user.id
676
- expect(assignments.first.scope['project']['id']).to eq foobar_project.id
677
- expect(assignments.first.links['assignment'].end_with? "/v3/projects/#{foobar_project.id}/groups/#{foobar_group.id}/roles/#{baz_role.id}").to be true
678
- expect(assignments.first.links['membership'].end_with? "/v3/groups/#{foobar_group.id}/users/#{foobar_user.id}").to be true
679
-
680
- # and we check that the user is in the project because of group membership
681
- expect(foobar_user.projects.length).to be 1
682
-
683
- # Revoke role from the group in the new project - this removes the group from the project
684
- foobar_project.revoke_role_from_group(baz_role.id, foobar_group.id)
685
- expect(foobar_user.projects.length).to be 0
686
- expect(foobar_project.check_group_role(foobar_group.id, baz_role.id)).to be false
687
-
688
- # Clean up
689
- foobar_user.destroy
690
- foobar_group.destroy
691
- baz_role.destroy
692
- foobar_project.update(:enabled => false)
693
- foobar_project.destroy
694
723
  end
695
724
  end
696
725
 
@@ -717,34 +746,30 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
717
746
 
718
747
  all_services = @id_v3.services.all
719
748
 
720
- # Make sure there are no existing services called foobar or baz
721
- @id_v3.services.all.select { |service| ['foobar', 'baz'].include? service.name }.each do |service|
722
- service.destroy
749
+ begin
750
+ # Create a service called foobar
751
+ foobar_service = @id_v3.services.create(:type => 'volume', :name => 'foobar')
752
+ foobar_id = foobar_service.id
753
+ expect(@id_v3.services.all(:type => 'volume').select { |service| service.name == 'foobar' }.length).to be 1
754
+
755
+ # Rename it to baz
756
+ foobar_service.update(:name => 'baz')
757
+ expect(foobar_service.name).to eq 'baz'
758
+
759
+ # Read the service freshly and check the name
760
+ expect(@id_v3.services.all.select { |service| service.name == 'baz' }.length).to be 1
761
+ baz_service = @id_v3.services.find_by_id foobar_id
762
+ expect(baz_service).to_not be_nil
763
+ expect(baz_service.name).to eq 'baz'
764
+ expect(baz_service.type).to eq 'volume'
765
+ ensure
766
+ # Delete the service
767
+ baz_service.destroy if baz_service
768
+
769
+ # Check that the deletion worked
770
+ expect { @id_v3.services.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound) if foobar_id
771
+ expect(@id_v3.services.all.select { |service| ['foobar', 'baz'].include? service.name }.length).to be 0
723
772
  end
724
- expect(all_services.select { |service| ['foobar', 'baz'].include? service.name }.length).to be 0
725
-
726
- # Create a service called foobar
727
- foobar_service = @id_v3.services.create(:type => 'volume', :name => 'foobar')
728
- foobar_id = foobar_service.id
729
- expect(@id_v3.services.all(:type => 'volume').select { |service| service.name == 'foobar' }.length).to be 1
730
-
731
- # Rename it to baz
732
- foobar_service.update(:name => 'baz')
733
- expect(foobar_service.name).to eq 'baz'
734
-
735
- # Read the service freshly and check the name
736
- expect(@id_v3.services.all.select { |service| service.name == 'baz' }.length).to be 1
737
- baz_service = @id_v3.services.find_by_id foobar_id
738
- expect(baz_service).to_not be_nil
739
- expect(baz_service.name).to eq 'baz'
740
- expect(baz_service.type).to eq 'volume'
741
-
742
- # Delete the service
743
- baz_service.destroy
744
-
745
- # Check that the deletion worked
746
- expect { @id_v3.services.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
747
- expect(@id_v3.services.all.select { |service| ['foobar', 'baz'].include? service.name }.length).to be 0
748
773
  end
749
774
  end
750
775
 
@@ -772,40 +797,36 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
772
797
  service = @id_v3.services.all.first
773
798
  all_endpoints = @id_v3.endpoints.all
774
799
 
775
- # Make sure there are no existing endpoints called foobar or baz
776
- @id_v3.endpoints.all.select { |endpoint| ['foobar', 'baz'].include? endpoint.name }.each do |endpoint|
777
- endpoint.destroy
800
+ begin
801
+ # Create a endpoint called foobar
802
+ foobar_endpoint = @id_v3.endpoints.create(:service_id => service.id,
803
+ :interface => 'internal',
804
+ :name => 'foobar',
805
+ :url => 'http://example.com/foobar',
806
+ :enabled => false)
807
+ foobar_id = foobar_endpoint.id
808
+ expect(@id_v3.endpoints.all(:interface => 'internal').select { |endpoint| endpoint.name == 'foobar' }.length).to be 1
809
+
810
+ # Rename it to baz
811
+ foobar_endpoint.update(:name => 'baz', :url => 'http://example.com/baz')
812
+ expect(foobar_endpoint.name).to eq 'baz'
813
+ expect(foobar_endpoint.url).to eq 'http://example.com/baz'
814
+
815
+ # Read the endpoint freshly and check the name
816
+ expect(@id_v3.endpoints.all(:interface => 'internal').select { |endpoint| endpoint.name == 'baz' }.length).to be 1
817
+ baz_endpoint = @id_v3.endpoints.find_by_id foobar_id
818
+ expect(baz_endpoint).to_not be_nil
819
+ expect(baz_endpoint.name).to eq 'baz'
820
+ expect(baz_endpoint.url).to eq 'http://example.com/baz'
821
+ expect(baz_endpoint.interface).to eq 'internal'
822
+ ensure
823
+ # Delete the endpoint
824
+ baz_endpoint.destroy
825
+
826
+ # Check that the deletion worked
827
+ expect { @id_v3.endpoints.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
828
+ expect(@id_v3.endpoints.all.select { |endpoint| ['foobar', 'baz'].include? endpoint.name }.length).to be 0
778
829
  end
779
- expect(all_endpoints.select { |endpoint| ['foobar', 'baz'].include? endpoint.name }.length).to be 0
780
-
781
- # Create a endpoint called foobar
782
- foobar_endpoint = @id_v3.endpoints.create(:service_id => service.id,
783
- :interface => 'internal',
784
- :name => 'foobar',
785
- :url => 'http://example.com/foobar',
786
- :enabled => false)
787
- foobar_id = foobar_endpoint.id
788
- expect(@id_v3.endpoints.all(:interface => 'internal').select { |endpoint| endpoint.name == 'foobar' }.length).to be 1
789
-
790
- # Rename it to baz
791
- foobar_endpoint.update(:name => 'baz', :url => 'http://example.com/baz')
792
- expect(foobar_endpoint.name).to eq 'baz'
793
- expect(foobar_endpoint.url).to eq 'http://example.com/baz'
794
-
795
- # Read the endpoint freshly and check the name
796
- expect(@id_v3.endpoints.all(:interface => 'internal').select { |endpoint| endpoint.name == 'baz' }.length).to be 1
797
- baz_endpoint = @id_v3.endpoints.find_by_id foobar_id
798
- expect(baz_endpoint).to_not be_nil
799
- expect(baz_endpoint.name).to eq 'baz'
800
- expect(baz_endpoint.url).to eq 'http://example.com/baz'
801
- expect(baz_endpoint.interface).to eq 'internal'
802
-
803
- # Delete the endpoint
804
- baz_endpoint.destroy
805
-
806
- # Check that the deletion worked
807
- expect { @id_v3.endpoints.find_by_id foobar_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
808
- expect(@id_v3.endpoints.all.select { |endpoint| ['foobar', 'baz'].include? endpoint.name }.length).to be 0
809
830
  end
810
831
  end
811
832
 
@@ -824,56 +845,63 @@ RSpec.describe Fog::Identity::OpenStack::V3 do
824
845
  it "CRUD OS credentials" do
825
846
  VCR.use_cassette('idv3_credential_crud') do
826
847
 
827
- # Create a user
828
- foobar_user = @id_v3.users.find_by_name('u-foobar').first
829
- foobar_user.destroy if foobar_user
830
- foobar_user = @id_v3.users.create(:name => 'u-foobar',
831
- :email => 'foobar@example.com',
832
- :password => 's3cret!')
848
+ begin
849
+ # Create a user
850
+ foobar_user = @id_v3.users.create(:name => 'u-foobar_cred',
851
+ :email => 'foobar@example.com',
852
+ :password => 's3cret!')
853
+ project = @id_v3.projects.all.first
833
854
 
834
- project = @id_v3.projects.all.first
855
+ access_key = '9c4e774a-f644-498f-90c4-970b3f817fc5'
856
+ secret_key = '7e084117-b13d-4656-9eca-85376b690897'
835
857
 
836
- access_key = '9c4e774a-f644-498f-90c4-970b3f817fc5'
837
- secret_key = '7e084117-b13d-4656-9eca-85376b690897'
858
+ # OpenStack Keystone requires the blob to be a JSON string - i.e. not JSON, but a string containing JSON :-/
859
+ blob_json = {:access => access_key,
860
+ :secret => secret_key}.to_json
838
861
 
839
- # OpenStack Keystone requires the blob to be a JSON string - i.e. not JSON, but a string containing JSON :-/
840
- blob_json = {:access => access_key,
841
- :secret => secret_key}.to_json
862
+ # Make sure there are no existing ec2 credentials
863
+ @id_v3.os_credentials.all.select { |credential| credential.type == 'foo' || credential.type == 'ec2' }.each do |credential|
864
+ credential.destroy
865
+ end
866
+ expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 0
867
+
868
+ # Create a credential
869
+ foo_credential = @id_v3.os_credentials.create(:type => 'ec2',
870
+ :project_id => project.id,
871
+ :user_id => foobar_user.id,
872
+ :blob => blob_json)
873
+ credential_id = foo_credential.id
874
+ expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 1
875
+
876
+ # Update secret key
877
+ new_secret_key = '62307bcd-ca3c-47ae-a114-27a6cadb5bc9'
878
+ new_blob_json = {:access => access_key,
879
+ :secret => new_secret_key}.to_json
880
+ foo_credential.update(:blob => new_blob_json)
881
+ expect(JSON.parse(foo_credential.blob)['secret']).to eq new_secret_key
882
+
883
+ # Read the credential freshly and check the secret key
884
+ expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 1
885
+ updated_credential = @id_v3.os_credentials.find_by_id credential_id
886
+ expect(updated_credential).to_not be_nil
887
+ expect(updated_credential.type).to eq 'ec2'
888
+ expect(JSON.parse(updated_credential.blob)['secret']).to eq new_secret_key
889
+
890
+ ensure
891
+ foobar_user = @id_v3.users.find_by_name('u-foobar_cred').first unless foobar_user
892
+ foobar_user.destroy if foobar_user
893
+ # Delete the credential
894
+ begin
895
+ updated_credential.destroy if updated_credential
896
+ foo_credential.destroy if foo_credential
897
+ rescue
898
+ false
899
+ end
842
900
 
843
- # Make sure there are no existing ec2 credentials
844
- @id_v3.os_credentials.all.select { |credential| credential.type == 'foo' || credential.type == 'ec2' }.each do |credential|
845
- credential.destroy
901
+ # Check that the deletion worked
902
+ expect { @id_v3.os_credentials.find_by_id credential_id }.to raise_error(Fog::Identity::OpenStack::NotFound) if credential_id
903
+ expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 0
846
904
  end
847
- expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 0
848
-
849
- # Create a credential
850
- foo_credential = @id_v3.os_credentials.create(:type => 'ec2',
851
- :project_id => project.id,
852
- :user_id => foobar_user.id,
853
- :blob => blob_json)
854
- credential_id = foo_credential.id
855
- expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 1
856
-
857
- # Update secret key
858
- new_secret_key = '62307bcd-ca3c-47ae-a114-27a6cadb5bc9'
859
- new_blob_json = {:access => access_key,
860
- :secret => new_secret_key}.to_json
861
- foo_credential.update(:blob => new_blob_json)
862
- expect(JSON.parse(foo_credential.blob)['secret']).to eq new_secret_key
863
-
864
- # Read the credential freshly and check the secret key
865
- expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 1
866
- updated_credential = @id_v3.os_credentials.find_by_id credential_id
867
- expect(updated_credential).to_not be_nil
868
- expect(updated_credential.type).to eq 'ec2'
869
- expect(JSON.parse(updated_credential.blob)['secret']).to eq new_secret_key
870
-
871
- # Delete the credential
872
- updated_credential.destroy
873
-
874
- # Check that the deletion worked
875
- expect { @id_v3.os_credentials.find_by_id credential_id }.to raise_error(Fog::Identity::OpenStack::NotFound)
876
- expect(@id_v3.os_credentials.all.select { |credential| credential.type == 'ec2' }.length).to be 0
877
905
  end
878
906
  end
879
907