vagrant-openstack-provider 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +8 -8
  2. data/Appraisals +6 -6
  3. data/CHANGELOG.md +44 -1
  4. data/Gemfile +10 -6
  5. data/Vagrantfile +7 -15
  6. data/functional_tests/Vagrantfile +58 -0
  7. data/functional_tests/keys/vagrant-openstack +27 -0
  8. data/functional_tests/keys/vagrant-openstack.pub +1 -0
  9. data/functional_tests/run_tests.sh +142 -0
  10. data/gemfiles/latest_stable.gemfile +5 -0
  11. data/gemfiles/oldest_current.gemfile +5 -0
  12. data/gemfiles/previous_release.gemfile +5 -0
  13. data/lib/vagrant-openstack-provider/action.rb +17 -2
  14. data/lib/vagrant-openstack-provider/action/connect_openstack.rb +60 -8
  15. data/lib/vagrant-openstack-provider/action/create_server.rb +131 -43
  16. data/lib/vagrant-openstack-provider/action/delete_server.rb +2 -0
  17. data/lib/vagrant-openstack-provider/action/read_ssh_info.rb +22 -3
  18. data/lib/vagrant-openstack-provider/action/resume.rb +2 -0
  19. data/lib/vagrant-openstack-provider/action/stop_server.rb +1 -0
  20. data/lib/vagrant-openstack-provider/action/suspend.rb +2 -0
  21. data/lib/vagrant-openstack-provider/action/sync_folders.rb +3 -2
  22. data/lib/vagrant-openstack-provider/action/wait_active.rb +29 -0
  23. data/lib/vagrant-openstack-provider/action/wait_stop.rb +1 -1
  24. data/lib/vagrant-openstack-provider/client/domain.rb +26 -0
  25. data/lib/vagrant-openstack-provider/client/http_utils.rb +96 -0
  26. data/lib/vagrant-openstack-provider/client/keystone.rb +30 -41
  27. data/lib/vagrant-openstack-provider/client/neutron.rb +24 -11
  28. data/lib/vagrant-openstack-provider/client/nova.rb +99 -104
  29. data/lib/vagrant-openstack-provider/client/openstack.rb +4 -0
  30. data/lib/vagrant-openstack-provider/client/request_logger.rb +24 -0
  31. data/lib/vagrant-openstack-provider/command/abstract_command.rb +31 -0
  32. data/lib/vagrant-openstack-provider/command/flavor_list.rb +21 -0
  33. data/lib/vagrant-openstack-provider/command/floatingip_list.rb +34 -0
  34. data/lib/vagrant-openstack-provider/command/image_list.rb +21 -0
  35. data/lib/vagrant-openstack-provider/command/main.rb +51 -0
  36. data/lib/vagrant-openstack-provider/command/network_list.rb +21 -0
  37. data/lib/vagrant-openstack-provider/command/utils.rb +22 -0
  38. data/lib/vagrant-openstack-provider/config.rb +31 -3
  39. data/lib/vagrant-openstack-provider/errors.rb +28 -0
  40. data/lib/vagrant-openstack-provider/plugin.rb +5 -0
  41. data/lib/vagrant-openstack-provider/version.rb +1 -1
  42. data/locales/en.yml +45 -1
  43. data/spec/vagrant-openstack-provider/action/connect_openstack_spec.rb +190 -0
  44. data/spec/vagrant-openstack-provider/action/create_server_spec.rb +166 -1
  45. data/spec/vagrant-openstack-provider/action/read_ssh_info_spec.rb +109 -0
  46. data/spec/vagrant-openstack-provider/client/keystone_spec.rb +32 -48
  47. data/spec/vagrant-openstack-provider/client/neutron_spec.rb +42 -4
  48. data/spec/vagrant-openstack-provider/client/nova_spec.rb +247 -6
  49. data/spec/vagrant-openstack-provider/client/utils_spec.rb +58 -5
  50. data/spec/vagrant-openstack-provider/command/floatingip_list_spec.rb +67 -0
  51. data/spec/vagrant-openstack-provider/config_spec.rb +21 -6
  52. data/spec/vagrant-openstack-provider/spec_helper.rb +7 -0
  53. data/{numergyrc → stackrc} +4 -1
  54. metadata +24 -4
  55. data/lib/vagrant-openstack-provider/client/utils.rb +0 -38
@@ -2,7 +2,7 @@ require 'vagrant-openstack-provider/spec_helper'
2
2
 
3
3
  include VagrantPlugins::Openstack
4
4
 
5
- describe VagrantPlugins::Openstack::Utils do
5
+ describe VagrantPlugins::Openstack::HttpUtils do
6
6
 
7
7
  let(:keystone) do
8
8
  double('keystone').tap do |keystone|
@@ -20,8 +20,11 @@ describe VagrantPlugins::Openstack::Utils do
20
20
  end
21
21
 
22
22
  class TestUtils
23
- include VagrantPlugins::Openstack::Utils
23
+ include VagrantPlugins::Openstack::HttpUtils
24
24
  include VagrantPlugins::Openstack::Errors
25
+
26
+ attr_writer :logger
27
+
25
28
  def target(env)
26
29
  authenticated(env) do
27
30
  env[:target].call
@@ -36,7 +39,12 @@ describe VagrantPlugins::Openstack::Utils do
36
39
  describe 'authenticated' do
37
40
 
38
41
  before :each do
42
+ TestUtils.send(:public, *TestUtils.private_instance_methods)
39
43
  @utils = TestUtils.new
44
+ @utils.logger = double.tap do |logger|
45
+ logger.stub(:debug)
46
+ logger.stub(:info)
47
+ end
40
48
  end
41
49
 
42
50
  context 'with two authentication errors' do
@@ -72,13 +80,21 @@ describe VagrantPlugins::Openstack::Utils do
72
80
 
73
81
  describe 'handle_response' do
74
82
  before :each do
83
+ TestUtils.send(:public, *TestUtils.private_instance_methods)
75
84
  @utils = TestUtils.new
85
+ @utils.logger = double.tap do |logger|
86
+ logger.stub(:debug)
87
+ logger.stub(:info)
88
+ end
76
89
  end
77
90
 
78
91
  [200, 201, 202, 204].each do |code|
79
92
  context "response code is #{code}" do
80
93
  it 'should return the response' do
81
- mock_resp = double.tap { |mock| mock.stub(:code).and_return(code) }
94
+ mock_resp = double.tap do |mock|
95
+ mock.stub(:code).and_return(code)
96
+ mock.stub(:headers)
97
+ end
82
98
  resp = @utils.handle_response(mock_resp)
83
99
  expect(resp.code).to eq(code)
84
100
  end
@@ -87,15 +103,19 @@ describe VagrantPlugins::Openstack::Utils do
87
103
 
88
104
  context 'response code is 401' do
89
105
  it 'should return raise a AuthenticationRequired error' do
90
- mock_resp = double.tap { |mock| mock.stub(:code).and_return(401) }
106
+ mock_resp = double.tap do |mock|
107
+ mock.stub(:code).and_return(401)
108
+ mock.stub(:headers)
109
+ end
91
110
  expect { @utils.handle_response(mock_resp) }.to raise_error Errors::AuthenticationRequired
92
111
  end
93
112
  end
94
113
 
95
114
  context 'response code is 400' do
96
- it 'should return raise a VagrantOpenstackError error with error message' do
115
+ it 'should return raise a VagrantOpenstackError with bad request message' do
97
116
  mock_resp = double.tap do |mock|
98
117
  mock.stub(:code).and_return(400)
118
+ mock.stub(:headers)
99
119
  mock.stub(:to_s).and_return('{ "badRequest": { "message": "Error... Bad request" } }')
100
120
  end
101
121
  begin
@@ -107,10 +127,43 @@ describe VagrantPlugins::Openstack::Utils do
107
127
  end
108
128
  end
109
129
 
130
+ context 'response code is 404' do
131
+ it 'should return raise a VagrantOpenstackError with conflict message' do
132
+ mock_resp = double.tap do |mock|
133
+ mock.stub(:code).and_return(404)
134
+ mock.stub(:headers)
135
+ mock.stub(:to_s).and_return('{ "itemNotFound": { "message": "Error... Not found" } }')
136
+ end
137
+ begin
138
+ @utils.handle_response(mock_resp)
139
+ fail
140
+ rescue Errors::VagrantOpenstackError => e
141
+ expect(e.message).to eq('Error... Not found')
142
+ end
143
+ end
144
+ end
145
+
146
+ context 'response code is 409' do
147
+ it 'should return raise a VagrantOpenstackError with conflict message' do
148
+ mock_resp = double.tap do |mock|
149
+ mock.stub(:code).and_return(409)
150
+ mock.stub(:headers)
151
+ mock.stub(:to_s).and_return('{ "conflictingRequest": { "message": "Error... Conflict" } }')
152
+ end
153
+ begin
154
+ @utils.handle_response(mock_resp)
155
+ fail
156
+ rescue Errors::VagrantOpenstackError => e
157
+ expect(e.message).to eq('Error... Conflict')
158
+ end
159
+ end
160
+ end
161
+
110
162
  context 'response code is 500' do
111
163
  it 'should return raise a VagrantOpenstackError error with error message' do
112
164
  mock_resp = double.tap do |mock|
113
165
  mock.stub(:code).and_return(500)
166
+ mock.stub(:headers)
114
167
  mock.stub(:to_s).and_return('Internal server error')
115
168
  end
116
169
  begin
@@ -0,0 +1,67 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Command::FloatingIpList do
4
+ describe 'cmd' do
5
+
6
+ let(:config) do
7
+ double('config').tap do |config|
8
+ config.stub(:openstack_auth_url) { 'http://keystoneAuthV2' }
9
+ config.stub(:openstack_compute_url) { nil }
10
+ config.stub(:openstack_network_url) { nil }
11
+ config.stub(:tenant_name) { 'testTenant' }
12
+ config.stub(:username) { 'username' }
13
+ config.stub(:password) { 'password' }
14
+ end
15
+ end
16
+
17
+ let(:nova) do
18
+ double('nova').tap do |nova|
19
+ nova.stub(:get_floating_ip_pools) do
20
+ [
21
+ {
22
+ 'name' => 'pool1'
23
+ },
24
+ {
25
+ 'name' => 'pool2'
26
+ }
27
+ ]
28
+ end
29
+ nova.stub(:get_floating_ips) do
30
+ [
31
+ {
32
+ 'fixed_ip' => nil,
33
+ 'id' => 1,
34
+ 'instance_id' => nil,
35
+ 'ip' => '10.10.10.1',
36
+ 'pool' => 'pool1'
37
+ },
38
+ {
39
+ 'fixed_ip' => nil,
40
+ 'id' => 2,
41
+ 'instance_id' => 'inst001',
42
+ 'ip' => '10.10.10.2',
43
+ 'pool' => 'pool2'
44
+ }
45
+ ]
46
+ end
47
+ end
48
+ end
49
+
50
+ let(:env) do
51
+ Hash.new.tap do |env|
52
+ env[:ui] = double('ui')
53
+ env[:ui].stub(:info).with(anything)
54
+ env[:openstack_client] = double
55
+ env[:openstack_client].stub(:nova) { nova }
56
+ end
57
+ end
58
+
59
+ before :each do
60
+ @floating_ip_list_cmd = VagrantPlugins::Openstack::Command::FloatingIpList.new(nil, env)
61
+ end
62
+
63
+ it 'should get floating ip and floating ip pool from server' do
64
+ @floating_ip_list_cmd.cmd('floatingip-list', ['--'], env)
65
+ end
66
+ end
67
+ end
@@ -19,6 +19,8 @@ describe VagrantPlugins::Openstack::Config do
19
19
  its(:username) { should be_nil }
20
20
  its(:rsync_includes) { should be_nil }
21
21
  its(:keypair_name) { should be_nil }
22
+ its(:public_key_path) { should be_nil }
23
+ its(:availability_zone) { should be_nil }
22
24
  its(:ssh_username) { should be_nil }
23
25
  end
24
26
 
@@ -32,7 +34,9 @@ describe VagrantPlugins::Openstack::Config do
32
34
  :server_name,
33
35
  :username,
34
36
  :keypair_name,
35
- :ssh_username].each do |attribute|
37
+ :ssh_username,
38
+ :availability_zone,
39
+ :public_key_path].each do |attribute|
36
40
  it "should not default #{attribute} if overridden" do
37
41
  subject.send("#{attribute}=".to_sym, 'foo')
38
42
  subject.finalize!
@@ -53,8 +57,15 @@ describe VagrantPlugins::Openstack::Config do
53
57
  let(:validation_errors) { subject.validate(machine)['Openstack Provider'] }
54
58
  let(:error_message) { double('error message') }
55
59
 
60
+ let(:config) { double('config') }
61
+ let(:ssh) { double('ssh') }
62
+
56
63
  before(:each) do
64
+ error_message.stub(:yellow) { 'Yellowed Error message ' }
57
65
  machine.stub_chain(:env, :root_path).and_return '/'
66
+ ssh.stub(:private_key_path) { 'private key path' }
67
+ config.stub(:ssh) { ssh }
68
+ machine.stub(:config) { config }
58
69
  subject.username = 'foo'
59
70
  subject.password = 'bar'
60
71
  subject.keypair_name = 'keypair'
@@ -74,17 +85,21 @@ describe VagrantPlugins::Openstack::Config do
74
85
  validation_errors.first.should == error_message
75
86
  end
76
87
  end
88
+
77
89
  context 'with good values' do
78
90
  it 'should validate' do
79
91
  validation_errors.should be_empty
80
92
  end
81
93
  end
82
94
 
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
95
+ context 'private_key_path is not set' do
96
+ context 'keypair_name or public_key_path is set' do
97
+ it 'should error if not given' do
98
+ ssh.stub(:private_key_path) { nil }
99
+ subject.public_key_path = 'public_key'
100
+ I18n.should_receive(:t).with('vagrant_openstack.config.private_key_missing').and_return error_message
101
+ validation_errors.first.should == error_message
102
+ end
88
103
  end
89
104
  end
90
105
 
@@ -16,8 +16,15 @@ Dir[
16
16
  'lib/vagrant-openstack-provider/errors.rb',
17
17
  'lib/vagrant-openstack-provider/provider.rb',
18
18
  'lib/vagrant-openstack-provider/client/*.rb',
19
+ 'lib/vagrant-openstack-provider/command/*.rb',
19
20
  'lib/vagrant-openstack-provider/action/*.rb'].each { |file| require file[4, file.length - 1] }
20
21
 
21
22
  require 'webmock/rspec'
23
+ require 'fakefs/safe'
24
+ require 'fakefs/spec_helpers'
25
+
26
+ RSpec.configure do |config|
27
+ config.include FakeFS::SpecHelpers, fakefs: true
28
+ end
22
29
 
23
30
  I18n.load_path << File.expand_path('locales/en.yml', Pathname.new(File.expand_path('../../../', __FILE__)))
@@ -1,7 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
+ #Provider examples:
4
+ #Numergy
3
5
  export OS_AUTH_URL=https://cloud.numergy.com/identity/v2.0/tokens
4
- export OS_COMPUTE_URL=https://cloud.numergy.com/compute/v2
6
+ export OS_NETWORK_URL=https://cloud.numergy.com/network/v2.0
7
+ #....
5
8
 
6
9
  if [ -z "$OS_USERNAME" ]; then
7
10
  echo "Please enter your OpenStack tenant name: "
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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Giamarchi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-26 00:00:00.000000000 Z
12
+ date: 2014-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -73,6 +73,10 @@ files:
73
73
  - dummy.box
74
74
  - example_box/README.md
75
75
  - example_box/metadata.json
76
+ - functional_tests/Vagrantfile
77
+ - functional_tests/keys/vagrant-openstack
78
+ - functional_tests/keys/vagrant-openstack.pub
79
+ - functional_tests/run_tests.sh
76
80
  - gemfiles/latest_stable.gemfile
77
81
  - gemfiles/oldest_current.gemfile
78
82
  - gemfiles/previous_release.gemfile
@@ -89,27 +93,40 @@ files:
89
93
  - lib/vagrant-openstack-provider/action/stop_server.rb
90
94
  - lib/vagrant-openstack-provider/action/suspend.rb
91
95
  - lib/vagrant-openstack-provider/action/sync_folders.rb
96
+ - lib/vagrant-openstack-provider/action/wait_active.rb
92
97
  - lib/vagrant-openstack-provider/action/wait_stop.rb
98
+ - lib/vagrant-openstack-provider/client/domain.rb
99
+ - lib/vagrant-openstack-provider/client/http_utils.rb
93
100
  - lib/vagrant-openstack-provider/client/keystone.rb
94
101
  - lib/vagrant-openstack-provider/client/neutron.rb
95
102
  - lib/vagrant-openstack-provider/client/nova.rb
96
103
  - lib/vagrant-openstack-provider/client/openstack.rb
97
- - lib/vagrant-openstack-provider/client/utils.rb
104
+ - lib/vagrant-openstack-provider/client/request_logger.rb
105
+ - lib/vagrant-openstack-provider/command/abstract_command.rb
106
+ - lib/vagrant-openstack-provider/command/flavor_list.rb
107
+ - lib/vagrant-openstack-provider/command/floatingip_list.rb
108
+ - lib/vagrant-openstack-provider/command/image_list.rb
109
+ - lib/vagrant-openstack-provider/command/main.rb
110
+ - lib/vagrant-openstack-provider/command/network_list.rb
111
+ - lib/vagrant-openstack-provider/command/utils.rb
98
112
  - lib/vagrant-openstack-provider/config.rb
99
113
  - lib/vagrant-openstack-provider/errors.rb
100
114
  - lib/vagrant-openstack-provider/plugin.rb
101
115
  - lib/vagrant-openstack-provider/provider.rb
102
116
  - lib/vagrant-openstack-provider/version.rb
103
117
  - locales/en.yml
104
- - numergyrc
118
+ - spec/vagrant-openstack-provider/action/connect_openstack_spec.rb
105
119
  - spec/vagrant-openstack-provider/action/create_server_spec.rb
120
+ - spec/vagrant-openstack-provider/action/read_ssh_info_spec.rb
106
121
  - spec/vagrant-openstack-provider/client/keystone_spec.rb
107
122
  - spec/vagrant-openstack-provider/client/neutron_spec.rb
108
123
  - spec/vagrant-openstack-provider/client/nova_spec.rb
109
124
  - spec/vagrant-openstack-provider/client/utils_spec.rb
125
+ - spec/vagrant-openstack-provider/command/floatingip_list_spec.rb
110
126
  - spec/vagrant-openstack-provider/config_spec.rb
111
127
  - spec/vagrant-openstack-provider/provider_spec.rb
112
128
  - spec/vagrant-openstack-provider/spec_helper.rb
129
+ - stackrc
113
130
  - vagrant-openstack-provider.gemspec
114
131
  homepage: https://github.com/ggiamarchi/vagrant-openstack
115
132
  licenses: []
@@ -135,11 +152,14 @@ signing_key:
135
152
  specification_version: 4
136
153
  summary: Enables Vagrant to manage machines in Openstack Cloud.
137
154
  test_files:
155
+ - spec/vagrant-openstack-provider/action/connect_openstack_spec.rb
138
156
  - spec/vagrant-openstack-provider/action/create_server_spec.rb
157
+ - spec/vagrant-openstack-provider/action/read_ssh_info_spec.rb
139
158
  - spec/vagrant-openstack-provider/client/keystone_spec.rb
140
159
  - spec/vagrant-openstack-provider/client/neutron_spec.rb
141
160
  - spec/vagrant-openstack-provider/client/nova_spec.rb
142
161
  - spec/vagrant-openstack-provider/client/utils_spec.rb
162
+ - spec/vagrant-openstack-provider/command/floatingip_list_spec.rb
143
163
  - spec/vagrant-openstack-provider/config_spec.rb
144
164
  - spec/vagrant-openstack-provider/provider_spec.rb
145
165
  - spec/vagrant-openstack-provider/spec_helper.rb
@@ -1,38 +0,0 @@
1
- require 'log4r'
2
- require 'restclient'
3
- require 'json'
4
-
5
- require 'vagrant-openstack-provider/client/keystone'
6
-
7
- module VagrantPlugins
8
- module Openstack
9
- module Utils
10
- def handle_response(response)
11
- case response.code
12
- when 200, 201, 202, 204
13
- response
14
- when 401
15
- fail Errors::AuthenticationRequired
16
- when 400
17
- fail Errors::VagrantOpenstackError, message: JSON.parse(response.to_s)['badRequest']['message']
18
- else
19
- fail Errors::VagrantOpenstackError, message: response.to_s
20
- end
21
- end
22
-
23
- def authenticated(env)
24
- nb_retry = 0
25
- begin
26
- return yield
27
- rescue Errors::AuthenticationRequired => e
28
- nb_retry += 1
29
- env[:ui].warn(e)
30
- env[:ui].warn(I18n.t('vagrant_openstack.trying_authentication'))
31
- env[:openstack_client].keystone.authenticate(env)
32
- retry if nb_retry < 3
33
- raise e
34
- end
35
- end
36
- end
37
- end
38
- end