amazon-ec2 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +9 -0
- data/Manifest.txt +0 -2
- data/README.txt +1 -1
- data/lib/EC2.rb +60 -60
- data/lib/EC2/console.rb +11 -11
- data/lib/EC2/exceptions.rb +35 -35
- data/lib/EC2/image_attributes.rb +39 -39
- data/lib/EC2/images.rb +58 -58
- data/lib/EC2/instances.rb +86 -73
- data/lib/EC2/keypairs.rb +26 -26
- data/lib/EC2/products.rb +10 -10
- data/lib/EC2/responses.rb +37 -37
- data/lib/EC2/security_groups.rb +79 -79
- data/lib/EC2/version.rb +1 -1
- data/test/test_EC2.rb +10 -10
- data/test/test_EC2_console.rb +15 -15
- data/test/test_EC2_image_attributes.rb +74 -74
- data/test/test_EC2_images.rb +45 -45
- data/test/test_EC2_instances.rb +103 -88
- data/test/test_EC2_keypairs.rb +24 -24
- data/test/test_EC2_products.rb +10 -10
- data/test/test_EC2_responses.rb +29 -29
- data/test/test_EC2_security_groups.rb +50 -50
- data/test/test_EC2_version.rb +13 -13
- data/test/test_helper.rb +1 -1
- data/website/index.html +1 -1
- metadata +2 -4
- data/website/announce.html +0 -109
- data/website/announce.txt +0 -36
data/lib/EC2/version.rb
CHANGED
data/test/test_EC2.rb
CHANGED
@@ -11,42 +11,42 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "The EC2 method " do
|
14
|
-
|
14
|
+
|
15
15
|
setup do
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
specify "EC2::Base attribute readers should be available" do
|
19
19
|
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
20
20
|
:secret_access_key => "not a secret",
|
21
21
|
:use_ssl => true,
|
22
22
|
:server => "foo.example.com" )
|
23
|
-
|
23
|
+
|
24
24
|
@ec2.use_ssl.should.equal true
|
25
25
|
@ec2.port.should.equal 443
|
26
26
|
@ec2.server.should.equal "foo.example.com"
|
27
27
|
end
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
|
30
30
|
specify "EC2::Base should work with insecure connections as well" do
|
31
31
|
@ec2 = EC2::Base.new( :access_key_id => "not a key",
|
32
32
|
:secret_access_key => "not a secret",
|
33
33
|
:use_ssl => false,
|
34
34
|
:server => "foo.example.com" )
|
35
|
-
|
35
|
+
|
36
36
|
@ec2.use_ssl.should.equal false
|
37
37
|
@ec2.port.should.equal 80
|
38
38
|
@ec2.server.should.equal "foo.example.com"
|
39
39
|
end
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
specify "EC2.canonical_string(path) should data that is stripped of ?,&,= " do
|
43
43
|
path = "?name1=value1&name2=value2&name3=value3"
|
44
44
|
EC2.canonical_string(path).should.equal "name1value1name2value2name3value3"
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
specify "EC2.encode should return the expected string" do
|
48
48
|
EC2.encode("secretaccesskey", "foobar123", urlencode=true).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g%3D"
|
49
49
|
EC2.encode("secretaccesskey", "foobar123", urlencode=false).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g="
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end
|
data/test/test_EC2_console.rb
CHANGED
@@ -11,29 +11,29 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "The EC2 console " do
|
14
|
-
|
14
|
+
|
15
15
|
setup do
|
16
16
|
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
-
|
17
|
+
|
18
18
|
@get_console_output_response_body = <<-RESPONSE
|
19
19
|
<GetConsoleOutputResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
20
|
<instanceId>i-28a64341</instanceId>
|
21
21
|
<timestamp>2007-01-03 15:00:00</timestamp>
|
22
22
|
<output>
|
23
|
-
YyB2ZXJzaW9uIDQuMC4xIDIwMDUwNzI3IChSZWQgSGF0IDQuMC4xLTUpKSAjMSBTTVAgVGh1IE9j
|
24
|
-
dCAyNiAwODo0MToyNiBTQVNUIDIwMDYKQklPUy1wcm92aWRlZCBwaHlzaWNhbCBSQU0gbWFwOgpY
|
25
|
-
ZW46IDAwMDAwMDAwMDAwMDAwMDAgLSAwMDAwMDAwMDZhNDAwMDAwICh1c2FibGUpCjk4ME1CIEhJ
|
26
|
-
R0hNRU0gYXZhaWxhYmxlLgo3MjdNQiBMT1dNRU0gYXZhaWxhYmxlLgpOWCAoRXhlY3V0ZSBEaXNh
|
27
|
-
YmxlKSBwcm90ZWN0aW9uOiBhY3RpdmUKSVJRIGxvY2t1cCBkZXRlY3Rpb24gZGlzYWJsZWQKQnVp
|
28
|
-
bHQgMSB6b25lbGlzdHMKS2VybmVsIGNvbW1hbmQgbGluZTogcm9vdD0vZGV2L3NkYTEgcm8gNApF
|
23
|
+
YyB2ZXJzaW9uIDQuMC4xIDIwMDUwNzI3IChSZWQgSGF0IDQuMC4xLTUpKSAjMSBTTVAgVGh1IE9j
|
24
|
+
dCAyNiAwODo0MToyNiBTQVNUIDIwMDYKQklPUy1wcm92aWRlZCBwaHlzaWNhbCBSQU0gbWFwOgpY
|
25
|
+
ZW46IDAwMDAwMDAwMDAwMDAwMDAgLSAwMDAwMDAwMDZhNDAwMDAwICh1c2FibGUpCjk4ME1CIEhJ
|
26
|
+
R0hNRU0gYXZhaWxhYmxlLgo3MjdNQiBMT1dNRU0gYXZhaWxhYmxlLgpOWCAoRXhlY3V0ZSBEaXNh
|
27
|
+
YmxlKSBwcm90ZWN0aW9uOiBhY3RpdmUKSVJRIGxvY2t1cCBkZXRlY3Rpb24gZGlzYWJsZWQKQnVp
|
28
|
+
bHQgMSB6b25lbGlzdHMKS2VybmVsIGNvbW1hbmQgbGluZTogcm9vdD0vZGV2L3NkYTEgcm8gNApF
|
29
29
|
bmFibGluZyBmYXN0IEZQVSBzYXZlIGFuZCByZXN0b3JlLi4uIGRvbmUuCg==
|
30
30
|
</output>
|
31
31
|
</GetConsoleOutputResponse>
|
32
32
|
RESPONSE
|
33
|
-
|
33
|
+
|
34
34
|
end
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
|
37
37
|
specify "should return info written to a specific instances console" do
|
38
38
|
@ec2.stubs(:make_request).with('GetConsoleOutput', {"InstanceId"=>"i-2ea64347"}).
|
39
39
|
returns stub(:body => @get_console_output_response_body, :is_a? => true)
|
@@ -42,13 +42,13 @@ context "The EC2 console " do
|
|
42
42
|
response.instanceId.should.equal "i-28a64341"
|
43
43
|
response.timestamp.should.equal "2007-01-03 15:00:00"
|
44
44
|
end
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
|
47
47
|
specify "method get_console_output should raise an exception when called without nil/empty string arguments" do
|
48
48
|
lambda { @ec2.get_console_output() }.should.raise(EC2::ArgumentError)
|
49
49
|
lambda { @ec2.get_console_output(:instance_id => nil) }.should.raise(EC2::ArgumentError)
|
50
50
|
lambda { @ec2.get_console_output(:instance_id => "") }.should.raise(EC2::ArgumentError)
|
51
51
|
end
|
52
|
-
|
53
|
-
|
52
|
+
|
53
|
+
|
54
54
|
end
|
@@ -11,22 +11,22 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "EC2 image_attributes " do
|
14
|
-
|
14
|
+
|
15
15
|
setup do
|
16
16
|
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
-
|
17
|
+
|
18
18
|
@modify_image_attribute_response_body = <<-RESPONSE
|
19
19
|
<ModifyImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
20
|
<return>true</return>
|
21
21
|
</ModifyImageAttributeResponse>
|
22
22
|
RESPONSE
|
23
|
-
|
23
|
+
|
24
24
|
@reset_image_attribute_response_body = <<-RESPONSE
|
25
|
-
<ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
25
|
+
<ResetImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
26
26
|
<return>true</return>
|
27
27
|
</ResetImageAttributeResponse>
|
28
28
|
RESPONSE
|
29
|
-
|
29
|
+
|
30
30
|
@describe_image_attribute_response_body_launch_permissions = <<-RESPONSE
|
31
31
|
<DescribeImageAttributeResponse xm-lns="http://ec2.amazonaws.com/doc/2007-03-01">
|
32
32
|
<imageId>ami-61a54008</imageId>
|
@@ -40,7 +40,7 @@ context "EC2 image_attributes " do
|
|
40
40
|
</launchPermission>
|
41
41
|
</DescribeImageAttributeResponse>
|
42
42
|
RESPONSE
|
43
|
-
|
43
|
+
|
44
44
|
@describe_image_attribute_response_body_product_codes = <<-RESPONSE
|
45
45
|
<DescribeImageAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2007-01-03">
|
46
46
|
<imageId>ami-61a54008</imageId>
|
@@ -51,188 +51,188 @@ context "EC2 image_attributes " do
|
|
51
51
|
</productCodes>
|
52
52
|
</DescribeImageAttributeResponse>
|
53
53
|
RESPONSE
|
54
|
-
|
54
|
+
|
55
55
|
end
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
|
58
58
|
specify "should be able to be changed with modify_image_attribute (with :attribute and single value :user_id and :group)" do
|
59
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
60
|
-
"Attribute"=>"launchPermission",
|
59
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
60
|
+
"Attribute"=>"launchPermission",
|
61
61
|
"OperationType"=>"add",
|
62
62
|
"UserId.1"=>"123",
|
63
63
|
"Group.1"=>"all"}).
|
64
64
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
65
65
|
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id=>["123"], :group=>["all"]).should.be.an.instance_of EC2::Response
|
66
66
|
end
|
67
|
-
|
68
|
-
|
67
|
+
|
68
|
+
|
69
69
|
specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :group only)" do
|
70
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
71
|
-
"Attribute"=>"launchPermission",
|
70
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
71
|
+
"Attribute"=>"launchPermission",
|
72
72
|
"OperationType"=>"add",
|
73
73
|
"Group.1"=>"all"}).
|
74
74
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
75
75
|
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]).should.be.an.instance_of EC2::Response
|
76
76
|
end
|
77
|
-
|
78
|
-
|
77
|
+
|
78
|
+
|
79
79
|
specify "should be able to be changed with modify_image_attribute ( with :operation_type 'remove')" do
|
80
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
81
|
-
"Attribute"=>"launchPermission",
|
80
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
81
|
+
"Attribute"=>"launchPermission",
|
82
82
|
"OperationType"=>"remove",
|
83
83
|
"Group.1"=>"all"}).
|
84
84
|
returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
85
85
|
@ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"remove", :group=>["all"]).should.be.an.instance_of EC2::Response
|
86
86
|
end
|
87
|
-
|
88
|
-
|
87
|
+
|
88
|
+
|
89
89
|
specify "should be able to be changed with modify_image_attribute ( with :attribute but specifying :user_id only)" do
|
90
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
91
|
-
"Attribute"=>"launchPermission",
|
90
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
91
|
+
"Attribute"=>"launchPermission",
|
92
92
|
"OperationType"=>"add",
|
93
93
|
"UserId.1"=>"123"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
94
|
-
|
95
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
96
|
-
:attribute=>"launchPermission",
|
97
|
-
:operation_type=>"add",
|
94
|
+
|
95
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
96
|
+
:attribute=>"launchPermission",
|
97
|
+
:operation_type=>"add",
|
98
98
|
:user_id=>["123"]).should.be.an.instance_of EC2::Response
|
99
99
|
end
|
100
|
-
|
101
|
-
|
100
|
+
|
101
|
+
|
102
102
|
specify "should be able to be changed with modify_image_attribute ( with :attribute=>'productCodes')" do
|
103
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
104
|
-
"Attribute"=>"productCodes",
|
103
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
104
|
+
"Attribute"=>"productCodes",
|
105
105
|
"OperationType"=>"",
|
106
106
|
"ProductCode.1"=>"774F4FF8"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
107
|
-
|
108
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
109
|
-
:attribute=>"productCodes",
|
107
|
+
|
108
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
109
|
+
:attribute=>"productCodes",
|
110
110
|
:product_code=>["774F4FF8"]).should.be.an.instance_of EC2::Response
|
111
111
|
end
|
112
|
-
|
113
|
-
|
112
|
+
|
113
|
+
|
114
114
|
specify "should be able to be changed with modify_image_attribute ( with :attribute and multiple :user_id and :group elements)" do
|
115
|
-
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
116
|
-
"Attribute"=>"launchPermission",
|
115
|
+
@ec2.stubs(:make_request).with('ModifyImageAttribute', {"ImageId"=>"ami-61a54008",
|
116
|
+
"Attribute"=>"launchPermission",
|
117
117
|
"OperationType"=>"add",
|
118
118
|
"UserId.1"=>"123",
|
119
119
|
"UserId.2"=>"345",
|
120
120
|
"Group.1"=>"123",
|
121
121
|
"Group.2"=>"all"}).returns stub(:body => @modify_image_attribute_response_body, :is_a? => true)
|
122
|
-
|
123
|
-
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
124
|
-
:attribute=>"launchPermission",
|
125
|
-
:operation_type=>"add",
|
126
|
-
:user_id=>["123", "345"],
|
122
|
+
|
123
|
+
@ec2.modify_image_attribute(:image_id=>"ami-61a54008",
|
124
|
+
:attribute=>"launchPermission",
|
125
|
+
:operation_type=>"add",
|
126
|
+
:user_id=>["123", "345"],
|
127
127
|
:group=>["123", "all"]).should.be.an.instance_of EC2::Response
|
128
128
|
end
|
129
|
-
|
130
|
-
|
129
|
+
|
130
|
+
|
131
131
|
specify "should raise an exception when modify_image_attribute is called with incorrect arguments" do
|
132
132
|
# method args can't be nil or empty
|
133
133
|
lambda { @ec2.modify_image_attribute() }.should.raise(EC2::ArgumentError)
|
134
134
|
lambda { @ec2.modify_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
|
135
|
-
|
135
|
+
|
136
136
|
# :image_id option must be not be empty or nil
|
137
137
|
lambda { @ec2.modify_image_attribute(:image_id=>nil, :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
138
138
|
lambda { @ec2.modify_image_attribute(:image_id=>"", :attribute=>"launchPermission", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
139
|
-
|
139
|
+
|
140
140
|
# :attribute currently has two options which are 'launchPermission' and 'productCodes, it should fail with any other value, nil, or empty
|
141
141
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil, :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
142
142
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
143
143
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo", :operation_type=>"add", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
144
|
-
|
144
|
+
|
145
145
|
# :attribute => 'launchPermission' option should fail if neither :group nor :user_id are also provided
|
146
146
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add") }.should.raise(EC2::ArgumentError)
|
147
147
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => nil) }.should.raise(EC2::ArgumentError)
|
148
148
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :group => "") }.should.raise(EC2::ArgumentError)
|
149
149
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => nil) }.should.raise(EC2::ArgumentError)
|
150
150
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"add", :user_id => "") }.should.raise(EC2::ArgumentError)
|
151
|
-
|
151
|
+
|
152
152
|
# :attribute => 'productCodes' option should fail if :product_code isn't also provided
|
153
153
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>nil) }.should.raise(EC2::ArgumentError)
|
154
154
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes", :product_code=>"") }.should.raise(EC2::ArgumentError)
|
155
|
-
|
155
|
+
|
156
156
|
# :operation_type currently has two options which are 'add' and 'remove', and it should fail with any other, nil or empty
|
157
157
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>nil, :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
158
158
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
159
159
|
lambda { @ec2.modify_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission", :operation_type=>"foo", :group=>["all"]) }.should.raise(EC2::ArgumentError)
|
160
160
|
end
|
161
|
-
|
162
|
-
|
161
|
+
|
162
|
+
|
163
163
|
specify "method describe_image_attribute should return the proper attributes when called with launchPermission" do
|
164
|
-
@ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
|
164
|
+
@ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
|
165
165
|
"Attribute"=>"launchPermission" }).
|
166
166
|
returns stub(:body => @describe_image_attribute_response_body_launch_permissions, :is_a? => true)
|
167
|
-
|
167
|
+
|
168
168
|
@ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "launchPermission").
|
169
169
|
should.be.an.instance_of EC2::Response
|
170
|
-
|
170
|
+
|
171
171
|
response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission")
|
172
172
|
response.imageId.should.equal "ami-61a54008"
|
173
173
|
response.launchPermission.item[0].group.should.equal "all"
|
174
174
|
response.launchPermission.item[1].userId.should.equal "495219933132"
|
175
175
|
end
|
176
|
-
|
177
|
-
|
176
|
+
|
177
|
+
|
178
178
|
specify "method describe_image_attribute should return the proper attributes when called with productCodes" do
|
179
|
-
@ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
|
179
|
+
@ec2.stubs(:make_request).with('DescribeImageAttribute', {"ImageId"=>"ami-61a54008",
|
180
180
|
"Attribute"=>"productCodes" }).
|
181
181
|
returns stub(:body => @describe_image_attribute_response_body_product_codes, :is_a? => true)
|
182
|
-
|
182
|
+
|
183
183
|
@ec2.describe_image_attribute(:image_id => "ami-61a54008", :attribute => "productCodes").
|
184
184
|
should.be.an.instance_of EC2::Response
|
185
|
-
|
185
|
+
|
186
186
|
response = @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"productCodes")
|
187
187
|
response.imageId.should.equal "ami-61a54008"
|
188
188
|
response.productCodes.item[0].productCode.should.equal "774F4FF8"
|
189
189
|
end
|
190
|
-
|
191
|
-
|
190
|
+
|
191
|
+
|
192
192
|
specify "should raise an exception when describe_image_attribute is called with incorrect arguments" do
|
193
193
|
# method args can't be nil or empty
|
194
194
|
lambda { @ec2.describe_image_attribute() }.should.raise(EC2::ArgumentError)
|
195
195
|
lambda { @ec2.describe_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
|
196
|
-
|
196
|
+
|
197
197
|
# :image_id option must be not be empty or nil w/ launchPermission
|
198
198
|
lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
|
199
199
|
lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
|
200
|
-
|
200
|
+
|
201
201
|
# :image_id option must be not be empty or nil w/ productCodes
|
202
202
|
lambda { @ec2.describe_image_attribute(:image_id=>nil, :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
|
203
203
|
lambda { @ec2.describe_image_attribute(:image_id=>"", :attribute=>"productCodes") }.should.raise(EC2::ArgumentError)
|
204
|
-
|
204
|
+
|
205
205
|
# :attribute currently has two options which are 'launchPermission' and 'productCodes', it should fail with any other values,
|
206
206
|
# nil, or empty
|
207
207
|
lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(EC2::ArgumentError)
|
208
208
|
lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
|
209
209
|
lambda { @ec2.describe_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
|
210
210
|
end
|
211
|
-
|
212
|
-
|
211
|
+
|
212
|
+
|
213
213
|
specify "should be able to reset attributes with reset_image_attribute " do
|
214
|
-
@ec2.stubs(:make_request).with('ResetImageAttribute', {"ImageId"=>"ami-61a54008",
|
214
|
+
@ec2.stubs(:make_request).with('ResetImageAttribute', {"ImageId"=>"ami-61a54008",
|
215
215
|
"Attribute"=>"launchPermission"}).
|
216
216
|
returns stub(:body => @reset_image_attribute_response_body, :is_a? => true)
|
217
217
|
@ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").should.be.an.instance_of EC2::Response
|
218
218
|
@ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"launchPermission").return.should.equal "true"
|
219
219
|
end
|
220
|
-
|
221
|
-
|
220
|
+
|
221
|
+
|
222
222
|
specify "should raise an exception when reset_image_attribute is called with incorrect arguments" do
|
223
223
|
# method args can't be nil or empty
|
224
224
|
lambda { @ec2.reset_image_attribute() }.should.raise(EC2::ArgumentError)
|
225
225
|
lambda { @ec2.reset_image_attribute(:image_id=>"") }.should.raise(EC2::ArgumentError)
|
226
|
-
|
226
|
+
|
227
227
|
# :image_id option must be not be empty or nil
|
228
228
|
lambda { @ec2.reset_image_attribute(:image_id=>nil, :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
|
229
229
|
lambda { @ec2.reset_image_attribute(:image_id=>"", :attribute=>"launchPermission") }.should.raise(EC2::ArgumentError)
|
230
|
-
|
230
|
+
|
231
231
|
# :attribute currently has one option which is 'launchPermission', it should fail with any other value, nil, or empty
|
232
232
|
lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>nil) }.should.raise(EC2::ArgumentError)
|
233
233
|
lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"") }.should.raise(EC2::ArgumentError)
|
234
234
|
lambda { @ec2.reset_image_attribute(:image_id=>"ami-61a54008", :attribute=>"foo") }.should.raise(EC2::ArgumentError)
|
235
235
|
end
|
236
|
-
|
237
|
-
|
236
|
+
|
237
|
+
|
238
238
|
end
|
data/test/test_EC2_images.rb
CHANGED
@@ -11,18 +11,18 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "An EC2 image " do
|
14
|
-
|
14
|
+
|
15
15
|
setup do
|
16
16
|
@ec2 = EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
|
17
|
-
|
17
|
+
|
18
18
|
@register_image_response_body = <<-RESPONSE
|
19
|
-
<RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
19
|
+
<RegisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
20
|
<imageId>ami-61a54008</imageId>
|
21
21
|
</RegisterImageResponse>
|
22
22
|
RESPONSE
|
23
|
-
|
23
|
+
|
24
24
|
@describe_image_response_body = <<-RESPONSE
|
25
|
-
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
25
|
+
<DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
26
26
|
<imagesSet>
|
27
27
|
<item>
|
28
28
|
<imageId>ami-61a54008</imageId>
|
@@ -46,30 +46,30 @@ context "An EC2 image " do
|
|
46
46
|
</imagesSet>
|
47
47
|
</DescribeImagesResponse>
|
48
48
|
RESPONSE
|
49
|
-
|
49
|
+
|
50
50
|
@deregister_image_response_body = <<-RESPONSE
|
51
|
-
<DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
52
|
-
<return>true</return>
|
51
|
+
<DeregisterImageResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
52
|
+
<return>true</return>
|
53
53
|
</DeregisterImageResponse>
|
54
54
|
RESPONSE
|
55
|
-
|
55
|
+
|
56
56
|
end
|
57
|
-
|
58
|
-
|
57
|
+
|
58
|
+
|
59
59
|
specify "should be able to be registered" do
|
60
60
|
@ec2.stubs(:make_request).with('RegisterImage', {"ImageLocation"=>"mybucket-myimage.manifest.xml"}).
|
61
61
|
returns stub(:body => @register_image_response_body, :is_a? => true)
|
62
62
|
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").imageId.should.equal "ami-61a54008"
|
63
63
|
@ec2.register_image(:image_location => "mybucket-myimage.manifest.xml").should.be.an.instance_of EC2::Response
|
64
64
|
end
|
65
|
-
|
66
|
-
|
65
|
+
|
66
|
+
|
67
67
|
specify "method register_image should raise an exception when called without nil/empty string arguments" do
|
68
68
|
lambda { @ec2.register_image() }.should.raise(EC2::ArgumentError)
|
69
69
|
lambda { @ec2.register_image(:image_location => "") }.should.raise(EC2::ArgumentError)
|
70
70
|
end
|
71
|
-
|
72
|
-
|
71
|
+
|
72
|
+
|
73
73
|
specify "should be able to be described and return the correct Ruby response class for parent and members" do
|
74
74
|
@ec2.stubs(:make_request).with('DescribeImages', {}).
|
75
75
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
@@ -77,21 +77,21 @@ context "An EC2 image " do
|
|
77
77
|
response = @ec2.describe_images
|
78
78
|
response.should.be.an.instance_of EC2::Response
|
79
79
|
end
|
80
|
-
|
81
|
-
|
80
|
+
|
81
|
+
|
82
82
|
specify "should be able to be described with no params and return an imagesSet" do
|
83
83
|
@ec2.stubs(:make_request).with('DescribeImages', {}).
|
84
84
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
85
85
|
@ec2.describe_images.imagesSet.item.length.should.equal 2
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
specify "should be able to be described by an Array of ImageId.N ID's and return an array of Items" do
|
89
89
|
@ec2.stubs(:make_request).with('DescribeImages', {"ImageId.1"=>"ami-61a54008", "ImageId.2"=>"ami-61a54009"}).
|
90
90
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
91
91
|
@ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] ).imagesSet.item.length.should.equal 2
|
92
|
-
|
92
|
+
|
93
93
|
response = @ec2.describe_images( :image_id => ["ami-61a54008", "ami-61a54009"] )
|
94
|
-
|
94
|
+
|
95
95
|
# test first 'Item' object returned
|
96
96
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
97
97
|
response.imagesSet.item[0].imageLocation.should.equal "foobar1/image.manifest.xml"
|
@@ -99,7 +99,7 @@ context "An EC2 image " do
|
|
99
99
|
response.imagesSet.item[0].imageOwnerId.should.equal "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA"
|
100
100
|
response.imagesSet.item[0].isPublic.should.equal "true"
|
101
101
|
response.imagesSet.item[0].productCodes.item[0].productCode.should.equal "774F4FF8"
|
102
|
-
|
102
|
+
|
103
103
|
# test second 'Item' object returned
|
104
104
|
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
105
105
|
response.imagesSet.item[1].imageLocation.should.equal "foobar2/image.manifest.xml"
|
@@ -107,91 +107,91 @@ context "An EC2 image " do
|
|
107
107
|
response.imagesSet.item[1].imageOwnerId.should.equal "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"
|
108
108
|
response.imagesSet.item[1].isPublic.should.equal "false"
|
109
109
|
end
|
110
|
-
|
111
|
-
|
110
|
+
|
111
|
+
|
112
112
|
specify "should be able to be described by an owners with Owner.N ID's and return an array of Items" do
|
113
113
|
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "Owner.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
|
114
114
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
115
115
|
@ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
|
116
|
-
|
116
|
+
|
117
117
|
# owner ID's
|
118
118
|
response = @ec2.describe_images( :owner_id => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
|
119
119
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
120
120
|
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
121
121
|
end
|
122
|
-
|
123
|
-
|
122
|
+
|
123
|
+
|
124
124
|
specify "should be able to be described by an owner of 'self' and return an array of Items that I own" do
|
125
125
|
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "self").
|
126
126
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
127
127
|
@ec2.describe_images( :owner_id => "self" ).imagesSet.item.length.should.equal 2
|
128
|
-
|
128
|
+
|
129
129
|
# 'self' - Those that I own
|
130
130
|
response = @ec2.describe_images( :owner_id => "self" )
|
131
131
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
132
132
|
end
|
133
|
-
|
134
|
-
|
133
|
+
|
134
|
+
|
135
135
|
specify "should be able to be described by an owner of 'amazon' and return an array of Items that are Amazon Public AMI's" do
|
136
136
|
@ec2.stubs(:make_request).with('DescribeImages', "Owner.1" => "amazon").
|
137
137
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
138
138
|
@ec2.describe_images( :owner_id => "amazon" ).imagesSet.item.length.should.equal 2
|
139
|
-
|
139
|
+
|
140
140
|
# 'amazon' - Those that are owned and created by AWS
|
141
141
|
response = @ec2.describe_images( :owner_id => "amazon" )
|
142
142
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
143
143
|
end
|
144
|
-
|
145
|
-
|
144
|
+
|
145
|
+
|
146
146
|
specify "should be able to be described by an owners with Owner.N ID's who can execute AMI's and return an array of Items" do
|
147
147
|
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ExecutableBy.2" => "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ").
|
148
148
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
149
149
|
@ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] ).imagesSet.item.length.should.equal 2
|
150
|
-
|
150
|
+
|
151
151
|
# executable by owner ID's
|
152
152
|
response = @ec2.describe_images( :executable_by => ["AAAATLBUXIEON5NQVUUX6OMPWBZIAAAA", "ZZZZTLBUXIEON5NQVUUX6OMPWBZIZZZZ"] )
|
153
153
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
154
154
|
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
155
155
|
end
|
156
|
-
|
157
|
-
|
156
|
+
|
157
|
+
|
158
158
|
specify "should be able to be described by an owners with Owner.N of 'self' who can execute AMI's and return an array of Items" do
|
159
159
|
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "self").
|
160
160
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
161
161
|
@ec2.describe_images( :executable_by => "self" ).imagesSet.item.length.should.equal 2
|
162
|
-
|
162
|
+
|
163
163
|
# executable by owner ID's
|
164
164
|
response = @ec2.describe_images( :executable_by => "self" )
|
165
165
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
166
166
|
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
167
167
|
end
|
168
|
-
|
169
|
-
|
168
|
+
|
169
|
+
|
170
170
|
specify "should be able to be described by an owners with Owner.N of 'all' who can execute AMI's and return an array of Items" do
|
171
171
|
@ec2.stubs(:make_request).with('DescribeImages', "ExecutableBy.1" => "all").
|
172
172
|
returns stub(:body => @describe_image_response_body, :is_a? => true)
|
173
173
|
@ec2.describe_images( :executable_by => "all" ).imagesSet.item.length.should.equal 2
|
174
|
-
|
174
|
+
|
175
175
|
# executable by owner ID's
|
176
176
|
response = @ec2.describe_images( :executable_by => "all" )
|
177
177
|
response.imagesSet.item[0].imageId.should.equal "ami-61a54008"
|
178
178
|
response.imagesSet.item[1].imageId.should.equal "ami-61a54009"
|
179
179
|
end
|
180
|
-
|
181
|
-
|
180
|
+
|
181
|
+
|
182
182
|
specify "should be able to be de-registered" do
|
183
183
|
@ec2.stubs(:make_request).with('DeregisterImage', {"ImageId"=>"ami-61a54008"}).
|
184
184
|
returns stub(:body => @deregister_image_response_body, :is_a? => true)
|
185
185
|
@ec2.deregister_image(:image_id => "ami-61a54008" ).should.be.an.instance_of EC2::Response
|
186
186
|
@ec2.deregister_image(:image_id => "ami-61a54008" ).return.should.equal "true"
|
187
187
|
end
|
188
|
-
|
189
|
-
|
188
|
+
|
189
|
+
|
190
190
|
specify "method deregister_image should raise an exception when called without nil/empty string arguments" do
|
191
191
|
lambda { @ec2.deregister_image() }.should.raise(EC2::ArgumentError)
|
192
192
|
lambda { @ec2.deregister_image( :image_id => nil ) }.should.raise(EC2::ArgumentError)
|
193
193
|
lambda { @ec2.deregister_image( :image_id => "" ) }.should.raise(EC2::ArgumentError)
|
194
194
|
end
|
195
|
-
|
196
|
-
|
195
|
+
|
196
|
+
|
197
197
|
end
|