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
data/spec/mongoid.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
# mongoid defaults for configurable settings
|
3
|
+
# autocreate_indexes: false
|
4
|
+
# allow_dynamic_fields: true
|
5
|
+
# include_root_in_json: false
|
6
|
+
# parameterize_keys: true
|
7
|
+
persist_in_safe_mode: true
|
8
|
+
# raise_not_found_error: true
|
9
|
+
# reconnect_time: 3
|
10
|
+
logger: false
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *defaults
|
14
|
+
host: localhost
|
15
|
+
database: tengine_resource_development
|
16
|
+
|
17
|
+
test:
|
18
|
+
<<: *defaults
|
19
|
+
host: localhost
|
20
|
+
database: tengine_resource_test
|
21
|
+
autocreate_indexes: true
|
22
|
+
|
23
|
+
# set these environment variables on your prod server
|
24
|
+
production:
|
25
|
+
<<: *defaults
|
26
|
+
host: <%= ENV['MONGOID_HOST'] %>
|
27
|
+
port: <%= ENV['MONGOID_PORT'] %>
|
28
|
+
username: <%= ENV['MONGOID_USERNAME'] %>
|
29
|
+
password: <%= ENV['MONGOID_PASSWORD'] %>
|
30
|
+
database: <%= ENV['MONGOID_DATABASE'] %>
|
31
|
+
# slaves:
|
32
|
+
# - host: slave1.local
|
33
|
+
# port: 27018
|
34
|
+
# - host: slave2.local
|
35
|
+
# port: 27019
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
ENV["RACK_ENV"] ||= "test" # Mongoid.load!で参照しています
|
3
|
+
|
4
|
+
require 'simplecov'
|
5
|
+
SimpleCov.start if ENV["COVERAGE"]
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
8
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
|
+
require 'rspec'
|
10
|
+
# require 'factory_girl'
|
11
|
+
|
12
|
+
require 'tengine_resource'
|
13
|
+
require 'mongoid'
|
14
|
+
Mongoid.load!(File.expand_path('mongoid.yml', File.dirname(__FILE__)))
|
15
|
+
Mongoid.database.connection.drop_database(Mongoid.database.name)
|
16
|
+
|
17
|
+
# Requires supporting files with custom matchers and macros, etc,
|
18
|
+
# in ./support/ and its subdirectories.
|
19
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
20
|
+
|
21
|
+
# Requires fixtures files in ./fixtures/ and its subdirectories.
|
22
|
+
Dir["#{File.dirname(__FILE__)}/fixtures/**/*.rb"].each {|f| require f}
|
23
|
+
|
24
|
+
Tengine::Core::MethodTraceable.disabled = true
|
25
|
+
require 'logger'
|
26
|
+
log_path = File.expand_path("../tmp/log/test.log", File.dirname(__FILE__))
|
27
|
+
Tengine.logger = Logger.new(log_path)
|
28
|
+
Tengine.logger.level = Logger::DEBUG
|
29
|
+
Tengine::Core.stdout_logger = Logger.new(log_path)
|
30
|
+
Tengine::Core.stdout_logger.level = Logger::DEBUG
|
31
|
+
Tengine::Core.stderr_logger = Logger.new(log_path)
|
32
|
+
Tengine::Core.stderr_logger.level = Logger::DEBUG
|
33
|
+
|
34
|
+
Tengine::Core::Kernel.event_exception_reporter = :raise_all
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
# config.include Factory::Syntax::Methods
|
38
|
+
end
|
39
|
+
|
40
|
+
# Dir["#{File.expand_path('factories', File.dirname(__FILE__))}/**/*.rb"].each {|f| require f}
|
data/spec/support/ec2.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
def setup_ec2_images
|
3
|
+
klass = Tengine::Resource::VirtualServerImage
|
4
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
5
|
+
result = [
|
6
|
+
# us-west-1
|
7
|
+
klass.create!(:name => "ami-10101010mysql", :provided_id => "ami-10101000", :description => "MySQL server"), # *1 同じAMI ID
|
8
|
+
klass.create!(:name => "ami-10101010rails", :provided_id => "ami-10101000", :description => "Rails App Server"), # *1 同じAMI ID
|
9
|
+
klass.create!(:name => "ami-10102000" , :provided_id => "ami-10102000", :description => "Nginx Server"),
|
10
|
+
# us-west-2
|
11
|
+
klass.create!(:name => "ami-10103000" , :provided_id => "ami-10103000", :description => "APP1 servers"),
|
12
|
+
klass.create!(:name => "ami-10104000" , :provided_id => "ami-10104000", :description => "APP2 servers"),
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def setup_ec2_stub(images = setup_ec2_images)
|
18
|
+
mock_ec2 = mock(:ec2)
|
19
|
+
mock_ec2.stub!(:describe_regions).and_return([
|
20
|
+
"eu-west-1", "us-east-1", "us-west-1", "ap-southeast-1"
|
21
|
+
])
|
22
|
+
mock_ec2.stub!(:describe_availability_zones).and_return([
|
23
|
+
{:region_name=>"us-west-1", :zone_name=>"us-west-1a", :zone_state=>"available"},
|
24
|
+
{:region_name=>"us-west-1", :zone_name=>"us-west-1b", :zone_state=>"available"},
|
25
|
+
])
|
26
|
+
mock_ec2.stub!(:describe_key_pairs).and_return([
|
27
|
+
{:aws_key_name=>"goku" , :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:97"},
|
28
|
+
{:aws_key_name=>"dev" , :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:98"},
|
29
|
+
{:aws_key_name=>"default", :aws_fingerprint=>"7c:89:2f:c9:4a:1c:02:65:1b:14:dc:a5:c9:a0:da:fb:46:08:4a:99"},
|
30
|
+
])
|
31
|
+
mock_ec2.stub!(:describe_security_groups).and_return([
|
32
|
+
{ :aws_owner=>"892601002221", :aws_group_name=>"default", :aws_description=>"default group",
|
33
|
+
:aws_perms=>[{:owner=>"892601002221", :group=>"default"}, {:from_port=>"22", :to_port=>"22", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
34
|
+
{ :aws_owner=>"892601002221", :aws_group_name=>"hadoop-dev", :aws_description=>"for developmewnt with hadoop",
|
35
|
+
:aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
36
|
+
{ :aws_owner=>"892601002221", :aws_group_name=>"ruby-dev", :aws_description=>"for developmewnt with ruby",
|
37
|
+
:aws_perms=>[{:from_port=>"80", :to_port=>"80", :cidr_ips=>"0.0.0.0/0", :protocol=>"tcp"}]},
|
38
|
+
])
|
39
|
+
mock_ec2.stub!(:describe_images).
|
40
|
+
with(images.map(&:provided_id).uniq).
|
41
|
+
and_return([
|
42
|
+
{
|
43
|
+
:aws_id=>images[0].provided_id, # "ami-012b7a44",
|
44
|
+
:aws_architecture=>"i386", :root_device_type=>"instance-store",
|
45
|
+
:aws_kernel_id=>"aki-f70657b2", :aws_ramdisk_id=>"ari-ff0657ba",
|
46
|
+
:root_device_name=>"/dev/sda5",
|
47
|
+
:aws_location=>"zeus-technology-us-west-1/zeus-load-balancer-60r2-v2-100tps-100mbps-32bit.manifest.xml",
|
48
|
+
:aws_image_type=>"machine", :aws_state=>"available",
|
49
|
+
:aws_owner=>"106430830294", :aws_is_public=>true,
|
50
|
+
:aws_product_codes=>["F6F58AC9"]
|
51
|
+
},
|
52
|
+
{
|
53
|
+
:aws_id=>images[2].provided_id, # "ami-05530240",
|
54
|
+
:aws_architecture=>"x86_64", :root_device_type=>"ebs",
|
55
|
+
:aws_kernel_id=>"aki-6f3c6d2a", :aws_ramdisk_id=>"ari-693c6d2c",
|
56
|
+
:root_device_name=>"/dev/sda1",
|
57
|
+
:aws_location=>"063491364108/ubuntu-8.04.3-hardy-server-amd64-20091130",
|
58
|
+
:aws_image_type=>"machine",
|
59
|
+
:description=>"Ubuntu 8.04.3 Hardy server amd64 20091130", :aws_state=>"available",
|
60
|
+
:aws_owner=>"063491364108", :aws_is_public=>true,
|
61
|
+
:block_device_mappings=>[{:ebs_volume_size=>15, :ebs_delete_on_termination=>true, :device_name=>"/dev/sda1", :ebs_snapshot_id=>"snap-ea54fb82"}],
|
62
|
+
:name=>"ubuntu-8.04.3-hardy-server-amd64-20091130"
|
63
|
+
}
|
64
|
+
])
|
65
|
+
|
66
|
+
mock_ec2.stub!(:describe_images_by_owner).with("amazon").and_return([
|
67
|
+
# kernels = conn.describe_images_by_owner('amazon').select{|i| i[:aws_image_type] == "kernel"}
|
68
|
+
# kernels.select{|k| h[:aws_architecture] == "i386"} の中から抜粋
|
69
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-00000000", :aws_architecture=>"i386"},
|
70
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/vmlinuz-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-11111111", :aws_architecture=>"i386"},
|
71
|
+
# kernels.select{|k| h[:aws_architecture] == "x86_64"} の中から抜粋
|
72
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/ec2-vmlinuz-2.6.21.7-2.fc8xen.x86_64.manifest.xml", :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-22222222", :aws_architecture=>"x86_64"},
|
73
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/pv-grub-hd0-V1.01-x86_64.gz.manifest.xml" , :aws_image_type=>"kernel", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"aki-33333333", :aws_architecture=>"x86_64"},
|
74
|
+
|
75
|
+
# ramdisks = conn.describe_images_by_owner('amazon').select{|i| i[:aws_image_type] == "ramdisk"}
|
76
|
+
# ramdisks.select{|k| h[:aws_architecture] == "i386"} の中から抜粋
|
77
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-00000000", :aws_architecture=>"i386"},
|
78
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-paid-ibm-images-us-west-1/initrd-2.6.16.60-0.29-xenpae.i386.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"470254534024", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-11111111", :aws_architecture=>"i386"},
|
79
|
+
# ramdisks.select{|k| h[:aws_architecture] == "x86_64"} の中から抜粋
|
80
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/ec2-initrd-2.6.21.7-2.fc8xen.x86_64.manifest.xml" , :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :image_owner_alias=>"amazon", :aws_id=>"ari-22222222", :aws_architecture=>"x86_64"},
|
81
|
+
{:root_device_type=>"instance-store", :aws_location=>"ec2-public-images-us-west-1/initrd-2.6.21.7-2.ec2.v1.1.fc8xen-x86_64-lvm-rootVG-rootFS.manifest.xml", :aws_image_type=>"ramdisk", :aws_state=>"available", :aws_owner=>"206029621532", :aws_is_public=>true, :name=>"initrd-2.6.21.7-2.ec2.v1.1.fc8xen-x86_64-lvm-rootVG-rootFS", :image_owner_alias=>"amazon", :aws_id=>"ari-33333333", :aws_architecture=>"x86_64"},
|
82
|
+
])
|
83
|
+
|
84
|
+
# http://rightscale.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html#M000285
|
85
|
+
mock_ec2.stub!(:run_instances).with("ami-e444444d", 1, 1, ["my_awesome_group"], "my_awesome_key", "", nil, "m1.small", "aki-9905e0f0", "ari-8605e0ef", "us-east-1b", nil).and_return([
|
86
|
+
{
|
87
|
+
:aws_image_id => "ami-e444444d",
|
88
|
+
:aws_reason => "",
|
89
|
+
:aws_state_code => "0",
|
90
|
+
:aws_owner => "000000000888",
|
91
|
+
:aws_instance_id => "i-123f1234",
|
92
|
+
:aws_reservation_id => "r-aabbccdd",
|
93
|
+
:aws_state => "pending",
|
94
|
+
:dns_name => "",
|
95
|
+
:ssh_key_name => "my_awesome_key",
|
96
|
+
:aws_groups => ["my_awesome_group"],
|
97
|
+
:private_dns_name => "",
|
98
|
+
:aws_instance_type => "m1.small",
|
99
|
+
:aws_launch_time => "2008-1-1T00:00:00.000Z",
|
100
|
+
:aws_ramdisk_id => "ari-8605e0ef",
|
101
|
+
:aws_kernel_id => "aki-9905e0f0",
|
102
|
+
:ami_launch_index => "0",
|
103
|
+
:aws_availability_zone => "us-east-1b",
|
104
|
+
}
|
105
|
+
])
|
106
|
+
|
107
|
+
# http://rightscale.rubyforge.org/right_aws_gem_doc/classes/RightAws/Ec2.html#M000287
|
108
|
+
mock_ec2.stub!(:terminate_instances).with(['i-f222222d','i-f222222e']).and_return(
|
109
|
+
[{:aws_shutdown_state => "shutting-down",
|
110
|
+
:aws_instance_id => "i-f222222d",
|
111
|
+
:aws_shutdown_state_code => 32,
|
112
|
+
:aws_prev_state => "running",
|
113
|
+
:aws_prev_state_code => 16},
|
114
|
+
{:aws_shutdown_state => "shutting-down",
|
115
|
+
:aws_instance_id => "i-f222222e",
|
116
|
+
:aws_shutdown_state_code => 32,
|
117
|
+
:aws_prev_state => "running",
|
118
|
+
:aws_prev_state_code => 16}]
|
119
|
+
)
|
120
|
+
mock_ec2.stub!(:terminate_instances).with(['i-f222222d']).and_return(
|
121
|
+
[{:aws_shutdown_state => "shutting-down",
|
122
|
+
:aws_instance_id => "i-f222222d",
|
123
|
+
:aws_shutdown_state_code => 32,
|
124
|
+
:aws_prev_state => "running",
|
125
|
+
:aws_prev_state_code => 16},]
|
126
|
+
)
|
127
|
+
|
128
|
+
mock_ec2
|
129
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# 使い方
|
3
|
+
# テスト実行時に 環境変数MONGO_INDEX_KEY_LOGにログの出力先のファイル名を指定しておくと、
|
4
|
+
# そこにmongoに対してどんな検索条件やソート、ヒントなどをどのように指定しているのかを出力できます
|
5
|
+
#
|
6
|
+
# この出力された結果のファイルに対して sort と uniq をかけることにより、どんなインデックスを
|
7
|
+
# 作れば良いのか判断する材料となります。
|
8
|
+
#
|
9
|
+
# export MONGO_INDEX_KEY_LOG=$HOME/tmp/mongo_index_key.log
|
10
|
+
# cd tenigne_core && rake spec
|
11
|
+
# cd tenigne_resource && rake spec
|
12
|
+
# cd tenigne_job && rake spec
|
13
|
+
# cd tenigne_console && rake spec
|
14
|
+
# cd $HOME/tmp
|
15
|
+
# cat mongo_index_key.log | sort | uniq > mongo_index_key_summary.log
|
16
|
+
#
|
17
|
+
# これで $HOME/tmp/mongo_index_key_summary.log にどのようなキーが使われているのかがまとめられます
|
18
|
+
#
|
19
|
+
if ENV['MONGO_INDEX_KEY_LOG']
|
20
|
+
file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
|
21
|
+
STDOUT.puts("MONGO_INDEX_KEY_LOG enable logging key infomation for index to #{file_path}")
|
22
|
+
|
23
|
+
Mongo::Collection.class_eval do
|
24
|
+
def index_key_log_file
|
25
|
+
unless defined?(@@index_key_log_file)
|
26
|
+
file_path = File.expand_path(ENV['MONGO_INDEX_KEY_LOG'])
|
27
|
+
@@index_key_log_file = File.open(file_path, "a")
|
28
|
+
end
|
29
|
+
@@index_key_log_file
|
30
|
+
end
|
31
|
+
|
32
|
+
def find_with_index_key_log(selector={}, opts={}, &block)
|
33
|
+
result = find_without_index_key_log(selector, opts, &block)
|
34
|
+
index_key_log_file.puts("#{self.name}.find({#{_hash_keys_(selector)}}, {#{_hash_keys_(opts.dup)}}): #{_explain_summary_(result.explain)}")
|
35
|
+
result
|
36
|
+
end
|
37
|
+
alias_method :find_without_index_key_log, :find
|
38
|
+
alias_method :find, :find_with_index_key_log
|
39
|
+
|
40
|
+
|
41
|
+
def find_and_modify_with_index_key_log(opts={}, &block)
|
42
|
+
o = opts.dup
|
43
|
+
query = o.delete(:query)
|
44
|
+
index_key_log_file.puts("#{self.name}.find_and_modify({#{_hash_keys_(query)}}, {#{_hash_keys_(o)}})")
|
45
|
+
find_and_modify_without_index_key_log(opts, &block)
|
46
|
+
end
|
47
|
+
alias_method :find_and_modify_without_index_key_log, :find_and_modify
|
48
|
+
alias_method :find_and_modify, :find_and_modify_with_index_key_log
|
49
|
+
|
50
|
+
def _hash_keys_(hash)
|
51
|
+
res = []
|
52
|
+
[:sort, :hint, :limit].each do |key|
|
53
|
+
if value = hash.delete(key)
|
54
|
+
res << "#{key.inspect} => #{value.inspect}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
res += hash.keys.map(&:inspect)
|
58
|
+
res.join(',')
|
59
|
+
end
|
60
|
+
|
61
|
+
def _explain_summary_(hash)
|
62
|
+
case cursor = hash['cursor']
|
63
|
+
when /^BtreeCursor/ then
|
64
|
+
res = []
|
65
|
+
%w[cursor].each do |key|
|
66
|
+
if value = hash.delete(key)
|
67
|
+
res << "#{key.inspect} => #{value.inspect}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
res += hash.keys.map(&:inspect)
|
71
|
+
"{" << res.join(',') << "}"
|
72
|
+
else
|
73
|
+
res = []
|
74
|
+
res << "'cursor' => #{hash.delete('cursor').inspect}"
|
75
|
+
{"nscanned" => 1, "nscannedObjects" => 1, "n" => 1, "millis" => 0, "nYields"=>0, "nChunkSkips"=>0 }.each do |key, border|
|
76
|
+
if value = hash.delete(key)
|
77
|
+
if value > border
|
78
|
+
res << "#{key.inspect} => '>#{border.inspect}'"
|
79
|
+
else
|
80
|
+
res << "#{key.inspect} => #{value.inspect}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
res += hash.keys.map(&:inspect)
|
85
|
+
"{" << res.join(',') << "}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'eventmachine'
|
4
|
+
require 'amqp'
|
5
|
+
require 'tengine/mq/suite'
|
6
|
+
require 'apis/wakame'
|
7
|
+
require 'controllers/controller'
|
8
|
+
|
9
|
+
describe Tengine::Resource::Provider::Wakame do
|
10
|
+
|
11
|
+
before :all do
|
12
|
+
class Tengine::Resource::VirtualServerType
|
13
|
+
def destroy; $stdout.puts "invoked"; super; end
|
14
|
+
end
|
15
|
+
class Tengine::Resource::VirtualServerImage
|
16
|
+
def destroy; $stdout.puts "invoked"; super; end
|
17
|
+
end
|
18
|
+
class Tengine::Resource::PhysicalServer
|
19
|
+
def destroy; $stdout.puts "invoked"; super; end
|
20
|
+
end
|
21
|
+
class Tengine::Resource::VirtualServer
|
22
|
+
def destroy; $stdout.puts "invoked"; super; end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
after :all do
|
27
|
+
Tengine::Resource::VirtualServerType.class_eval { remove_method :destroy }
|
28
|
+
Tengine::Resource::VirtualServerImage.class_eval { remove_method :destroy }
|
29
|
+
Tengine::Resource::PhysicalServer.class_eval { remove_method :destroy }
|
30
|
+
Tengine::Resource::VirtualServer.class_eval { remove_method :destroy }
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
Tengine::Resource::Provider.delete_all
|
35
|
+
@provider_wakame = Tengine::Resource::Provider::Wakame.create!({
|
36
|
+
:name => "wakame-vdc",
|
37
|
+
:description => "",
|
38
|
+
:properties => {
|
39
|
+
:key_name => "ssh-xxxxx"
|
40
|
+
},
|
41
|
+
:polling_interval => 5,
|
42
|
+
:connection_settings => {
|
43
|
+
:account => "tama_account1",
|
44
|
+
:ec2_host => "10.10.10.10",
|
45
|
+
:ec2_port => 80,
|
46
|
+
:ec2_protocol => "https",
|
47
|
+
:wakame_host => "192.168.0.10",
|
48
|
+
:wakame_port => 8080,
|
49
|
+
:wakame_protocol => "http",
|
50
|
+
},
|
51
|
+
})
|
52
|
+
Tengine::Resource::VirtualServerType.delete_all
|
53
|
+
@virtual_server_type_wakame = @provider_wakame.virtual_server_types.create!({
|
54
|
+
:provided_id => "is-demospec",
|
55
|
+
:caption => "is-demospec",
|
56
|
+
:cpu_cores => 2,
|
57
|
+
:memory_size => 512,
|
58
|
+
:properties => {
|
59
|
+
:arch => "x86_64",
|
60
|
+
:hypervisor => "kvm",
|
61
|
+
:account_id => "a-shpoolxx",
|
62
|
+
:vifs => "--- \neth0: \n :bandwidth: 100000\n :index: 0\n",
|
63
|
+
:quota_weight => "1.0",
|
64
|
+
:drives => "--- \nephemeral1: \n :type: :local\n :size: 100\n :index: 0\n",
|
65
|
+
:created_at => "2011-10-28T02:58:57Z",
|
66
|
+
:updated_at => "2011-10-28T02:58:57Z",
|
67
|
+
}
|
68
|
+
})
|
69
|
+
Tengine::Resource::VirtualServerImage.delete_all
|
70
|
+
@virtual_server_image_wakame = @provider_wakame.virtual_server_images.create!({
|
71
|
+
:name => "vimage",
|
72
|
+
:description => "",
|
73
|
+
:provided_id => "wmi-lucid6",
|
74
|
+
:provided_description => "ubuntu-10.04_with-metadata_kvm_i386.raw volume",
|
75
|
+
})
|
76
|
+
Tengine::Resource::PhysicalServer.delete_all
|
77
|
+
@physical_server_wakame = @provider_wakame.physical_servers.create!({
|
78
|
+
:name => "demohost",
|
79
|
+
:description => "",
|
80
|
+
:provided_id => "hp-demohost",
|
81
|
+
:status => "online",
|
82
|
+
:addresses => {},
|
83
|
+
:address_order => [],
|
84
|
+
:cpu_cores => 100,
|
85
|
+
:memory_size => 400000,
|
86
|
+
:properties => {
|
87
|
+
:uuid => "hp-demohost",
|
88
|
+
:account_id => "a-shpoolxx",
|
89
|
+
:arch => "x86_64",
|
90
|
+
:hypervisor => "kvm",
|
91
|
+
:created_at => "2011-10-18T03:53:24Z",
|
92
|
+
:updated_at => "2011-10-18T03:53:24Z",
|
93
|
+
}
|
94
|
+
})
|
95
|
+
Tengine::Resource::VirtualServer.delete_all
|
96
|
+
@provider_wakame.virtual_servers.create!({
|
97
|
+
:name => "vhost",
|
98
|
+
:description => "",
|
99
|
+
:provided_id => "i-jria301q",
|
100
|
+
:provided_image_id => "wmi-lucid5",
|
101
|
+
:provided_type_id => "is-demospec",
|
102
|
+
:host_server => @physical_server_wakame,
|
103
|
+
:status => "running",
|
104
|
+
:addresses => {
|
105
|
+
"private_ip_address" => "192.168.2.188",
|
106
|
+
"nw-data" => "192.168.2.188",
|
107
|
+
},
|
108
|
+
:address_order => ["private_ip_address"],
|
109
|
+
:properties => {
|
110
|
+
:aws_kernel_id => "",
|
111
|
+
:aws_launch_time => "2011-10-18T06:51:16Z",
|
112
|
+
:tags => {},
|
113
|
+
:aws_reservation_id => "",
|
114
|
+
:aws_owner => "a-shpoolxx",
|
115
|
+
:instance_lifecycle => "",
|
116
|
+
:block_device_mappings => [{
|
117
|
+
:ebs_volume_id => "",
|
118
|
+
:ebs_status => "",
|
119
|
+
:ebs_attach_time => "",
|
120
|
+
:ebs_delete_on_termination => false,
|
121
|
+
:device_name => ""
|
122
|
+
}],
|
123
|
+
:ami_launch_index => "",
|
124
|
+
:root_device_name => "",
|
125
|
+
:aws_ramdisk_id => "",
|
126
|
+
:aws_availability_zone => "hp-demohost",
|
127
|
+
:aws_groups => nil,
|
128
|
+
:spot_instance_request_id => "",
|
129
|
+
:ssh_key_name => nil,
|
130
|
+
:virtualization_type => "",
|
131
|
+
:placement_group_name => "",
|
132
|
+
:requester_id => "",
|
133
|
+
:aws_product_codes => [],
|
134
|
+
:client_token => "",
|
135
|
+
:architecture => "x86_64",
|
136
|
+
:aws_state_code => 0,
|
137
|
+
:root_device_type => "",
|
138
|
+
:monitoring_state => "",
|
139
|
+
:aws_reason => ""
|
140
|
+
}
|
141
|
+
})
|
142
|
+
|
143
|
+
@tama_controller_factory = mock(::Tama::Controllers::ControllerFactory.allocate)
|
144
|
+
::Tama::Controllers::ControllerFactory.
|
145
|
+
stub(:create_controller).
|
146
|
+
with("tama_account1", "10.10.10.10", 80, "https", "192.168.0.10", 8080, "http").
|
147
|
+
and_return(@tama_controller_factory)
|
148
|
+
end
|
149
|
+
|
150
|
+
describe :sync_virtual_server_types do
|
151
|
+
it "削除の通知は一度しか行われない" do
|
152
|
+
@tama_controller_factory.stub(:describe_instance_specs).with([]).and_return([])
|
153
|
+
|
154
|
+
# 一度も呼び出されない
|
155
|
+
@provider_wakame.should_not_receive(:dirrefential_update_virtual_server_type_hashs)
|
156
|
+
@provider_wakame.should_not_receive(:create_virtual_server_type_hashs)
|
157
|
+
# 一度だけ呼び出される
|
158
|
+
$stdout.should_receive(:puts).with("invoked").once
|
159
|
+
|
160
|
+
3.times do
|
161
|
+
@provider_wakame.virtual_server_type_watch
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe :sync_virtual_server_images do
|
167
|
+
# bug [大量にTengine::Resource::VirtualServer.destroyed.tengine_resource_watchdという種別名イベントが登録されつづけている]
|
168
|
+
it "削除の通知は一度しか行われない" do
|
169
|
+
@tama_controller_factory.stub(:describe_instances).with([]).and_return([])
|
170
|
+
|
171
|
+
# 一度も呼び出されない
|
172
|
+
@provider_wakame.should_not_receive(:dirrefential_update_virtual_server_hashs)
|
173
|
+
@provider_wakame.should_not_receive(:create_virtual_server_hashs)
|
174
|
+
# 一度だけ呼び出される
|
175
|
+
$stdout.should_receive(:puts).with("invoked").once
|
176
|
+
|
177
|
+
3.times do
|
178
|
+
@provider_wakame.virtual_server_watch
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe :sync_virtual_server_images do
|
184
|
+
it "削除の通知は一度しか行われない" do
|
185
|
+
@tama_controller_factory.stub(:describe_images).with([]).and_return([])
|
186
|
+
|
187
|
+
# 一度も呼び出されない
|
188
|
+
@provider_wakame.should_not_receive(:dirrefential_update_virtual_server_image_hashs)
|
189
|
+
@provider_wakame.should_not_receive(:create_virtual_server_image_hashs)
|
190
|
+
# 一度だけ呼び出される
|
191
|
+
$stdout.should_receive(:puts).with("invoked").once
|
192
|
+
|
193
|
+
3.times do
|
194
|
+
@provider_wakame.virtual_server_image_watch
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe :sync_virtual_servers do
|
200
|
+
# bug [大量にTengine::Resource::VirtualServer.destroyed.tengine_resource_watchdという種別名イベントが登録されつづけている]
|
201
|
+
it "削除の通知は一度しか行われない" do
|
202
|
+
@tama_controller_factory.stub(:describe_instances).with([]).and_return([])
|
203
|
+
|
204
|
+
# 一度も呼び出されない
|
205
|
+
@provider_wakame.should_not_receive(:dirrefential_update_virtual_server_hashs)
|
206
|
+
@provider_wakame.should_not_receive(:create_virtual_server_hashs)
|
207
|
+
# 一度だけ呼び出される
|
208
|
+
$stdout.should_receive(:puts).with("invoked").once
|
209
|
+
|
210
|
+
3.times do
|
211
|
+
@provider_wakame.virtual_server_watch
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe :sync_physical_servers do
|
217
|
+
it "削除の通知は一度しか行われない" do
|
218
|
+
@tama_controller_factory.stub(:describe_host_nodes).with([]).and_return([])
|
219
|
+
|
220
|
+
# 一度も呼び出されない
|
221
|
+
@provider_wakame.should_not_receive(:dirrefential_update_physical_server_hashs)
|
222
|
+
@provider_wakame.should_not_receive(:create_physical_server_hashs)
|
223
|
+
# 一度だけ呼び出される
|
224
|
+
$stdout.should_receive(:puts).with("invoked").once
|
225
|
+
|
226
|
+
3.times do
|
227
|
+
@provider_wakame.physical_server_watch
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|