vagrant-rimu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +12 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +1170 -0
- data/.travis.yml +55 -0
- data/Gemfile +23 -0
- data/LICENSE +373 -0
- data/README.md +109 -0
- data/Rakefile +6 -0
- data/Vagrantfile +6 -0
- data/gemfiles/vagrant_1.5.gemfile +18 -0
- data/gemfiles/vagrant_1.6.gemfile +18 -0
- data/gemfiles/vagrant_1.7.gemfile +18 -0
- data/lib/vagrant-rimu/actions/billing_methods.rb +20 -0
- data/lib/vagrant-rimu/actions/connect_to_rimu.rb +23 -0
- data/lib/vagrant-rimu/actions/create.rb +91 -0
- data/lib/vagrant-rimu/actions/is_created.rb +16 -0
- data/lib/vagrant-rimu/actions/is_stopped.rb +17 -0
- data/lib/vagrant-rimu/actions/list_distributions.rb +20 -0
- data/lib/vagrant-rimu/actions/list_servers.rb +20 -0
- data/lib/vagrant-rimu/actions/message_already_created.rb +16 -0
- data/lib/vagrant-rimu/actions/message_already_off.rb +16 -0
- data/lib/vagrant-rimu/actions/message_not_created.rb +16 -0
- data/lib/vagrant-rimu/actions/message_will_not_destroy.rb +17 -0
- data/lib/vagrant-rimu/actions/modify_provision_path.rb +37 -0
- data/lib/vagrant-rimu/actions/move.rb +22 -0
- data/lib/vagrant-rimu/actions/read_ssh_info.rb +43 -0
- data/lib/vagrant-rimu/actions/read_state.rb +37 -0
- data/lib/vagrant-rimu/actions/rebuild.rb +52 -0
- data/lib/vagrant-rimu/actions/reload.rb +23 -0
- data/lib/vagrant-rimu/actions/setup_sudo.rb +43 -0
- data/lib/vagrant-rimu/actions/setup_user.rb +68 -0
- data/lib/vagrant-rimu/actions/start_instance.rb +29 -0
- data/lib/vagrant-rimu/actions/stop_instance.rb +26 -0
- data/lib/vagrant-rimu/actions/terminate_instance.rb +26 -0
- data/lib/vagrant-rimu/actions.rb +237 -0
- data/lib/vagrant-rimu/commands/billing_methods.rb +18 -0
- data/lib/vagrant-rimu/commands/distributions.rb +18 -0
- data/lib/vagrant-rimu/commands/list_servers.rb +18 -0
- data/lib/vagrant-rimu/commands/move.rb +18 -0
- data/lib/vagrant-rimu/commands/rebuild.rb +20 -0
- data/lib/vagrant-rimu/commands/root.rb +67 -0
- data/lib/vagrant-rimu/config.rb +190 -0
- data/lib/vagrant-rimu/errors.rb +21 -0
- data/lib/vagrant-rimu/plugin.rb +80 -0
- data/lib/vagrant-rimu/provider.rb +54 -0
- data/lib/vagrant-rimu/version.rb +5 -0
- data/lib/vagrant-rimu.rb +20 -0
- data/locales/en.yml +79 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/vagrant-rimu/actions/connect_to_rimu_spec.rb +38 -0
- data/spec/vagrant-rimu/actions/message_already_created_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_already_off_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_not_created_spec.rb +33 -0
- data/spec/vagrant-rimu/actions/message_will_not_destroy_spec.rb +36 -0
- data/spec/vagrant-rimu/actions/modify_provision_path_spec.rb +81 -0
- data/spec/vagrant-rimu/actions/read_ssh_info_spec.rb +62 -0
- data/spec/vagrant-rimu/actions/read_state_spec.rb +59 -0
- data/spec/vagrant-rimu/actions/rebuild_spec.rb +148 -0
- data/spec/vagrant-rimu/actions/reload_spec.rb +42 -0
- data/spec/vagrant-rimu/actions/setup_sudo_spec.rb +94 -0
- data/spec/vagrant-rimu/actions/setup_user_spec.rb +78 -0
- data/spec/vagrant-rimu/actions/start_instance_spec.rb +64 -0
- data/spec/vagrant-rimu/actions/stop_instance_spec.rb +57 -0
- data/spec/vagrant-rimu/actions/terminate_instance_spec.rb +54 -0
- data/spec/vagrant-rimu/actions_spec.rb +22 -0
- data/spec/vagrant-rimu/commands/billing_methods_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/distributions_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/list_servers_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/move_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/rebuild_spec.rb +4 -0
- data/spec/vagrant-rimu/commands/root_spec.rb +4 -0
- data/spec/vagrant-rimu/config_spec.rb +162 -0
- data/spec/vagrant-rimu/provider_spec.rb +13 -0
- data/test/Vagrantfile +30 -0
- data/test/scripts/provision.sh +3 -0
- data/test/test.sh +12 -0
- data/test/test_rimu_id_rsa +51 -0
- data/test/test_rimu_id_rsa.pub +1 -0
- data/vagrant-rimu.gemspec +25 -0
- metadata +238 -0
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::Rebuild do
|
8
|
+
let(:ssh) { double('ssh') }
|
9
|
+
let(:servers) { double('servers') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:reinstall) { double('reinstall') }
|
12
|
+
let(:communicate) { double('communicate') }
|
13
|
+
let(:id) { '200' }
|
14
|
+
|
15
|
+
let(:config) do
|
16
|
+
double.tap do |config|
|
17
|
+
config.stub(:api_url) { nil }
|
18
|
+
config.stub(:api_key) { 'foo' }
|
19
|
+
config.stub(:host_name) { 'rimu.example.com' }
|
20
|
+
config.stub(:root_password) { nil }
|
21
|
+
config.stub(:distro_code) { nil }
|
22
|
+
config.stub(:control_panel) { nil }
|
23
|
+
config.stub(:vps_to_clone) { nil }
|
24
|
+
config.stub(:minimal_init) { nil }
|
25
|
+
config.stub(:disk_space_mb) { nil }
|
26
|
+
config.stub(:memory_mb) { nil }
|
27
|
+
config.stub(:disk_space_2_mb) { nil }
|
28
|
+
config.stub(:setup?) { true }
|
29
|
+
ssh.stub(:username) { 'rimu' }
|
30
|
+
ssh.stub(:username=) { 'rimu' }
|
31
|
+
ssh.stub(:private_key_path) { 'test/test_rimu_id_rsa' }
|
32
|
+
config.stub(:ssh) { ssh }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
let(:env) do
|
37
|
+
{}.tap do |env|
|
38
|
+
env[:ui] = double('ui').tap do |ui|
|
39
|
+
ui.stub(:info).with(anything)
|
40
|
+
ui.stub(:error).with(anything)
|
41
|
+
end
|
42
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
43
|
+
servers.stub(:reinstall) { reinstall }
|
44
|
+
os.stub(:servers) { servers }
|
45
|
+
end
|
46
|
+
machine.stub(:id) { id }
|
47
|
+
env[:machine] = machine
|
48
|
+
env[:machine].stub(:config) { config }
|
49
|
+
env[:machine].stub(:provider_config) { config }
|
50
|
+
communicate.stub(:ready?) { true }
|
51
|
+
env[:machine].stub(:communicate) { communicate }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:app) do
|
56
|
+
double('app').tap do |app|
|
57
|
+
app.stub(:call).with(anything)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'call' do
|
62
|
+
context 'when vps_to_clone option is not set' do
|
63
|
+
it 'reinstall the server using instantiation_options' do
|
64
|
+
# env.stub(:interrupted) { false }
|
65
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
66
|
+
expect(env[:machine].communicate).to receive(:ready?)
|
67
|
+
expect(env[:machine].config.ssh).to receive(:username=).with(ssh.username)
|
68
|
+
expect(env[:rimu_api].servers).to receive(:reinstall).with(
|
69
|
+
id.to_i,
|
70
|
+
{
|
71
|
+
:instantiation_options=> {
|
72
|
+
:domain_name=>config.host_name,
|
73
|
+
:password=>nil,
|
74
|
+
:distro=>nil,
|
75
|
+
:control_panel=>nil
|
76
|
+
},
|
77
|
+
:is_just_minimal_init=>nil,
|
78
|
+
:vps_parameters=>{
|
79
|
+
:disk_space_mb=>nil,
|
80
|
+
:memory_mb=>nil,
|
81
|
+
:disk_space_2_mb=>nil
|
82
|
+
}
|
83
|
+
}
|
84
|
+
)
|
85
|
+
expect(app).to receive(:call)
|
86
|
+
@action = VagrantPlugins::Rimu::Actions::Rebuild.new(app, env)
|
87
|
+
@action.call(env)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'when vps_to_clone option is set' do
|
92
|
+
it 'reinstall the server using instantiation_via_clone_options' do
|
93
|
+
vps_clone = 9999
|
94
|
+
# env.stub(:interrupted) { false }
|
95
|
+
env[:machine].provider_config.stub(:vps_to_clone) { vps_clone }
|
96
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
97
|
+
expect(env[:machine].communicate).to receive(:ready?)
|
98
|
+
expect(env[:machine].config.ssh).to receive(:username=).with(ssh.username)
|
99
|
+
expect(env[:rimu_api].servers).to receive(:reinstall).with(
|
100
|
+
id.to_i,
|
101
|
+
{
|
102
|
+
:instantiation_via_clone_options=> {
|
103
|
+
:domain_name=>config.host_name,
|
104
|
+
:vps_order_oid_to_clone => vps_clone,
|
105
|
+
},
|
106
|
+
:is_just_minimal_init=>nil,
|
107
|
+
:vps_parameters=>{
|
108
|
+
:disk_space_mb=>nil,
|
109
|
+
:memory_mb=>nil,
|
110
|
+
:disk_space_2_mb=>nil
|
111
|
+
}
|
112
|
+
}
|
113
|
+
)
|
114
|
+
expect(app).to receive(:call)
|
115
|
+
@action = VagrantPlugins::Rimu::Actions::Rebuild.new(app, env)
|
116
|
+
@action.call(env)
|
117
|
+
end
|
118
|
+
|
119
|
+
# it 'raise an exception if ssh not ready' do
|
120
|
+
# vps_clone = 9999
|
121
|
+
# env.stub(:interrupted) { nil }
|
122
|
+
# env[:machine].communicate.stub(:ready?) { false }
|
123
|
+
# env[:machine].provider_config.stub(:vps_to_clone) { vps_clone }
|
124
|
+
# expect(env[:machine].provider_config).to receive(:setup?)
|
125
|
+
# expect(env[:machine].communicate).to receive(:ready?)
|
126
|
+
# # expect(env[:machine].config.ssh).to receive(:username=).with(ssh.username)
|
127
|
+
# expect(env[:rimu_api].servers).to receive(:reinstall).with(
|
128
|
+
# id.to_i,
|
129
|
+
# {
|
130
|
+
# :instantiation_via_clone_options=> {
|
131
|
+
# :domain_name=>config.host_name,
|
132
|
+
# :vps_order_oid_to_clone => vps_clone,
|
133
|
+
# },
|
134
|
+
# :is_just_minimal_init=>nil,
|
135
|
+
# :vps_parameters=>{
|
136
|
+
# :disk_space_mb=>nil,
|
137
|
+
# :memory_mb=>nil,
|
138
|
+
# :disk_space_2_mb=>nil
|
139
|
+
# }
|
140
|
+
# }
|
141
|
+
# )
|
142
|
+
# expect(app).not_to receive(:call)
|
143
|
+
# @action = VagrantPlugins::Rimu::Actions::Rebuild.new(app, env)
|
144
|
+
# lambda { @action.call(env) }.should raise_error
|
145
|
+
# end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::Reload do
|
8
|
+
let(:servers) { double('servers') }
|
9
|
+
let(:reboot) { double('reboot') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:id) { '200' }
|
12
|
+
|
13
|
+
let(:env) do
|
14
|
+
{}.tap do |env|
|
15
|
+
env[:ui] = double('ui').tap do |ui|
|
16
|
+
ui.stub(:info).with(anything)
|
17
|
+
ui.stub(:error).with(anything)
|
18
|
+
end
|
19
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
20
|
+
servers.stub(:reboot) { reboot }
|
21
|
+
os.stub(:servers) { servers }
|
22
|
+
end
|
23
|
+
machine.stub(:id) { id }
|
24
|
+
env[:machine] = machine
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:app) do
|
29
|
+
double('app').tap do |app|
|
30
|
+
app.stub(:call).with(anything)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'call' do
|
35
|
+
it 'restarts the server' do
|
36
|
+
expect(env[:rimu_api].servers).to receive(:reboot).with(id.to_i)
|
37
|
+
expect(app).to receive(:call)
|
38
|
+
@action = VagrantPlugins::Rimu::Actions::Reload.new(app, env)
|
39
|
+
@action.call(env)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::SetupSudo do
|
8
|
+
let(:ssh) { double('ssh') }
|
9
|
+
let(:guest) { double('guest') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:execute) { double('execute') }
|
12
|
+
let(:communicate) { double('communicate') }
|
13
|
+
|
14
|
+
let(:config) do
|
15
|
+
double.tap do |config|
|
16
|
+
config.stub(:api_url) { nil }
|
17
|
+
config.stub(:api_key) { 'foo' }
|
18
|
+
ssh.stub(:username) { 'rimu' }
|
19
|
+
ssh.stub(:username=) { 'rimu' }
|
20
|
+
ssh.stub(:private_key_path) { 'test/test_rimu_id_rsa' }
|
21
|
+
config.stub(:ssh) { ssh }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:env) do
|
26
|
+
{}.tap do |env|
|
27
|
+
env[:ui] = double('ui').tap do |ui|
|
28
|
+
ui.stub(:info).with(anything)
|
29
|
+
ui.stub(:error).with(anything)
|
30
|
+
end
|
31
|
+
communicate.stub(:execute) { execute }
|
32
|
+
env[:machine] = machine
|
33
|
+
guest.stub(:name) { 'redhat' }
|
34
|
+
guest.stub(:respond_to?).with(:name) { true }
|
35
|
+
env[:machine].stub(:guest) { guest }
|
36
|
+
env[:machine].stub(:config) { config }
|
37
|
+
env[:machine].stub(:communicate) { communicate }
|
38
|
+
env[:machine].stub(:provider_config) { config }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:app) do
|
43
|
+
double('app').tap do |app|
|
44
|
+
app.stub(:call).with(anything)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'call' do
|
49
|
+
user = 'rimu'
|
50
|
+
context 'when guest name is set to redhat' do
|
51
|
+
it 'setup sudo' do
|
52
|
+
env[:machine].provider_config.stub(:setup?) { true }
|
53
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
54
|
+
expect(env[:machine].config.ssh).to receive(:username=).with('root')
|
55
|
+
expect(env[:machine].guest).to receive(:respond_to?).with(:name)
|
56
|
+
expect(env[:machine].communicate).to receive(:execute)
|
57
|
+
expect(env[:machine].config.ssh).to receive(:username=).with(user)
|
58
|
+
expect(app).to receive(:call)
|
59
|
+
@action = VagrantPlugins::Rimu::Actions::SetupSudo.new(app, env)
|
60
|
+
@action.call(env)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when guest name is not set to redhat' do
|
65
|
+
it 'do nothing' do
|
66
|
+
env[:machine].provider_config.stub(:setup?) { true }
|
67
|
+
env[:machine].guest.stub(:name) { 'debian' }
|
68
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
69
|
+
expect(env[:machine].config.ssh).to receive(:username=).with('root')
|
70
|
+
expect(env[:machine].guest).to receive(:respond_to?).with(:name)
|
71
|
+
expect(env[:machine].communicate).not_to receive(:execute)
|
72
|
+
expect(env[:machine].config.ssh).to receive(:username=).with(user)
|
73
|
+
expect(app).to receive(:call)
|
74
|
+
@action = VagrantPlugins::Rimu::Actions::SetupSudo.new(app, env)
|
75
|
+
@action.call(env)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when setup is not enabled' do
|
80
|
+
it 'do nothing' do
|
81
|
+
env[:machine].provider_config.stub(:setup?) { false }
|
82
|
+
env[:machine].guest.stub(:name) { 'debian' }
|
83
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
84
|
+
expect(env[:machine].config.ssh).not_to receive(:username=).with('root')
|
85
|
+
expect(env[:machine].guest).not_to receive(:respond_to?).with(:name)
|
86
|
+
expect(env[:machine].communicate).not_to receive(:execute)
|
87
|
+
expect(env[:machine].config.ssh).not_to receive(:username=).with(user)
|
88
|
+
expect(app).to receive(:call)
|
89
|
+
@action = VagrantPlugins::Rimu::Actions::SetupSudo.new(app, env)
|
90
|
+
@action.call(env)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::SetupUser do
|
8
|
+
let(:ssh) { double('ssh') }
|
9
|
+
let(:m_env) { double('m_env') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:execute) { double('execute') }
|
12
|
+
let(:communicate) { double('communicate') }
|
13
|
+
|
14
|
+
let(:config) do
|
15
|
+
double.tap do |config|
|
16
|
+
config.stub(:api_url) { nil }
|
17
|
+
config.stub(:api_key) { 'foo' }
|
18
|
+
ssh.stub(:username) { 'rimu' }
|
19
|
+
ssh.stub(:username=) { 'rimu' }
|
20
|
+
ssh.stub(:private_key_path) { 'test/test_rimu_id_rsa' }
|
21
|
+
config.stub(:ssh) { ssh }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:env) do
|
26
|
+
{}.tap do |env|
|
27
|
+
env[:ui] = double('ui').tap do |ui|
|
28
|
+
ui.stub(:info).with(anything)
|
29
|
+
ui.stub(:error).with(anything)
|
30
|
+
end
|
31
|
+
communicate.stub(:execute) { execute }
|
32
|
+
env[:machine] = machine
|
33
|
+
m_env.stub(:root_path) { '.' }
|
34
|
+
env[:machine].stub(:env) { m_env }
|
35
|
+
env[:machine].stub(:config) { config }
|
36
|
+
env[:machine].stub(:communicate) { communicate }
|
37
|
+
env[:machine].stub(:provider_config) { config }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:app) do
|
42
|
+
double('app').tap do |app|
|
43
|
+
app.stub(:call).with(anything)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe 'call' do
|
48
|
+
user = 'rimu'
|
49
|
+
context 'when setup is enabled' do
|
50
|
+
it 'setup user' do
|
51
|
+
env[:machine].provider_config.stub(:setup?) { true }
|
52
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
53
|
+
expect(env[:machine].config.ssh).to receive(:username)
|
54
|
+
expect(env[:machine].config.ssh).to receive(:username=).with('root')
|
55
|
+
expect(env[:machine].communicate).to receive(:execute)
|
56
|
+
expect(env[:machine].config.ssh).to receive(:private_key_path)
|
57
|
+
expect(env[:machine].config.ssh).to receive(:username=).with(user)
|
58
|
+
expect(app).to receive(:call)
|
59
|
+
@action = VagrantPlugins::Rimu::Actions::SetupUser.new(app, env)
|
60
|
+
@action.call(env)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
context 'when setup is not enabled' do
|
64
|
+
it 'do nothing' do
|
65
|
+
env[:machine].provider_config.stub(:setup?) { false }
|
66
|
+
expect(env[:machine].provider_config).to receive(:setup?)
|
67
|
+
expect(env[:machine].config.ssh).not_to receive(:username)
|
68
|
+
expect(env[:machine].config.ssh).not_to receive(:username=).with('root')
|
69
|
+
expect(env[:machine].communicate).not_to receive(:execute)
|
70
|
+
expect(env[:machine].config.ssh).not_to receive(:private_key_path)
|
71
|
+
expect(env[:machine].config.ssh).not_to receive(:username=).with(user)
|
72
|
+
expect(app).to receive(:call)
|
73
|
+
@action = VagrantPlugins::Rimu::Actions::SetupUser.new(app, env)
|
74
|
+
@action.call(env)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StartInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::StartInstance do
|
8
|
+
let(:servers) { double('servers') }
|
9
|
+
let(:start) { double('start') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:id) { '200' }
|
12
|
+
|
13
|
+
let(:env) do
|
14
|
+
{}.tap do |env|
|
15
|
+
env[:ui] = double('ui').tap do |ui|
|
16
|
+
ui.stub(:info).with(anything)
|
17
|
+
ui.stub(:error).with(anything)
|
18
|
+
end
|
19
|
+
machine.stub(:id) { id }
|
20
|
+
env[:machine] = machine
|
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
|
+
it 'starts server' do
|
32
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
33
|
+
start.stub(:running_state) { 'RUNNING' }
|
34
|
+
servers.stub(:start) { start }
|
35
|
+
os.stub(:servers) { servers }
|
36
|
+
end
|
37
|
+
expect(env[:rimu_api].servers).to receive(:start).with(id.to_i)
|
38
|
+
expect(app).to receive(:call)
|
39
|
+
@action = VagrantPlugins::Rimu::Actions::StartInstance.new(app, env)
|
40
|
+
@action.call(env)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises exception if api does not respond' do
|
44
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
45
|
+
servers.stub(:start) { nil }
|
46
|
+
os.stub(:servers) { servers }
|
47
|
+
end
|
48
|
+
expect(env[:rimu_api].servers).to receive(:start).with(id.to_i)
|
49
|
+
@action = VagrantPlugins::Rimu::Actions::StartInstance.new(app, env)
|
50
|
+
lambda { @action.call(env) }.should raise_error(VagrantPlugins::Rimu::Errors::ApiError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'raises exception if server does not start' do
|
54
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
55
|
+
start.stub(:running_state) { 'NOTRUNNING' }
|
56
|
+
servers.stub(:start) { start }
|
57
|
+
os.stub(:servers) { servers }
|
58
|
+
end
|
59
|
+
expect(env[:rimu_api].servers).to receive(:start).with(id.to_i)
|
60
|
+
@action = VagrantPlugins::Rimu::Actions::StartInstance.new(app, env)
|
61
|
+
lambda { @action.call(env) }.should raise_error(VagrantPlugins::Rimu::Errors::ApiError)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
5
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
6
|
+
|
7
|
+
describe VagrantPlugins::Rimu::Actions::StopInstance do
|
8
|
+
let(:servers) { double('servers') }
|
9
|
+
let(:shutdown) { double('shutdown') }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
let(:state) { double('state') }
|
12
|
+
let(:id) { '200' }
|
13
|
+
|
14
|
+
let(:env) do
|
15
|
+
{}.tap do |env|
|
16
|
+
env[:ui] = double('ui').tap do |ui|
|
17
|
+
ui.stub(:info).with(anything)
|
18
|
+
ui.stub(:error).with(anything)
|
19
|
+
end
|
20
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
21
|
+
servers.stub(:shutdown) { shutdown }
|
22
|
+
os.stub(:servers) { servers }
|
23
|
+
end
|
24
|
+
machine.stub(:id) { id }
|
25
|
+
env[:machine] = machine
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:app) do
|
30
|
+
double('app').tap do |app|
|
31
|
+
app.stub(:call).with(anything)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'call' do
|
36
|
+
context 'when server state id is not :stopped' do
|
37
|
+
it 'stops the server' do
|
38
|
+
state.stub(:id) { :running }
|
39
|
+
env[:machine].stub(:state) { state }
|
40
|
+
expect(env[:rimu_api].servers).to receive(:shutdown).with(id.to_i)
|
41
|
+
expect(app).to receive(:call)
|
42
|
+
@action = VagrantPlugins::Rimu::Actions::StopInstance.new(app, env)
|
43
|
+
@action.call(env)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'when server id is :stopped' do
|
47
|
+
it 'does nothing' do
|
48
|
+
state.stub(:id) { :stopped }
|
49
|
+
env[:machine].stub(:state) { state }
|
50
|
+
expect(env[:rimu_api].servers).to_not receive(:shutdown)
|
51
|
+
expect(app).to receive(:call)
|
52
|
+
@action = VagrantPlugins::Rimu::Actions::StopInstance.new(app, env)
|
53
|
+
@action.call(env)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
# action_root = Pathname.new(File.expand_path('../../../../lib/vagrant-rimu/actions', __FILE__))
|
7
|
+
# autoload :StopInstance, action_root.join('stop_instance')
|
8
|
+
|
9
|
+
describe VagrantPlugins::Rimu::Actions::TerminateInstance do
|
10
|
+
let(:servers) { double('servers') }
|
11
|
+
let(:cancel) { double('cancel') }
|
12
|
+
|
13
|
+
let(:env) do
|
14
|
+
{}.tap do |env|
|
15
|
+
env[:ui] = double('ui').tap do |ui|
|
16
|
+
ui.stub(:info).with(anything)
|
17
|
+
ui.stub(:error).with(anything)
|
18
|
+
end
|
19
|
+
env[:rimu_api] = double('rimu_api').tap do |os|
|
20
|
+
servers.stub(:cancel) { cancel }
|
21
|
+
os.stub(:servers) { servers }
|
22
|
+
end
|
23
|
+
env[:machine] = OpenStruct.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:app) do
|
28
|
+
double('app').tap do |app|
|
29
|
+
app.stub(:call).with(anything)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'call' do
|
34
|
+
context 'when server id is set' do
|
35
|
+
it 'terminates the server' do
|
36
|
+
id = '200'
|
37
|
+
env[:machine].id = id
|
38
|
+
expect(env[:rimu_api].servers).to receive(:cancel).with(id.to_i)
|
39
|
+
expect(app).to receive(:call)
|
40
|
+
@action = VagrantPlugins::Rimu::Actions::TerminateInstance.new(app, env)
|
41
|
+
@action.call(env)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'when server id is not set' do
|
45
|
+
it 'do nothing' do
|
46
|
+
env[:machine].id = nil
|
47
|
+
expect(env[:rimu_api].servers).to_not receive(:cancel)
|
48
|
+
expect(app).to receive(:call)
|
49
|
+
@action = VagrantPlugins::Rimu::Actions::TerminateInstance.new(app, env)
|
50
|
+
@action.call(env)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VagrantPlugins::Rimu::Actions do
|
4
|
+
let(:builder) do
|
5
|
+
double('builder').tap do |builder|
|
6
|
+
builder.stub(:use)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# before :each do
|
11
|
+
# Actions.stub(:new_builder) { builder }
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# describe 'action_destroy' do
|
15
|
+
# it 'add others middleware to builder' do
|
16
|
+
# expect(builder).to receive(:use).with(ConfigValidate)
|
17
|
+
# expect(builder).to receive(:use).with(ConnectToRimu)
|
18
|
+
# expect(builder).to receive(:use).with(Call, ReadState)
|
19
|
+
# Actions.action_destroy
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
end
|