vagrant-openstack-provider 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/CHANGELOG.md +22 -0
  4. data/Gemfile +8 -15
  5. data/Vagrantfile +12 -10
  6. data/gemfiles/latest_stable.gemfile +6 -16
  7. data/gemfiles/minimal_release.gemfile +10 -0
  8. data/gemfiles/previous_release.gemfile +6 -16
  9. data/lib/vagrant-openstack-provider/action/connect_openstack.rb +2 -1
  10. data/lib/vagrant-openstack-provider/action/create_server.rb +40 -248
  11. data/lib/vagrant-openstack-provider/action/read_ssh_info.rb +30 -29
  12. data/lib/vagrant-openstack-provider/action/sync_folders.rb +19 -9
  13. data/lib/vagrant-openstack-provider/action/wait_accessible.rb +58 -0
  14. data/lib/vagrant-openstack-provider/action/wait_active.rb +5 -3
  15. data/lib/vagrant-openstack-provider/action/wait_stop.rb +5 -3
  16. data/lib/vagrant-openstack-provider/action.rb +19 -11
  17. data/lib/vagrant-openstack-provider/client/http_utils.rb +3 -2
  18. data/lib/vagrant-openstack-provider/client/neutron.rb +11 -1
  19. data/lib/vagrant-openstack-provider/client/nova.rb +49 -30
  20. data/lib/vagrant-openstack-provider/command/abstract_command.rb +10 -1
  21. data/lib/vagrant-openstack-provider/command/flavor_list.rb +1 -1
  22. data/lib/vagrant-openstack-provider/command/floatingip_list.rb +1 -1
  23. data/lib/vagrant-openstack-provider/command/image_list.rb +1 -1
  24. data/lib/vagrant-openstack-provider/command/main.rb +2 -1
  25. data/lib/vagrant-openstack-provider/command/network_list.rb +8 -2
  26. data/lib/vagrant-openstack-provider/command/reset.rb +21 -0
  27. data/lib/vagrant-openstack-provider/command/utils.rb +1 -1
  28. data/lib/vagrant-openstack-provider/command/volume_list.rb +1 -1
  29. data/lib/vagrant-openstack-provider/config.rb +16 -1
  30. data/lib/vagrant-openstack-provider/config_resolver.rb +262 -0
  31. data/lib/vagrant-openstack-provider/errors.rb +40 -0
  32. data/lib/vagrant-openstack-provider/plugin.rb +3 -3
  33. data/lib/vagrant-openstack-provider/utils.rb +21 -0
  34. data/lib/vagrant-openstack-provider/version.rb +1 -1
  35. data/locales/en.yml +35 -1
  36. data/spec/vagrant-openstack-provider/action/create_server_spec.rb +121 -368
  37. data/spec/vagrant-openstack-provider/action/delete_server_spec.rb +54 -0
  38. data/spec/vagrant-openstack-provider/action/message_spec.rb +34 -0
  39. data/spec/vagrant-openstack-provider/action/read_ssh_info_spec.rb +34 -17
  40. data/spec/vagrant-openstack-provider/action/read_state_spec.rb +70 -0
  41. data/spec/vagrant-openstack-provider/action/resume_server_spec.rb +50 -0
  42. data/spec/vagrant-openstack-provider/action/start_server_spec.rb +50 -0
  43. data/spec/vagrant-openstack-provider/action/stop_server_spec.rb +50 -0
  44. data/spec/vagrant-openstack-provider/action/suspend_server_spec.rb +50 -0
  45. data/spec/vagrant-openstack-provider/action/sync_folders_spec.rb +155 -0
  46. data/spec/vagrant-openstack-provider/action/wait_accessible_spec.rb +68 -0
  47. data/spec/vagrant-openstack-provider/action/wait_active_spec.rb +47 -0
  48. data/spec/vagrant-openstack-provider/action/wait_stop_spec.rb +47 -0
  49. data/spec/vagrant-openstack-provider/action_spec.rb +121 -0
  50. data/spec/vagrant-openstack-provider/client/cinder_spec.rb +1 -1
  51. data/spec/vagrant-openstack-provider/client/keystone_spec.rb +1 -1
  52. data/spec/vagrant-openstack-provider/client/neutron_spec.rb +37 -1
  53. data/spec/vagrant-openstack-provider/client/nova_spec.rb +60 -7
  54. data/spec/vagrant-openstack-provider/client/utils_spec.rb +1 -1
  55. data/spec/vagrant-openstack-provider/command/flavor_list_spec.rb +44 -0
  56. data/spec/vagrant-openstack-provider/command/floatingip_list_spec.rb +19 -2
  57. data/spec/vagrant-openstack-provider/command/image_list_spec.rb +48 -0
  58. data/spec/vagrant-openstack-provider/command/network_list_spec.rb +67 -0
  59. data/spec/vagrant-openstack-provider/command/reset_spec.rb +25 -0
  60. data/spec/vagrant-openstack-provider/command/volume_list_spec.rb +10 -2
  61. data/spec/vagrant-openstack-provider/config_resolver_spec.rb +680 -0
  62. data/spec/vagrant-openstack-provider/config_spec.rb +15 -1
  63. data/spec/vagrant-openstack-provider/spec_helper.rb +3 -0
  64. data/spec/vagrant-openstack-provider/utils_spec.rb +103 -0
  65. data/vagrant-openstack-provider.gemspec +4 -2
  66. metadata +78 -11
  67. data/Appraisals +0 -13
  68. data/gemfiles/oldest_current.gemfile +0 -20
@@ -0,0 +1,54 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::DeleteServer do
4
+
5
+ let(:nova) do
6
+ double('nova').tap do |app|
7
+ app.stub(:delete_server)
8
+ app.stub(:delete_keypair_if_vagrant)
9
+ end
10
+ end
11
+
12
+ let(:openstack_client) do
13
+ double('openstack_client').tap do |os|
14
+ os.stub(:nova) { nova }
15
+ end
16
+ end
17
+
18
+ let(:env) do
19
+ Hash.new.tap do |env|
20
+ env[:ui] = double('ui')
21
+ env[:ui].stub(:info).with(anything)
22
+ env[:ui].stub(:error).with(anything)
23
+ env[:openstack_client] = openstack_client
24
+ env[:machine] = OpenStruct.new.tap do |m|
25
+ m.id = 'server_id'
26
+ end
27
+ end
28
+ end
29
+
30
+ let(:app) do
31
+ double('app').tap do |app|
32
+ app.stub(:call).with(anything)
33
+ end
34
+ end
35
+
36
+ describe 'call' do
37
+ context 'when id is present' do
38
+ it 'delete server' do
39
+ expect(nova).to receive(:delete_server).with(env, 'server_id')
40
+ expect(nova).to receive(:delete_keypair_if_vagrant).with(env, 'server_id')
41
+ @action = DeleteServer.new(app, nil)
42
+ @action.call(env)
43
+ end
44
+ end
45
+ context 'when id is not present' do
46
+ it 'delete server' do
47
+ expect(nova).should_not_receive(:delete_server)
48
+ expect(nova).should_not_receive(:delete_keypair_if_vagrant)
49
+ @action = DeleteServer.new(app, nil)
50
+ @action.call(env)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::Message do
4
+
5
+ let(:ui) do
6
+ double('ui').tap do |ui|
7
+ ui.stub(:info).with(anything)
8
+ ui.stub(:error).with(anything)
9
+ end
10
+ end
11
+
12
+ let(:env) do
13
+ Hash.new.tap do |env|
14
+ env[:ui] = ui
15
+ end
16
+ end
17
+
18
+ let(:app) do
19
+ double('app').tap do |app|
20
+ app.stub(:call).with(anything)
21
+ end
22
+ end
23
+
24
+ describe 'call' do
25
+ context 'when message is given' do
26
+ it 'print out the message' do
27
+ expect(ui).to receive(:info).with('Message to show')
28
+ expect(app).to receive(:call)
29
+ @action = Message.new(app, nil, 'Message to show')
30
+ @action.call(env)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -19,14 +19,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
19
19
  config.stub(:floating_ip_pool) { nil }
20
20
  config.stub(:keypair_name) { nil }
21
21
  config.stub(:public_key_path) { nil }
22
- end
23
- end
24
-
25
- let(:neutron) do
26
- double('neutron').tap do |neutron|
27
- neutron.stub(:get_private_networks).with(anything) do
28
- [Item.new('net-id-1', 'net-1'), Item.new('net-id-2', 'net-2')]
29
- end
22
+ config.stub(:ssh_disabled) { false }
30
23
  end
31
24
  end
32
25
 
@@ -66,9 +59,27 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
66
59
  end
67
60
  end
68
61
 
62
+ let(:app) do
63
+ double('app').tap do |app|
64
+ app.stub(:call).with(anything)
65
+ end
66
+ end
67
+
69
68
  before :each do
70
69
  ReadSSHInfo.send(:public, *ReadSSHInfo.private_instance_methods)
71
- @action = ReadSSHInfo.new(nil, nil)
70
+ @action = ReadSSHInfo.new(app, env)
71
+ end
72
+
73
+ describe 'call' do
74
+ context 'when called three times' do
75
+ it 'read ssh info only once' do
76
+ config.stub(:keypair_name) { 'my_keypair' }
77
+ @action.stub(:read_ssh_info) { { host: '', port: '', username: '' } }
78
+ expect(@action).to receive(:read_ssh_info).exactly(1).times
79
+ expect(app).to receive(:call)
80
+ (1..3).each { @action.call(env) }
81
+ end
82
+ end
72
83
  end
73
84
 
74
85
  describe 'read_ssh_info' do
@@ -79,7 +90,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
79
90
  config.stub(:ssh_username) { 'test_username' }
80
91
  config.stub(:floating_ip) { '80.80.80.80' }
81
92
  config.stub(:keypair_name) { 'my_keypair' }
82
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser')
93
+ @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser', log_level: 'ERROR')
83
94
  end
84
95
  end
85
96
  context 'without ssh.username specified' do
@@ -88,7 +99,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
88
99
  config.stub(:ssh_username) { 'test_username' }
89
100
  config.stub(:floating_ip) { '80.80.80.80' }
90
101
  config.stub(:keypair_name) { 'my_keypair' }
91
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'test_username')
102
+ @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'test_username', log_level: 'ERROR')
92
103
  end
93
104
  end
94
105
  end
@@ -98,7 +109,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
98
109
  ssh_config.stub(:port) { 33 }
99
110
  config.stub(:floating_ip) { '80.80.80.80' }
100
111
  config.stub(:keypair_name) { 'my_keypair' }
101
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 33, username: 'sshuser')
112
+ @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 33, username: 'sshuser', log_level: 'ERROR')
102
113
  end
103
114
  end
104
115
 
@@ -107,7 +118,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
107
118
  it 'returns the specified floating ip' do
108
119
  config.stub(:floating_ip) { '80.80.80.80' }
109
120
  config.stub(:keypair_name) { 'my_keypair' }
110
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser')
121
+ @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser', log_level: 'ERROR')
111
122
  end
112
123
  end
113
124
 
@@ -116,7 +127,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
116
127
  config.stub(:floating_ip) { '80.80.80.80' }
117
128
  config.stub(:keypair_name) { nil }
118
129
  config.stub(:public_key_path) { '/public/key/path' }
119
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser')
130
+ @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser', log_level: 'ERROR')
120
131
  end
121
132
  end
122
133
 
@@ -125,8 +136,14 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
125
136
  config.stub(:floating_ip) { '80.80.80.80' }
126
137
  config.stub(:keypair_name) { nil }
127
138
  config.stub(:public_key_path) { nil }
128
- @action.stub(:get_keypair_name) { 'my_keypair_name' }
129
- @action.read_ssh_info(env).should eq(host: '80.80.80.80', port: 22, username: 'sshuser', private_key_path: '/data/dir/my_keypair_name')
139
+ nova.stub(:get_server_details) { { 'key_name' => 'my_keypair_name' } }
140
+ expect(nova).to receive(:get_server_details).with(env, '1234')
141
+ @action.read_ssh_info(env).should eq(
142
+ host: '80.80.80.80',
143
+ port: 22,
144
+ username: 'sshuser',
145
+ private_key_path: '/data/dir/my_keypair_name',
146
+ log_level: 'ERROR')
130
147
  end
131
148
  end
132
149
  end
@@ -146,7 +163,7 @@ describe VagrantPlugins::Openstack::Action::ReadSSHInfo do
146
163
  }
147
164
  end
148
165
  config.stub(:keypair_name) { 'my_keypair' }
149
- @action.read_ssh_info(env).should eq(host: '12.12.12.12', port: 22, username: 'sshuser')
166
+ @action.read_ssh_info(env).should eq(host: '12.12.12.12', port: 22, username: 'sshuser', log_level: 'ERROR')
150
167
  end
151
168
  end
152
169
  end
@@ -0,0 +1,70 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::ReadState do
4
+
5
+ let(:nova) do
6
+ double('nova')
7
+ end
8
+
9
+ let(:env) do
10
+ Hash.new.tap do |env|
11
+ env[:ui] = double('ui').tap do |ui|
12
+ ui.stub(:info).with(anything)
13
+ ui.stub(:error).with(anything)
14
+ end
15
+ env[:openstack_client] = double('openstack_client').tap do |os|
16
+ os.stub(:nova) { nova }
17
+ end
18
+ env[:machine] = OpenStruct.new
19
+ end
20
+ end
21
+
22
+ let(:app) do
23
+ double('app').tap do |app|
24
+ app.stub(:call).with(anything)
25
+ end
26
+ end
27
+
28
+ describe 'call' do
29
+ context 'when server id is present' do
30
+ it 'set the state to the one returned by nova' do
31
+ env[:machine].id = 'server_id'
32
+ nova.stub(:get_server_details).and_return('status' => 'ACTIVE')
33
+
34
+ expect(nova).to receive(:get_server_details).with(env, 'server_id')
35
+ expect(app).to receive(:call)
36
+
37
+ @action = ReadState.new(app, nil)
38
+ @action.call(env)
39
+
40
+ expect(env[:machine_state_id]).to eq(:active)
41
+ end
42
+ end
43
+ context 'when server id is not present' do
44
+ it 'set the state to :not_created' do
45
+ env[:machine].id = nil
46
+ expect(nova).to_not receive(:get_server_details)
47
+ expect(app).to receive(:call)
48
+
49
+ @action = ReadState.new(app, nil)
50
+ @action.call(env)
51
+
52
+ expect(env[:machine_state_id]).to eq(:not_created)
53
+ end
54
+ end
55
+ context 'when server cannot be found' do
56
+ it 'set the state to :not_created' do
57
+ env[:machine].id = 'server_id'
58
+ nova.stub(:get_server_details).and_return(nil)
59
+
60
+ expect(nova).to receive(:get_server_details).with(env, 'server_id')
61
+ expect(app).to receive(:call)
62
+
63
+ @action = ReadState.new(app, nil)
64
+ @action.call(env)
65
+
66
+ expect(env[:machine_state_id]).to eq(:not_created)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,50 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::Resume do
4
+
5
+ let(:nova) do
6
+ double('nova').tap do |nova|
7
+ nova.stub(:resume_server)
8
+ end
9
+ end
10
+
11
+ let(:env) do
12
+ Hash.new.tap do |env|
13
+ env[:ui] = double('ui').tap do |ui|
14
+ ui.stub(:info).with(anything)
15
+ ui.stub(:error).with(anything)
16
+ end
17
+ env[:openstack_client] = double('openstack_client').tap do |os|
18
+ os.stub(:nova) { nova }
19
+ end
20
+ env[:machine] = OpenStruct.new
21
+ end
22
+ end
23
+
24
+ let(:app) do
25
+ double('app').tap do |app|
26
+ app.stub(:call).with(anything)
27
+ end
28
+ end
29
+
30
+ describe 'call' do
31
+ context 'when server id is present' do
32
+ it 'starts the server' do
33
+ env[:machine].id = 'server_id'
34
+ expect(nova).to receive(:resume_server).with(env, 'server_id')
35
+ expect(app).to receive(:call)
36
+ @action = Resume.new(app, nil)
37
+ @action.call(env)
38
+ end
39
+ end
40
+ context 'when server id is not present' do
41
+ it 'does nothing' do
42
+ env[:machine].id = nil
43
+ expect(nova).to_not receive(:resume_server)
44
+ expect(app).to receive(:call)
45
+ @action = Resume.new(app, nil)
46
+ @action.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::StartServer do
4
+
5
+ let(:nova) do
6
+ double('nova').tap do |nova|
7
+ nova.stub(:start_server)
8
+ end
9
+ end
10
+
11
+ let(:env) do
12
+ Hash.new.tap do |env|
13
+ env[:ui] = double('ui').tap do |ui|
14
+ ui.stub(:info).with(anything)
15
+ ui.stub(:error).with(anything)
16
+ end
17
+ env[:openstack_client] = double('openstack_client').tap do |os|
18
+ os.stub(:nova) { nova }
19
+ end
20
+ env[:machine] = OpenStruct.new
21
+ end
22
+ end
23
+
24
+ let(:app) do
25
+ double('app').tap do |app|
26
+ app.stub(:call).with(anything)
27
+ end
28
+ end
29
+
30
+ describe 'call' do
31
+ context 'when server id is present' do
32
+ it 'starts the server' do
33
+ env[:machine].id = 'server_id'
34
+ expect(nova).to receive(:start_server).with(env, 'server_id')
35
+ expect(app).to receive(:call)
36
+ @action = StartServer.new(app, nil)
37
+ @action.call(env)
38
+ end
39
+ end
40
+ context 'when server id is not present' do
41
+ it 'does nothing' do
42
+ env[:machine].id = nil
43
+ expect(nova).to_not receive(:start_server)
44
+ expect(app).to receive(:call)
45
+ @action = StartServer.new(app, nil)
46
+ @action.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::StopServer do
4
+
5
+ let(:nova) do
6
+ double('nova').tap do |nova|
7
+ nova.stub(:stop_server)
8
+ end
9
+ end
10
+
11
+ let(:env) do
12
+ Hash.new.tap do |env|
13
+ env[:ui] = double('ui').tap do |ui|
14
+ ui.stub(:info).with(anything)
15
+ ui.stub(:error).with(anything)
16
+ end
17
+ env[:openstack_client] = double('openstack_client').tap do |os|
18
+ os.stub(:nova) { nova }
19
+ end
20
+ env[:machine] = OpenStruct.new
21
+ end
22
+ end
23
+
24
+ let(:app) do
25
+ double('app').tap do |app|
26
+ app.stub(:call).with(anything)
27
+ end
28
+ end
29
+
30
+ describe 'call' do
31
+ context 'when server id is present' do
32
+ it 'stops the server' do
33
+ env[:machine].id = 'server_id'
34
+ expect(nova).to receive(:stop_server).with(env, 'server_id')
35
+ expect(app).to receive(:call)
36
+ @action = StopServer.new(app, nil)
37
+ @action.call(env)
38
+ end
39
+ end
40
+ context 'when server id is not present' do
41
+ it 'does nothing' do
42
+ env[:machine].id = nil
43
+ expect(nova).to_not receive(:stop_server)
44
+ expect(app).to receive(:call)
45
+ @action = StopServer.new(app, nil)
46
+ @action.call(env)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::Suspend do
4
+
5
+ let(:nova) do
6
+ double('nova').tap do |nova|
7
+ nova.stub(:suspend_server)
8
+ end
9
+ end
10
+
11
+ let(:env) do
12
+ Hash.new.tap do |env|
13
+ env[:ui] = double('ui').tap do |ui|
14
+ ui.stub(:info).with(anything)
15
+ ui.stub(:error).with(anything)
16
+ end
17
+ env[:openstack_client] = double('openstack_client').tap do |os|
18
+ os.stub(:nova) { nova }
19
+ end
20
+ env[:machine] = OpenStruct.new
21
+ end
22
+ end
23
+
24
+ let(:app) do
25
+ double('app').tap do |app|
26
+ app.stub(:call).with(anything)
27
+ end
28
+ end
29
+
30
+ describe 'call' do
31
+ context 'when server id is present' do
32
+ it 'starts the server' do
33
+ env[:machine].id = 'server_id'
34
+ expect(nova).to receive(:suspend_server).with(env, 'server_id')
35
+ expect(app).to receive(:call)
36
+ @action = Suspend.new(app, nil)
37
+ @action.call(env)
38
+ end
39
+ end
40
+ context 'when server id is not present' do
41
+ it 'does nothing' do
42
+ env[:machine].id = nil
43
+ expect(nova).to_not receive(:suspend_server)
44
+ expect(app).to receive(:call)
45
+ @action = Suspend.new(app, nil)
46
+ @action.call(env)
47
+ end
48
+ end
49
+ end
50
+ end