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,373 @@
1
+ require 'vagrant-conoha/spec_helper'
2
+
3
+ describe VagrantPlugins::ConoHa::Config do
4
+ describe 'defaults' do
5
+ let(:vagrant_public_key) { Vagrant.source_root.join('keys/vagrant.pub') }
6
+
7
+ subject do
8
+ super().tap(&:finalize!)
9
+ end
10
+
11
+ its(:password) { should be_nil }
12
+ its(:openstack_compute_url) { should be_nil }
13
+ its(:openstack_auth_url) { should be_nil }
14
+ its(:openstack_orchestration_url) { should be_nil }
15
+ its(:flavor) { should be_nil }
16
+ its(:image) { should be_nil }
17
+ its(:server_name) { should be_nil }
18
+ its(:username) { should be_nil }
19
+ its(:rsync_includes) { should be_nil }
20
+ its(:keypair_name) { should be_nil }
21
+ its(:public_key_path) { should be_nil }
22
+ its(:availability_zone) { should be_nil }
23
+ its(:ssh_username) { should be_nil }
24
+ its(:floating_ip_pool_always_allocate) { should eq(false) }
25
+ its(:scheduler_hints) { should be_nil }
26
+ its(:security_groups) { should be_nil }
27
+ its(:user_data) { should be_nil }
28
+ its(:metadata) { should be_nil }
29
+ end
30
+
31
+ describe 'overriding defaults' do
32
+ [
33
+ :password,
34
+ :openstack_compute_url,
35
+ :openstack_auth_url,
36
+ :flavor,
37
+ :image,
38
+ :server_name,
39
+ :username,
40
+ :keypair_name,
41
+ :ssh_username,
42
+ :floating_ip_pool_always_allocate,
43
+ :scheduler_hints,
44
+ :security_groups,
45
+ :openstack_orchestration_url,
46
+ :stacks,
47
+ :user_data,
48
+ :metadata,
49
+ :availability_zone,
50
+ :public_key_path].each do |attribute|
51
+ it "should not default #{attribute} if overridden" do
52
+ subject.send("#{attribute}=".to_sym, 'foo')
53
+ subject.finalize!
54
+ subject.send(attribute).should == 'foo'
55
+ end
56
+ end
57
+
58
+ it 'should not default rsync_includes if overridden' do
59
+ inc = 'core'
60
+ subject.send(:rsync_include, inc)
61
+ subject.finalize!
62
+ subject.send(:rsync_includes).should include(inc)
63
+ end
64
+ end
65
+
66
+ describe 'merge' do
67
+ let(:foo_class) do
68
+ Class.new(described_class) do
69
+ attr_accessor :networks
70
+ attr_accessor :floating_ip_pool
71
+ end
72
+ end
73
+
74
+ subject { foo_class.new }
75
+
76
+ context 'with original network not empty array' do
77
+ it 'should overidde the config' do
78
+ one = foo_class.new
79
+ one.networks = ['foo']
80
+
81
+ two = foo_class.new
82
+ two.networks = ['bar']
83
+
84
+ result = one.merge(two)
85
+ result.networks.should =~ ['bar']
86
+ end
87
+ end
88
+
89
+ context 'with original network empty array' do
90
+ it 'should add the network to the existing list' do
91
+ one = foo_class.new
92
+ one.networks = []
93
+
94
+ two = foo_class.new
95
+ two.networks = ['bar']
96
+
97
+ result = one.merge(two)
98
+ result.networks.should =~ ['bar']
99
+ end
100
+ end
101
+
102
+ context 'with original network not empty array and new empty array' do
103
+ it 'should keep the original network' do
104
+ one = foo_class.new
105
+ one.networks = ['foo']
106
+
107
+ two = foo_class.new
108
+ two.networks = []
109
+
110
+ result = one.merge(two)
111
+ result.networks.should =~ ['foo']
112
+ end
113
+ end
114
+
115
+ context 'with original network is a string and new empty array' do
116
+ it 'should keep the original network and wrap it into an array' do
117
+ one = foo_class.new
118
+ one.networks = 'foo'
119
+
120
+ two = foo_class.new
121
+ two.networks = []
122
+
123
+ result = one.merge(two)
124
+ result.networks.should =~ ['foo']
125
+ end
126
+ end
127
+
128
+ context 'with original network is a string and new is a string' do
129
+ it 'should overidde the config and wrap it into an array' do
130
+ one = foo_class.new
131
+ one.networks = 'foo'
132
+
133
+ two = foo_class.new
134
+ two.networks = 'bar'
135
+
136
+ result = one.merge(two)
137
+ result.networks.should =~ ['bar']
138
+ end
139
+ end
140
+
141
+ context 'with original floating_ip_pool as string' do
142
+ context 'and new as empty array' do
143
+ it 'should put original string in a single entry array' do
144
+ one = foo_class.new
145
+ one.floating_ip_pool = 'pool'
146
+
147
+ two = foo_class.new
148
+ two.floating_ip_pool = []
149
+
150
+ result = one.merge(two)
151
+ result.floating_ip_pool.should =~ ['pool']
152
+ end
153
+ end
154
+ context 'and new as empty string' do
155
+ it 'should put original string in a single entry array' do
156
+ one = foo_class.new
157
+ one.floating_ip_pool = 'pool'
158
+
159
+ two = foo_class.new
160
+ two.floating_ip_pool = ''
161
+
162
+ result = one.merge(two)
163
+ result.floating_ip_pool.should =~ ['']
164
+ end
165
+ end
166
+ context 'and new as string' do
167
+ it 'should put new string in a single entry array' do
168
+ one = foo_class.new
169
+ one.floating_ip_pool = 'pool'
170
+
171
+ two = foo_class.new
172
+ two.floating_ip_pool = 'new-pool'
173
+
174
+ result = one.merge(two)
175
+ result.floating_ip_pool.should =~ ['new-pool']
176
+ end
177
+ end
178
+ context 'and new as array' do
179
+ it 'should put new array' do
180
+ one = foo_class.new
181
+ one.floating_ip_pool = 'pool'
182
+
183
+ two = foo_class.new
184
+ two.floating_ip_pool = %w(pool-1 pool-2)
185
+
186
+ result = one.merge(two)
187
+ result.floating_ip_pool.should =~ %w(pool-1 pool-2)
188
+ end
189
+ end
190
+ end
191
+
192
+ context 'with original floating_ip_pool as array' do
193
+ context 'and new empty' do
194
+ it 'should put original array' do
195
+ one = foo_class.new
196
+ one.floating_ip_pool = %w(pool-1 pool-2)
197
+
198
+ two = foo_class.new
199
+ two.floating_ip_pool = []
200
+
201
+ result = one.merge(two)
202
+ result.floating_ip_pool.should =~ %w(pool-1 pool-2)
203
+ end
204
+ end
205
+ context 'and new as string' do
206
+ it 'should put new string in a single entry array' do
207
+ one = foo_class.new
208
+ one.floating_ip_pool = %w(pool-1 pool-2)
209
+
210
+ two = foo_class.new
211
+ two.floating_ip_pool = 'pool'
212
+
213
+ result = one.merge(two)
214
+ result.floating_ip_pool.should =~ ['pool']
215
+ end
216
+ end
217
+ context 'and new as array' do
218
+ it 'should put new array' do
219
+ one = foo_class.new
220
+ one.floating_ip_pool = %w(pool-1 pool-2)
221
+
222
+ two = foo_class.new
223
+ two.floating_ip_pool = %w(new-pool-1 new-pool-2)
224
+
225
+ result = one.merge(two)
226
+ result.floating_ip_pool.should =~ %w(new-pool-1 new-pool-2)
227
+ end
228
+ end
229
+ end
230
+ end
231
+
232
+ describe 'validation' do
233
+ let(:machine) { double('machine') }
234
+ let(:validation_errors) { subject.validate(machine)['Openstack Provider'] }
235
+ let(:error_message) { double('error message') }
236
+
237
+ let(:config) { double('config') }
238
+ let(:ssh) { double('ssh') }
239
+
240
+ before(:each) do
241
+ error_message.stub(:yellow) { 'Yellowed Error message ' }
242
+ machine.stub_chain(:env, :root_path).and_return '/'
243
+ ssh.stub(:private_key_path) { 'private key path' }
244
+ ssh.stub(:username) { 'ssh username' }
245
+ config.stub(:ssh) { ssh }
246
+ machine.stub(:config) { config }
247
+ subject.username = 'foo'
248
+ subject.password = 'bar'
249
+ subject.tenant_name = 'tenant'
250
+ subject.keypair_name = 'keypair'
251
+ end
252
+
253
+ subject do
254
+ super().tap(&:finalize!)
255
+ end
256
+
257
+ context 'with invalid stack' do
258
+ it 'should raise an error' do
259
+ subject.stacks = [
260
+ {
261
+ name: 'test1'
262
+ }
263
+ ]
264
+ I18n.should_receive(:t).with('vagrant_openstack.config.invalid_stack').and_return error_message
265
+ validation_errors.first.should == error_message
266
+ end
267
+
268
+ it 'should raise an error' do
269
+ subject.stacks = [
270
+ {
271
+ name: 'test1',
272
+ tempslate: 'tes1'
273
+ }
274
+ ]
275
+ I18n.should_receive(:t).with('vagrant_openstack.config.invalid_stack').and_return error_message
276
+ validation_errors.first.should == error_message
277
+ end
278
+
279
+ it 'should not raise an error' do
280
+ subject.stacks = [
281
+ {
282
+ name: 'test1',
283
+ template: 'tes1'
284
+ }
285
+ ]
286
+ expect(validation_errors).to be_empty
287
+ end
288
+ end
289
+
290
+ context 'with invalid key' do
291
+ it 'should raise an error' do
292
+ subject.nonsense1 = true
293
+ subject.nonsense2 = false
294
+ I18n.should_receive(:t).with('vagrant.config.common.bad_field', fields: 'nonsense1, nonsense2').and_return error_message
295
+ validation_errors.first.should == error_message
296
+ end
297
+ end
298
+
299
+ context 'with no ssh username provider' do
300
+ it 'should raise an error' do
301
+ ssh.stub(:username) { nil }
302
+ subject.ssh_username = nil
303
+ I18n.should_receive(:t).with('vagrant_openstack.config.ssh_username_required').and_return error_message
304
+ validation_errors.first.should == error_message
305
+ end
306
+ end
307
+
308
+ context 'with good values' do
309
+ it 'should validate' do
310
+ validation_errors.should be_empty
311
+ end
312
+ end
313
+
314
+ context 'private_key_path is not set' do
315
+ context 'keypair_name or public_key_path is set' do
316
+ it 'should error if not given' do
317
+ ssh.stub(:private_key_path) { nil }
318
+ subject.public_key_path = 'public_key'
319
+ I18n.should_receive(:t).with('vagrant_openstack.config.private_key_missing').and_return error_message
320
+ validation_errors.first.should == error_message
321
+ end
322
+ end
323
+ end
324
+
325
+ context 'the password' do
326
+ it 'should error if not given' do
327
+ subject.password = nil
328
+ I18n.should_receive(:t).with('vagrant_openstack.config.password_required').and_return error_message
329
+ validation_errors.first.should == error_message
330
+ end
331
+ end
332
+
333
+ context 'the username' do
334
+ it 'should error if not given' do
335
+ subject.username = nil
336
+ I18n.should_receive(:t).with('vagrant_openstack.config.username_required').and_return error_message
337
+ validation_errors.first.should == error_message
338
+ end
339
+ end
340
+
341
+ context 'the tenant name' do
342
+ it 'should error if not given' do
343
+ subject.tenant_name = nil
344
+ I18n.should_receive(:t).with('vagrant_openstack.config.tenant_name_required').and_return error_message
345
+ validation_errors.first.should == error_message
346
+ end
347
+ end
348
+
349
+ context 'the ssh_timeout' do
350
+ it 'should error if do not represent an integer' do
351
+ subject.ssh_timeout = 'timeout'
352
+ I18n.should_receive(:t).with('vagrant_openstack.config.invalid_value_for_parameter',
353
+ parameter: 'ssh_timeout', value: 'timeout').and_return error_message
354
+ validation_errors.first.should == error_message
355
+ end
356
+ it 'should be parsed as integer if is a string that represent an integer' do
357
+ subject.ssh_timeout = '100'
358
+ validation_errors.size.should eq(0)
359
+ expect(subject.ssh_timeout).to eq(100)
360
+ end
361
+ end
362
+
363
+ [:openstack_compute_url, :openstack_auth_url, :openstack_orchestration_url].each do |url|
364
+ context "the #{url}" do
365
+ it 'should not validate if the URL is invalid' do
366
+ subject.send "#{url}=", 'baz'
367
+ I18n.should_receive(:t).with('vagrant_openstack.config.invalid_uri', key: url, uri: 'baz').and_return error_message
368
+ validation_errors.first.should == error_message
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end
@@ -0,0 +1,27 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ require 'aruba'
4
+ require 'aruba/api'
5
+
6
+ include Aruba::Api
7
+
8
+ # spec/template_spec.rb
9
+ require 'pathname'
10
+
11
+ root = Pathname.new(__FILE__).parent.parent
12
+
13
+ # Allows us to run commands directly, without worrying about the CWD
14
+ ENV['PATH'] = "#{root.join('bin').to_s}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
15
+
16
+ describe "genud" do
17
+ context "YAML templates" do
18
+ it "should emit valid YAML to STDOUT", :focus do
19
+
20
+ puts '#####################'
21
+ # Run the command with Aruba's run_simple helper
22
+ run_simple "bundle exec vagrant openstack", false, 10
23
+
24
+ # assert_exit_status(0)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'vagrant-conoha/spec_helper'
2
+
3
+ describe VagrantPlugins::ConoHa::Provider do
4
+ before :each do
5
+ @provider = VagrantPlugins::ConoHa::Provider.new :machine
6
+ end
7
+
8
+ describe 'to string' do
9
+ it 'should give the provider name' do
10
+ @provider.to_s.should eq('Vagrant ConoHa provider')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+
2
+ if ENV['COVERAGE'] != 'false'
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+ SimpleCov.start do
10
+ add_filter 'spec'
11
+ end
12
+ end
13
+
14
+ Dir[
15
+ 'lib/vagrant-conoha/version_checker.rb',
16
+ 'lib/vagrant-conoha/logging.rb',
17
+ 'lib/vagrant-conoha/config.rb',
18
+ 'lib/vagrant-conoha/config_resolver.rb',
19
+ 'lib/vagrant-conoha/utils.rb',
20
+ 'lib/vagrant-conoha/errors.rb',
21
+ 'lib/vagrant-conoha/provider.rb',
22
+ 'lib/vagrant-conoha/client/*.rb',
23
+ 'lib/vagrant-conoha/command/*.rb',
24
+ 'lib/vagrant-conoha/action/*.rb'].each { |file| require file[4, file.length - 1] }
25
+
26
+ require 'rspec/its'
27
+ require 'webmock/rspec'
28
+ require 'fakefs/safe'
29
+ require 'fakefs/spec_helpers'
30
+
31
+ RSpec.configure do |config|
32
+ config.include FakeFS::SpecHelpers, fakefs: true
33
+ end
34
+
35
+ I18n.load_path << File.expand_path('locales/en.yml', Pathname.new(File.expand_path('../../../', __FILE__)))
36
+
37
+ VagrantPlugins::ConoHa::Logging.init