vagrant-conoha 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +35 -0
  4. data/CHANGELOG.md +3 -0
  5. data/Gemfile +19 -0
  6. data/LICENSE +23 -0
  7. data/Rakefile +25 -0
  8. data/Vagrantfile +71 -0
  9. data/dummy.box +0 -0
  10. data/example_box/README.md +13 -0
  11. data/example_box/metadata.json +3 -0
  12. data/functional_tests/Vagrantfile +58 -0
  13. data/functional_tests/keys/vagrant-openstack +27 -0
  14. data/functional_tests/keys/vagrant-openstack.pub +1 -0
  15. data/functional_tests/run_tests.sh +142 -0
  16. data/lib/vagrant-conoha.rb +29 -0
  17. data/lib/vagrant-conoha/action.rb +227 -0
  18. data/lib/vagrant-conoha/action/abstract_action.rb +22 -0
  19. data/lib/vagrant-conoha/action/connect_openstack.rb +60 -0
  20. data/lib/vagrant-conoha/action/create_server.rb +154 -0
  21. data/lib/vagrant-conoha/action/create_stack.rb +68 -0
  22. data/lib/vagrant-conoha/action/delete_server.rb +53 -0
  23. data/lib/vagrant-conoha/action/delete_stack.rb +73 -0
  24. data/lib/vagrant-conoha/action/message.rb +19 -0
  25. data/lib/vagrant-conoha/action/provision.rb +60 -0
  26. data/lib/vagrant-conoha/action/read_ssh_info.rb +72 -0
  27. data/lib/vagrant-conoha/action/read_state.rb +43 -0
  28. data/lib/vagrant-conoha/action/resume.rb +24 -0
  29. data/lib/vagrant-conoha/action/start_server.rb +24 -0
  30. data/lib/vagrant-conoha/action/stop_server.rb +25 -0
  31. data/lib/vagrant-conoha/action/suspend.rb +24 -0
  32. data/lib/vagrant-conoha/action/sync_folders.rb +129 -0
  33. data/lib/vagrant-conoha/action/wait_accessible.rb +61 -0
  34. data/lib/vagrant-conoha/action/wait_active.rb +33 -0
  35. data/lib/vagrant-conoha/action/wait_stop.rb +33 -0
  36. data/lib/vagrant-conoha/catalog/openstack_catalog.rb +67 -0
  37. data/lib/vagrant-conoha/client/cinder.rb +39 -0
  38. data/lib/vagrant-conoha/client/domain.rb +159 -0
  39. data/lib/vagrant-conoha/client/glance.rb +65 -0
  40. data/lib/vagrant-conoha/client/heat.rb +49 -0
  41. data/lib/vagrant-conoha/client/http_utils.rb +116 -0
  42. data/lib/vagrant-conoha/client/keystone.rb +77 -0
  43. data/lib/vagrant-conoha/client/neutron.rb +48 -0
  44. data/lib/vagrant-conoha/client/nova.rb +212 -0
  45. data/lib/vagrant-conoha/client/openstack.rb +59 -0
  46. data/lib/vagrant-conoha/client/request_logger.rb +23 -0
  47. data/lib/vagrant-conoha/client/rest_utils.rb +25 -0
  48. data/lib/vagrant-conoha/command/abstract_command.rb +51 -0
  49. data/lib/vagrant-conoha/command/flavor_list.rb +24 -0
  50. data/lib/vagrant-conoha/command/image_list.rb +29 -0
  51. data/lib/vagrant-conoha/command/main.rb +51 -0
  52. data/lib/vagrant-conoha/command/network_list.rb +25 -0
  53. data/lib/vagrant-conoha/command/openstack_command.rb +16 -0
  54. data/lib/vagrant-conoha/command/reset.rb +20 -0
  55. data/lib/vagrant-conoha/command/subnet_list.rb +22 -0
  56. data/lib/vagrant-conoha/command/utils.rb +22 -0
  57. data/lib/vagrant-conoha/command/volume_list.rb +25 -0
  58. data/lib/vagrant-conoha/config.rb +390 -0
  59. data/lib/vagrant-conoha/config/http.rb +39 -0
  60. data/lib/vagrant-conoha/config_resolver.rb +285 -0
  61. data/lib/vagrant-conoha/errors.rb +187 -0
  62. data/lib/vagrant-conoha/logging.rb +39 -0
  63. data/lib/vagrant-conoha/plugin.rb +48 -0
  64. data/lib/vagrant-conoha/provider.rb +50 -0
  65. data/lib/vagrant-conoha/utils.rb +26 -0
  66. data/lib/vagrant-conoha/version.rb +15 -0
  67. data/lib/vagrant-conoha/version_checker.rb +76 -0
  68. data/locales/en.yml +393 -0
  69. data/spec/vagrant-conoha/action/connect_openstack_spec.rb +695 -0
  70. data/spec/vagrant-conoha/action/create_server_spec.rb +225 -0
  71. data/spec/vagrant-conoha/action/create_stack_spec.rb +99 -0
  72. data/spec/vagrant-conoha/action/delete_server_spec.rb +89 -0
  73. data/spec/vagrant-conoha/action/delete_stack_spec.rb +63 -0
  74. data/spec/vagrant-conoha/action/message_spec.rb +33 -0
  75. data/spec/vagrant-conoha/action/provision_spec.rb +104 -0
  76. data/spec/vagrant-conoha/action/read_ssh_info_spec.rb +190 -0
  77. data/spec/vagrant-conoha/action/read_state_spec.rb +81 -0
  78. data/spec/vagrant-conoha/action/resume_server_spec.rb +49 -0
  79. data/spec/vagrant-conoha/action/start_server_spec.rb +49 -0
  80. data/spec/vagrant-conoha/action/stop_server_spec.rb +49 -0
  81. data/spec/vagrant-conoha/action/suspend_server_spec.rb +49 -0
  82. data/spec/vagrant-conoha/action/sync_folders_spec.rb +155 -0
  83. data/spec/vagrant-conoha/action/wait_accessible_spec.rb +67 -0
  84. data/spec/vagrant-conoha/action/wait_active_spec.rb +53 -0
  85. data/spec/vagrant-conoha/action/wait_stop_spec.rb +53 -0
  86. data/spec/vagrant-conoha/action_spec.rb +120 -0
  87. data/spec/vagrant-conoha/client/cinder_spec.rb +127 -0
  88. data/spec/vagrant-conoha/client/glance_spec.rb +143 -0
  89. data/spec/vagrant-conoha/client/heat_spec.rb +128 -0
  90. data/spec/vagrant-conoha/client/keystone_spec.rb +150 -0
  91. data/spec/vagrant-conoha/client/neutron_spec.rb +171 -0
  92. data/spec/vagrant-conoha/client/nova_spec.rb +757 -0
  93. data/spec/vagrant-conoha/client/utils_spec.rb +176 -0
  94. data/spec/vagrant-conoha/command/flavor_list_spec.rb +43 -0
  95. data/spec/vagrant-conoha/command/image_list_spec.rb +95 -0
  96. data/spec/vagrant-conoha/command/network_list_spec.rb +65 -0
  97. data/spec/vagrant-conoha/command/reset_spec.rb +24 -0
  98. data/spec/vagrant-conoha/command/subnet_list_spec.rb +45 -0
  99. data/spec/vagrant-conoha/command/volume_list_spec.rb +40 -0
  100. data/spec/vagrant-conoha/config_resolver_spec.rb +860 -0
  101. data/spec/vagrant-conoha/config_spec.rb +373 -0
  102. data/spec/vagrant-conoha/e2e_spec.rb.save +27 -0
  103. data/spec/vagrant-conoha/provider_spec.rb +13 -0
  104. data/spec/vagrant-conoha/spec_helper.rb +37 -0
  105. data/spec/vagrant-conoha/utils_spec.rb +129 -0
  106. data/spec/vagrant-conoha/version_checker_spec.rb +39 -0
  107. data/stackrc +25 -0
  108. data/vagrant-conoha.gemspec +32 -0
  109. metadata +343 -0
@@ -0,0 +1,695 @@
1
+ require 'vagrant-conoha/spec_helper'
2
+
3
+ include VagrantPlugins::ConoHa::Action
4
+ include VagrantPlugins::ConoHa::HttpUtils
5
+
6
+ describe VagrantPlugins::ConoHa::Action::ConnectOpenstack do
7
+ let(:app) do
8
+ double.tap do |app|
9
+ app.stub(:call)
10
+ end
11
+ end
12
+
13
+ let(:config) do
14
+ double.tap do |config|
15
+ config.stub(:openstack_auth_url) { 'http://keystoneAuthV2' }
16
+ config.stub(:openstack_compute_url) { nil }
17
+ config.stub(:openstack_network_url) { nil }
18
+ config.stub(:openstack_volume_url) { nil }
19
+ config.stub(:openstack_image_url) { nil }
20
+ config.stub(:tenant_name) { 'testTenant' }
21
+ config.stub(:username) { 'username' }
22
+ config.stub(:password) { 'password' }
23
+ config.stub(:region) { nil }
24
+ config.stub(:endpoint_type) { 'publicURL' }
25
+ end
26
+ end
27
+
28
+ let(:neutron) do
29
+ double.tap do |neutron|
30
+ neutron.stub(:get_api_version_list).with(anything, anything) do
31
+ [
32
+ {
33
+ 'status' => 'CURRENT',
34
+ 'id' => 'v2.0',
35
+ 'links' => [
36
+ {
37
+ 'href' => 'http://neutron/v2.0',
38
+ 'rel' => 'self'
39
+ }
40
+ ]
41
+ }
42
+ ]
43
+ end
44
+ end
45
+ end
46
+
47
+ let(:neutron_admin_url) do
48
+ double.tap do |neutron|
49
+ neutron.stub(:get_api_version_list).with(anything, anything) do
50
+ [
51
+ {
52
+ 'status' => 'CURRENT',
53
+ 'id' => 'v2.0',
54
+ 'links' => [
55
+ {
56
+ 'href' => 'http://neutron/v2.0/admin',
57
+ 'rel' => 'self'
58
+ }
59
+ ]
60
+ }
61
+ ]
62
+ end
63
+ end
64
+ end
65
+
66
+ let(:neutron_france) do
67
+ double.tap do |neutron|
68
+ neutron.stub(:get_api_version_list).with(anything, anything) do
69
+ [
70
+ {
71
+ 'status' => 'CURRENT',
72
+ 'id' => 'v2.0',
73
+ 'links' => [
74
+ {
75
+ 'href' => 'http://france.neutron/v2.0',
76
+ 'rel' => 'self'
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ end
82
+ end
83
+ end
84
+
85
+ let(:glance) do
86
+ double.tap do |glance|
87
+ glance.stub(:get_api_version_list).with(anything) do
88
+ [
89
+ {
90
+ 'status' => 'CURRENT',
91
+ 'id' => 'v2.1',
92
+ 'links' => [
93
+ {
94
+ 'href' => 'http://glance/v2.0',
95
+ 'rel' => 'self'
96
+ }
97
+ ]
98
+ }
99
+ ]
100
+ end
101
+ end
102
+ end
103
+
104
+ let(:glance_admin_url) do
105
+ double.tap do |glance|
106
+ glance.stub(:get_api_version_list).with(anything) do
107
+ [
108
+ {
109
+ 'status' => 'CURRENT',
110
+ 'id' => 'v2.1',
111
+ 'links' => [
112
+ {
113
+ 'href' => 'http://glance/v2.0/admin',
114
+ 'rel' => 'self'
115
+ }
116
+ ]
117
+ }
118
+ ]
119
+ end
120
+ end
121
+ end
122
+
123
+ let(:glance_v1) do
124
+ double.tap do |glance|
125
+ glance.stub(:get_api_version_list).with(anything) do
126
+ [
127
+ {
128
+ 'status' => 'CURRENT',
129
+ 'id' => 'v1.0',
130
+ 'links' => [
131
+ {
132
+ 'href' => 'http://glance/v1',
133
+ 'rel' => 'self'
134
+ }
135
+ ]
136
+ }
137
+ ]
138
+ end
139
+ end
140
+ end
141
+
142
+ let(:glance_france) do
143
+ double.tap do |glance|
144
+ glance.stub(:get_api_version_list).with(anything) do
145
+ [
146
+ {
147
+ 'status' => 'CURRENT',
148
+ 'id' => 'v2.1',
149
+ 'links' => [
150
+ {
151
+ 'href' => 'http://france.glance/v2.0',
152
+ 'rel' => 'self'
153
+ }
154
+ ]
155
+ }
156
+ ]
157
+ end
158
+ end
159
+ end
160
+
161
+ let(:env) do
162
+ {}.tap do |env|
163
+ env[:ui] = double
164
+ env[:ui].stub(:info).with(anything)
165
+ env[:ui].stub(:warn).with(anything)
166
+ env[:machine] = double('machine')
167
+ env[:machine].stub(:provider_config) { config }
168
+ env[:openstack_client] = double('openstack_client')
169
+ env[:openstack_client].stub(:neutron) { neutron }
170
+ env[:openstack_client].stub(:glance) { glance }
171
+ end
172
+ end
173
+
174
+ before(:all) do
175
+ ConnectOpenstack.send(:public, *ConnectOpenstack.private_instance_methods)
176
+ end
177
+
178
+ before :each do
179
+ VagrantPlugins::ConoHa.session.reset
180
+ @action = ConnectOpenstack.new(app, env)
181
+ end
182
+
183
+ describe 'ConnectOpenstack' do
184
+ context 'with one endpoint by service' do
185
+ it 'read service catalog and stores endpoints URL in session' do
186
+ catalog = [
187
+ {
188
+ 'endpoints' => [
189
+ {
190
+ 'publicURL' => 'http://nova/v2/projectId',
191
+ 'id' => '1'
192
+ }
193
+ ],
194
+ 'type' => 'compute',
195
+ 'name' => 'nova'
196
+ },
197
+ {
198
+ 'endpoints' => [
199
+ {
200
+ 'publicURL' => 'http://neutron',
201
+ 'id' => '2'
202
+ }
203
+ ],
204
+ 'type' => 'network',
205
+ 'name' => 'neutron'
206
+ },
207
+ {
208
+ 'endpoints' => [
209
+ {
210
+ 'publicURL' => 'http://cinder/v2/projectId',
211
+ 'id' => '2'
212
+ }
213
+ ],
214
+ 'type' => 'volume',
215
+ 'name' => 'cinder'
216
+ },
217
+ {
218
+ 'endpoints' => [
219
+ {
220
+ 'publicURL' => 'http://glance',
221
+ 'id' => '2'
222
+ }
223
+ ],
224
+ 'type' => 'image',
225
+ 'name' => 'glance'
226
+ }
227
+ ]
228
+
229
+ double.tap do |keystone|
230
+ keystone.stub(:authenticate).with(anything) { catalog }
231
+ env[:openstack_client].stub(:keystone) { keystone }
232
+ end
233
+ env[:openstack_client].stub(:neutron) { neutron }
234
+ env[:openstack_client].stub(:glance) { glance }
235
+
236
+ @action.call(env)
237
+
238
+ expect(env[:openstack_client].session.endpoints)
239
+ .to eq(compute: 'http://nova/v2/projectId',
240
+ network: 'http://neutron/v2.0',
241
+ volume: 'http://cinder/v2/projectId',
242
+ image: 'http://glance/v2.0')
243
+ end
244
+ end
245
+
246
+ context 'with multiple regions' do
247
+ it 'read service catalog and stores endpoints URL for desired regions in session' do
248
+ catalog = [
249
+ {
250
+ 'endpoints' => [
251
+ {
252
+ 'publicURL' => 'http://france.nova/v2/projectId',
253
+ 'id' => '1',
254
+ 'region' => 'france'
255
+ },
256
+ {
257
+ 'publicURL' => 'http://us.nova/v2/projectId',
258
+ 'id' => '4',
259
+ 'region' => 'us'
260
+ }
261
+ ],
262
+ 'type' => 'compute',
263
+ 'name' => 'nova'
264
+ },
265
+ {
266
+ 'endpoints' => [
267
+ {
268
+ 'publicURL' => 'http://france.neutron',
269
+ 'id' => '2',
270
+ 'region' => 'france'
271
+ },
272
+ {
273
+ 'publicURL' => 'http://us.neutron',
274
+ 'id' => '5',
275
+ 'region' => 'us'
276
+ }
277
+ ],
278
+ 'type' => 'network',
279
+ 'name' => 'neutron'
280
+ },
281
+ {
282
+ 'endpoints' => [
283
+ {
284
+ 'publicURL' => 'http://france.glance',
285
+ 'id' => '3',
286
+ 'region' => 'france'
287
+ },
288
+ {
289
+ 'publicURL' => 'http://us.glance',
290
+ 'id' => '6',
291
+ 'region' => 'us'
292
+ }
293
+ ],
294
+ 'type' => 'image',
295
+ 'name' => 'glance'
296
+ }
297
+ ]
298
+
299
+ double.tap do |keystone|
300
+ keystone.stub(:authenticate).with(anything) { catalog }
301
+ env[:openstack_client].stub(:keystone) { keystone }
302
+ end
303
+
304
+ env[:openstack_client].stub(:neutron) { neutron_france }
305
+ env[:openstack_client].stub(:glance) { glance_france }
306
+ config.stub(:region) { 'france' }
307
+
308
+ @action.call(env)
309
+
310
+ expect(env[:openstack_client].session.endpoints)
311
+ .to eq(compute: 'http://france.nova/v2/projectId',
312
+ network: 'http://france.neutron/v2.0',
313
+ image: 'http://france.glance/v2.0')
314
+ end
315
+ end
316
+
317
+ context 'with multiple endpoints for a service' do
318
+ it 'takes the first one' do
319
+ catalog = [
320
+ {
321
+ 'endpoints' => [
322
+ {
323
+ 'publicURL' => 'http://nova',
324
+ 'id' => '1'
325
+ }
326
+ ],
327
+ 'type' => 'compute',
328
+ 'name' => 'nova'
329
+ },
330
+ {
331
+ 'endpoints' => [
332
+ {
333
+ 'publicURL' => 'http://neutron/alt',
334
+ 'id' => '2'
335
+ },
336
+ {
337
+ 'publicURL' => 'http://neutron',
338
+ 'id' => '3'
339
+ }
340
+ ],
341
+ 'type' => 'network',
342
+ 'name' => 'neutron'
343
+ }
344
+ ]
345
+
346
+ double.tap do |keystone|
347
+ keystone.stub(:authenticate).with(anything) { catalog }
348
+ env[:openstack_client].stub(:keystone) { keystone }
349
+ end
350
+ env[:openstack_client].stub(:neutron) { neutron }
351
+
352
+ @action.call(env)
353
+
354
+ expect(env[:openstack_client].session.endpoints).to eq(compute: 'http://nova', network: 'http://neutron/v2.0')
355
+ end
356
+ end
357
+
358
+ describe 'endpoint_type' do
359
+ context 'with adminURL specified' do
360
+ it 'read service catalog and stores endpoints URL in session' do
361
+ catalog = [
362
+ {
363
+ 'endpoints' => [
364
+ {
365
+ 'publicURL' => 'http://nova/v2/projectId',
366
+ 'adminURL' => 'http://nova/v2/projectId/admin',
367
+ 'id' => '1'
368
+ }
369
+ ],
370
+ 'type' => 'compute',
371
+ 'name' => 'nova'
372
+ },
373
+ {
374
+ 'endpoints' => [
375
+ {
376
+ 'publicURL' => 'http://neutron',
377
+ 'adminURL' => 'http://neutron/admin',
378
+ 'id' => '2'
379
+ }
380
+ ],
381
+ 'type' => 'network',
382
+ 'name' => 'neutron'
383
+ },
384
+ {
385
+ 'endpoints' => [
386
+ {
387
+ 'publicURL' => 'http://cinder/v2/projectId',
388
+ 'adminURL' => 'http://cinder/v2/projectId/admin',
389
+ 'id' => '2'
390
+ }
391
+ ],
392
+ 'type' => 'volume',
393
+ 'name' => 'cinder'
394
+ },
395
+ {
396
+ 'endpoints' => [
397
+ {
398
+ 'publicURL' => 'http://glance',
399
+ 'adminURL' => 'http://glance/admin',
400
+ 'id' => '2'
401
+ }
402
+ ],
403
+ 'type' => 'image',
404
+ 'name' => 'glance'
405
+ }
406
+ ]
407
+
408
+ double.tap do |keystone|
409
+ keystone.stub(:authenticate).with(anything) { catalog }
410
+ env[:openstack_client].stub(:keystone) { keystone }
411
+ end
412
+ env[:openstack_client].stub(:neutron) { neutron_admin_url }
413
+ env[:openstack_client].stub(:glance) { glance_admin_url }
414
+ config.stub(:endpoint_type) { 'adminURL' }
415
+
416
+ @action.call(env)
417
+
418
+ expect(env[:openstack_client].session.endpoints)
419
+ .to eq(compute: 'http://nova/v2/projectId/admin',
420
+ network: 'http://neutron/v2.0/admin',
421
+ volume: 'http://cinder/v2/projectId/admin',
422
+ image: 'http://glance/v2.0/admin')
423
+ end
424
+ end
425
+ end
426
+
427
+ describe 'endpoint_type' do
428
+ context 'with internalURL specified' do
429
+ it 'read service catalog and stores endpoints URL in session' do
430
+ catalog = [
431
+ {
432
+ 'endpoints' => [
433
+ {
434
+ 'publicURL' => 'http://nova/v2/projectId',
435
+ 'adminURL' => 'http://nova/v2/projectId/admin',
436
+ 'internalURL' => 'http://nova/v2/projectId/internal',
437
+ 'id' => '1'
438
+ }
439
+ ],
440
+ 'type' => 'compute',
441
+ 'name' => 'nova'
442
+ },
443
+ {
444
+ 'endpoints' => [
445
+ {
446
+ 'publicURL' => 'http://cinder/v2/projectId',
447
+ 'adminURL' => 'http://cinder/v2/projectId/admin',
448
+ 'internalURL' => 'http://cinder/v2/projectId/internal',
449
+ 'id' => '2'
450
+ }
451
+ ],
452
+ 'type' => 'volume',
453
+ 'name' => 'cinder'
454
+ }
455
+ ]
456
+
457
+ double.tap do |keystone|
458
+ keystone.stub(:authenticate).with(anything) { catalog }
459
+ env[:openstack_client].stub(:keystone) { keystone }
460
+ end
461
+ config.stub(:endpoint_type) { 'internalURL' }
462
+
463
+ @action.call(env)
464
+
465
+ expect(env[:openstack_client].session.endpoints)
466
+ .to eq(compute: 'http://nova/v2/projectId/internal',
467
+ volume: 'http://cinder/v2/projectId/internal')
468
+ end
469
+ end
470
+ end
471
+
472
+ describe 'endpoint_type' do
473
+ context 'with publicURL specified' do
474
+ it 'read service catalog and stores endpoints URL in session' do
475
+ catalog = [
476
+ {
477
+ 'endpoints' => [
478
+ {
479
+ 'publicURL' => 'http://nova/v2/projectId',
480
+ 'adminURL' => 'http://nova/v2/projectId/admin',
481
+ 'id' => '1'
482
+ }
483
+ ],
484
+ 'type' => 'compute',
485
+ 'name' => 'nova'
486
+ },
487
+ {
488
+ 'endpoints' => [
489
+ {
490
+ 'publicURL' => 'http://neutron',
491
+ 'adminURL' => 'http://neutron/admin',
492
+ 'id' => '2'
493
+ }
494
+ ],
495
+ 'type' => 'network',
496
+ 'name' => 'neutron'
497
+ },
498
+ {
499
+ 'endpoints' => [
500
+ {
501
+ 'publicURL' => 'http://cinder/v2/projectId',
502
+ 'adminURL' => 'http://cinder/v2/projectId/admin',
503
+ 'id' => '2'
504
+ }
505
+ ],
506
+ 'type' => 'volume',
507
+ 'name' => 'cinder'
508
+ },
509
+ {
510
+ 'endpoints' => [
511
+ {
512
+ 'publicURL' => 'http://glance',
513
+ 'adminURL' => 'http://glance/admin',
514
+ 'id' => '2'
515
+ }
516
+ ],
517
+ 'type' => 'image',
518
+ 'name' => 'glance'
519
+ }
520
+ ]
521
+
522
+ double.tap do |keystone|
523
+ keystone.stub(:authenticate).with(anything) { catalog }
524
+ env[:openstack_client].stub(:keystone) { keystone }
525
+ end
526
+ env[:openstack_client].stub(:neutron) { neutron }
527
+ env[:openstack_client].stub(:glance) { glance }
528
+ config.stub(:endpoint_type) { 'publicURL' }
529
+
530
+ @action.call(env)
531
+
532
+ expect(env[:openstack_client].session.endpoints)
533
+ .to eq(compute: 'http://nova/v2/projectId',
534
+ network: 'http://neutron/v2.0',
535
+ volume: 'http://cinder/v2/projectId',
536
+ image: 'http://glance/v2.0')
537
+ end
538
+ end
539
+ end
540
+
541
+ context 'with glance v1 only' do
542
+ it 'read service catalog and stores endpoints URL in session' do
543
+ catalog = [
544
+ {
545
+ 'endpoints' => [
546
+ {
547
+ 'publicURL' => 'http://nova/v2/projectId',
548
+ 'id' => '1'
549
+ }
550
+ ],
551
+ 'type' => 'compute',
552
+ 'name' => 'nova'
553
+ },
554
+ {
555
+ 'endpoints' => [
556
+ {
557
+ 'publicURL' => 'http://glance',
558
+ 'id' => '2'
559
+ }
560
+ ],
561
+ 'type' => 'image',
562
+ 'name' => 'glance'
563
+ }
564
+ ]
565
+
566
+ double.tap do |keystone|
567
+ keystone.stub(:authenticate).with(anything) { catalog }
568
+ env[:openstack_client].stub(:keystone) { keystone }
569
+ end
570
+ env[:openstack_client].stub(:glance) { glance_v1 }
571
+
572
+ @action.call(env)
573
+
574
+ expect(env[:openstack_client].session.endpoints)
575
+ .to eq(compute: 'http://nova/v2/projectId',
576
+ image: 'http://glance/v1')
577
+ end
578
+ end
579
+
580
+ context 'with nova endpoint missing' do
581
+ it 'raise an error' do
582
+ catalog = [
583
+ {
584
+ 'endpoints' => [
585
+ {
586
+ 'publicURL' => 'http://keystone',
587
+ 'id' => '1'
588
+ }
589
+ ],
590
+ 'type' => 'identity',
591
+ 'name' => 'keystone'
592
+ }
593
+ ]
594
+
595
+ double.tap do |keystone|
596
+ keystone.stub(:authenticate).with(anything) { catalog }
597
+ env[:openstack_client].stub(:keystone) { keystone }
598
+ end
599
+
600
+ expect { @action.call(env) }.to raise_error Errors::MissingNovaEndpoint
601
+ end
602
+ end
603
+
604
+ context 'with no matching versions for network service' do
605
+ let(:neutron) do
606
+ double.tap do |neutron|
607
+ neutron.stub(:get_api_version_list).with(anything, anything) do
608
+ [
609
+ {
610
+ 'status' => 'CURRENT',
611
+ 'id' => 'v1.1',
612
+ 'links' => [
613
+ {
614
+ 'href' => 'http://neutron/v1.1',
615
+ 'rel' => 'self'
616
+ }
617
+ ]
618
+ },
619
+ {
620
+ 'status' => '...',
621
+ 'id' => 'v1.0',
622
+ 'links' => [
623
+ {
624
+ 'href' => 'http://neutron/v1.0',
625
+ 'rel' => 'self'
626
+ }
627
+ ]
628
+ }
629
+ ]
630
+ end
631
+ end
632
+ end
633
+
634
+ it 'raise an error' do
635
+ catalog = [
636
+ {
637
+ 'endpoints' => [
638
+ {
639
+ 'publicURL' => 'http://neutron',
640
+ 'id' => '3'
641
+ }
642
+ ],
643
+ 'type' => 'network',
644
+ 'name' => 'neutron'
645
+ }
646
+ ]
647
+
648
+ double.tap do |keystone|
649
+ keystone.stub(:authenticate).with(anything) { catalog }
650
+ env[:openstack_client].stub(:keystone) { keystone }
651
+ end
652
+ env[:openstack_client].stub(:neutron) { neutron }
653
+
654
+ expect { @action.call(env) }.to raise_error(Errors::NoMatchingApiVersion)
655
+ end
656
+ end
657
+
658
+ context 'with only keystone and nova' do
659
+ it 'read service catalog and stores endpoints URL in session' do
660
+ catalog = [
661
+ {
662
+ 'endpoints' => [
663
+ {
664
+ 'publicURL' => 'http://nova/v2/projectId',
665
+ 'id' => '1'
666
+ }
667
+ ],
668
+ 'type' => 'compute',
669
+ 'name' => 'nova'
670
+ },
671
+ {
672
+ 'endpoints' => [
673
+ {
674
+ 'publicURL' => 'http://keystone/v2.0',
675
+ 'id' => '2'
676
+ }
677
+ ],
678
+ 'type' => 'identity',
679
+ 'name' => 'keystone'
680
+ }
681
+ ]
682
+
683
+ double.tap do |keystone|
684
+ keystone.stub(:authenticate).with(anything) { catalog }
685
+ env[:openstack_client].stub(:keystone) { keystone }
686
+ end
687
+
688
+ @action.call(env)
689
+
690
+ expect(env[:openstack_client].session.endpoints)
691
+ .to eq(compute: 'http://nova/v2/projectId', identity: 'http://keystone/v2.0')
692
+ end
693
+ end
694
+ end
695
+ end