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,225 @@
1
+ require 'vagrant-conoha/spec_helper'
2
+ require 'ostruct'
3
+ require 'sshkey'
4
+
5
+ include VagrantPlugins::ConoHa::Action
6
+ include VagrantPlugins::ConoHa::HttpUtils
7
+ include VagrantPlugins::ConoHa::Domain
8
+
9
+ describe VagrantPlugins::ConoHa::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_security_groups).with(anything) do
71
+ [{ name: 'group1' }, { name: 'group2' }]
72
+ end
73
+ end
74
+ end
75
+
76
+ let(:utils) do
77
+ double('utils').tap do |u|
78
+ u.stub(:get_ip_address) { '1.2.3.4' }
79
+ end
80
+ end
81
+
82
+ before :each do
83
+ CreateServer.send(:public, *CreateServer.private_instance_methods)
84
+ app = double('app')
85
+ app.stub(:call).with(anything)
86
+ @action = CreateServer.new(app, nil, resolver, utils)
87
+ end
88
+
89
+ describe 'call' do
90
+ context 'with both image and volume_boot specified' do
91
+ it 'should raise an error' do
92
+ config.stub(:image) { 'linux-image' }
93
+ config.stub(:volume_boot) { 'linux-volume' }
94
+ expect { @action.call(env) }.to raise_error Errors::ConflictBootOption
95
+ end
96
+ end
97
+ context 'with neither image nor volume_boot specified' do
98
+ it 'should raise an error' do
99
+ config.stub(:image) { nil }
100
+ config.stub(:volume_boot) { nil }
101
+ expect { @action.call(env) }.to raise_error Errors::MissingBootOption
102
+ end
103
+ end
104
+ context 'with full options' do
105
+ it 'works' do
106
+ allow(@action).to receive(:create_server).and_return('45678')
107
+ allow(@action).to receive(:waiting_for_server_to_be_built)
108
+ allow(@action).to receive(:attach_volumes)
109
+ allow(@action).to receive(:waiting_for_server_to_be_reachable)
110
+
111
+ expect(@action).to receive(:waiting_for_server_to_be_built).with(env, '45678')
112
+ expect(@action).to receive(:attach_volumes).with(env, '45678', [{ id: 'vol-01', device: nil }])
113
+
114
+ @action.call(env)
115
+ end
116
+ end
117
+ end
118
+
119
+ describe 'create_server' do
120
+ context 'with all options specified' do
121
+ it 'calls nova with all the options' do
122
+ nova.stub(:create_server).with(
123
+ env,
124
+ name: 'testName',
125
+ flavor_ref: flavor.id,
126
+ image_ref: image.id,
127
+ volume_boot: nil,
128
+ networks: [{ uuid: 'test-networks-1' }, { uuid: 'test-networks-2', fixed_ip: '1.2.3.4' }],
129
+ keypair: 'test-keypair',
130
+ availability_zone: 'test-az',
131
+ scheduler_hints: 'test-sched-hints',
132
+ security_groups: ['test-sec-groups'],
133
+ user_data: 'test-user_data',
134
+ metadata: 'test-metadata') do
135
+ '1234'
136
+ end
137
+
138
+ options = {
139
+ flavor: flavor,
140
+ image: image,
141
+ networks: [{ uuid: 'test-networks-1' }, { uuid: 'test-networks-2', fixed_ip: '1.2.3.4' }],
142
+ volumes: [{ id: '001', device: :auto }, { id: '002', device: '/dev/vdc' }],
143
+ keypair_name: 'test-keypair',
144
+ availability_zone: 'test-az',
145
+ scheduler_hints: 'test-sched-hints',
146
+ security_groups: ['test-sec-groups'],
147
+ user_data: 'test-user_data',
148
+ metadata: 'test-metadata'
149
+ }
150
+
151
+ expect(@action.create_server(env, options)).to eq '1234'
152
+ end
153
+ end
154
+ context 'with minimal configuration and a single network' do
155
+ it 'calls nova' do
156
+ config.stub(:server_name) { nil }
157
+ nova.stub(:create_server).with(
158
+ env,
159
+ name: nil,
160
+ flavor_ref: flavor.id,
161
+ image_ref: image.id,
162
+ volume_boot: nil,
163
+ networks: [{ uuid: 'test-networks-1' }],
164
+ keypair: 'test-keypair',
165
+ availability_zone: nil,
166
+ scheduler_hints: nil,
167
+ security_groups: [],
168
+ user_data: nil,
169
+ metadata: nil) do
170
+ '1234'
171
+ end
172
+
173
+ options = {
174
+ flavor: flavor,
175
+ image: image,
176
+ networks: [{ uuid: 'test-networks-1' }],
177
+ volumes: [],
178
+ keypair_name: 'test-keypair',
179
+ availability_zone: nil,
180
+ scheduler_hints: nil,
181
+ security_groups: [],
182
+ user_data: nil,
183
+ metadata: nil
184
+ }
185
+
186
+ expect(@action.create_server(env, options)).to eq '1234'
187
+ end
188
+ end
189
+ end
190
+
191
+ describe 'waiting_for_server_to_be_built' do
192
+ context 'when server is not yet active' do
193
+ it 'become active after one retry' do
194
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'ACTIVE')
195
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
196
+ config.stub(:server_create_timeout) { 5 }
197
+ @action.waiting_for_server_to_be_built(env, 'server-01', 1)
198
+ end
199
+ it 'timeout before the server become active' do
200
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'BUILD')
201
+ nova.should_receive(:get_server_details).with(env, 'server-01').at_least(2).times
202
+ config.stub(:server_create_timeout) { 3 }
203
+ expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::Timeout
204
+ end
205
+ it 'raise an error after one retry' do
206
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, 'status' => 'ERROR')
207
+ nova.should_receive(:get_server_details).with(env, 'server-01').exactly(2).times
208
+ config.stub(:server_create_timeout) { 3 }
209
+ expect { @action.waiting_for_server_to_be_built(env, 'server-01', 1) }.to raise_error Errors::ServerStatusError
210
+ end
211
+ end
212
+ end
213
+
214
+ describe 'attach_volumes' do
215
+ context 'with volume attached in all possible ways' do
216
+ it 'returns normalized volume list' do
217
+ nova.stub(:attach_volume).with(anything, anything, anything, anything) {}
218
+ nova.should_receive(:attach_volume).with(env, 'server-01', '001', nil)
219
+ nova.should_receive(:attach_volume).with(env, 'server-01', '002', '/dev/vdb')
220
+
221
+ @action.attach_volumes(env, 'server-01', [{ id: '001', device: nil }, { id: '002', device: '/dev/vdb' }])
222
+ end
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,99 @@
1
+ require 'vagrant-conoha/spec_helper'
2
+ require 'ostruct'
3
+ require 'sshkey'
4
+
5
+ include VagrantPlugins::ConoHa::Action
6
+ include VagrantPlugins::ConoHa::HttpUtils
7
+ include VagrantPlugins::ConoHa::Domain
8
+
9
+ describe VagrantPlugins::ConoHa::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-conoha/spec_helper'
2
+
3
+ describe VagrantPlugins::ConoHa::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-conoha/spec_helper'
2
+
3
+ describe VagrantPlugins::ConoHa::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