tengine_resource 0.5.15 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/Gemfile +1 -27
  2. data/Gemfile.lock +60 -73
  3. data/README.rdoc +2 -2
  4. data/bin/create_indexes_for_tengine_resource +18 -0
  5. data/lib/tengine/resource/config/resource.rb +0 -3
  6. data/lib/tengine/resource/credential.rb +16 -17
  7. data/lib/tengine/resource/net_ssh.rb +22 -10
  8. data/lib/tengine/resource/physical_server.rb +8 -0
  9. data/lib/tengine/resource/provider.rb +206 -35
  10. data/lib/tengine/resource/server.rb +3 -3
  11. data/lib/tengine/resource/virtual_server.rb +1 -1
  12. data/lib/tengine/resource/virtual_server_image.rb +8 -8
  13. data/lib/tengine/resource/virtual_server_type.rb +2 -2
  14. data/lib/tengine/resource/watcher.rb +39 -9
  15. data/tmp/.gitkeep +0 -0
  16. metadata +92 -141
  17. data/.document +0 -5
  18. data/.rspec +0 -1
  19. data/Rakefile +0 -42
  20. data/VERSION +0 -1
  21. data/config/.gitignore +0 -2
  22. data/lib/tengine/resource/credential/ec2.rb +0 -5
  23. data/lib/tengine/resource/credential/ec2/dummy.rb +0 -148
  24. data/lib/tengine/resource/credential/ec2/launch_options.rb +0 -179
  25. data/lib/tengine/resource/provider/ec2.rb +0 -187
  26. data/lib/tengine/resource/provider/wakame.rb +0 -638
  27. data/spec/fixtures/goku_at_ec2_ap_northeast.rb +0 -177
  28. data/spec/mongoid.yml +0 -35
  29. data/spec/mongoid_en.yml +0 -48
  30. data/spec/spec_helper.rb +0 -43
  31. data/spec/support/ec2.rb +0 -129
  32. data/spec/support/mongo_index_key_log.rb +0 -91
  33. data/spec/tengine/resource/bugfix/watcher_for_wakame_spec.rb +0 -232
  34. data/spec/tengine/resource/credential_spec.rb +0 -205
  35. data/spec/tengine/resource/drivers/resource_control_driver_spec.rb +0 -84
  36. data/spec/tengine/resource/net_ssh_spec.rb +0 -148
  37. data/spec/tengine/resource/physical_server_spec.rb +0 -47
  38. data/spec/tengine/resource/provider/ec2_spec.rb +0 -473
  39. data/spec/tengine/resource/provider/test_files/describe_host_nodes.json +0 -22
  40. data/spec/tengine/resource/provider/test_files/describe_images.json +0 -23
  41. data/spec/tengine/resource/provider/test_files/describe_instance_specs.json +0 -23
  42. data/spec/tengine/resource/provider/test_files/describe_instances.json +0 -56
  43. data/spec/tengine/resource/provider/test_files/run_instances.json +0 -30
  44. data/spec/tengine/resource/provider/test_files/terminate_instances.json +0 -3
  45. data/spec/tengine/resource/provider/wakame/00_describe_host_nodes_0_physical_servers.json +0 -8
  46. data/spec/tengine/resource/provider/wakame/01_describe_host_nodes_10_physical_servers.json +0 -139
  47. data/spec/tengine/resource/provider/wakame/02_describe_host_nodes_60_physical_servers.json +0 -795
  48. data/spec/tengine/resource/provider/wakame/10_describe_instances_0_virtual_servers.json +0 -8
  49. data/spec/tengine/resource/provider/wakame/11_describe_instances_10_virtual_servers.json +0 -469
  50. data/spec/tengine/resource/provider/wakame/12_describe_instances_after_run_instances.json +0 -280
  51. data/spec/tengine/resource/provider/wakame/13_describe_instances_after_terminate_instances.json +0 -279
  52. data/spec/tengine/resource/provider/wakame/20_describe_images_0_virtual_server_images.json +0 -8
  53. data/spec/tengine/resource/provider/wakame/21_describe_images_5_virtual_server_images.json +0 -84
  54. data/spec/tengine/resource/provider/wakame/22_describe_images_60_virtual_server_images.json +0 -856
  55. data/spec/tengine/resource/provider/wakame/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
  56. data/spec/tengine/resource/provider/wakame/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
  57. data/spec/tengine/resource/provider/wakame/40_run_instances_0_virtual_servers.json +0 -1
  58. data/spec/tengine/resource/provider/wakame/41_run_instances_1_virtual_servers.json +0 -22
  59. data/spec/tengine/resource/provider/wakame/42_run_instances_5_virtual_servers.json +0 -106
  60. data/spec/tengine/resource/provider/wakame/50_terminate_instances_0_virtual_servers.json +0 -1
  61. data/spec/tengine/resource/provider/wakame/51_terminate_instances_3_virtual_servers.json +0 -5
  62. data/spec/tengine/resource/provider/wakame/sync_physical_servers_spec.rb +0 -114
  63. data/spec/tengine/resource/provider/wakame/sync_virtual_server_images_spec.rb +0 -116
  64. data/spec/tengine/resource/provider/wakame/sync_virtual_server_types_spec.rb +0 -116
  65. data/spec/tengine/resource/provider/wakame/sync_virtual_servers_spec.rb +0 -216
  66. data/spec/tengine/resource/provider/wakame_api_spec.rb +0 -319
  67. data/spec/tengine/resource/provider/wakame_spec.rb +0 -339
  68. data/spec/tengine/resource/provider_spec.rb +0 -252
  69. data/spec/tengine/resource/server_spec.rb +0 -195
  70. data/spec/tengine/resource/test_files/.gitignore +0 -6
  71. data/spec/tengine/resource/test_files/00_describe_host_nodes_0_physical_servers.json +0 -8
  72. data/spec/tengine/resource/test_files/01_describe_host_nodes_10_physical_servers.json +0 -139
  73. data/spec/tengine/resource/test_files/02_describe_host_nodes_60_physical_servers.json +0 -795
  74. data/spec/tengine/resource/test_files/10_describe_instances_0_virtual_servers.json +0 -8
  75. data/spec/tengine/resource/test_files/11_describe_instances_10_virtual_servers.json +0 -469
  76. data/spec/tengine/resource/test_files/12_describe_instances_after_run_instances.json +0 -280
  77. data/spec/tengine/resource/test_files/13_describe_instances_after_terminate_instances.json +0 -279
  78. data/spec/tengine/resource/test_files/14_describe_instances_after_run_1_instance.json +0 -55
  79. data/spec/tengine/resource/test_files/20_describe_images_0_virtual_server_images.json +0 -8
  80. data/spec/tengine/resource/test_files/21_describe_images_5_virtual_server_images.json +0 -84
  81. data/spec/tengine/resource/test_files/22_describe_images_60_virtual_server_images.json +0 -856
  82. data/spec/tengine/resource/test_files/30_describe_instance_specs_0_virtual_server_specs.json +0 -8
  83. data/spec/tengine/resource/test_files/31_describe_instance_specs_4_virtual_server_specs.json +0 -66
  84. data/spec/tengine/resource/test_files/40_run_instances_0_virtual_servers.json +0 -1
  85. data/spec/tengine/resource/test_files/41_run_instances_1_virtual_servers.json +0 -22
  86. data/spec/tengine/resource/test_files/42_run_instances_5_virtual_servers.json +0 -106
  87. data/spec/tengine/resource/test_files/43_run_instances_1_virtual_servers_without_aws_availability_zone.json +0 -22
  88. data/spec/tengine/resource/test_files/50_terminate_instances_0_virtual_servers.json +0 -1
  89. data/spec/tengine/resource/test_files/51_terminate_instances_3_virtual_servers.json +0 -5
  90. data/spec/tengine/resource/virtual_server_image_spec.rb +0 -94
  91. data/spec/tengine/resource/virtual_server_spec.rb +0 -116
  92. data/spec/tengine/resource/virtual_server_type_spec.rb +0 -4
  93. data/spec/tengine/resource/watcher_spec.rb +0 -1027
  94. data/spec/tengine_resource_spec.rb +0 -5
  95. data/tengine_resource.gemspec +0 -172
  96. data/tmp/log/.gitignore +0 -1
@@ -1,148 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
- require 'tengine/resource/net_ssh'
4
-
5
- describe Net::SSH do
6
- describe :start do
7
- before do
8
- @e = Exception.new("ok")
9
- Net::SSH::Transport::Session.stub(:new).with(anything, anything).and_raise(@e)
10
- end
11
-
12
- after do
13
- Tengine::Resource::Credential.delete_all(:name => "ssh1")
14
- end
15
-
16
- describe "``Net::SSH.start(hostname, credential) {|ctx| ... }''" do
17
- describe "auth_type_key: :ssh_password" do
18
- it "starts" do
19
- c = Tengine::Resource::Credential.new(
20
- :name => "ssh1",
21
- :auth_type_key => :ssh_password,
22
- :auth_values => {:username => 'goku', :password => "password1"})
23
-
24
- expect { Net::SSH.start "localhost", c }.to raise_error(@e)
25
- end
26
- end
27
-
28
- describe "auth_type_key: :ssh_public_key" do
29
- it "starts" do
30
- c = Tengine::Resource::Credential.new(
31
- :name => "ssh1",
32
- :auth_type_key => :ssh_public_key,
33
- :auth_values => {:username => 'goku', :private_keys => <<END, :passphrase => ""})
34
- -----BEGIN RSA PRIVATE KEY-----
35
- MIIEoAIBAAKCAQEAvdBvdpWxMumGZsyWpnsPetEW0da5/5sIfSgP8pAVgibp492O
36
- l++LQlITsSf3Lt/WOQNEfOrfU7HFZuRk3b7dPTJFneG+AIXS8PdrxDO8e9DSG1D4
37
- xDAgSrG4inuSQju1EPaPhIz7r0eg1tupP6UM8GVUu90zO7OCnvjYOPjNRvibW5ao
38
- dzo4T5cOLBZuUm3RqclQLehLAQpG6p+d6DbADTVVNpvgk+VfPpKI9E+q944ivJIM
39
- 0KLNWyfEbxjoXuYnZYn1em6MHcaXsR1I5rlzuhfOaukerqFulG3MkU6A2t/CfbXM
40
- PiOtwPSse7ZuoBtdFhnxUpGRmlPoSvezfSz23wIBIwKCAQA7p+iEWu6MWAWrR50P
41
- wEaxkiu+Ssy+DCc9Rxr0dm0o56iYEm6kx6DLs2VGTmOhBIUn3HScSdEo7rpiKoYZ
42
- zkWIQv/vyprM9tvlVRM9qdwm6duiL2QgZuWT0XSDS2h7N1Yp5xcpqKbfUQap7UPS
43
- LI8JuXJm7b+lDIgjVYXIwzkzj2qEkoF+p8hHWD7X3v6db6Gz7+HMQx/rc6yMrZ0H
44
- RF/CKHOWvriY/41CxsYvpAK0ksXTXupxzEJdItvHYIJsQW6gxBGtxWo7Y55si8w/
45
- VBgmkiQ/wPVZsQ5omo3lwrLohW0k7xO8ZX2sAweb/NUKhZi0KcrwTHFT5MbwxrHi
46
- GGcbAoGBAPvjaPtg9171h+xu/MlpOBivhfApdhrEoRfn5Np8OmSRtOC5hK/UyQtk
47
- Ot4G10KQziK98xkSQ3OphR/kQA8oiq+TfZvPKJ69GYqLpWkBdM2rNXph5BCahri+
48
- qO04wqgpZkG7obCMrKXPNQj1MWhCAy5mRNYcuWSEeIXZZ66TT1SZAoGBAMDpoVbg
49
- W4qlmUKCme8i0ofsSB00s+HyJ6zmBriDaJ8o/77jQ/ypwKmox+6Ebo5WvnNGzgnI
50
- puOgkNH5MWjGoowvnH6CXWzSQYlvAOGnZ58IhbIm5OolRHC3fASUw0JZRVQGvlFC
51
- v73ltf+td9TfhmAVfqzE5PMK7C9E6UNJBFo3AoGAVlyZBbrYeFQumjSucPDgCHax
52
- lCt48zwZ+ZFVx0CJDIm6W61SEGY2TQxr9Fod6u/RpYL0Qxw0Yit+GZAV9pGOopj3
53
- 3aYcjjI0pIembSUSGqEZpk1yw901gSttHiIW2pHZ6qa7F/W3iU5bU4dEI77chO/d
54
- FjW75/Lnflkq3MTKvesCgYALBgk4KhPcCXZ41ENPflUsVqUI+7KB8JSNiXy6FiM8
55
- S3xUDPySGFQm87OnOsR9KYc5yYgd0POX+ovuvchPIUsd9BeSM1XLtD5CXh1OuRvd
56
- M6/eS12JuPyYugcWNGLt2TcpX3iW7d8SKmIr3gbY9tR6hOKqyWwrJTIRVGUZyah6
57
- LwKBgA+Fdse5WibNPG1smoS/JzmPdrdD46x2D7HoLtbcNF4rPlduVI8yS3dRSqi4
58
- Gh5L65ukAbWSC8yuQpKtq3EfpNcf83a+Xc5XXANbTgN/+sJjgd+ycmPzLv5Zcsg9
59
- 8xlb43zLCiEf5TyrlbmqfM97hxuPbrgifyU7jMaTdmHHGsDx
60
- -----END RSA PRIVATE KEY-----
61
- END
62
-
63
- expect { Net::SSH.start "localhost", c }.to raise_error(@e)
64
- end
65
- end
66
- end
67
-
68
- describe "``Net::SSH.start(hostname, user, credential) {|ctx| ... }''" do
69
- describe "normal path" do
70
- it "starts" do
71
- c = Tengine::Resource::Credential.new(
72
- :name => "ssh1",
73
- :auth_type_key => :ssh_password,
74
- :auth_values => {:password => "password1"})
75
-
76
- expect { Net::SSH.start "localhost", "goku", c }.to raise_error(@e)
77
- end
78
- end
79
-
80
- describe "conflicted username" do
81
- subject do
82
- c = Tengine::Resource::Credential.new(
83
- :name => "ssh1",
84
- :auth_type_key => :ssh_password,
85
- :auth_values => {:username => "goku", :password => "password1"})
86
-
87
- expect { Net::SSH.start "localhost", "goku", c }
88
- end
89
- it { should raise_error(ArgumentError) }
90
- end
91
- end
92
-
93
- describe "``Net::SSH.start(hostname, credential, other_opts) {|ctx| ... }''" do
94
- describe "normal path" do
95
- it "starts" do
96
- c = Tengine::Resource::Credential.new(
97
- :name => "ssh1",
98
- :auth_type_key => :ssh_password,
99
- :auth_values => {:username => "goku"})
100
-
101
- expect { Net::SSH.start "localhost", c, :password => "passowrd1" }.to raise_error(@e)
102
- end
103
- end
104
-
105
- describe "conflicted option" do
106
- subject do
107
- c = Tengine::Resource::Credential.new(
108
- :name => "ssh1",
109
- :auth_type_key => :ssh_password,
110
- :auth_values => {:username => "goku", :password => "password1"})
111
-
112
- expect { Net::SSH.start "localhost", c, :password => "password1" }
113
- end
114
- it { should raise_error(ArgumentError) }
115
- end
116
- end
117
-
118
- describe "``Net::SSH.start(hostname, user, other_opts) {|ctx| ... }''" do
119
- describe "normal path" do
120
- it "starts" do
121
- expect { Net::SSH.start "localhost", "goku", :password => "passowrd1" }.to raise_error(@e)
122
- end
123
- end
124
-
125
- describe "unknown key" do
126
- subject do
127
- expect { Net::SSH.start "localhost", "goku", :foo => "bar" }
128
- end
129
- it { should raise_error(ArgumentError) }
130
- end
131
- end
132
-
133
- describe "``Net::SSH.start(hostname, other_opts) {|ctx| ... }''" do
134
- describe "normal path" do
135
- it "starts" do
136
- expect { Net::SSH.start "localhost", :username => "goku", :password => "passowrd1" }.to raise_error(@e)
137
- end
138
- end
139
-
140
- describe "missing username" do
141
- subject do
142
- expect { Net::SSH.start "localhost", :password => "password1" }
143
- end
144
- it { should raise_error(ArgumentError) }
145
- end
146
- end
147
- end
148
- end
@@ -1,47 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require 'spec_helper'
3
-
4
- describe Tengine::Resource::PhysicalServer do
5
- context "nameで検索" do
6
- before do
7
- Tengine::Resource::Server.delete_all
8
- @fixture = GokuAtEc2ApNortheast.new
9
- @physical1 = @fixture.availability_zone(1)
10
- @virtual1 = @fixture.hadoop_master_node
11
- end
12
-
13
- context "見つかる場合" do
14
- it "find_by_name" do
15
- found_credential = nil
16
- lambda{
17
- found_credential = Tengine::Resource::PhysicalServer.find_by_name(@physical1.name)
18
- }.should_not raise_error
19
- found_credential.should_not be_nil
20
- found_credential.id.should == @physical1.id
21
- end
22
-
23
- it "find_by_name!" do
24
- found_credential = nil
25
- lambda{
26
- found_credential = Tengine::Resource::PhysicalServer.find_by_name!(@physical1.name)
27
- }.should_not raise_error
28
- found_credential.should_not be_nil
29
- found_credential.id.should == @physical1.id
30
- end
31
- end
32
-
33
- context "見つからない場合" do
34
- it "find_by_name" do
35
- found_credential = Tengine::Resource::PhysicalServer.find_by_name(@virtual1.name).should == nil
36
- end
37
-
38
- it "find_by_name!" do
39
- lambda{
40
- found_credential = Tengine::Resource::PhysicalServer.find_by_name!(@virtual1.name)
41
- }.should raise_error(Tengine::Core::FindByName::Error)
42
- end
43
- end
44
-
45
- end
46
-
47
- end
@@ -1,473 +0,0 @@
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