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,205 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'net/ssh'
|
4
|
+
|
5
|
+
describe Tengine::Resource::Credential do
|
6
|
+
|
7
|
+
valid_attributes1 = {
|
8
|
+
:name => "ssh-private_key",
|
9
|
+
:auth_type_key => :ssh_password,
|
10
|
+
:auth_values => {
|
11
|
+
:username => 'user1',
|
12
|
+
:password => "password1",
|
13
|
+
}
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
context "name、auth_type_cd、auth_values は必須" do
|
17
|
+
it "正常系" do
|
18
|
+
Tengine::Resource::Credential.delete_all
|
19
|
+
credential1 = Tengine::Resource::Credential.new(valid_attributes1)
|
20
|
+
credential1.valid?.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
[:name, :auth_type_key].each do |key|
|
24
|
+
it "#{key}なし" do
|
25
|
+
attrs = valid_attributes1.dup
|
26
|
+
attrs.delete(key)
|
27
|
+
credential1 = Tengine::Resource::Credential.new(attrs)
|
28
|
+
credential1.valid?.should == false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
context "nameはユニーク" do
|
35
|
+
before do
|
36
|
+
Tengine::Resource::Credential.delete_all
|
37
|
+
@credential1 = Tengine::Resource::Credential.create!(valid_attributes1)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "同じ名前で登録されているものが存在する場合エラー" do
|
41
|
+
expect{
|
42
|
+
@credential1 = Tengine::Resource::Credential.create!(valid_attributes1)
|
43
|
+
}.to raise_error(Mongoid::Errors::Validations, "Validation failed - Name is already taken.")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "nameはベース名として定義される文字列です" do
|
48
|
+
it "スラッシュ'/’はリソース識別子で使われるのでnameには使用できません" do
|
49
|
+
server1 = Tengine::Resource::Credential.new(:name => "foo/bar")
|
50
|
+
server1.valid?.should == false
|
51
|
+
server1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
|
52
|
+
end
|
53
|
+
|
54
|
+
it "コロン':'はリソース識別子で使われるのでnameには使用できません" do
|
55
|
+
server1 = Tengine::Resource::Credential.new(:name => "foo:bar")
|
56
|
+
server1.valid?.should == false
|
57
|
+
server1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
context "nameで検索" do
|
63
|
+
before do
|
64
|
+
Tengine::Resource::Credential.delete_all
|
65
|
+
@credential = Tengine::Resource::Credential.create!(valid_attributes1)
|
66
|
+
end
|
67
|
+
|
68
|
+
context "見つかる場合" do
|
69
|
+
it "name で検索できるか" do
|
70
|
+
found_credential = nil
|
71
|
+
lambda{
|
72
|
+
found_credential = Tengine::Resource::Credential.first(:conditions => {:name => "ssh-private_key"})
|
73
|
+
}.should_not raise_error
|
74
|
+
found_credential.should_not be_nil
|
75
|
+
found_credential.id.should == @credential.id
|
76
|
+
end
|
77
|
+
|
78
|
+
it "find_by_name" do
|
79
|
+
found_credential = nil
|
80
|
+
lambda{
|
81
|
+
found_credential = Tengine::Resource::Credential.find_by_name("ssh-private_key")
|
82
|
+
}.should_not raise_error
|
83
|
+
found_credential.should_not be_nil
|
84
|
+
found_credential.id.should == @credential.id
|
85
|
+
end
|
86
|
+
|
87
|
+
it "find_by_name!" do
|
88
|
+
found_credential = nil
|
89
|
+
lambda{
|
90
|
+
found_credential = Tengine::Resource::Credential.find_by_name!("ssh-private_key")
|
91
|
+
}.should_not raise_error
|
92
|
+
found_credential.should_not be_nil
|
93
|
+
found_credential.id.should == @credential.id
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "見つからない場合" do
|
98
|
+
it "find_by_name" do
|
99
|
+
found_credential = Tengine::Resource::Credential.find_by_name("unexist_name").should == nil
|
100
|
+
end
|
101
|
+
|
102
|
+
it "find_by_name!" do
|
103
|
+
lambda{
|
104
|
+
found_credential = Tengine::Resource::Credential.find_by_name!("unexist_name")
|
105
|
+
}.should raise_error(Tengine::Core::FindByName::Error)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
describe :secure_auth_values, "外部に見せても良いように見せちゃ拙い情報は取り除く" do
|
113
|
+
it :ssh_password do
|
114
|
+
credential = Tengine::Resource::Credential.new(:name => "ssh-pass1",
|
115
|
+
:auth_type_key => :ssh_password,
|
116
|
+
:auth_values => {:username => 'goku', :password => "password1"})
|
117
|
+
credential.secure_auth_values.should == {'username' => 'goku'}
|
118
|
+
end
|
119
|
+
|
120
|
+
it :ssh_public_key do
|
121
|
+
credential = Tengine::Resource::Credential.new(:name => "ssh-pk1",
|
122
|
+
:auth_type_key => :ssh_public_key,
|
123
|
+
:auth_values => {:username => 'goku', :private_keys => "pkxxxxx", :passphrase => "abc"})
|
124
|
+
credential.secure_auth_values.should == {'username' => 'goku'}
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe :auth_values_validation do
|
130
|
+
context "valid" do
|
131
|
+
|
132
|
+
describe :ssh_password do
|
133
|
+
it "キーがSymbol" do
|
134
|
+
Tengine::Resource::Credential.new(:name => "ssh-pass1",
|
135
|
+
:auth_type_key => :ssh_password,
|
136
|
+
:auth_values => {:username => 'goku', :password => "password1"}).valid?.should == true
|
137
|
+
end
|
138
|
+
it "キーが文字列" do
|
139
|
+
Tengine::Resource::Credential.new(:name => "ssh-pass1",
|
140
|
+
:auth_type_key => :ssh_password,
|
141
|
+
:auth_values => {'username' => 'goku', 'password' => "password1"}).valid?.should == true
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe :ssh_public_key do
|
146
|
+
it "キーがSymbol" do
|
147
|
+
Tengine::Resource::Credential.new(:name => "ssh-pk1",
|
148
|
+
:auth_type_key => :ssh_public_key,
|
149
|
+
:auth_values => {:username => 'goku', :private_keys => "pkxxxxx"}).valid?.should == true
|
150
|
+
end
|
151
|
+
it "キーが文字列" do
|
152
|
+
Tengine::Resource::Credential.new(:name => "ssh-pk1",
|
153
|
+
:auth_type_key => :ssh_public_key,
|
154
|
+
:auth_values => {'username' => 'goku', 'private_keys' => "pkxxxxx"}).valid?.should == true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
context "invalid" do
|
161
|
+
describe :ssh_password do
|
162
|
+
it ":usernameが空文字列" do
|
163
|
+
Tengine::Resource::Credential.new(:name => "ssh-pass1",
|
164
|
+
:auth_type_key => :ssh_password,
|
165
|
+
:auth_values => {:username => '', :password => "password1"}).valid?.should == false
|
166
|
+
end
|
167
|
+
it "passwordなし" do
|
168
|
+
Tengine::Resource::Credential.new(:name => "ssh-pass1",
|
169
|
+
:auth_type_key => :ssh_password,
|
170
|
+
:auth_values => {'username' => 'goku'}).valid?.should == false
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe :ssh_public_key do
|
175
|
+
it ":usernameなし" do
|
176
|
+
credential1 = Tengine::Resource::Credential.new(:name => "ssh-pk1",
|
177
|
+
:auth_type_key => :ssh_public_key,
|
178
|
+
:auth_values => {:private_keys => "pkxxxxx"})
|
179
|
+
credential1.valid?.should == false
|
180
|
+
end
|
181
|
+
it "private_keyが空文字列" do
|
182
|
+
credential1 = Tengine::Resource::Credential.new(:name => "ssh-pk1",
|
183
|
+
:auth_type_key => :ssh_public_key,
|
184
|
+
:auth_values => {'username' => 'goku', 'private_keys' => ""})
|
185
|
+
credential1.valid?.should == false
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe :ec2_access_key do
|
190
|
+
it "access_keyが空文字列" do
|
191
|
+
credential1 = Tengine::Resource::Credential.new(:name => "ec2-access-key1",
|
192
|
+
:auth_type_key => :ec2_access_key,
|
193
|
+
:auth_values => {:access_key => '', :secret_access_key => "abcdef"})
|
194
|
+
credential1.valid?.should == false
|
195
|
+
end
|
196
|
+
it "secret_access_keyがnil" do
|
197
|
+
credential1 = Tengine::Resource::Credential.new(:name => "ec2-access-key1",
|
198
|
+
:auth_type_key => :ec2_access_key,
|
199
|
+
:auth_values => {'access_key' => '12345', 'secret_access_key' => nil})
|
200
|
+
credential1.valid?.should == false
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
__END__
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'tengine/rspec'
|
5
|
+
|
6
|
+
describe 'resource_control_driver' do
|
7
|
+
include Tengine::RSpec::Extension
|
8
|
+
|
9
|
+
target_dsl File.expand_path("../../../../lib/tengine/resource/drivers/resource_control_driver.rb", File.dirname(__FILE__))
|
10
|
+
driver :resource_control_driver
|
11
|
+
|
12
|
+
before do
|
13
|
+
Tengine::Resource::Provider::Wakame.delete_all(:name => 'tama0001')
|
14
|
+
@provider = Tengine::Resource::Provider::Wakame.create!(
|
15
|
+
:name => "tama0001",
|
16
|
+
:description => "provided by wakame / tama",
|
17
|
+
:connection_settings => {
|
18
|
+
:account => "a-shpoolxx",
|
19
|
+
:ec2_host => "192.168.2.22",
|
20
|
+
:ec2_port => 9005,
|
21
|
+
:ec2_protocol => "https",
|
22
|
+
:wakame_host => "192.168.2.22",
|
23
|
+
:wakame_port => 9001,
|
24
|
+
:wakame_protocol => "https",},
|
25
|
+
:properties => { :key_name => "ssh-xxxxx" })
|
26
|
+
end
|
27
|
+
|
28
|
+
context '仮想サーバ起動リクエストイベント' do
|
29
|
+
it "反応する" do
|
30
|
+
vi = @provider.virtual_server_images.create!(:provided_id => "wmi-lucid5", :name => "wmi-lucid5")
|
31
|
+
vt = @provider.virtual_server_types.create!(:provided_id => "is-small", :name => "is-small")
|
32
|
+
ps = @provider.physical_servers.create!(:provided_id => "foo-dc", :name => "foo-dc")
|
33
|
+
@provider.
|
34
|
+
should_receive(:create_virtual_servers).
|
35
|
+
with(:virtual_server_image => vi,
|
36
|
+
:virtual_server_type => vt,
|
37
|
+
:physical_server => ps,
|
38
|
+
:count => 1)
|
39
|
+
Tengine::Resource::Provider::Wakame.stub(:instantiate).with(anything).and_return(@provider)
|
40
|
+
|
41
|
+
tengine.receive('仮想サーバ起動リクエストイベント', :properties => {
|
42
|
+
:provider_id => @provider._id,
|
43
|
+
:virtual_server_image_id => vi._id,
|
44
|
+
:virtual_server_type_id => vt._id,
|
45
|
+
:physical_server_id => ps._id,
|
46
|
+
:count => 1,})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '仮想サーバ停止リクエストイベント' do
|
51
|
+
before do
|
52
|
+
Tengine::Resource::VirtualServer.delete_all
|
53
|
+
end
|
54
|
+
|
55
|
+
it "反応する" do
|
56
|
+
v1 = @provider.virtual_servers.create!(:provided_id => 'i-f222222d', :name => 'i-f222222d')
|
57
|
+
v2 = @provider.virtual_servers.create!(:provided_id => 'i-f222222e', :name => 'i-f222222e')
|
58
|
+
@provider.
|
59
|
+
should_receive(:terminate_virtual_servers).
|
60
|
+
with([v1, v2])
|
61
|
+
Tengine::Resource::Provider::Wakame.stub(:instantiate).with(anything).and_return(@provider)
|
62
|
+
|
63
|
+
tengine.receive('仮想サーバ停止リクエストイベント', :properties => {
|
64
|
+
:provider_id => @provider._id,
|
65
|
+
:virtual_servers => [v1._id, v2._id] })
|
66
|
+
end
|
67
|
+
|
68
|
+
it "存在しない仮想サーバを停止しようとすると例外がraiseされる" do
|
69
|
+
v1 = @provider.virtual_servers.create!(:provided_id => 'i-f222222d', :name => 'i-f222222d')
|
70
|
+
v2 = @provider.virtual_servers.create!(:provided_id => 'i-f222222e', :name => 'i-f222222e')
|
71
|
+
|
72
|
+
# 存在するはずの仮想サーバのデータを削除して例外を起こします
|
73
|
+
Tengine::Resource::VirtualServer.delete_all
|
74
|
+
|
75
|
+
begin
|
76
|
+
tengine.receive('仮想サーバ停止リクエストイベント', :properties => {
|
77
|
+
:provider_id => @provider._id,
|
78
|
+
:virtual_servers => [v1._id, v2._id] })
|
79
|
+
fail
|
80
|
+
rescue Mongoid::Errors::DocumentNotFound => e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,148 @@
|
|
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
|
@@ -0,0 +1,47 @@
|
|
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
|