vagrant-openstack-provider 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +13 -5
  2. data/.rubocop.yml +28 -0
  3. data/Appraisals +3 -3
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +3 -0
  6. data/Rakefile +6 -2
  7. data/Vagrantfile +4 -15
  8. data/gemfiles/latest_stable.gemfile +2 -0
  9. data/gemfiles/oldest_current.gemfile +2 -0
  10. data/gemfiles/previous_release.gemfile +2 -0
  11. data/lib/vagrant-openstack-provider.rb +18 -13
  12. data/lib/vagrant-openstack-provider/action.rb +112 -46
  13. data/lib/vagrant-openstack-provider/action/connect_openstack.rb +9 -10
  14. data/lib/vagrant-openstack-provider/action/create_server.rb +86 -57
  15. data/lib/vagrant-openstack-provider/action/delete_server.rb +5 -6
  16. data/lib/vagrant-openstack-provider/action/{is_created.rb → message.rb} +4 -3
  17. data/lib/vagrant-openstack-provider/action/read_ssh_info.rb +7 -27
  18. data/lib/vagrant-openstack-provider/action/read_state.rb +7 -9
  19. data/lib/vagrant-openstack-provider/action/resume.rb +20 -0
  20. data/lib/vagrant-openstack-provider/action/start_server.rb +22 -0
  21. data/lib/vagrant-openstack-provider/action/stop_server.rb +22 -0
  22. data/lib/vagrant-openstack-provider/action/suspend.rb +20 -0
  23. data/lib/vagrant-openstack-provider/action/sync_folders.rb +27 -38
  24. data/lib/vagrant-openstack-provider/action/wait_stop.rb +29 -0
  25. data/lib/vagrant-openstack-provider/client/keystone.rb +76 -0
  26. data/lib/vagrant-openstack-provider/client/neutron.rb +32 -0
  27. data/lib/vagrant-openstack-provider/client/nova.rb +166 -0
  28. data/lib/vagrant-openstack-provider/client/openstack.rb +41 -0
  29. data/lib/vagrant-openstack-provider/client/utils.rb +38 -0
  30. data/lib/vagrant-openstack-provider/config.rb +38 -110
  31. data/lib/vagrant-openstack-provider/errors.rb +7 -3
  32. data/lib/vagrant-openstack-provider/plugin.rb +8 -8
  33. data/lib/vagrant-openstack-provider/provider.rb +6 -6
  34. data/lib/vagrant-openstack-provider/version.rb +1 -1
  35. data/locales/en.yml +83 -5
  36. data/numergyrc +22 -0
  37. data/spec/vagrant-openstack-provider/action/create_server_spec.rb +89 -0
  38. data/spec/vagrant-openstack-provider/client/keystone_spec.rb +140 -0
  39. data/spec/vagrant-openstack-provider/client/neutron_spec.rb +53 -0
  40. data/spec/vagrant-openstack-provider/client/nova_spec.rb +373 -0
  41. data/spec/vagrant-openstack-provider/client/utils_spec.rb +125 -0
  42. data/spec/vagrant-openstack-provider/config_spec.rb +117 -0
  43. data/spec/vagrant-openstack-provider/provider_spec.rb +13 -0
  44. data/spec/vagrant-openstack-provider/spec_helper.rb +23 -0
  45. data/vagrant-openstack-provider.gemspec +13 -14
  46. metadata +40 -30
  47. data/features/provision.feature +0 -35
  48. data/features/steps/sdk_steps.rb +0 -13
  49. data/features/steps/server_steps.rb +0 -25
  50. data/features/support/env.rb +0 -37
  51. data/features/support/fog_mock.rb +0 -19
  52. data/features/vagrant-openstack-provider.feature +0 -70
  53. data/lib/vagrant-openstack-provider/action/message_already_created.rb +0 -16
  54. data/lib/vagrant-openstack-provider/action/message_not_created.rb +0 -16
  55. data/lib/vagrant-openstack-provider/openstack_client.rb +0 -98
  56. data/spec/vagrant-openstack/config_spec.rb +0 -184
  57. data/stackrc +0 -31
@@ -0,0 +1,125 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ include VagrantPlugins::Openstack
4
+
5
+ describe VagrantPlugins::Openstack::Utils do
6
+
7
+ let(:keystone) do
8
+ double('keystone').tap do |keystone|
9
+ keystone.stub(:authenticate).with(anything)
10
+ end
11
+ end
12
+
13
+ let(:env) do
14
+ Hash.new.tap do |env|
15
+ env[:ui] = double('ui')
16
+ env[:ui].stub(:warn).with(anything)
17
+ env[:openstack_client] = double('openstack_client')
18
+ env[:openstack_client].stub(:keystone) { keystone }
19
+ end
20
+ end
21
+
22
+ class TestUtils
23
+ include VagrantPlugins::Openstack::Utils
24
+ include VagrantPlugins::Openstack::Errors
25
+ def target(env)
26
+ authenticated(env) do
27
+ env[:target].call
28
+ end
29
+ end
30
+ end
31
+
32
+ def error
33
+ fail Errors::AuthenticationRequired
34
+ end
35
+
36
+ describe 'authenticated' do
37
+
38
+ before :each do
39
+ @utils = TestUtils.new
40
+ end
41
+
42
+ context 'with two authentication errors' do
43
+ it 'should retry two times and success' do
44
+ env[:target] = double.tap do |stub|
45
+ nb_calls = 0
46
+ stub.stub(:call) do
47
+ nb_calls += 1
48
+ fail Errors::AuthenticationRequired if nb_calls < 3
49
+ end.and_return('object response')
50
+ end
51
+ env[:target].should_receive(:call).exactly(3).times
52
+
53
+ response = @utils.target(env)
54
+
55
+ expect(response).to eq('object response')
56
+ end
57
+ end
58
+
59
+ context 'with three authentication errors' do
60
+ it 'should retry two times and fail' do
61
+ env[:target] = double.tap do |stub|
62
+ stub.stub(:call) do
63
+ fail Errors::AuthenticationRequired
64
+ end
65
+ end
66
+ env[:target].should_receive(:call).exactly(3).times
67
+
68
+ expect { @utils.target(env) }.to raise_error Errors::AuthenticationRequired
69
+ end
70
+ end
71
+ end
72
+
73
+ describe 'handle_response' do
74
+ before :each do
75
+ @utils = TestUtils.new
76
+ end
77
+
78
+ [200, 201, 202, 204].each do |code|
79
+ context "response code is #{code}" do
80
+ it 'should return the response' do
81
+ mock_resp = double.tap { |mock| mock.stub(:code).and_return(code) }
82
+ resp = @utils.handle_response(mock_resp)
83
+ expect(resp.code).to eq(code)
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'response code is 401' do
89
+ it 'should return raise a AuthenticationRequired error' do
90
+ mock_resp = double.tap { |mock| mock.stub(:code).and_return(401) }
91
+ expect { @utils.handle_response(mock_resp) }.to raise_error Errors::AuthenticationRequired
92
+ end
93
+ end
94
+
95
+ context 'response code is 400' do
96
+ it 'should return raise a VagrantOpenstackError error with error message' do
97
+ mock_resp = double.tap do |mock|
98
+ mock.stub(:code).and_return(400)
99
+ mock.stub(:to_s).and_return('{ "badRequest": { "message": "Error... Bad request" } }')
100
+ end
101
+ begin
102
+ @utils.handle_response(mock_resp)
103
+ fail
104
+ rescue Errors::VagrantOpenstackError => e
105
+ expect(e.message).to eq('Error... Bad request')
106
+ end
107
+ end
108
+ end
109
+
110
+ context 'response code is 500' do
111
+ it 'should return raise a VagrantOpenstackError error with error message' do
112
+ mock_resp = double.tap do |mock|
113
+ mock.stub(:code).and_return(500)
114
+ mock.stub(:to_s).and_return('Internal server error')
115
+ end
116
+ begin
117
+ @utils.handle_response(mock_resp)
118
+ fail
119
+ rescue Errors::VagrantOpenstackError => e
120
+ expect(e.message).to eq('Internal server error')
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,117 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::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 do |o|
9
+ o.finalize!
10
+ end
11
+ end
12
+
13
+ its(:password) { should be_nil }
14
+ its(:openstack_compute_url) { should be_nil }
15
+ its(:openstack_auth_url) { should be_nil }
16
+ its(:flavor) { should be_nil }
17
+ its(:image) { should be_nil }
18
+ its(:server_name) { should be_nil }
19
+ its(:username) { should be_nil }
20
+ its(:rsync_includes) { should be_nil }
21
+ its(:keypair_name) { should be_nil }
22
+ its(:ssh_username) { should be_nil }
23
+ end
24
+
25
+ describe 'overriding defaults' do
26
+ [
27
+ :password,
28
+ :openstack_compute_url,
29
+ :openstack_auth_url,
30
+ :flavor,
31
+ :image,
32
+ :server_name,
33
+ :username,
34
+ :keypair_name,
35
+ :ssh_username].each do |attribute|
36
+ it "should not default #{attribute} if overridden" do
37
+ subject.send("#{attribute}=".to_sym, 'foo')
38
+ subject.finalize!
39
+ subject.send(attribute).should == 'foo'
40
+ end
41
+ end
42
+
43
+ it 'should not default rsync_includes if overridden' do
44
+ inc = 'core'
45
+ subject.send(:rsync_include, inc)
46
+ subject.finalize!
47
+ subject.send(:rsync_includes).should include(inc)
48
+ end
49
+ end
50
+
51
+ describe 'validation' do
52
+ let(:machine) { double('machine') }
53
+ let(:validation_errors) { subject.validate(machine)['Openstack Provider'] }
54
+ let(:error_message) { double('error message') }
55
+
56
+ before(:each) do
57
+ machine.stub_chain(:env, :root_path).and_return '/'
58
+ subject.username = 'foo'
59
+ subject.password = 'bar'
60
+ subject.keypair_name = 'keypair'
61
+ end
62
+
63
+ subject do
64
+ super().tap do |o|
65
+ o.finalize!
66
+ end
67
+ end
68
+
69
+ context 'with invalid key' do
70
+ it 'should raise an error' do
71
+ subject.nonsense1 = true
72
+ subject.nonsense2 = false
73
+ I18n.should_receive(:t).with('vagrant.config.common.bad_field', fields: 'nonsense1, nonsense2').and_return error_message
74
+ validation_errors.first.should == error_message
75
+ end
76
+ end
77
+ context 'with good values' do
78
+ it 'should validate' do
79
+ validation_errors.should be_empty
80
+ end
81
+ end
82
+
83
+ context 'the keypair name' do
84
+ it 'should error if not given' do
85
+ subject.keypair_name = nil
86
+ I18n.should_receive(:t).with('vagrant_openstack.config.keypair_name_required').and_return error_message
87
+ validation_errors.first.should == error_message
88
+ end
89
+ end
90
+
91
+ context 'the API key' do
92
+ it 'should error if not given' do
93
+ subject.password = nil
94
+ I18n.should_receive(:t).with('vagrant_openstack.config.password_required').and_return error_message
95
+ validation_errors.first.should == error_message
96
+ end
97
+ end
98
+
99
+ context 'the username' do
100
+ it 'should error if not given' do
101
+ subject.username = nil
102
+ I18n.should_receive(:t).with('vagrant_openstack.config.username_required').and_return error_message
103
+ validation_errors.first.should == error_message
104
+ end
105
+ end
106
+
107
+ [:openstack_compute_url, :openstack_auth_url].each do |url|
108
+ context "the #{url}" do
109
+ it 'should not validate if the URL is invalid' do
110
+ subject.send "#{url}=", 'baz'
111
+ I18n.should_receive(:t).with('vagrant_openstack.config.invalid_uri', key: url, uri: 'baz').and_return error_message
112
+ validation_errors.first.should == error_message
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,13 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Provider do
4
+ before :each do
5
+ @provider = VagrantPlugins::Openstack::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('Openstack Cloud')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
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-openstack-provider/config.rb',
16
+ 'lib/vagrant-openstack-provider/errors.rb',
17
+ 'lib/vagrant-openstack-provider/provider.rb',
18
+ 'lib/vagrant-openstack-provider/client/*.rb',
19
+ 'lib/vagrant-openstack-provider/action/*.rb'].each { |file| require file[4, file.length - 1] }
20
+
21
+ require 'webmock/rspec'
22
+
23
+ I18n.load_path << File.expand_path('locales/en.yml', Pathname.new(File.expand_path('../../../', __FILE__)))
@@ -1,23 +1,22 @@
1
- # -*- encoding: utf-8 -*-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'vagrant-openstack-provider/version'
5
4
 
6
5
  Gem::Specification.new do |gem|
7
- gem.name = "vagrant-openstack-provider"
6
+ gem.name = 'vagrant-openstack-provider'
8
7
  gem.version = VagrantPlugins::Openstack::VERSION
9
- gem.authors = ["Guillaume Giamarchi", "Julien Vey"]
10
- gem.email = ["guillaume.giamarchi@gmail.com", "vey.julien@gmail.com"]
11
- gem.description = "Enables Vagrant to manage machines in Openstack Cloud."
12
- gem.summary = "Enables Vagrant to manage machines in Openstack Cloud."
13
- gem.homepage = "https://github.com/ggiamarchi/vagrant-openstack"
8
+ gem.authors = ['Guillaume Giamarchi', 'Julien Vey']
9
+ gem.email = ['guillaume.giamarchi@gmail.com', 'vey.julien@gmail.com']
10
+ gem.description = 'Enables Vagrant to manage machines in Openstack Cloud.'
11
+ gem.summary = 'Enables Vagrant to manage machines in Openstack Cloud.'
12
+ gem.homepage = 'https://github.com/ggiamarchi/vagrant-openstack'
14
13
 
15
- gem.add_development_dependency "rake"
16
- gem.add_development_dependency "rspec", "~> 2.13.0"
17
- gem.add_development_dependency "aruba"
14
+ gem.add_development_dependency 'rake'
15
+ gem.add_development_dependency 'rspec', '~> 2.13.0'
16
+ gem.add_development_dependency 'aruba'
18
17
 
19
- gem.files = `git ls-files`.split($/)
20
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
- gem.require_paths = ["lib"]
18
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
19
+ gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(/^(test|spec|features)\//)
21
+ gem.require_paths = ['lib']
23
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-openstack-provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Giamarchi
@@ -9,48 +9,48 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-25 00:00:00.000000000 Z
12
+ date: 2014-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - ! '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: 2.13.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: 2.13.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: aruba
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  description: Enables Vagrant to manage machines in Openstack Cloud.
@@ -61,7 +61,8 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".gitignore"
64
+ - .gitignore
65
+ - .rubocop.yml
65
66
  - Appraisals
66
67
  - CHANGELOG.md
67
68
  - Gemfile
@@ -72,12 +73,6 @@ files:
72
73
  - dummy.box
73
74
  - example_box/README.md
74
75
  - example_box/metadata.json
75
- - features/provision.feature
76
- - features/steps/sdk_steps.rb
77
- - features/steps/server_steps.rb
78
- - features/support/env.rb
79
- - features/support/fog_mock.rb
80
- - features/vagrant-openstack-provider.feature
81
76
  - gemfiles/latest_stable.gemfile
82
77
  - gemfiles/oldest_current.gemfile
83
78
  - gemfiles/previous_release.gemfile
@@ -86,21 +81,35 @@ files:
86
81
  - lib/vagrant-openstack-provider/action/connect_openstack.rb
87
82
  - lib/vagrant-openstack-provider/action/create_server.rb
88
83
  - lib/vagrant-openstack-provider/action/delete_server.rb
89
- - lib/vagrant-openstack-provider/action/is_created.rb
90
- - lib/vagrant-openstack-provider/action/message_already_created.rb
91
- - lib/vagrant-openstack-provider/action/message_not_created.rb
84
+ - lib/vagrant-openstack-provider/action/message.rb
92
85
  - lib/vagrant-openstack-provider/action/read_ssh_info.rb
93
86
  - lib/vagrant-openstack-provider/action/read_state.rb
87
+ - lib/vagrant-openstack-provider/action/resume.rb
88
+ - lib/vagrant-openstack-provider/action/start_server.rb
89
+ - lib/vagrant-openstack-provider/action/stop_server.rb
90
+ - lib/vagrant-openstack-provider/action/suspend.rb
94
91
  - lib/vagrant-openstack-provider/action/sync_folders.rb
92
+ - lib/vagrant-openstack-provider/action/wait_stop.rb
93
+ - lib/vagrant-openstack-provider/client/keystone.rb
94
+ - lib/vagrant-openstack-provider/client/neutron.rb
95
+ - lib/vagrant-openstack-provider/client/nova.rb
96
+ - lib/vagrant-openstack-provider/client/openstack.rb
97
+ - lib/vagrant-openstack-provider/client/utils.rb
95
98
  - lib/vagrant-openstack-provider/config.rb
96
99
  - lib/vagrant-openstack-provider/errors.rb
97
- - lib/vagrant-openstack-provider/openstack_client.rb
98
100
  - lib/vagrant-openstack-provider/plugin.rb
99
101
  - lib/vagrant-openstack-provider/provider.rb
100
102
  - lib/vagrant-openstack-provider/version.rb
101
103
  - locales/en.yml
102
- - spec/vagrant-openstack/config_spec.rb
103
- - stackrc
104
+ - numergyrc
105
+ - spec/vagrant-openstack-provider/action/create_server_spec.rb
106
+ - spec/vagrant-openstack-provider/client/keystone_spec.rb
107
+ - spec/vagrant-openstack-provider/client/neutron_spec.rb
108
+ - spec/vagrant-openstack-provider/client/nova_spec.rb
109
+ - spec/vagrant-openstack-provider/client/utils_spec.rb
110
+ - spec/vagrant-openstack-provider/config_spec.rb
111
+ - spec/vagrant-openstack-provider/provider_spec.rb
112
+ - spec/vagrant-openstack-provider/spec_helper.rb
104
113
  - vagrant-openstack-provider.gemspec
105
114
  homepage: https://github.com/ggiamarchi/vagrant-openstack
106
115
  licenses: []
@@ -111,12 +120,12 @@ require_paths:
111
120
  - lib
112
121
  required_ruby_version: !ruby/object:Gem::Requirement
113
122
  requirements:
114
- - - ">="
123
+ - - ! '>='
115
124
  - !ruby/object:Gem::Version
116
125
  version: '0'
117
126
  required_rubygems_version: !ruby/object:Gem::Requirement
118
127
  requirements:
119
- - - ">="
128
+ - - ! '>='
120
129
  - !ruby/object:Gem::Version
121
130
  version: '0'
122
131
  requirements: []
@@ -126,10 +135,11 @@ signing_key:
126
135
  specification_version: 4
127
136
  summary: Enables Vagrant to manage machines in Openstack Cloud.
128
137
  test_files:
129
- - features/provision.feature
130
- - features/steps/sdk_steps.rb
131
- - features/steps/server_steps.rb
132
- - features/support/env.rb
133
- - features/support/fog_mock.rb
134
- - features/vagrant-openstack-provider.feature
135
- - spec/vagrant-openstack/config_spec.rb
138
+ - spec/vagrant-openstack-provider/action/create_server_spec.rb
139
+ - spec/vagrant-openstack-provider/client/keystone_spec.rb
140
+ - spec/vagrant-openstack-provider/client/neutron_spec.rb
141
+ - spec/vagrant-openstack-provider/client/nova_spec.rb
142
+ - spec/vagrant-openstack-provider/client/utils_spec.rb
143
+ - spec/vagrant-openstack-provider/config_spec.rb
144
+ - spec/vagrant-openstack-provider/provider_spec.rb
145
+ - spec/vagrant-openstack-provider/spec_helper.rb