cmeiklejohn-aws 2.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +186 -0
- data/lib/acf/right_acf_interface.rb +379 -0
- data/lib/aws.rb +30 -0
- data/lib/awsbase/aws_response_array.rb +30 -0
- data/lib/awsbase/benchmark_fix.rb +39 -0
- data/lib/awsbase/right_awsbase.rb +1237 -0
- data/lib/awsbase/support.rb +119 -0
- data/lib/ec2/right_ec2.rb +1772 -0
- data/lib/ec2/right_mon_interface.rb +233 -0
- data/lib/elb/elb_interface.rb +359 -0
- data/lib/rds/rds.rb +216 -0
- data/lib/right_aws.rb +57 -0
- data/lib/s3/right_s3.rb +1101 -0
- data/lib/s3/right_s3_interface.rb +1231 -0
- data/lib/sdb/active_sdb.rb +954 -0
- data/lib/sdb/right_sdb_interface.rb +812 -0
- data/lib/sqs/right_sqs.rb +287 -0
- data/lib/sqs/right_sqs_interface.rb +445 -0
- data/test/acf/test_acf.rb +148 -0
- data/test/acf/test_helper.rb +2 -0
- data/test/ec2/test_ec2.rb +110 -0
- data/test/ec2/test_helper.rb +2 -0
- data/test/ec2/test_mon.rb +17 -0
- data/test/elb/test_elb.rb +51 -0
- data/test/http_connection.rb +87 -0
- data/test/rds/test_rds.rb +181 -0
- data/test/s3/test_helper.rb +3 -0
- data/test/s3/test_s3.rb +425 -0
- data/test/s3/test_s3_stubbed.rb +97 -0
- data/test/sdb/test_active_sdb.rb +338 -0
- data/test/sdb/test_helper.rb +3 -0
- data/test/sdb/test_sdb.rb +207 -0
- data/test/sqs/test_helper.rb +2 -0
- data/test/sqs/test_sqs.rb +206 -0
- data/test/test_credentials.rb +54 -0
- data/test/ts_right_aws.rb +13 -0
- metadata +163 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require 'pp'
|
3
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
4
|
+
|
5
|
+
class TestEc2 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
8
|
+
# are not tested here due to their potentially risk.
|
9
|
+
|
10
|
+
def setup
|
11
|
+
TestCredentials.get_credentials
|
12
|
+
@ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
|
13
|
+
TestCredentials.aws_secret_access_key)
|
14
|
+
@key = 'right_ec2_awesome_test_key'
|
15
|
+
@group = 'right_ec2_awesome_test_security_group'
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_01_create_describe_key_pairs
|
19
|
+
new_key = @ec2.create_key_pair(@key)
|
20
|
+
assert new_key[:aws_material][/BEGIN RSA PRIVATE KEY/], "New key material is absent"
|
21
|
+
keys = @ec2.describe_key_pairs
|
22
|
+
assert keys.map{|key| key[:aws_key_name] }.include?(@key), "#{@key} must exist"
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_02_create_security_group
|
26
|
+
assert @ec2.create_security_group(@group,'My awesone test group'), 'Create_security_group fail'
|
27
|
+
group = @ec2.describe_security_groups([@group])[0]
|
28
|
+
assert_equal @group, group[:aws_group_name], 'Group must be created but does not exist'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_03_perms_add
|
32
|
+
assert @ec2.authorize_security_group_named_ingress(@group, TestCredentials.account_number, 'default')
|
33
|
+
assert @ec2.authorize_security_group_IP_ingress(@group, 80,80,'udp','192.168.1.0/8')
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_04_check_new_perms_exist
|
37
|
+
assert_equal 2, @ec2.describe_security_groups([@group])[0][:aws_perms].size
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_05_perms_remove
|
41
|
+
assert @ec2.revoke_security_group_IP_ingress(@group, 80,80,'udp','192.168.1.0/8')
|
42
|
+
assert @ec2.revoke_security_group_named_ingress(@group,
|
43
|
+
TestCredentials.account_number, 'default')
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_06_describe_images
|
47
|
+
images = @ec2.describe_images
|
48
|
+
assert images.size>0, 'Amazon must have at least some public images'
|
49
|
+
# unknown image
|
50
|
+
assert_raise(Aws::AwsError){ @ec2.describe_images(['ami-ABCDEFGH'])}
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_07_describe_instanses
|
54
|
+
assert @ec2.describe_instances
|
55
|
+
# unknown image
|
56
|
+
assert_raise(Aws::AwsError){ @ec2.describe_instances(['i-ABCDEFGH'])}
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_08_delete_security_group
|
60
|
+
assert @ec2.delete_security_group(@group), 'Delete_security_group fail'
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_09_delete_key_pair
|
64
|
+
assert @ec2.delete_key_pair(@key), 'Delete_key_pair fail'
|
65
|
+
## Hmmm... Amazon does not through the exception any more. It now just returns a 'true' if the key does not exist any more...
|
66
|
+
## # key must be deleted already
|
67
|
+
## assert_raise(Aws::AwsError) { @ec2.delete_key_pair(@key) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_10_signature_version_0
|
71
|
+
ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :signature_version => '0')
|
72
|
+
images = ec2.describe_images
|
73
|
+
assert images.size>0, 'Amazon must have at least some public images'
|
74
|
+
# check that the request has correct signature version
|
75
|
+
assert ec2.last_request.path.include?('SignatureVersion=0')
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_11_regions
|
79
|
+
regions = nil
|
80
|
+
assert_nothing_raised do
|
81
|
+
regions = @ec2.describe_regions
|
82
|
+
end
|
83
|
+
# check we got more that 0 regions
|
84
|
+
assert regions.size > 0
|
85
|
+
# check an access to regions
|
86
|
+
regions.each do |region|
|
87
|
+
regional_ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :region => region)
|
88
|
+
# do we have a correct endpoint server?
|
89
|
+
assert_equal "#{region}.ec2.amazonaws.com", regional_ec2.params[:server]
|
90
|
+
# get a list of images from every region
|
91
|
+
images = nil
|
92
|
+
assert_nothing_raised do
|
93
|
+
images = regional_ec2.describe_regions
|
94
|
+
end
|
95
|
+
# every region must have images
|
96
|
+
assert images.size > 0
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_12_endpoint_url
|
101
|
+
ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :endpoint_url => 'a://b.c:0/d/', :region => 'z')
|
102
|
+
# :endpoint_url has a priority hence :region should be ommitted
|
103
|
+
assert_equal 'a', ec2.params[:protocol]
|
104
|
+
assert_equal 'b.c', ec2.params[:server]
|
105
|
+
assert_equal '/d/', ec2.params[:service]
|
106
|
+
assert_equal 0, ec2.params[:port]
|
107
|
+
assert_nil ec2.params[:region]
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
class TestEc2 < Test::Unit::TestCase
|
6
|
+
|
7
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
8
|
+
# are not tested here due to their potentially risk.
|
9
|
+
|
10
|
+
def setup
|
11
|
+
TestCredentials.get_credentials
|
12
|
+
@ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
|
13
|
+
TestCredentials.aws_secret_access_key)
|
14
|
+
@key = 'right_ec2_awesome_test_key'
|
15
|
+
@group = 'right_ec2_awesome_test_security_group'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../../lib/aws'
|
3
|
+
require 'pp'
|
4
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
5
|
+
|
6
|
+
class TestElb < Test::Unit::TestCase
|
7
|
+
|
8
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
9
|
+
# are not tested here due to their potentially risk.
|
10
|
+
|
11
|
+
def setup
|
12
|
+
TestCredentials.get_credentials
|
13
|
+
|
14
|
+
@ec2 = Aws::Ec2.new(TestCredentials.aws_access_key_id,
|
15
|
+
TestCredentials.aws_secret_access_key)
|
16
|
+
|
17
|
+
@elb = Aws::Elb.new(TestCredentials.aws_access_key_id,
|
18
|
+
TestCredentials.aws_secret_access_key)
|
19
|
+
@key = 'right_ec2_awesome_test_key'
|
20
|
+
@group = 'right_ec2_awesome_test_security_group'
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_01_create_elb
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_02_register_instances
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_03_deregister_instances
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def test_04_describe_elb
|
37
|
+
desc = @elb.describe_load_balancers
|
38
|
+
puts desc.inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_06_describe_instance_health
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
def test_15_delete_elb
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2007 RightScale, Inc.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
'Software'), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
|
24
|
+
# Stub extension/redefinition of RightHttpConnection for testing purposes.
|
25
|
+
require 'net/http'
|
26
|
+
require 'rubygems'
|
27
|
+
require 'right_http_connection'
|
28
|
+
|
29
|
+
module Net
|
30
|
+
class HTTPResponse
|
31
|
+
alias_method :real_body, :body
|
32
|
+
def setmsg(msg)
|
33
|
+
@mymsg = msg
|
34
|
+
end
|
35
|
+
|
36
|
+
def body
|
37
|
+
# defined?() helps us to get rid of a bunch of 'warnings'
|
38
|
+
(defined?(@mymsg) && @mymsg) ? @mymsg : real_body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Rightscale
|
44
|
+
|
45
|
+
class HttpConnection
|
46
|
+
@@response_stack = []
|
47
|
+
|
48
|
+
alias_method :real_request, :request
|
49
|
+
|
50
|
+
def request(request_params, &block)
|
51
|
+
if(@@response_stack.length == 0)
|
52
|
+
return real_request(request_params, &block)
|
53
|
+
end
|
54
|
+
|
55
|
+
if(block)
|
56
|
+
# Do something special
|
57
|
+
else
|
58
|
+
next_response = HttpConnection::pop()
|
59
|
+
classname = Net::HTTPResponse::CODE_TO_OBJ["#{next_response[:code]}"]
|
60
|
+
response = classname.new("1.1", next_response[:code], next_response[:msg])
|
61
|
+
if(next_response[:msg])
|
62
|
+
response.setmsg(next_response[:msg])
|
63
|
+
end
|
64
|
+
response
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.reset
|
69
|
+
@@response_stack = []
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.push(code, msg=nil)
|
73
|
+
response = {:code => code, :msg => msg}
|
74
|
+
@@response_stack << response
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.pop
|
78
|
+
@@response_stack.pop
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.length
|
82
|
+
@@response_stack.length
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../../lib/aws'
|
3
|
+
require 'rds/rds'
|
4
|
+
require 'pp'
|
5
|
+
require File.dirname(__FILE__) + '/../test_credentials.rb'
|
6
|
+
|
7
|
+
class TestRds < Test::Unit::TestCase
|
8
|
+
|
9
|
+
# Some of RightEc2 instance methods concerning instance launching and image registration
|
10
|
+
# are not tested here due to their potentially risk.
|
11
|
+
|
12
|
+
def setup
|
13
|
+
TestCredentials.get_credentials
|
14
|
+
|
15
|
+
@rds = Aws::Rds.new(TestCredentials.aws_access_key_id,
|
16
|
+
TestCredentials.aws_secret_access_key)
|
17
|
+
|
18
|
+
@identifier = 'test-db-instance1b'
|
19
|
+
# deleting this one....
|
20
|
+
#@identifier2 = 'my-db-instance2'
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def test_00_describe_db_instances_empty
|
25
|
+
instances = @rds.describe_db_instances
|
26
|
+
# puts "instances_result=" + instances_result.inspect
|
27
|
+
# instances = instances_result["DescribeDBInstancesResult"]["DBInstances"]["DBInstance"]
|
28
|
+
puts "instances count = " + instances.count.to_s
|
29
|
+
puts 'instances=' + instances.inspect
|
30
|
+
assert instances.size == 0
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_01_create_db_instance
|
35
|
+
begin
|
36
|
+
db_instance3 = @rds.create_db_instance('bad_test_key', "db.m1.small", 5, "master", "masterpass")
|
37
|
+
rescue => ex
|
38
|
+
#puts "msg=" + ex.message
|
39
|
+
#puts "response=" + ex.response
|
40
|
+
assert ex.message[0, "InvalidParameterValue".size] == "InvalidParameterValue"
|
41
|
+
end
|
42
|
+
|
43
|
+
db_instance = @rds.create_db_instance(@identifier, "db.m1.small", 5, "master", "masterpass")
|
44
|
+
assert db_instance[:db_instance_status] == "creating"
|
45
|
+
|
46
|
+
start = Time.now
|
47
|
+
tries=0
|
48
|
+
catch (:done) do
|
49
|
+
while tries < 100
|
50
|
+
instances = @rds.describe_db_instances
|
51
|
+
|
52
|
+
#puts "INSTANCES -----> " + instances.inspect
|
53
|
+
|
54
|
+
instances.each do |i|
|
55
|
+
db_status = i[:db_instance_status]
|
56
|
+
puts 'i=' + db_status.to_s
|
57
|
+
next unless i[:db_instance_identifier] == @identifier
|
58
|
+
throw :done if db_status == "available"
|
59
|
+
puts "Database not ready yet.... attempt #{tries.to_s} of 100, db state --> #{i[:db_instance_status].to_s}"
|
60
|
+
tries += 1
|
61
|
+
sleep 5
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
puts "Duration to start db instance: #{Time.now-start}"
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def test_02_describe_db_instances
|
70
|
+
instances = @rds.describe_db_instances
|
71
|
+
# puts "instances_result=" + instances_result.inspect
|
72
|
+
# instances = instances_result["DescribeDBInstancesResult"]["DBInstances"]["DBInstance"]
|
73
|
+
puts "instances count = " + instances.count.to_s
|
74
|
+
puts 'instances=' + instances.inspect
|
75
|
+
assert instances.size > 0
|
76
|
+
i_describe = nil
|
77
|
+
instances.each do |rdi|
|
78
|
+
puts 'rdi=' + rdi.inspect
|
79
|
+
i_describe = rdi if rdi[:db_instance_identifier] == @identifier
|
80
|
+
end
|
81
|
+
assert i_describe
|
82
|
+
|
83
|
+
puts 'response_metadata=' + instances.response_metadata.inspect
|
84
|
+
assert instances.response_metadata
|
85
|
+
assert instances.response_metadata[:request_id]
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def test_03_describe_security_groups
|
90
|
+
security_groups = @rds.describe_db_security_groups()
|
91
|
+
puts "security_groups=" + security_groups.inspect
|
92
|
+
default_present = false
|
93
|
+
assert security_groups.is_a?(Array)
|
94
|
+
security_groups.each do |security_group|
|
95
|
+
security_group.inspect
|
96
|
+
if security_group[:db_security_group_name] == "default"
|
97
|
+
default_present=true
|
98
|
+
end
|
99
|
+
assert security_group[:ec2_security_groups].is_a? Array
|
100
|
+
end
|
101
|
+
assert default_present
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def test_04_authorize_security_groups_ingress
|
106
|
+
# Create
|
107
|
+
# security_groups = @rds.describe_db_security_groups
|
108
|
+
# @security_info = security_groups[0]
|
109
|
+
@rds.authorize_db_security_group_ingress_range("default", "122.122.122.122/12")
|
110
|
+
|
111
|
+
# Check
|
112
|
+
security_groups = @rds.describe_db_security_groups
|
113
|
+
@security_info = security_groups[0]
|
114
|
+
|
115
|
+
ip_found = @security_info.inspect.include? "122.122.122.122/12"
|
116
|
+
assert ip_found
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def test_05_delete_db_instance
|
121
|
+
@rds.delete_db_instance(@identifier) # todo: can't delete unless it's in "available" state
|
122
|
+
#@rds.delete_db_instance(@identifier2)
|
123
|
+
sleep 3
|
124
|
+
|
125
|
+
instances = @rds.describe_db_instances(:db_instance_identifier=>@identifier)
|
126
|
+
#puts "instances_result=" + instances_result.inspect
|
127
|
+
|
128
|
+
instances.each do |i|
|
129
|
+
next unless i[:db_instance_identifier] == @identifier
|
130
|
+
db_status = i[:db_instance_status]
|
131
|
+
puts "Trying to delete and getting i[DBInstanceStatus] -----------> " + db_status
|
132
|
+
@rds.delete_db_instance(i[:db_instance_identifier]) if db_status == "available"
|
133
|
+
assert db_status == "deleting"
|
134
|
+
end
|
135
|
+
sleep 2
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def test_06_create_security_groups
|
141
|
+
group_present=false
|
142
|
+
|
143
|
+
@rds.create_db_security_group("new_sample_group", "new_sample_group_description")
|
144
|
+
|
145
|
+
security_groups = @rds.describe_db_security_groups
|
146
|
+
|
147
|
+
security_groups.each do |security_group|
|
148
|
+
if (security_group[:db_security_group_name]=="new_sample_group")&&(security_group[:db_security_group_description]=="new_sample_group_description")
|
149
|
+
group_present = true
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
assert group_present
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def test_07_revoking_security_groups_ingress
|
158
|
+
# sleep 15
|
159
|
+
@rds.revoke_db_security_group_ingress("default", "122.122.122.122/12")
|
160
|
+
sleep 2
|
161
|
+
security_groups = @rds.describe_db_security_groups
|
162
|
+
revoking = security_groups[0].inspect.include? "revoking"
|
163
|
+
assert revoking
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def test_08_delete_security_group
|
168
|
+
group_present=false
|
169
|
+
@rds.delete_db_security_group("new_sample_group")
|
170
|
+
sleep 2
|
171
|
+
security_groups = @rds.describe_db_security_groups
|
172
|
+
security_groups.each do |security_group|
|
173
|
+
if (security_group[:db_security_group_name]=="new_sample_group")
|
174
|
+
group_present=true
|
175
|
+
end
|
176
|
+
end
|
177
|
+
assert !group_present
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
end
|