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,66 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"owner_total": 2,
|
4
|
+
"start": 0,
|
5
|
+
"results": [
|
6
|
+
{
|
7
|
+
"id": "virtual_server_spec_uuid_01",
|
8
|
+
"uuid": "virtual_server_spec_uuid_01",
|
9
|
+
"cpu_cores": 1,
|
10
|
+
"memory_size": 256,
|
11
|
+
"arch": "x86_64",
|
12
|
+
"hypervisor": "kvm",
|
13
|
+
"updated_at": "2011-10-28T02:58:57Z",
|
14
|
+
"account_id": "a-shpoolxx",
|
15
|
+
"vifs": "--- \neth0: \n :bandwidth: 100000\n :index: 0\n",
|
16
|
+
"quota_weight": 1.0,
|
17
|
+
"created_at": "2011-10-28T02:58:57Z",
|
18
|
+
"drives": "--- \nephemeral1: \n :type: :local\n :size: 100\n :index: 0\n"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"id": "virtual_server_spec_uuid_02",
|
22
|
+
"uuid": "virtual_server_spec_uuid_02",
|
23
|
+
"cpu_cores": 2,
|
24
|
+
"memory_size": 512,
|
25
|
+
"arch": "x86_64",
|
26
|
+
"hypervisor": "kvm",
|
27
|
+
"updated_at": "2011-10-28T02:58:57Z",
|
28
|
+
"account_id": "a-shpoolxx",
|
29
|
+
"vifs": "--- \neth0: \n :bandwidth: 100000\n :index: 0\n",
|
30
|
+
"quota_weight": 1.0,
|
31
|
+
"created_at": "2011-10-28T02:58:57Z",
|
32
|
+
"drives": "--- \nephemeral1: \n :type: :local\n :size: 100\n :index: 0\n"
|
33
|
+
},
|
34
|
+
{
|
35
|
+
"id": "virtual_server_spec_uuid_03",
|
36
|
+
"uuid": "virtual_server_spec_uuid_03",
|
37
|
+
"cpu_cores": 5,
|
38
|
+
"memory_size": 1,
|
39
|
+
"arch": "x86_64",
|
40
|
+
"hypervisor": "kvm",
|
41
|
+
"updated_at": "2011-10-28T02:58:57Z",
|
42
|
+
"account_id": "a-shpoolxx",
|
43
|
+
"vifs": "--- \neth0: \n :bandwidth: 100000\n :index: 0\n",
|
44
|
+
"quota_weight": 1.0,
|
45
|
+
"created_at": "2011-10-28T02:58:57Z",
|
46
|
+
"drives": "--- \nephemeral1: \n :type: :local\n :size: 100\n :index: 0\n"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"id": "virtual_server_spec_uuid_04",
|
50
|
+
"uuid": "virtual_server_spec_uuid_04",
|
51
|
+
"cpu_cores": 1,
|
52
|
+
"memory_size": 1500,
|
53
|
+
"arch": "x86_64",
|
54
|
+
"hypervisor": "kvm",
|
55
|
+
"updated_at": "2011-10-28T02:58:57Z",
|
56
|
+
"account_id": "a-shpoolxx",
|
57
|
+
"vifs": "--- \neth0: \n :bandwidth: 100000\n :index: 0\n",
|
58
|
+
"quota_weight": 1.0,
|
59
|
+
"created_at": "2011-10-28T02:58:57Z",
|
60
|
+
"drives": "--- \nephemeral1: \n :type: :local\n :size: 100\n :index: 0\n"
|
61
|
+
}
|
62
|
+
|
63
|
+
],
|
64
|
+
"limit": null
|
65
|
+
}
|
66
|
+
]
|
@@ -0,0 +1 @@
|
|
1
|
+
[]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "virtual_server_uuid_91",
|
4
|
+
"state": "scheduling",
|
5
|
+
"image_id": "vertual_server_image_uuid_01",
|
6
|
+
"hostname": "physical_server_uuid_01",
|
7
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
8
|
+
"vif": [],
|
9
|
+
"status": "init",
|
10
|
+
"memory_size": 256,
|
11
|
+
"ha_enabled": 0,
|
12
|
+
"network": [],
|
13
|
+
"arch": "x86_64",
|
14
|
+
"host_node": "physical_server_uuid_01",
|
15
|
+
"created_at": "2011-10-18T06:48:47Z",
|
16
|
+
"netfilter_group_id": ["ng-demofgr"],
|
17
|
+
"ssh_key_pair": null,
|
18
|
+
"volume": [],
|
19
|
+
"netfilter_group": ["default"],
|
20
|
+
"cpu_cores": 1
|
21
|
+
}
|
22
|
+
]
|
@@ -0,0 +1,106 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "virtual_server_uuid_92",
|
4
|
+
"state": "scheduling",
|
5
|
+
"image_id": "vertual_server_image_uuid_01",
|
6
|
+
"hostname": "physical_server_uuid_01",
|
7
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
8
|
+
"vif": [],
|
9
|
+
"status": "init",
|
10
|
+
"memory_size": 256,
|
11
|
+
"ha_enabled": 0,
|
12
|
+
"network": [],
|
13
|
+
"arch": "x86_64",
|
14
|
+
"host_node": null,
|
15
|
+
"created_at": "2011-10-18T06:48:47Z",
|
16
|
+
"netfilter_group_id": ["ng-demofgr"],
|
17
|
+
"ssh_key_pair": null,
|
18
|
+
"volume": [],
|
19
|
+
"netfilter_group": ["default"],
|
20
|
+
"cpu_cores": 1
|
21
|
+
},
|
22
|
+
|
23
|
+
{
|
24
|
+
"id": "virtual_server_uuid_93",
|
25
|
+
"state": "scheduling",
|
26
|
+
"image_id": "vertual_server_image_uuid_01",
|
27
|
+
"hostname": "physical_server_uuid_01",
|
28
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
29
|
+
"vif": [],
|
30
|
+
"status": "init",
|
31
|
+
"memory_size": 256,
|
32
|
+
"ha_enabled": 0,
|
33
|
+
"network": [],
|
34
|
+
"arch": "x86_64",
|
35
|
+
"host_node": null,
|
36
|
+
"created_at": "2011-10-18T06:48:47Z",
|
37
|
+
"netfilter_group_id": ["ng-demofgr"],
|
38
|
+
"ssh_key_pair": null,
|
39
|
+
"volume": [],
|
40
|
+
"netfilter_group": ["default"],
|
41
|
+
"cpu_cores": 1
|
42
|
+
},
|
43
|
+
|
44
|
+
{
|
45
|
+
"id": "virtual_server_uuid_94",
|
46
|
+
"state": "scheduling",
|
47
|
+
"image_id": "vertual_server_image_uuid_01",
|
48
|
+
"hostname": "physical_server_uuid_01",
|
49
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
50
|
+
"vif": [],
|
51
|
+
"status": "init",
|
52
|
+
"memory_size": 256,
|
53
|
+
"ha_enabled": 0,
|
54
|
+
"network": [],
|
55
|
+
"arch": "x86_64",
|
56
|
+
"host_node": null,
|
57
|
+
"created_at": "2011-10-18T06:48:47Z",
|
58
|
+
"netfilter_group_id": ["ng-demofgr"],
|
59
|
+
"ssh_key_pair": null,
|
60
|
+
"volume": [],
|
61
|
+
"netfilter_group": ["default"],
|
62
|
+
"cpu_cores": 1
|
63
|
+
},
|
64
|
+
|
65
|
+
{
|
66
|
+
"id": "virtual_server_uuid_95",
|
67
|
+
"state": "scheduling",
|
68
|
+
"image_id": "vertual_server_image_uuid_01",
|
69
|
+
"hostname": "physical_server_uuid_01",
|
70
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
71
|
+
"vif": [],
|
72
|
+
"status": "init",
|
73
|
+
"memory_size": 256,
|
74
|
+
"ha_enabled": 0,
|
75
|
+
"network": [],
|
76
|
+
"arch": "x86_64",
|
77
|
+
"host_node": null,
|
78
|
+
"created_at": "2011-10-18T06:48:47Z",
|
79
|
+
"netfilter_group_id": ["ng-demofgr"],
|
80
|
+
"ssh_key_pair": null,
|
81
|
+
"volume": [],
|
82
|
+
"netfilter_group": ["default"],
|
83
|
+
"cpu_cores": 1
|
84
|
+
},
|
85
|
+
|
86
|
+
{
|
87
|
+
"id": "virtual_server_uuid_96",
|
88
|
+
"state": "scheduling",
|
89
|
+
"image_id": "vertual_server_image_uuid_01",
|
90
|
+
"hostname": "physical_server_uuid_01",
|
91
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
92
|
+
"vif": [],
|
93
|
+
"status": "init",
|
94
|
+
"memory_size": 256,
|
95
|
+
"ha_enabled": 0,
|
96
|
+
"network": [],
|
97
|
+
"arch": "x86_64",
|
98
|
+
"host_node": null,
|
99
|
+
"created_at": "2011-10-18T06:48:47Z",
|
100
|
+
"netfilter_group_id": ["ng-demofgr"],
|
101
|
+
"ssh_key_pair": null,
|
102
|
+
"volume": [],
|
103
|
+
"netfilter_group": ["default"],
|
104
|
+
"cpu_cores": 1
|
105
|
+
}
|
106
|
+
]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "virtual_server_uuid_91",
|
4
|
+
"state": "scheduling",
|
5
|
+
"image_id": "vertual_server_image_uuid_01",
|
6
|
+
"hostname": "physical_server_uuid_01",
|
7
|
+
"instance_spec_id": "virtual_server_spec_uuid_01",
|
8
|
+
"vif": [],
|
9
|
+
"status": "init",
|
10
|
+
"memory_size": 256,
|
11
|
+
"ha_enabled": 0,
|
12
|
+
"network": [],
|
13
|
+
"arch": "x86_64",
|
14
|
+
"host_node": "",
|
15
|
+
"created_at": "2011-10-18T06:48:47Z",
|
16
|
+
"netfilter_group_id": ["ng-demofgr"],
|
17
|
+
"ssh_key_pair": null,
|
18
|
+
"volume": [],
|
19
|
+
"netfilter_group": ["default"],
|
20
|
+
"cpu_cores": 1
|
21
|
+
}
|
22
|
+
]
|
@@ -0,0 +1 @@
|
|
1
|
+
[]
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tengine::Resource::VirtualServerImage do
|
5
|
+
valid_attributes1 = {
|
6
|
+
:name => "provider1"
|
7
|
+
}.freeze
|
8
|
+
|
9
|
+
context "nameは必須" do
|
10
|
+
it "正常系" do
|
11
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
12
|
+
credential1 = Tengine::Resource::VirtualServerImage.new(valid_attributes1)
|
13
|
+
credential1.valid?.should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
[:name].each do |key|
|
17
|
+
it "#{key}なし" do
|
18
|
+
attrs = valid_attributes1.dup
|
19
|
+
attrs.delete(key)
|
20
|
+
credential1 = Tengine::Resource::VirtualServerImage.new(attrs)
|
21
|
+
credential1.valid?.should == false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "nameはユニーク" do
|
28
|
+
before do
|
29
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
30
|
+
@credential1 = Tengine::Resource::VirtualServerImage.create!(valid_attributes1)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "同じ名前で登録されているものが存在する場合エラー" do
|
34
|
+
expect{
|
35
|
+
@credential1 = Tengine::Resource::VirtualServerImage.create!(valid_attributes1)
|
36
|
+
}.to raise_error(Mongoid::Errors::Validations, "Validation failed - Name is already taken.")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "nameはベース名として定義される文字列です" do
|
41
|
+
it "スラッシュ'/’はリソース識別子で使われるのでnameには使用できません" do
|
42
|
+
server1 = Tengine::Resource::VirtualServerImage.new(:name => "foo/bar")
|
43
|
+
server1.valid?.should == false
|
44
|
+
server1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "コロン':'はリソース識別子で使われるのでnameには使用できません" do
|
48
|
+
server1 = Tengine::Resource::VirtualServerImage.new(:name => "foo:bar")
|
49
|
+
server1.valid?.should == false
|
50
|
+
server1.errors[:name].should == [Tengine::Core::Validation::BASE_NAME.message]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "nameで検索" do
|
55
|
+
before do
|
56
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
57
|
+
@fixture = GokuAtEc2ApNortheast.new
|
58
|
+
@hadoop_image = @fixture.hadoop_image
|
59
|
+
end
|
60
|
+
|
61
|
+
context "見つかる場合" do
|
62
|
+
it "find_by_name" do
|
63
|
+
found_credential = nil
|
64
|
+
lambda{
|
65
|
+
found_credential = Tengine::Resource::VirtualServerImage.find_by_name(@hadoop_image.name)
|
66
|
+
}.should_not raise_error
|
67
|
+
found_credential.should_not be_nil
|
68
|
+
found_credential.id.should == @hadoop_image.id
|
69
|
+
end
|
70
|
+
|
71
|
+
it "find_by_name!" do
|
72
|
+
found_credential = nil
|
73
|
+
lambda{
|
74
|
+
found_credential = Tengine::Resource::VirtualServerImage.find_by_name!(@hadoop_image.name)
|
75
|
+
}.should_not raise_error
|
76
|
+
found_credential.should_not be_nil
|
77
|
+
found_credential.id.should == @hadoop_image.id
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "見つからない場合" do
|
82
|
+
it "find_by_name" do
|
83
|
+
found_credential = Tengine::Resource::VirtualServerImage.find_by_name("unexist_name").should == nil
|
84
|
+
end
|
85
|
+
|
86
|
+
it "find_by_name!" do
|
87
|
+
lambda{
|
88
|
+
found_credential = Tengine::Resource::VirtualServerImage.find_by_name!("unexist_name")
|
89
|
+
}.should raise_error(Tengine::Core::FindByName::Error)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Tengine::Resource::VirtualServer do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@fixture = GokuAtEc2ApNortheast.new
|
8
|
+
end
|
9
|
+
|
10
|
+
context "サーバの状態が変わったとき" do
|
11
|
+
before do
|
12
|
+
@fixture.virtual_servers
|
13
|
+
end
|
14
|
+
|
15
|
+
it "railsサーバが落とされたことを検出したのでサーバに反映できる" do
|
16
|
+
rails1 = @fixture.rails_server(1)
|
17
|
+
rails1.status = "terminated"
|
18
|
+
rails1.save!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
context "nameで検索" do
|
24
|
+
before do
|
25
|
+
Tengine::Resource::Server.delete_all
|
26
|
+
@fixture = GokuAtEc2ApNortheast.new
|
27
|
+
@physical1 = @fixture.availability_zone(1)
|
28
|
+
@virtual1 = @fixture.hadoop_master_node
|
29
|
+
@virtual2 = @fixture.hadoop_slave_node(1)
|
30
|
+
end
|
31
|
+
|
32
|
+
context "見つかる場合" do
|
33
|
+
it "find_by_name" do
|
34
|
+
found_credential = nil
|
35
|
+
lambda{
|
36
|
+
found_credential = Tengine::Resource::VirtualServer.find_by_name(@virtual1.name)
|
37
|
+
}.should_not raise_error
|
38
|
+
found_credential.should_not be_nil
|
39
|
+
found_credential.id.should == @virtual1.id
|
40
|
+
end
|
41
|
+
|
42
|
+
it "find_by_name!" do
|
43
|
+
found_credential = nil
|
44
|
+
lambda{
|
45
|
+
found_credential = Tengine::Resource::VirtualServer.find_by_name!(@virtual2.name)
|
46
|
+
}.should_not raise_error
|
47
|
+
found_credential.should_not be_nil
|
48
|
+
found_credential.id.should == @virtual2.id
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "見つからない場合" do
|
53
|
+
it "find_by_name" do
|
54
|
+
found_credential = Tengine::Resource::VirtualServer.find_by_name(@physical1).should == nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "find_by_name!" do
|
58
|
+
lambda{
|
59
|
+
found_credential = Tengine::Resource::VirtualServer.find_by_name!(@physical1)
|
60
|
+
}.should raise_error(Tengine::Core::FindByName::Error)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
describe :launch_mode? do
|
67
|
+
context "launch_countが設定されていたらtrue" do
|
68
|
+
subject{ Tengine::Resource::VirtualServer.new(:launch_count => '1') }
|
69
|
+
its(:launch_count){ should == 1}
|
70
|
+
its(:launch_mode?){ should == true}
|
71
|
+
end
|
72
|
+
|
73
|
+
context "launch_countがnilならばfalse" do
|
74
|
+
subject{ Tengine::Resource::VirtualServer.new(:launch_count => nil) }
|
75
|
+
its(:launch_count){ should == nil}
|
76
|
+
its(:launch_mode?){ should == false}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe :launch_mode do
|
81
|
+
before do
|
82
|
+
I18n.locale = :ja
|
83
|
+
end
|
84
|
+
|
85
|
+
before "既に重複する名前のモデルが登録されている場合" do
|
86
|
+
Tengine::Resource::VirtualServer.tap do |c|
|
87
|
+
c.delete_all
|
88
|
+
c.create!(:name => "test003", :provided_id => "provided_id_003")
|
89
|
+
c.create!(:name => "test004", :provided_id => "provided_id_004")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "testを2台起動しようとした場合" do
|
94
|
+
s = Tengine::Resource::VirtualServer.new(:name => "test", :launch_count => 2)
|
95
|
+
s.valid?
|
96
|
+
s.errors.full_messages.should == []
|
97
|
+
s.errors[:name].should == []
|
98
|
+
end
|
99
|
+
|
100
|
+
it "testを3台起動しようとした場合" do
|
101
|
+
s = Tengine::Resource::VirtualServer.new(:name => "test", :launch_count => 3)
|
102
|
+
s.valid?
|
103
|
+
s.errors[:name].should == ["に指定されたtest003は既に登録されています"]
|
104
|
+
s.errors.full_messages.should == ["Name に指定されたtest003は既に登録されています"]
|
105
|
+
end
|
106
|
+
|
107
|
+
it "testを4台起動しようとした場合" do
|
108
|
+
s = Tengine::Resource::VirtualServer.new(:name => "test", :launch_count => 4)
|
109
|
+
s.valid?
|
110
|
+
s.errors[:name].should == ["に指定されたtest003,test004は既に登録されています"]
|
111
|
+
s.errors.full_messages.should == ["Name に指定されたtest003,test004は既に登録されています"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
end
|