vagrant-openstack-illuin-provider 0.12.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 (115) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rubocop.yml +40 -0
  4. data/CHANGELOG.md +282 -0
  5. data/Gemfile +18 -0
  6. data/RELEASE.md +15 -0
  7. data/Rakefile +25 -0
  8. data/Vagrantfile +20 -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-openstack-illuin-provider.rb +29 -0
  17. data/lib/vagrant-openstack-illuin-provider/action.rb +344 -0
  18. data/lib/vagrant-openstack-illuin-provider/action/abstract_action.rb +22 -0
  19. data/lib/vagrant-openstack-illuin-provider/action/connect_openstack.rb +60 -0
  20. data/lib/vagrant-openstack-illuin-provider/action/create_server.rb +187 -0
  21. data/lib/vagrant-openstack-illuin-provider/action/create_stack.rb +76 -0
  22. data/lib/vagrant-openstack-illuin-provider/action/delete_server.rb +53 -0
  23. data/lib/vagrant-openstack-illuin-provider/action/delete_stack.rb +73 -0
  24. data/lib/vagrant-openstack-illuin-provider/action/message.rb +19 -0
  25. data/lib/vagrant-openstack-illuin-provider/action/provision.rb +60 -0
  26. data/lib/vagrant-openstack-illuin-provider/action/read_ssh_info.rb +74 -0
  27. data/lib/vagrant-openstack-illuin-provider/action/read_state.rb +43 -0
  28. data/lib/vagrant-openstack-illuin-provider/action/resume.rb +24 -0
  29. data/lib/vagrant-openstack-illuin-provider/action/snapshot_cleanup.rb +32 -0
  30. data/lib/vagrant-openstack-illuin-provider/action/snapshot_delete.rb +32 -0
  31. data/lib/vagrant-openstack-illuin-provider/action/snapshot_list.rb +22 -0
  32. data/lib/vagrant-openstack-illuin-provider/action/snapshot_restore.rb +29 -0
  33. data/lib/vagrant-openstack-illuin-provider/action/snapshot_save.rb +51 -0
  34. data/lib/vagrant-openstack-illuin-provider/action/start_server.rb +24 -0
  35. data/lib/vagrant-openstack-illuin-provider/action/stop_server.rb +25 -0
  36. data/lib/vagrant-openstack-illuin-provider/action/suspend.rb +24 -0
  37. data/lib/vagrant-openstack-illuin-provider/action/sync_folders.rb +138 -0
  38. data/lib/vagrant-openstack-illuin-provider/action/wait_active.rb +33 -0
  39. data/lib/vagrant-openstack-illuin-provider/action/wait_stop.rb +33 -0
  40. data/lib/vagrant-openstack-illuin-provider/cap/snapshot_list.rb +15 -0
  41. data/lib/vagrant-openstack-illuin-provider/catalog/openstack_catalog.rb +90 -0
  42. data/lib/vagrant-openstack-illuin-provider/client/cinder.rb +39 -0
  43. data/lib/vagrant-openstack-illuin-provider/client/domain.rb +163 -0
  44. data/lib/vagrant-openstack-illuin-provider/client/glance.rb +65 -0
  45. data/lib/vagrant-openstack-illuin-provider/client/heat.rb +49 -0
  46. data/lib/vagrant-openstack-illuin-provider/client/http_utils.rb +116 -0
  47. data/lib/vagrant-openstack-illuin-provider/client/keystone.rb +128 -0
  48. data/lib/vagrant-openstack-illuin-provider/client/neutron.rb +48 -0
  49. data/lib/vagrant-openstack-illuin-provider/client/nova.rb +303 -0
  50. data/lib/vagrant-openstack-illuin-provider/client/openstack.rb +59 -0
  51. data/lib/vagrant-openstack-illuin-provider/client/request_logger.rb +23 -0
  52. data/lib/vagrant-openstack-illuin-provider/client/rest_utils.rb +28 -0
  53. data/lib/vagrant-openstack-illuin-provider/command/abstract_command.rb +51 -0
  54. data/lib/vagrant-openstack-illuin-provider/command/flavor_list.rb +24 -0
  55. data/lib/vagrant-openstack-illuin-provider/command/floatingip_list.rb +32 -0
  56. data/lib/vagrant-openstack-illuin-provider/command/image_list.rb +29 -0
  57. data/lib/vagrant-openstack-illuin-provider/command/main.rb +52 -0
  58. data/lib/vagrant-openstack-illuin-provider/command/network_list.rb +25 -0
  59. data/lib/vagrant-openstack-illuin-provider/command/openstack_command.rb +16 -0
  60. data/lib/vagrant-openstack-illuin-provider/command/reset.rb +20 -0
  61. data/lib/vagrant-openstack-illuin-provider/command/subnet_list.rb +22 -0
  62. data/lib/vagrant-openstack-illuin-provider/command/utils.rb +22 -0
  63. data/lib/vagrant-openstack-illuin-provider/command/volume_list.rb +25 -0
  64. data/lib/vagrant-openstack-illuin-provider/config.rb +505 -0
  65. data/lib/vagrant-openstack-illuin-provider/config/http.rb +39 -0
  66. data/lib/vagrant-openstack-illuin-provider/config_resolver.rb +334 -0
  67. data/lib/vagrant-openstack-illuin-provider/errors.rb +187 -0
  68. data/lib/vagrant-openstack-illuin-provider/logging.rb +39 -0
  69. data/lib/vagrant-openstack-illuin-provider/plugin.rb +58 -0
  70. data/lib/vagrant-openstack-illuin-provider/provider.rb +50 -0
  71. data/lib/vagrant-openstack-illuin-provider/utils.rb +81 -0
  72. data/lib/vagrant-openstack-illuin-provider/version.rb +15 -0
  73. data/lib/vagrant-openstack-illuin-provider/version_checker.rb +76 -0
  74. data/locales/en.yml +412 -0
  75. data/spec/vagrant-openstack-illuin-provider/action/connect_openstack_spec.rb +770 -0
  76. data/spec/vagrant-openstack-illuin-provider/action/create_server_spec.rb +260 -0
  77. data/spec/vagrant-openstack-illuin-provider/action/create_stack_spec.rb +99 -0
  78. data/spec/vagrant-openstack-illuin-provider/action/delete_server_spec.rb +89 -0
  79. data/spec/vagrant-openstack-illuin-provider/action/delete_stack_spec.rb +63 -0
  80. data/spec/vagrant-openstack-illuin-provider/action/message_spec.rb +33 -0
  81. data/spec/vagrant-openstack-illuin-provider/action/provision_spec.rb +97 -0
  82. data/spec/vagrant-openstack-illuin-provider/action/read_ssh_info_spec.rb +202 -0
  83. data/spec/vagrant-openstack-illuin-provider/action/read_state_spec.rb +81 -0
  84. data/spec/vagrant-openstack-illuin-provider/action/resume_server_spec.rb +49 -0
  85. data/spec/vagrant-openstack-illuin-provider/action/start_server_spec.rb +49 -0
  86. data/spec/vagrant-openstack-illuin-provider/action/stop_server_spec.rb +49 -0
  87. data/spec/vagrant-openstack-illuin-provider/action/suspend_server_spec.rb +49 -0
  88. data/spec/vagrant-openstack-illuin-provider/action/sync_folders_spec.rb +155 -0
  89. data/spec/vagrant-openstack-illuin-provider/action/wait_active_spec.rb +53 -0
  90. data/spec/vagrant-openstack-illuin-provider/action/wait_stop_spec.rb +53 -0
  91. data/spec/vagrant-openstack-illuin-provider/action_spec.rb +120 -0
  92. data/spec/vagrant-openstack-illuin-provider/client/cinder_spec.rb +129 -0
  93. data/spec/vagrant-openstack-illuin-provider/client/glance_spec.rb +145 -0
  94. data/spec/vagrant-openstack-illuin-provider/client/heat_spec.rb +130 -0
  95. data/spec/vagrant-openstack-illuin-provider/client/keystone_spec.rb +226 -0
  96. data/spec/vagrant-openstack-illuin-provider/client/neutron_spec.rb +173 -0
  97. data/spec/vagrant-openstack-illuin-provider/client/nova_spec.rb +760 -0
  98. data/spec/vagrant-openstack-illuin-provider/client/utils_spec.rb +176 -0
  99. data/spec/vagrant-openstack-illuin-provider/command/flavor_list_spec.rb +43 -0
  100. data/spec/vagrant-openstack-illuin-provider/command/floatingip_list_spec.rb +74 -0
  101. data/spec/vagrant-openstack-illuin-provider/command/image_list_spec.rb +95 -0
  102. data/spec/vagrant-openstack-illuin-provider/command/network_list_spec.rb +65 -0
  103. data/spec/vagrant-openstack-illuin-provider/command/reset_spec.rb +24 -0
  104. data/spec/vagrant-openstack-illuin-provider/command/subnet_list_spec.rb +45 -0
  105. data/spec/vagrant-openstack-illuin-provider/command/volume_list_spec.rb +40 -0
  106. data/spec/vagrant-openstack-illuin-provider/config_resolver_spec.rb +879 -0
  107. data/spec/vagrant-openstack-illuin-provider/config_spec.rb +416 -0
  108. data/spec/vagrant-openstack-illuin-provider/e2e_spec.rb.save +27 -0
  109. data/spec/vagrant-openstack-illuin-provider/provider_spec.rb +13 -0
  110. data/spec/vagrant-openstack-illuin-provider/spec_helper.rb +37 -0
  111. data/spec/vagrant-openstack-illuin-provider/utils_spec.rb +197 -0
  112. data/spec/vagrant-openstack-illuin-provider/version_checker_spec.rb +39 -0
  113. data/stackrc +25 -0
  114. data/vagrant-openstack-illuin-provider.gemspec +35 -0
  115. metadata +379 -0
@@ -0,0 +1,260 @@
1
+ require 'vagrant-openstack-illuin-provider/spec_helper'
2
+ require 'ostruct'
3
+ require 'sshkey'
4
+
5
+ include VagrantPlugins::Openstack::Action
6
+ include VagrantPlugins::Openstack::HttpUtils
7
+ include VagrantPlugins::Openstack::Domain
8
+
9
+ describe VagrantPlugins::Openstack::Action::CreateServer do
10
+ let(:config) do
11
+ double('config').tap do |config|
12
+ config.stub(:tenant_name) { 'testTenant' }
13
+ config.stub(:server_name) { 'testName' }
14
+ config.stub(:image) { 'ubuntu' }
15
+ config.stub(:volume_boot) { nil }
16
+ config.stub(:availability_zone) { nil }
17
+ config.stub(:scheduler_hints) { nil }
18
+ config.stub(:security_groups) { nil }
19
+ config.stub(:user_data) { nil }
20
+ config.stub(:metadata) { nil }
21
+ end
22
+ end
23
+
24
+ let(:image) do
25
+ double('image').tap do |image|
26
+ image.stub(:name) { 'image_name' }
27
+ image.stub(:id) { 'image123' }
28
+ end
29
+ end
30
+
31
+ let(:flavor) do
32
+ double('flavor').tap do |flavor|
33
+ flavor.stub(:name) { 'flavor_name' }
34
+ flavor.stub(:id) { 'flavor123' }
35
+ end
36
+ end
37
+
38
+ let(:nova) do
39
+ double('nova')
40
+ end
41
+
42
+ let(:env) do
43
+ {}.tap do |env|
44
+ env[:ui] = double('ui')
45
+ env[:ui].stub(:info).with(anything)
46
+ env[:machine] = double('machine')
47
+ env[:machine] = OpenStruct.new.tap do |m|
48
+ m.provider_config = config
49
+ m.id = nil
50
+ end
51
+ env[:openstack_client] = double('openstack_client')
52
+ env[:openstack_client].stub(:nova) { nova }
53
+ end
54
+ end
55
+
56
+ let(:resolver) do
57
+ double('resolver').tap do |r|
58
+ r.stub(:resolve_flavor).with(anything) do
59
+ Flavor.new('flavor-01', 'small', nil, nil, nil)
60
+ end
61
+ r.stub(:resolve_image).with(anything) do
62
+ Item.new('image-01', 'ubuntu')
63
+ end
64
+ r.stub(:resolve_volume_boot).with(anything) { 'ubuntu-drive' }
65
+ r.stub(:resolve_networks).with(anything) { 'net-001' }
66
+ r.stub(:resolve_volumes).with(anything) do
67
+ [{ id: 'vol-01', device: nil }]
68
+ end
69
+ r.stub(:resolve_keypair).with(anything) { 'key' }
70
+ r.stub(:resolve_floating_ip).with(anything) { '1.2.3.4' }
71
+ r.stub(:resolve_security_groups).with(anything) do
72
+ [{ name: 'group1' }, { name: 'group2' }]
73
+ end
74
+ end
75
+ end
76
+
77
+ let(:utils) do
78
+ double('utils').tap do |u|
79
+ u.stub(:get_ip_address) { '1.2.3.4' }
80
+ end
81
+ end
82
+
83
+ before :each do
84
+ CreateServer.send(:public, *CreateServer.private_instance_methods)
85
+ app = double('app')
86
+ app.stub(:call).with(anything)
87
+ @action = CreateServer.new(app, nil, resolver, utils)
88
+ end
89
+
90
+ describe 'call' do
91
+ context 'with both image and volume_boot specified' do
92
+ it 'should raise an error' do
93
+ config.stub(:image) { 'linux-image' }
94
+ config.stub(:volume_boot) { 'linux-volume' }
95
+ expect { @action.call(env) }.to raise_error Errors::ConflictBootOption
96
+ end
97
+ end
98
+ context 'with neither image nor volume_boot specified' do
99
+ it 'should raise an error' do
100
+ config.stub(:image) { nil }
101
+ config.stub(:volume_boot) { nil }
102
+ expect { @action.call(env) }.to raise_error Errors::MissingBootOption
103
+ end
104
+ end
105
+ context 'with full options' do
106
+ it 'works' do
107
+ allow(@action).to receive(:create_server).and_return('45678')
108
+ allow(@action).to receive(:assign_floating_ip).and_return('1.2.3.4')
109
+ allow(@action).to receive(:waiting_for_server_to_be_built)
110
+ allow(@action).to receive(:attach_volumes)
111
+ allow(@action).to receive(:waiting_for_server_to_be_reachable)
112
+ allow(@action).to receive(:waiting_for_floating_ip_to_be_assigned)
113
+
114
+ expect(@action).to receive(:waiting_for_server_to_be_built).with(env, '45678')
115
+ expect(@action).to receive(:assign_floating_ip).with(env, '45678').and_return('1.2.3.4')
116
+ expect(@action).to receive(:attach_volumes).with(env, '45678', [{ id: 'vol-01', device: nil }])
117
+ expect(@action).to receive(:waiting_for_floating_ip_to_be_assigned).with(env, '45678')
118
+
119
+ @action.call(env)
120
+ end
121
+ end
122
+ end
123
+
124
+ describe 'create_server' do
125
+ context 'with all options specified' do
126
+ it 'calls nova with all the options' do
127
+ nova.stub(:create_server).with(
128
+ env,
129
+ name: 'testName',
130
+ flavor_ref: flavor.id,
131
+ image_ref: image.id,
132
+ volume_boot: nil,
133
+ networks: [{ uuid: 'test-networks-1' }, { uuid: 'test-networks-2', fixed_ip: '1.2.3.4' }],
134
+ keypair: 'test-keypair',
135
+ availability_zone: 'test-az',
136
+ scheduler_hints: 'test-sched-hints',
137
+ security_groups: ['test-sec-groups'],
138
+ user_data: 'test-user_data',
139
+ metadata: 'test-metadata') do
140
+ '1234'
141
+ end
142
+
143
+ options = {
144
+ flavor: flavor,
145
+ image: image,
146
+ networks: [{ uuid: 'test-networks-1' }, { uuid: 'test-networks-2', fixed_ip: '1.2.3.4' }],
147
+ volumes: [{ id: '001', device: :auto }, { id: '002', device: '/dev/vdc' }],
148
+ keypair_name: 'test-keypair',
149
+ availability_zone: 'test-az',
150
+ scheduler_hints: 'test-sched-hints',
151
+ security_groups: ['test-sec-groups'],
152
+ user_data: 'test-user_data',
153
+ metadata: 'test-metadata'
154
+ }
155
+
156
+ expect(@action.create_server(env, options)).to eq '1234'
157
+ end
158
+ end
159
+ context 'with minimal configuration and a single network' do
160
+ it 'calls nova' do
161
+ config.stub(:server_name) { nil }
162
+ nova.stub(:create_server).with(
163
+ env,
164
+ name: nil,
165
+ flavor_ref: flavor.id,
166
+ image_ref: image.id,
167
+ volume_boot: nil,
168
+ networks: [{ uuid: 'test-networks-1' }],
169
+ keypair: 'test-keypair',
170
+ availability_zone: nil,
171
+ scheduler_hints: nil,
172
+ security_groups: [],
173
+ user_data: nil,
174
+ metadata: nil) do
175
+ '1234'
176
+ end
177
+
178
+ options = {
179
+ flavor: flavor,
180
+ image: image,
181
+ networks: [{ uuid: 'test-networks-1' }],
182
+ volumes: [],
183
+ keypair_name: 'test-keypair',
184
+ availability_zone: nil,
185
+ scheduler_hints: nil,
186
+ security_groups: [],
187
+ user_data: nil,
188
+ metadata: nil
189
+ }
190
+
191
+ expect(@action.create_server(env, options)).to eq '1234'
192
+ end
193
+ end
194
+ end
195
+
196
+ describe 'waiting_for_server_to_be_built' do
197
+ context 'when server is not yet active' do
198
+ it 'become active after one retry' do
199
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'ACTIVE')
200
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
201
+ config.stub(:server_create_timeout) { 5 }
202
+ @action.waiting_for_server_to_be_built(env, 'server-01', 1)
203
+ end
204
+ it 'timeout before the server become active' do
205
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'BUILD')
206
+ nova.should_receive(:get_server_details).with(env, 'server-01').at_least(2).times
207
+ config.stub(:server_create_timeout) { 3 }
208
+ expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::Timeout
209
+ end
210
+ it 'raise an error after one retry' do
211
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'ERROR')
212
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
213
+ config.stub(:server_create_timeout) { 3 }
214
+ expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::ServerStatusError
215
+ end
216
+ end
217
+ end
218
+
219
+ describe 'assign_floating_ip' do
220
+ context 'When resolve correctly floating ip' do
221
+ it 'calls nova to assign floating ip' do
222
+ resolver.stub(:resolve_floating_ip).and_return '1.2.3.4'
223
+ nova.stub(:add_floating_ip)
224
+ expect(resolver).to receive(:resolve_floating_ip).with(env)
225
+ expect(nova).to receive(:add_floating_ip).with(env, 'server-01', '1.2.3.4')
226
+ @action.assign_floating_ip(env, 'server-01')
227
+ end
228
+ end
229
+ context 'When unable to resolve floating ip' do
230
+ it 'does not fail' do
231
+ resolver.stub(:resolve_floating_ip).and_raise Errors::UnableToResolveFloatingIP
232
+ nova.stub(:add_floating_ip)
233
+ expect(resolver).to receive(:resolve_floating_ip).with(env)
234
+ expect(nova).to_not receive(:add_floating_ip)
235
+ @action.assign_floating_ip(env, 'server-01')
236
+ end
237
+ end
238
+ context 'When neither floating ip nor floating ip pool is configured' do
239
+ it 'does nothing' do
240
+ resolver.stub(:resolve_floating_ip).and_return nil
241
+ nova.stub(:add_floating_ip)
242
+ expect(resolver).to receive(:resolve_floating_ip).with(env)
243
+ expect(nova).to_not receive(:add_floating_ip)
244
+ @action.assign_floating_ip(env, 'server-01')
245
+ end
246
+ end
247
+ end
248
+
249
+ describe 'attach_volumes' do
250
+ context 'with volume attached in all possible ways' do
251
+ it 'returns normalized volume list' do
252
+ nova.stub(:attach_volume).with(anything, anything, anything, anything) {}
253
+ nova.should_receive(:attach_volume).with(env, 'server-01', '001', nil)
254
+ nova.should_receive(:attach_volume).with(env, 'server-01', '002', '/dev/vdb')
255
+
256
+ @action.attach_volumes(env, 'server-01', [{ id: '001', device: nil }, { id: '002', device: '/dev/vdb' }])
257
+ end
258
+ end
259
+ end
260
+ end
@@ -0,0 +1,99 @@
1
+ require 'vagrant-openstack-illuin-provider/spec_helper'
2
+ require 'ostruct'
3
+ require 'sshkey'
4
+
5
+ include VagrantPlugins::Openstack::Action
6
+ include VagrantPlugins::Openstack::HttpUtils
7
+ include VagrantPlugins::Openstack::Domain
8
+
9
+ describe VagrantPlugins::Openstack::Action::CreateStack do
10
+ let(:config) do
11
+ double('config').tap do |config|
12
+ config.stub(:stacks) do
13
+ [
14
+ {
15
+ name: 'stack1',
16
+ template: 'template.yml'
17
+ },
18
+ {
19
+ name: 'stack2',
20
+ template: 'template.yml'
21
+ }
22
+ ]
23
+ end
24
+ config.stub(:stack_create_timeout) { 200 }
25
+ end
26
+ end
27
+
28
+ let(:heat) do
29
+ double('heat')
30
+ end
31
+
32
+ let(:env) do
33
+ {}.tap do |env|
34
+ env[:ui] = double('ui')
35
+ env[:ui].stub(:info).with(anything)
36
+ env[:machine] = double('machine')
37
+ env[:machine] = OpenStruct.new.tap do |m|
38
+ m.provider_config = config
39
+ m.id = nil
40
+ end
41
+ env[:openstack_client] = double('openstack_client')
42
+ env[:openstack_client].stub(:heat) { heat }
43
+ end
44
+ end
45
+ before :each do
46
+ CreateStack.send(:public, *CreateStack.private_instance_methods)
47
+ app = double('app')
48
+ app.stub(:call).with(anything)
49
+ @action = CreateStack.new(app, nil)
50
+ YAML.stub(:load_file).with('template.yml').and_return(YAML.load('
51
+ heat_template_version: 2013-05-23
52
+
53
+ description: Simple template to deploy a single compute instance
54
+
55
+ resources:
56
+ my_instance:
57
+ type: OS::Nova::Server
58
+ properties:
59
+ key_name: julien-mac
60
+ image: CoreOS
61
+ flavor: 1_vCPU_RAM_512M_HD_10G
62
+ '))
63
+ end
64
+
65
+ describe 'call' do
66
+ it 'should create stacks on heat twice' do
67
+ heat.stub(:create_stack).and_return('idstack')
68
+ File.should_receive(:write).with('/stack_stack1_id', 'idstack')
69
+ File.should_receive(:write).with('/stack_stack2_id', 'idstack')
70
+ # TODO(julienvey) assert content of create call is correct
71
+ heat.should_receive(:create_stack).exactly(2).times
72
+ heat.stub(:get_stack_details).and_return('stack_status' => 'CREATE_COMPLETE')
73
+ @action.call(env)
74
+ end
75
+ end
76
+
77
+ describe 'waiting_for_server_to_be_built' do
78
+ context 'when server is not yet active' do
79
+ it 'become active after one retry' do
80
+ heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, 'stack_status' => 'CREATE_COMPLETE')
81
+ heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times
82
+ config.stub(:stack_create_timeout) { 5 }
83
+ @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1)
84
+ end
85
+ it 'timeout before the server become active' do
86
+ heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, 'stack_status' => 'CREATE_IN_PROGRESS')
87
+ heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').at_least(2).times
88
+ config.stub(:stack_create_timeout) { 3 }
89
+ expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::Timeout
90
+ end
91
+ it 'raise an error after one retry' do
92
+ heat.stub(:get_stack_details).and_return({ 'stack_status' => 'CREATE_IN_PROGRESS' }, 'stack_status' => 'CREATE_FAILED')
93
+ heat.should_receive(:get_stack_details).with(env, 'stack1', 'id-01').exactly(2).times
94
+ config.stub(:stack_create_timeout) { 3 }
95
+ expect { @action.waiting_for_stack_to_be_created(env, 'stack1', 'id-01', 1) }.to raise_error Errors::StackStatusError
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,89 @@
1
+ require 'vagrant-openstack-illuin-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::DeleteServer do
4
+ let(:nova) do
5
+ double('nova').tap do |app|
6
+ app.stub(:delete_server)
7
+ app.stub(:delete_keypair_if_vagrant)
8
+ end
9
+ end
10
+
11
+ let(:openstack_client) do
12
+ double('openstack_client').tap do |os|
13
+ os.stub(:nova) { nova }
14
+ end
15
+ end
16
+
17
+ let(:config) do
18
+ double('config')
19
+ end
20
+
21
+ let(:env) do
22
+ {}.tap do |env|
23
+ env[:ui] = double('ui')
24
+ env[:ui].stub(:info).with(anything)
25
+ env[:ui].stub(:error).with(anything)
26
+ env[:openstack_client] = openstack_client
27
+ env[:machine] = OpenStruct.new.tap do |m|
28
+ m.provider_config = config
29
+ m.id = 'server_id'
30
+ end
31
+ end
32
+ end
33
+
34
+ before :each do
35
+ DeleteServer.send(:public, *DeleteServer.private_instance_methods)
36
+ app = double('app')
37
+ app.stub(:call).with(anything)
38
+ @action = DeleteServer.new(app, nil)
39
+ end
40
+
41
+ describe 'call' do
42
+ context 'when id is present' do
43
+ it 'delete server' do
44
+ expect(nova).to receive(:delete_server).with(env, 'server_id')
45
+ expect(nova).to receive(:delete_keypair_if_vagrant).with(env, 'server_id')
46
+ expect(@action).to receive(:waiting_for_instance_to_be_deleted).with(env, 'server_id')
47
+ @action.call(env)
48
+ end
49
+ end
50
+ context 'when id is not present' do
51
+ it 'delete server' do
52
+ env[:machine].id = nil
53
+ expect(nova).should_not_receive(:delete_server)
54
+ expect(nova).should_not_receive(:delete_keypair_if_vagrant)
55
+ @action.call(env)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe 'waiting_for_instance_to_be_deleted' do
61
+ context 'when server is not yet active' do
62
+ it 'become deleted after one retry' do
63
+ nova.stub(:get_server_details).once.and_return('status' => 'ACTIVE')
64
+ nova.stub(:get_server_details).once.and_raise(Errors::InstanceNotFound)
65
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(1).times
66
+ config.stub(:server_delete_timeout) { 5 }
67
+ @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1)
68
+ end
69
+ it 'become deleted after one retry' do
70
+ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, 'status' => 'DELETED')
71
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
72
+ config.stub(:server_delete_timeout) { 5 }
73
+ @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1)
74
+ end
75
+ it 'timeout before the server become active' do
76
+ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, 'status' => 'ACTIVE')
77
+ nova.should_receive(:get_server_details).with(env, 'server-01').at_least(2).times
78
+ config.stub(:server_delete_timeout) { 3 }
79
+ expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) }.to raise_error Errors::Timeout
80
+ end
81
+ it 'raise an error after one retry' do
82
+ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, 'status' => 'ERROR')
83
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
84
+ config.stub(:server_delete_timeout) { 3 }
85
+ expect { @action.waiting_for_instance_to_be_deleted(env, 'server-01', 1) }.to raise_error Errors::ServerStatusError
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,63 @@
1
+ require 'vagrant-openstack-illuin-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::DeleteStack do
4
+ let(:heat) do
5
+ double('heat').tap do |app|
6
+ app.stub(:delete_stack)
7
+ end
8
+ end
9
+
10
+ let(:openstack_client) do
11
+ double('openstack_client').tap do |os|
12
+ os.stub(:heat) { heat }
13
+ end
14
+ end
15
+
16
+ let(:env) do
17
+ {}.tap do |env|
18
+ env[:ui] = double('ui')
19
+ env[:ui].stub(:info).with(anything)
20
+ env[:ui].stub(:error).with(anything)
21
+ env[:openstack_client] = openstack_client
22
+ env[:machine] = OpenStruct.new.tap do |m|
23
+ m.id = 'server_id'
24
+ m.data_dir = '/test'
25
+ end
26
+ end
27
+ end
28
+
29
+ before :each do
30
+ DeleteStack.send(:public, *DeleteStack.private_instance_methods)
31
+ app = double('app')
32
+ app.stub(:call).with(anything)
33
+ @action = DeleteStack.new(app, nil)
34
+ end
35
+
36
+ describe 'call' do
37
+ context 'when id is present' do
38
+ it 'delete stack' do
39
+ expect(heat).to receive(:delete_stack).with(env, 'test1', '1234')
40
+ expect(heat).to receive(:delete_stack).with(env, 'test2', '2345')
41
+ @action.stub(:list_stack_files).with(env).and_return([
42
+ {
43
+ name: 'test1',
44
+ id: '1234'
45
+ }, {
46
+ name: 'test2',
47
+ id: '2345'
48
+ }])
49
+ expect(@action).to receive(:waiting_for_stack_to_be_deleted).with(env, 'test1', '1234')
50
+ expect(@action).to receive(:waiting_for_stack_to_be_deleted).with(env, 'test2', '2345')
51
+ @action.call(env)
52
+ end
53
+ end
54
+ context 'when id is not present' do
55
+ it 'delete stack' do
56
+ @action.stub(:list_stack_files).with(env).and_return([])
57
+ expect(heat).should_not_receive(:delete_stack)
58
+ expect(heat).should_not_receive(:waiting_for_stack_to_be_deleted)
59
+ @action.call(env)
60
+ end
61
+ end
62
+ end
63
+ end