vagrant-openstack-provider 0.4.1 → 0.5.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 (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,155 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+ require 'log4r'
3
+ require 'rbconfig'
4
+ require 'vagrant/util/subprocess'
5
+
6
+ include VagrantPlugins::Openstack::Action
7
+
8
+ describe VagrantPlugins::Openstack::Action::SyncFolders do
9
+
10
+ let(:app) do
11
+ double('app').tap do |app|
12
+ app.stub(:call).with(anything)
13
+ end
14
+ end
15
+
16
+ let(:vm) do
17
+ double('vm').tap do |vm|
18
+ vm.stub(:synced_folders) { { '/vagrant' => { hostpath: '/home/john/vagrant', guestpath: '/vagrant' } } }
19
+ end
20
+ end
21
+
22
+ let(:provider_config) do
23
+ double('provider_config').tap do |c|
24
+ c.stub(:rsync_includes) { nil }
25
+ c.stub(:ssh_disabled) { false }
26
+ end
27
+ end
28
+
29
+ let(:communicate) do
30
+ double('communicate').tap do |c|
31
+ c.stub(:sudo)
32
+ end
33
+ end
34
+
35
+ let(:env) do
36
+ Hash.new.tap do |env|
37
+ env[:ui] = double('ui').tap do |ui|
38
+ ui.stub(:info).with(anything)
39
+ ui.stub(:error).with(anything)
40
+ end
41
+ env[:openstack_client] = double('openstack_client').tap do |os|
42
+ os.stub(:nova) { nova }
43
+ end
44
+ env[:machine] = OpenStruct.new.tap do |m|
45
+ m.ssh_info = {
46
+ username: 'user',
47
+ port: '23',
48
+ host: '1.2.3.4',
49
+ private_key_path: '/tmp/key.pem'
50
+ }
51
+ m.provider_config = provider_config
52
+ m.config = double('config').tap do |c|
53
+ c.stub(:vm) { vm }
54
+ end
55
+ m.communicate = communicate
56
+ end
57
+ env[:root_path] = '.'
58
+ end
59
+ end
60
+
61
+ before :each do
62
+ @action = SyncFolders.new(app, nil)
63
+ end
64
+
65
+ describe 'call' do
66
+ context 'sync method is set to none and ssh_disabled is false' do
67
+ it 'does not sync folders' do
68
+ Vagrant::Util::Subprocess.stub(:execute)
69
+ provider_config.stub(:sync_method) { 'none' }
70
+ provider_config.stub(:ssh_disabled) { false }
71
+ expect(Vagrant::Util::Subprocess).to_not receive :execute
72
+ @action.call(env)
73
+ end
74
+ end
75
+ context 'sync method is set to none and ssh_disabled is true' do
76
+ it 'does not sync folders' do
77
+ Vagrant::Util::Subprocess.stub(:execute)
78
+ provider_config.stub(:sync_method) { 'none' }
79
+ provider_config.stub(:ssh_disabled) { true }
80
+ expect(Vagrant::Util::Subprocess).to_not receive :execute
81
+ @action.call(env)
82
+ end
83
+ end
84
+ context 'sync method is set to rsync and ssh_disabled is true' do
85
+ it 'does not sync folders' do
86
+ Vagrant::Util::Subprocess.stub(:execute)
87
+ provider_config.stub(:sync_method) { 'rsync' }
88
+ provider_config.stub(:ssh_disabled) { true }
89
+ expect(Vagrant::Util::Subprocess).to_not receive :execute
90
+ @action.call(env)
91
+ end
92
+ end
93
+ context 'sync method is set to rsync and ssh_disabled is false' do
94
+ it 'runs a rsync command' do
95
+ provider_config.stub(:sync_method) { 'rsync' }
96
+ Vagrant::Util::Subprocess.stub(:execute) do
97
+ OpenStruct.new.tap do |r|
98
+ r.exit_code = 0
99
+ r.stderr = nil
100
+ end
101
+ end
102
+ expected_command = ['rsync',
103
+ '--verbose',
104
+ '--archive',
105
+ '-z',
106
+ '--cvs-exclude',
107
+ '--exclude',
108
+ '.hg/',
109
+ '--exclude',
110
+ '.git/',
111
+ '--chmod',
112
+ 'ugo=rwX',
113
+ '-e',
114
+ "ssh -p 23 -o StrictHostKeyChecking=no -i '/tmp/key.pem' ",
115
+ '/home/john/vagrant/',
116
+ 'user@1.2.3.4:/vagrant',
117
+ '--exclude-from',
118
+ './.gitignore']
119
+ expect(communicate).to receive(:sudo).with "mkdir -p '/vagrant'"
120
+ expect(communicate).to receive(:sudo).with "chown -R user '/vagrant'"
121
+ expect(Vagrant::Util::Subprocess).to receive(:execute).with(*expected_command)
122
+ @action.call(env)
123
+ end
124
+ end
125
+ context 'rsync command returns a non zero status code' do
126
+ it 'raise an error' do
127
+ provider_config.stub(:sync_method) { 'rsync' }
128
+ Vagrant::Util::Subprocess.stub(:execute) do
129
+ OpenStruct.new.tap do |r|
130
+ r.exit_code = 1
131
+ r.stderr = 'Fatal error'
132
+ end
133
+ end
134
+ expect(Vagrant::Util::Subprocess).to receive(:execute)
135
+ expect { @action.call(env) }.to raise_error Errors::RsyncError
136
+ end
137
+ end
138
+ context 'sync method value is not valid' do
139
+ it 'raise an error' do
140
+ provider_config.stub(:sync_method) { 'nfs' }
141
+ expect { @action.call(env) }.to raise_error Errors::SyncMethodError
142
+ end
143
+ end
144
+ end
145
+
146
+ describe 'convert_path_to_windows_format' do
147
+ context 'hostpath in starting with C:/ ' do
148
+ it 'returns hostpath starting with /cygdrive/c/ and in downcase' do
149
+ RsyncFolders.send(:public, *RsyncFolders.private_instance_methods)
150
+ action = RsyncFolders.new(app, nil)
151
+ expect(action.add_cygdrive_prefix_to_path('C:/Directory')).to eq '/cygdrive/c/directory'
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,68 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::WaitForServerToBeAccessible do
4
+
5
+ let(:config) do
6
+ double('config')
7
+ end
8
+
9
+ let(:env) do
10
+ Hash.new.tap do |env|
11
+ env[:ui] = double('ui')
12
+ env[:ui].stub(:info).with(anything)
13
+ env[:ui].stub(:error).with(anything)
14
+ env[:machine] = double('machine').tap do |m|
15
+ m.stub(:provider_config) { config }
16
+ end
17
+ end
18
+ end
19
+
20
+ let(:resolver) do
21
+ double('resolver').tap do |r|
22
+ r.stub(:resolve_floating_ip).with(anything) { '1.2.3.4' }
23
+ end
24
+ end
25
+
26
+ let(:ssh) do
27
+ double('shh')
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
+ class SSHMock
37
+ def initialize(*exit_codes)
38
+ @times = 0
39
+ @exit_codes = exit_codes
40
+ end
41
+
42
+ def call(env)
43
+ env[:ssh_run_exit_status] = @exit_codes[@times]
44
+ @times += 1
45
+ end
46
+ end
47
+
48
+ describe 'call' do
49
+ context 'when server is not yet reachable' do
50
+ it 'retry until server is reachable' do
51
+ config.stub(:ssh_timeout) { 2 }
52
+ expect(app).to receive(:call)
53
+
54
+ @action = WaitForServerToBeAccessible.new(app, nil, resolver, SSHMock.new(1, 0))
55
+ @action.call(env)
56
+ end
57
+ end
58
+ context 'when server is not yet reachable after timeout' do
59
+ it 'raise an error' do
60
+ config.stub(:ssh_timeout) { 1 }
61
+ expect(app).should_not_receive(:call)
62
+
63
+ @action = WaitForServerToBeAccessible.new(app, nil, resolver, SSHMock.new(1, 1))
64
+ expect { @action.call(env) }.to raise_error Errors::SshUnavailable
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,47 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::WaitForServerToBeActive 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.tap do |m|
19
+ m.id = 'server_id'
20
+ end
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 is not yet active' do
32
+ it 'become active after one retry' do
33
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'ACTIVE' })
34
+ expect(nova).to receive(:get_server_details).with(env, 'server_id').exactly(2).times
35
+ expect(app).to receive(:call)
36
+ @action = WaitForServerToBeActive.new(app, nil, 1, 5)
37
+ @action.call(env)
38
+ end
39
+ it 'timeout after one retry' do
40
+ nova.stub(:get_server_details).and_return({ 'status' => 'BUILD' }, { 'status' => 'BUILD' })
41
+ expect(nova).to receive(:get_server_details).with(env, 'server_id').at_least(2).times
42
+ @action = WaitForServerToBeActive.new(app, nil, 1, 2)
43
+ expect { @action.call(env) }.to raise_error Timeout::Error
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action::WaitForServerToStop 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.tap do |m|
19
+ m.id = 'server_id'
20
+ end
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 is active' do
32
+ it 'become shutoff after one retry' do
33
+ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'SHUTOFF' })
34
+ expect(nova).to receive(:get_server_details).with(env, 'server_id').exactly(2).times
35
+ expect(app).to receive(:call)
36
+ @action = WaitForServerToStop.new(app, nil, 1, 5)
37
+ @action.call(env)
38
+ end
39
+ it 'timeout after one retry' do
40
+ nova.stub(:get_server_details).and_return({ 'status' => 'ACTIVE' }, { 'status' => 'ACTIVE' })
41
+ expect(nova).to receive(:get_server_details).with(env, 'server_id').at_least(2).times
42
+ @action = WaitForServerToStop.new(app, nil, 1, 2)
43
+ expect { @action.call(env) }.to raise_error Timeout::Error
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,121 @@
1
+ require 'vagrant-openstack-provider/spec_helper'
2
+
3
+ describe VagrantPlugins::Openstack::Action do
4
+
5
+ let(:builder) do
6
+ double('builder').tap do |builder|
7
+ builder.stub(:use)
8
+ end
9
+ end
10
+
11
+ before :each do
12
+ Action.stub(:new_builder) { builder }
13
+ end
14
+
15
+ describe 'action_destroy' do
16
+ it 'add others middleware to builder' do
17
+ expect(builder).to receive(:use).with(ConfigValidate)
18
+ expect(builder).to receive(:use).with(ConnectOpenstack)
19
+ expect(builder).to receive(:use).with(Call, ReadState)
20
+ # TODO, Impove this test to check what's happen after ReadState
21
+ Action.action_destroy
22
+ end
23
+ end
24
+
25
+ describe 'action_provision' do
26
+ it 'add others middleware to builder' do
27
+ expect(builder).to receive(:use).with(ConfigValidate)
28
+ expect(builder).to receive(:use).with(ConnectOpenstack)
29
+ expect(builder).to receive(:use).with(Call, ReadState)
30
+ # TODO, Impove this test to check what's happen after ReadState
31
+ Action.action_provision
32
+ end
33
+ end
34
+
35
+ describe 'action_read_ssh_info' do
36
+ it 'add others middleware to builder' do
37
+ expect(builder).to receive(:use).with(ConfigValidate)
38
+ expect(builder).to receive(:use).with(ConnectOpenstack)
39
+ expect(builder).to receive(:use).with(ReadSSHInfo)
40
+ Action.action_read_ssh_info
41
+ end
42
+ end
43
+
44
+ describe 'action_read_state' do
45
+ it 'add others middleware to builder' do
46
+ expect(builder).to receive(:use).with(ConfigValidate)
47
+ expect(builder).to receive(:use).with(ConnectOpenstack)
48
+ expect(builder).to receive(:use).with(ReadState)
49
+ Action.action_read_state
50
+ end
51
+ end
52
+
53
+ describe 'action_ssh' do
54
+ it 'add others middleware to builder' do
55
+ expect(builder).to receive(:use).with(ConfigValidate)
56
+ expect(builder).to receive(:use).with(ConnectOpenstack)
57
+ expect(builder).to receive(:use).with(Call, ReadState)
58
+ Action.action_ssh
59
+ end
60
+ end
61
+
62
+ describe 'action_ssh_run' do
63
+ it 'add others middleware to builder' do
64
+ expect(builder).to receive(:use).with(ConfigValidate)
65
+ expect(builder).to receive(:use).with(ConnectOpenstack)
66
+ expect(builder).to receive(:use).with(Call, ReadState)
67
+ # TODO, Impove this test to check what's happen after ReadState
68
+ Action.action_ssh_run
69
+ end
70
+ end
71
+
72
+ describe 'action_up' do
73
+ it 'add others middleware to builder' do
74
+ expect(builder).to receive(:use).with(ConfigValidate)
75
+ expect(builder).to receive(:use).with(ConnectOpenstack)
76
+ expect(builder).to receive(:use).with(Call, ReadState)
77
+ # TODO, Impove this test to check what's happen after ReadState
78
+ Action.action_up
79
+ end
80
+ end
81
+
82
+ describe 'action_halt' do
83
+ it 'add others middleware to builder' do
84
+ expect(builder).to receive(:use).with(ConfigValidate)
85
+ expect(builder).to receive(:use).with(ConnectOpenstack)
86
+ expect(builder).to receive(:use).with(Call, ReadState)
87
+ # TODO, Impove this test to check what's happen after ReadState
88
+ Action.action_halt
89
+ end
90
+ end
91
+
92
+ describe 'action_suspend' do
93
+ it 'add others middleware to builder' do
94
+ expect(builder).to receive(:use).with(ConfigValidate)
95
+ expect(builder).to receive(:use).with(ConnectOpenstack)
96
+ expect(builder).to receive(:use).with(Call, ReadState)
97
+ # TODO, Impove this test to check what's happen after ReadState
98
+ Action.action_suspend
99
+ end
100
+ end
101
+
102
+ describe 'action_resume' do
103
+ it 'add others middleware to builder' do
104
+ expect(builder).to receive(:use).with(ConfigValidate)
105
+ expect(builder).to receive(:use).with(ConnectOpenstack)
106
+ expect(builder).to receive(:use).with(Call, ReadState)
107
+ # TODO, Impove this test to check what's happen after ReadState
108
+ Action.action_resume
109
+ end
110
+ end
111
+
112
+ describe 'action_reload' do
113
+ it 'add others middleware to builder' do
114
+ expect(builder).to receive(:use).with(ConfigValidate)
115
+ expect(builder).to receive(:use).with(ConnectOpenstack)
116
+ expect(builder).to receive(:use).with(Call, ReadState)
117
+ # TODO, Impove this test to check what's happen after ReadState
118
+ Action.action_reload
119
+ end
120
+ end
121
+ end
@@ -14,7 +14,7 @@ describe VagrantPlugins::Openstack::CinderClient do
14
14
  session.token = '123456'
15
15
  session.project_id = 'a1b2c3'
16
16
  session.endpoints = { volume: 'http://cinder' }
17
- @cinder_client = VagrantPlugins::Openstack::CinderClient.instance
17
+ @cinder_client = VagrantPlugins::Openstack.cinder
18
18
  end
19
19
 
20
20
  describe 'get_all_volumes' do