tengine_resource 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +30 -0
- data/Gemfile.lock +106 -0
- data/README.rdoc +20 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/bin/tengine_resource_watchd +8 -0
- data/config/.gitignore +2 -0
- data/config/watchd.yml.erb.example +52 -0
- data/lib/tengine/resource.rb +29 -0
- data/lib/tengine/resource/config.rb +6 -0
- data/lib/tengine/resource/config/resource.rb +194 -0
- data/lib/tengine/resource/credential.rb +156 -0
- data/lib/tengine/resource/credential/ec2.rb +5 -0
- data/lib/tengine/resource/credential/ec2/dummy.rb +148 -0
- data/lib/tengine/resource/credential/ec2/launch_options.rb +179 -0
- data/lib/tengine/resource/drivers/resource_control_driver.rb +58 -0
- data/lib/tengine/resource/net_ssh.rb +134 -0
- data/lib/tengine/resource/observer.rb +25 -0
- data/lib/tengine/resource/physical_server.rb +7 -0
- data/lib/tengine/resource/provider.rb +82 -0
- data/lib/tengine/resource/provider/ec2.rb +187 -0
- data/lib/tengine/resource/provider/wakame.rb +615 -0
- data/lib/tengine/resource/server.rb +62 -0
- data/lib/tengine/resource/virtual_server.rb +62 -0
- data/lib/tengine/resource/virtual_server_image.rb +34 -0
- data/lib/tengine/resource/virtual_server_type.rb +21 -0
- data/lib/tengine/resource/watcher.rb +121 -0
- data/lib/tengine_resource.rb +4 -0
- data/spec/fixtures/goku_at_ec2_ap_northeast.rb +177 -0
- data/spec/mongoid.yml +35 -0
- data/spec/spec_helper.rb +40 -0
- data/spec/support/ec2.rb +129 -0
- data/spec/support/mongo_index_key_log.rb +91 -0
- data/spec/tengine/resource/bugfix/watcher_for_wakame_spec.rb +232 -0
- data/spec/tengine/resource/credential_spec.rb +205 -0
- data/spec/tengine/resource/drivers/resource_control_driver_spec.rb +84 -0
- data/spec/tengine/resource/net_ssh_spec.rb +148 -0
- data/spec/tengine/resource/physical_server_spec.rb +47 -0
- data/spec/tengine/resource/provider/ec2_spec.rb +473 -0
- data/spec/tengine/resource/provider/test_files/describe_host_nodes.json +22 -0
- data/spec/tengine/resource/provider/test_files/describe_images.json +23 -0
- data/spec/tengine/resource/provider/test_files/describe_instance_specs.json +23 -0
- data/spec/tengine/resource/provider/test_files/describe_instances.json +56 -0
- data/spec/tengine/resource/provider/test_files/run_instances.json +30 -0
- data/spec/tengine/resource/provider/test_files/terminate_instances.json +3 -0
- data/spec/tengine/resource/provider/wakame/00_describe_host_nodes_0_physical_servers.json +8 -0
- data/spec/tengine/resource/provider/wakame/01_describe_host_nodes_10_physical_servers.json +139 -0
- data/spec/tengine/resource/provider/wakame/02_describe_host_nodes_60_physical_servers.json +795 -0
- data/spec/tengine/resource/provider/wakame/10_describe_instances_0_virtual_servers.json +8 -0
- data/spec/tengine/resource/provider/wakame/11_describe_instances_10_virtual_servers.json +469 -0
- data/spec/tengine/resource/provider/wakame/12_describe_instances_after_run_instances.json +280 -0
- data/spec/tengine/resource/provider/wakame/13_describe_instances_after_terminate_instances.json +279 -0
- data/spec/tengine/resource/provider/wakame/20_describe_images_0_virtual_server_images.json +8 -0
- data/spec/tengine/resource/provider/wakame/21_describe_images_5_virtual_server_images.json +84 -0
- data/spec/tengine/resource/provider/wakame/22_describe_images_60_virtual_server_images.json +856 -0
- data/spec/tengine/resource/provider/wakame/30_describe_instance_specs_0_virtual_server_specs.json +8 -0
- data/spec/tengine/resource/provider/wakame/31_describe_instance_specs_4_virtual_server_specs.json +66 -0
- data/spec/tengine/resource/provider/wakame/40_run_instances_0_virtual_servers.json +1 -0
- data/spec/tengine/resource/provider/wakame/41_run_instances_1_virtual_servers.json +22 -0
- data/spec/tengine/resource/provider/wakame/42_run_instances_5_virtual_servers.json +106 -0
- data/spec/tengine/resource/provider/wakame/50_terminate_instances_0_virtual_servers.json +1 -0
- data/spec/tengine/resource/provider/wakame/51_terminate_instances_3_virtual_servers.json +5 -0
- data/spec/tengine/resource/provider/wakame/sync_physical_servers_spec.rb +114 -0
- data/spec/tengine/resource/provider/wakame/sync_virtual_server_images_spec.rb +116 -0
- data/spec/tengine/resource/provider/wakame/sync_virtual_server_types_spec.rb +116 -0
- data/spec/tengine/resource/provider/wakame/sync_virtual_servers_spec.rb +216 -0
- data/spec/tengine/resource/provider/wakame_api_spec.rb +319 -0
- data/spec/tengine/resource/provider/wakame_spec.rb +339 -0
- data/spec/tengine/resource/provider_spec.rb +252 -0
- data/spec/tengine/resource/server_spec.rb +195 -0
- data/spec/tengine/resource/test_files/.gitignore +6 -0
- data/spec/tengine/resource/test_files/00_describe_host_nodes_0_physical_servers.json +8 -0
- data/spec/tengine/resource/test_files/01_describe_host_nodes_10_physical_servers.json +139 -0
- data/spec/tengine/resource/test_files/02_describe_host_nodes_60_physical_servers.json +795 -0
- data/spec/tengine/resource/test_files/10_describe_instances_0_virtual_servers.json +8 -0
- data/spec/tengine/resource/test_files/11_describe_instances_10_virtual_servers.json +469 -0
- data/spec/tengine/resource/test_files/12_describe_instances_after_run_instances.json +280 -0
- data/spec/tengine/resource/test_files/13_describe_instances_after_terminate_instances.json +279 -0
- data/spec/tengine/resource/test_files/14_describe_instances_after_run_1_instance.json +55 -0
- data/spec/tengine/resource/test_files/20_describe_images_0_virtual_server_images.json +8 -0
- data/spec/tengine/resource/test_files/21_describe_images_5_virtual_server_images.json +84 -0
- data/spec/tengine/resource/test_files/22_describe_images_60_virtual_server_images.json +856 -0
- data/spec/tengine/resource/test_files/30_describe_instance_specs_0_virtual_server_specs.json +8 -0
- data/spec/tengine/resource/test_files/31_describe_instance_specs_4_virtual_server_specs.json +66 -0
- data/spec/tengine/resource/test_files/40_run_instances_0_virtual_servers.json +1 -0
- data/spec/tengine/resource/test_files/41_run_instances_1_virtual_servers.json +22 -0
- data/spec/tengine/resource/test_files/42_run_instances_5_virtual_servers.json +106 -0
- data/spec/tengine/resource/test_files/43_run_instances_1_virtual_servers_without_aws_availability_zone.json +22 -0
- data/spec/tengine/resource/test_files/50_terminate_instances_0_virtual_servers.json +1 -0
- data/spec/tengine/resource/test_files/51_terminate_instances_3_virtual_servers.json +5 -0
- data/spec/tengine/resource/virtual_server_image_spec.rb +94 -0
- data/spec/tengine/resource/virtual_server_spec.rb +116 -0
- data/spec/tengine/resource/virtual_server_type_spec.rb +4 -0
- data/spec/tengine/resource/watcher_spec.rb +1026 -0
- data/spec/tengine_resource_spec.rb +5 -0
- data/tengine_resource.gemspec +171 -0
- data/tmp/log/.gitignore +1 -0
- metadata +286 -0
@@ -0,0 +1,473 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'right_aws'
|
5
|
+
|
6
|
+
describe Tengine::Resource::Provider::Ec2 do
|
7
|
+
before do
|
8
|
+
Tengine::Resource::Provider::Ec2.delete_all
|
9
|
+
@conn = {:access_key => 'ACCESS_KEY1', :secret_access_key => "SECRET_ACCESS_KEY1", :region => "us-west-1"}
|
10
|
+
@valid_attributes1 = {
|
11
|
+
:name => "my_west-1",
|
12
|
+
:connection_settings => @conn
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe :validation do
|
17
|
+
context "valid" do
|
18
|
+
subject{ Tengine::Resource::Provider::Ec2.new(@valid_attributes1) }
|
19
|
+
its(:valid?){ should be_true }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "invalid" do
|
23
|
+
subject{ Tengine::Resource::Provider::Ec2.new }
|
24
|
+
its(:valid?){ should be_false }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'update resources' do
|
29
|
+
subject do
|
30
|
+
Tengine::Resource::Provider::Ec2.create!(:name => "ec2-us-west-1", :connection_settings => @conn)
|
31
|
+
end
|
32
|
+
|
33
|
+
context "物理サーバ" do
|
34
|
+
|
35
|
+
before do
|
36
|
+
Tengine::Resource::PhysicalServer.delete_all
|
37
|
+
# spec/support/ec2.rb を参照してください
|
38
|
+
RightAws::Ec2.should_receive(:new).
|
39
|
+
with('ACCESS_KEY1', "SECRET_ACCESS_KEY1", :region => "us-west-1", :logger => Tengine.logger).
|
40
|
+
and_return(setup_ec2_stub)
|
41
|
+
end
|
42
|
+
|
43
|
+
shared_examples_for "取得した内容が反映される" do
|
44
|
+
it do
|
45
|
+
servers = subject.physical_servers.order(:provided_id, :asc)
|
46
|
+
west_1a = servers.first
|
47
|
+
west_1a.provider.should == subject
|
48
|
+
west_1a.name.should == "us-west-1a"
|
49
|
+
west_1a.provided_id.should == "us-west-1a"
|
50
|
+
west_1a.status.should == "available"
|
51
|
+
west_1b = servers.last
|
52
|
+
west_1b.provider.should == subject
|
53
|
+
west_1b.name.should == "us-west-1b"
|
54
|
+
west_1b.provided_id.should == "us-west-1b"
|
55
|
+
west_1b.status.should == "available"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "最初の実行時には物理サーバを登録する" do
|
60
|
+
before do
|
61
|
+
subject.physical_servers.count.should == 0
|
62
|
+
subject.update_physical_servers
|
63
|
+
subject.physical_servers.count.should == 2
|
64
|
+
end
|
65
|
+
it_behaves_like "取得した内容が反映される"
|
66
|
+
end
|
67
|
+
|
68
|
+
context "すでに1台登録されている場合" do
|
69
|
+
before do
|
70
|
+
subject.physical_servers.create(:name => "us-west-1a", :provided_id => "us-west-1a", :status => "available")
|
71
|
+
subject.physical_servers.count.should == 1
|
72
|
+
subject.update_physical_servers
|
73
|
+
subject.physical_servers.count.should == 2
|
74
|
+
end
|
75
|
+
it_behaves_like "取得した内容が反映される"
|
76
|
+
end
|
77
|
+
|
78
|
+
context "すでに2台登録されている場合" do
|
79
|
+
context "何も変わらない場合" do
|
80
|
+
before do
|
81
|
+
subject.physical_servers.create(:name => "us-west-1a", :provided_id => "us-west-1a", :status => "available")
|
82
|
+
subject.physical_servers.create(:name => "us-west-1b", :provided_id => "us-west-1b", :status => "available")
|
83
|
+
subject.physical_servers.count.should == 2
|
84
|
+
subject.update_physical_servers
|
85
|
+
subject.physical_servers.count.should == 2
|
86
|
+
end
|
87
|
+
it_behaves_like "取得した内容が反映される"
|
88
|
+
end
|
89
|
+
|
90
|
+
context "状態が変わった場合" do
|
91
|
+
before do
|
92
|
+
subject.physical_servers.create(:name => "us-west-1a", :provided_id => "us-west-1a", :status => "available")
|
93
|
+
subject.physical_servers.create(:name => "us-west-1b", :provided_id => "us-west-1b", :status => "down")
|
94
|
+
# こんな定義はないはずですが、そもそも定義がないので。
|
95
|
+
# http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/index.html?ApiReference-query-DescribeAvailabilityZones.html
|
96
|
+
subject.physical_servers.count.should == 2
|
97
|
+
subject.update_physical_servers
|
98
|
+
subject.physical_servers.count.should == 2
|
99
|
+
end
|
100
|
+
it_behaves_like "取得した内容が反映される"
|
101
|
+
end
|
102
|
+
|
103
|
+
context "nameが管理画面で変更されていた場合" do
|
104
|
+
before do
|
105
|
+
subject.physical_servers.create(:name => "foo", :provided_id => "us-west-1a", :status => "available")
|
106
|
+
subject.physical_servers.create(:name => "us-west-1b", :provided_id => "us-west-1b", :status => "available")
|
107
|
+
subject.physical_servers.count.should == 2
|
108
|
+
subject.update_physical_servers
|
109
|
+
subject.physical_servers.count.should == 2
|
110
|
+
end
|
111
|
+
|
112
|
+
it do
|
113
|
+
servers = subject.physical_servers.order(:provided_id, :asc)
|
114
|
+
west_1a = servers.first
|
115
|
+
west_1a.provider.should == subject
|
116
|
+
west_1a.name.should == "foo"
|
117
|
+
west_1a.provided_id.should == "us-west-1a"
|
118
|
+
west_1a.status.should == "available"
|
119
|
+
west_1b = servers.last
|
120
|
+
west_1b.provider.should == subject
|
121
|
+
west_1b.name.should == "us-west-1b"
|
122
|
+
west_1b.provided_id.should == "us-west-1b"
|
123
|
+
west_1b.status.should == "available"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "すでに3台登録されている場合" do
|
129
|
+
before do
|
130
|
+
subject.physical_servers.create(:name => "us-west-1a", :provided_id => "us-west-1a", :status => "available")
|
131
|
+
subject.physical_servers.create(:name => "us-west-1b", :provided_id => "us-west-1b", :status => "available")
|
132
|
+
subject.physical_servers.create(:name => "us-west-1c", :provided_id => "us-west-1c", :status => "available")
|
133
|
+
subject.physical_servers.count.should == 3
|
134
|
+
subject.update_physical_servers
|
135
|
+
subject.physical_servers.count.should == 3
|
136
|
+
end
|
137
|
+
it "物理サーバが減るということは一大事なので、自動でデータを削除するのではなく、見つからなかったということにする" do
|
138
|
+
servers = subject.physical_servers.order(:provided_id, :asc)
|
139
|
+
west_1a = servers.first
|
140
|
+
west_1a.provider.should == subject
|
141
|
+
west_1a.name.should == "us-west-1a"
|
142
|
+
west_1a.provided_id.should == "us-west-1a"
|
143
|
+
west_1a.status.should == "available"
|
144
|
+
west_1b = servers[1]
|
145
|
+
west_1b.provider.should == subject
|
146
|
+
west_1b.name.should == "us-west-1b"
|
147
|
+
west_1b.provided_id.should == "us-west-1b"
|
148
|
+
west_1b.status.should == "available"
|
149
|
+
west_1c = servers[2]
|
150
|
+
west_1c.provider.should == subject
|
151
|
+
west_1c.name.should == "us-west-1c"
|
152
|
+
west_1c.provided_id.should == "us-west-1c"
|
153
|
+
west_1c.status.should == "not_found"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context "仮想サーバ" do
|
159
|
+
before do
|
160
|
+
@now = Time.now
|
161
|
+
Time.stub!(:now).and_return(@now)
|
162
|
+
Tengine::Resource::PhysicalServer.delete_all
|
163
|
+
Tengine::Resource::VirtualServer.delete_all
|
164
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
165
|
+
@us_west_1a = subject.physical_servers.create(:name => "us-west-1a", :provided_id => "us-west-1a", :status => "available")
|
166
|
+
@us_west_1b = subject.physical_servers.create(:name => "us-west-1b", :provided_id => "us-west-1b", :status => "available")
|
167
|
+
@ami_1 = subject.virtual_server_images.create(:name => "ami-11111111", :provided_id => "ami-11111111")
|
168
|
+
@response_base = {
|
169
|
+
# 起動後変更がない属性
|
170
|
+
# :aws_instance_id => "i-11111111",
|
171
|
+
:aws_image_id=>"ami-11111111",
|
172
|
+
:aws_availability_zone => "us-east-1a",
|
173
|
+
:ssh_key_name=>"tengine",
|
174
|
+
:aws_groups=>["default", "test2"],
|
175
|
+
:aws_launch_time => Time.now.iso8601,
|
176
|
+
:ami_launch_index=>"0",
|
177
|
+
:architecture=>"i386",
|
178
|
+
#
|
179
|
+
# 起動後変更がありえる属性
|
180
|
+
# :dns_name=>"ec2-184-72-203-101.us-west-1.compute.amazonaws.com",
|
181
|
+
# :ip_address=>"184.72.20.101",
|
182
|
+
# :private_dns_name=>"ip-10-162-153-101.us-west-1.compute.internal",
|
183
|
+
# :private_ip_address=>"10.162.153.101",
|
184
|
+
:aws_state_code=>16,
|
185
|
+
:aws_state=>"running",
|
186
|
+
:aws_reason=>"",
|
187
|
+
}
|
188
|
+
|
189
|
+
@base_attrs = {
|
190
|
+
:status => "running",
|
191
|
+
:provided_image_id => "ami-11111111",
|
192
|
+
:properties => {
|
193
|
+
:aws_availability_zone => "us-east-1a",
|
194
|
+
:ssh_key_name=>"tengine",
|
195
|
+
:aws_groups=>["default", "test2"],
|
196
|
+
:aws_launch_time => @now.iso8601,
|
197
|
+
:ami_launch_index=>"0",
|
198
|
+
:architecture=>"i386",
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
@server_base_attrs = [
|
203
|
+
{
|
204
|
+
:name => "i-11111111",
|
205
|
+
:provided_id => "i-11111111",
|
206
|
+
:addresses => {
|
207
|
+
:dns_name => "ec2-184-72-203-101.us-west-1.compute.amazonaws.com",
|
208
|
+
:ip_address => "184.72.20.101",
|
209
|
+
:private_dns_name => "ip-10-162-153-101.us-west-1.compute.internal",
|
210
|
+
:private_ip_address => "10.162.153.101",
|
211
|
+
}
|
212
|
+
},
|
213
|
+
{
|
214
|
+
:name => "i-22222222",
|
215
|
+
:provided_id => "i-22222222",
|
216
|
+
:addresses => {
|
217
|
+
:dns_name => "ec2-184-72-203-102.us-west-1.compute.amazonaws.com",
|
218
|
+
:ip_address => "184.72.20.102",
|
219
|
+
:private_dns_name => "ip-10-162-153-102.us-west-1.compute.internal",
|
220
|
+
:private_ip_address => "10.162.153.102",
|
221
|
+
}
|
222
|
+
},
|
223
|
+
{
|
224
|
+
:name => "i-33333333",
|
225
|
+
:provided_id => "i-33333333",
|
226
|
+
:addresses => {
|
227
|
+
:dns_name => "ec2-184-72-203-103.us-west-1.compute.amazonaws.com",
|
228
|
+
:ip_address => "184.72.20.103",
|
229
|
+
:private_dns_name => "ip-10-162-153-103.us-west-1.compute.internal",
|
230
|
+
:private_ip_address => "10.162.153.103",
|
231
|
+
}
|
232
|
+
},
|
233
|
+
{
|
234
|
+
:name => "i-44444444",
|
235
|
+
:provided_id => "i-44444444",
|
236
|
+
:addresses => {
|
237
|
+
:dns_name => "ec2-184-72-203-104.us-west-1.compute.amazonaws.com",
|
238
|
+
:ip_address => "184.72.20.104",
|
239
|
+
:private_dns_name => "ip-10-162-153-104.us-west-1.compute.internal",
|
240
|
+
:private_ip_address => "10.162.153.104",
|
241
|
+
}
|
242
|
+
}
|
243
|
+
]
|
244
|
+
|
245
|
+
describe_instances_item = lambda do |*args|
|
246
|
+
index, options = *args
|
247
|
+
result = @response_base.merge({
|
248
|
+
:aws_instance_id => "i-" << (index.to_s * 8),
|
249
|
+
:dns_name=>"ec2-184-72-203-#{index + 100}.us-west-1.compute.amazonaws.com",
|
250
|
+
:ip_address=>"184.72.20.#{index + 100}",
|
251
|
+
:private_dns_name=>"ip-10-162-153-#{index + 100}.us-west-1.compute.internal",
|
252
|
+
:private_ip_address=>"10.162.153.#{index + 100}",
|
253
|
+
})
|
254
|
+
result.update(options) if options
|
255
|
+
result
|
256
|
+
end
|
257
|
+
# spec/support/ec2.rb を参照してください
|
258
|
+
mock_ec2 = setup_ec2_stub
|
259
|
+
mock_ec2.stub!(:describe_instances).and_return([
|
260
|
+
describe_instances_item.call(1),
|
261
|
+
describe_instances_item.call(2),
|
262
|
+
describe_instances_item.call(3),
|
263
|
+
])
|
264
|
+
RightAws::Ec2.should_receive(:new).
|
265
|
+
with('ACCESS_KEY1', "SECRET_ACCESS_KEY1", :region => "us-west-1", :logger => Tengine.logger).
|
266
|
+
and_return(mock_ec2)
|
267
|
+
end
|
268
|
+
|
269
|
+
shared_examples_for "取得したstaticな情報が反映される" do
|
270
|
+
it do
|
271
|
+
assert_server = lambda do |server|
|
272
|
+
server.provided_image_id.should == "ami-11111111"
|
273
|
+
server.properties.should == {
|
274
|
+
'aws_availability_zone' => "us-east-1a",
|
275
|
+
'ssh_key_name'=>"tengine",
|
276
|
+
'aws_groups'=>["default", "test2"],
|
277
|
+
'aws_launch_time' => @now.iso8601,
|
278
|
+
'ami_launch_index'=>"0",
|
279
|
+
'architecture'=>"i386",
|
280
|
+
'aws_reason' => ""
|
281
|
+
}
|
282
|
+
end
|
283
|
+
servers = subject.virtual_servers.order(:provided_id, :asc).to_a
|
284
|
+
servers.each(&assert_server)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
shared_examples_for "取得した名前が反映される" do
|
289
|
+
it do
|
290
|
+
assert_server = lambda do |server, index|
|
291
|
+
name = "i-" + ((index + 1).to_s * 8)
|
292
|
+
server.name.should == name
|
293
|
+
server.provided_id.should == name
|
294
|
+
end
|
295
|
+
servers = subject.virtual_servers.order(:provided_id, :asc).to_a
|
296
|
+
servers.each_with_index(&assert_server)
|
297
|
+
end
|
298
|
+
end
|
299
|
+
|
300
|
+
shared_examples_for "取得したIPとホスト名が反映される" do
|
301
|
+
it do
|
302
|
+
assert_server = lambda do |server, index|
|
303
|
+
server.addresses['dns_name'].should == "ec2-184-72-203-#{index + 101}.us-west-1.compute.amazonaws.com"
|
304
|
+
server.addresses['ip_address'].should == "184.72.20.#{index + 101}"
|
305
|
+
server.addresses['private_dns_name'].should == "ip-10-162-153-#{index + 101}.us-west-1.compute.internal"
|
306
|
+
server.addresses['private_ip_address'].should == "10.162.153.#{index + 101}"
|
307
|
+
end
|
308
|
+
servers = subject.virtual_servers.order(:provided_id, :asc).to_a
|
309
|
+
servers.each_with_index(&assert_server)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
shared_examples_for "取得した状態が反映される" do
|
314
|
+
it do
|
315
|
+
servers = subject.virtual_servers.order(:provided_id, :asc).to_a
|
316
|
+
servers.each do |server|
|
317
|
+
server.status.should == "running"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context "最初の実行時には物理サーバを登録する" do
|
323
|
+
before do
|
324
|
+
subject.virtual_servers.count.should == 0
|
325
|
+
subject.update_virtual_servers
|
326
|
+
subject.virtual_servers.count.should == 3
|
327
|
+
end
|
328
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
329
|
+
it_behaves_like "取得した名前が反映される"
|
330
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
331
|
+
it_behaves_like "取得した状態が反映される"
|
332
|
+
end
|
333
|
+
|
334
|
+
context "すでに1台登録されている場合" do
|
335
|
+
before do
|
336
|
+
subject.virtual_servers.create(@base_attrs.merge({
|
337
|
+
:name => "i-11111111",
|
338
|
+
:provided_id => "i-11111111",
|
339
|
+
:addresses => {
|
340
|
+
'dns_name' => "ec2-184-72-203-101.us-west-1.compute.amazonaws.com",
|
341
|
+
'ip_address' => "184.72.20.101",
|
342
|
+
'private_dns_name' => "ip-10-162-153-101.us-west-1.compute.internal",
|
343
|
+
'private_ip_address' => "10.162.153.101",
|
344
|
+
},
|
345
|
+
}))
|
346
|
+
subject.virtual_servers.count.should == 1
|
347
|
+
subject.update_virtual_servers
|
348
|
+
subject.virtual_servers.count.should == 3
|
349
|
+
end
|
350
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
351
|
+
it_behaves_like "取得した名前が反映される"
|
352
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
353
|
+
it_behaves_like "取得した状態が反映される"
|
354
|
+
end
|
355
|
+
|
356
|
+
context "すでに3台登録されている場合" do
|
357
|
+
context "何も変わらない場合" do
|
358
|
+
before do
|
359
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[0]))
|
360
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[1]))
|
361
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[2]))
|
362
|
+
subject.virtual_servers.count.should == 3
|
363
|
+
subject.update_virtual_servers
|
364
|
+
subject.virtual_servers.count.should == 3
|
365
|
+
end
|
366
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
367
|
+
it_behaves_like "取得した名前が反映される"
|
368
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
369
|
+
it_behaves_like "取得した状態が反映される"
|
370
|
+
end
|
371
|
+
|
372
|
+
context "状態が変わった場合" do
|
373
|
+
before do
|
374
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[0]))
|
375
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[1]).merge(:state => "shutting_down"))
|
376
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[2]))
|
377
|
+
subject.virtual_servers.count.should == 3
|
378
|
+
subject.update_virtual_servers
|
379
|
+
subject.virtual_servers.count.should == 3
|
380
|
+
end
|
381
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
382
|
+
it_behaves_like "取得した名前が反映される"
|
383
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
384
|
+
it_behaves_like "取得した状態が反映される"
|
385
|
+
end
|
386
|
+
|
387
|
+
context "nameが管理画面で変更されていた場合" do
|
388
|
+
before do
|
389
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[0]).merge(:name => "master1"))
|
390
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[1]).merge(:name => "slave1"))
|
391
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[2]).merge(:name => "slave2"))
|
392
|
+
subject.virtual_servers.count.should == 3
|
393
|
+
subject.update_virtual_servers
|
394
|
+
subject.virtual_servers.count.should == 3
|
395
|
+
end
|
396
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
397
|
+
# it_behaves_like "取得した名前が反映される"
|
398
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
399
|
+
it_behaves_like "取得した状態が反映される"
|
400
|
+
|
401
|
+
it "nameはTenigneで指定するものなので更新されません" do
|
402
|
+
servers = subject.virtual_servers.order(:provided_id, :asc).to_a
|
403
|
+
servers[0].name.should == "master1"
|
404
|
+
servers[1].name.should == "slave1"
|
405
|
+
servers[2].name.should == "slave2"
|
406
|
+
servers[0].provided_id.should == "i-11111111"
|
407
|
+
servers[1].provided_id.should == "i-22222222"
|
408
|
+
servers[2].provided_id.should == "i-33333333"
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context "すでに4台登録されている場合" do
|
414
|
+
before do
|
415
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[0]))
|
416
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[1]))
|
417
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[2]))
|
418
|
+
subject.virtual_servers.create(@base_attrs.merge(@server_base_attrs[3]))
|
419
|
+
subject.virtual_servers.count.should == 4
|
420
|
+
subject.update_virtual_servers
|
421
|
+
subject.reload
|
422
|
+
subject.virtual_servers.count.should == 3
|
423
|
+
end
|
424
|
+
# 仮想サーバ基盤が管理している仮想サーバが減ることは通常あり得ることなので、物理サーバの場合と違ってTenigneもデータを削除する
|
425
|
+
it_behaves_like "取得したstaticな情報が反映される"
|
426
|
+
it_behaves_like "取得した名前が反映される"
|
427
|
+
it_behaves_like "取得したIPとホスト名が反映される"
|
428
|
+
it_behaves_like "取得した状態が反映される"
|
429
|
+
end
|
430
|
+
|
431
|
+
context "仮想マシンの起動" do
|
432
|
+
it "1台の起動" do
|
433
|
+
vi = subject.virtual_server_images.create(:provided_id => "ami-e444444d")
|
434
|
+
vt = subject.virtual_server_types.create(:provided_id => "m1.small")
|
435
|
+
vs = subject.create_virtual_servers(
|
436
|
+
"name", vi, vt, "us-east-1b", "description", 1, 1, ["my_awesome_group"], "my_awesome_key", "", "aki-9905e0f0", "ari-8605e0ef",
|
437
|
+
)
|
438
|
+
vs.count.should == 1
|
439
|
+
v = vs.first
|
440
|
+
v.should be_valid
|
441
|
+
v.status.should == "pending"
|
442
|
+
v.name.should == "name001"
|
443
|
+
v.provided_image_id.should == vi.provided_id
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "仮想マシンの停止" do
|
448
|
+
it "1台の停止" do
|
449
|
+
vs = subject.virtual_servers.create(:provided_id => 'i-f222222d', :name => 'i-f222222d')
|
450
|
+
va = subject.terminate_virtual_servers([vs])
|
451
|
+
va.count.should == 1
|
452
|
+
v = va[0]
|
453
|
+
v.should_not be_nil
|
454
|
+
v.should be_valid
|
455
|
+
v.provided_id.should == 'i-f222222d'
|
456
|
+
end
|
457
|
+
|
458
|
+
it "複数台の停止" do
|
459
|
+
v1 = subject.virtual_servers.create(:provided_id => 'i-f222222d', :name => 'i-f222222d')
|
460
|
+
v2 = subject.virtual_servers.create(:provided_id => 'i-f222222e', :name => 'i-f222222e')
|
461
|
+
va = subject.terminate_virtual_servers([v1 ,v2])
|
462
|
+
va.count.should == 2
|
463
|
+
va[0].should_not be_nil
|
464
|
+
va[0].should be_valid
|
465
|
+
va[0].provided_id.should == 'i-f222222d'
|
466
|
+
va[1].should_not be_nil
|
467
|
+
va[1].should be_valid
|
468
|
+
va[1].provided_id.should == 'i-f222222e'
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
472
|
+
end
|
473
|
+
end
|