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/test/test_EC2_instances.rb
CHANGED
@@ -11,12 +11,12 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "EC2 instances " 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
|
@run_instances_response_body = <<-RESPONSE
|
19
|
-
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-
|
19
|
+
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
|
20
20
|
<reservationId>r-47a5402e</reservationId>
|
21
21
|
<ownerId>495219933132</ownerId>
|
22
22
|
<groupSet>
|
@@ -30,40 +30,49 @@ context "EC2 instances " do
|
|
30
30
|
<imageId>ami-60a54009</imageId>
|
31
31
|
<instanceState>
|
32
32
|
<code>0</code>
|
33
|
-
|
33
|
+
<name>pending</name>
|
34
34
|
</instanceState>
|
35
|
-
<privateDnsName
|
36
|
-
<dnsName
|
35
|
+
<privateDnsName></privateDnsName>
|
36
|
+
<dnsName></dnsName>
|
37
37
|
<keyName>example-key-name</keyName>
|
38
|
+
<amiLaunchIndex>0</amiLaunchIndex>
|
39
|
+
<instanceType>m1.small</instanceType>
|
40
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
38
41
|
</item>
|
39
42
|
<item>
|
40
43
|
<instanceId>i-2bc64242</instanceId>
|
41
44
|
<imageId>ami-60a54009</imageId>
|
42
45
|
<instanceState>
|
43
46
|
<code>0</code>
|
44
|
-
|
47
|
+
<name>pending</name>
|
45
48
|
</instanceState>
|
46
|
-
<privateDnsName
|
47
|
-
<dnsName
|
49
|
+
<privateDnsName></privateDnsName>
|
50
|
+
<dnsName></dnsName>
|
48
51
|
<keyName>example-key-name</keyName>
|
52
|
+
<amiLaunchIndex>1</amiLaunchIndex>
|
53
|
+
<instanceType>m1.small</instanceType>
|
54
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
49
55
|
</item>
|
50
56
|
<item>
|
51
57
|
<instanceId>i-2be64332</instanceId>
|
52
58
|
<imageId>ami-60a54009</imageId>
|
53
59
|
<instanceState>
|
54
60
|
<code>0</code>
|
55
|
-
|
61
|
+
<name>pending</name>
|
56
62
|
</instanceState>
|
57
|
-
<privateDnsName
|
58
|
-
<dnsName
|
63
|
+
<privateDnsName></privateDnsName>
|
64
|
+
<dnsName></dnsName>
|
59
65
|
<keyName>example-key-name</keyName>
|
66
|
+
<amiLaunchIndex>2</amiLaunchIndex>
|
67
|
+
<instanceType>m1.small</instanceType>
|
68
|
+
<launchTime>2007-08-07T11:51:50.000Z</launchTime>
|
60
69
|
</item>
|
61
70
|
</instancesSet>
|
62
71
|
</RunInstancesResponse>
|
63
72
|
RESPONSE
|
64
|
-
|
73
|
+
|
65
74
|
@describe_instances_response_body = <<-RESPONSE
|
66
|
-
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-
|
75
|
+
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-08-29">
|
67
76
|
<reservationSet>
|
68
77
|
<item>
|
69
78
|
<reservationId>r-44a5402d</reservationId>
|
@@ -82,72 +91,72 @@ context "EC2 instances " do
|
|
82
91
|
<name>running</name>
|
83
92
|
</instanceState>
|
84
93
|
<privateDnsName>domU-12-31-35-00-1E-01.z-2.compute-1.internal</privateDnsName>
|
85
|
-
|
94
|
+
<dnsName>ec2-72-44-33-4.z-2.compute-1.amazonaws.com</dnsName>
|
86
95
|
<keyName>example-key-name</keyName>
|
87
96
|
<productCodesSet>
|
88
|
-
<item>
|
89
|
-
<productCode>774F4FF8</productCode>
|
90
|
-
</item>
|
97
|
+
<item><productCode>774F4FF8</productCode></item>
|
91
98
|
</productCodesSet>
|
99
|
+
<instanceType>m1.small</instanceType>
|
100
|
+
<launchTime>2007-08-07T11:54:42.000Z</launchTime>
|
92
101
|
</item>
|
93
102
|
</instancesSet>
|
94
103
|
</item>
|
95
104
|
</reservationSet>
|
96
105
|
</DescribeInstancesResponse>
|
97
106
|
RESPONSE
|
98
|
-
|
107
|
+
|
99
108
|
@reboot_instances_response_body = <<-RESPONSE
|
100
109
|
<RebootInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
101
110
|
<return>true</return>
|
102
111
|
</RebootInstancesResponse>
|
103
112
|
RESPONSE
|
104
|
-
|
113
|
+
|
105
114
|
@terminate_instances_response_body = <<-RESPONSE
|
106
|
-
<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
107
|
-
<instancesSet>
|
108
|
-
<item>
|
109
|
-
<instanceId>i-28a64341</instanceId>
|
110
|
-
<shutdownState>
|
111
|
-
<code>32</code>
|
112
|
-
<name>shutting-down</name>
|
113
|
-
</shutdownState>
|
114
|
-
<previousState>
|
115
|
-
<code>0</code>
|
116
|
-
<name>pending</name>
|
117
|
-
</previousState>
|
118
|
-
</item>
|
119
|
-
<item>
|
120
|
-
<instanceId>i-21a64348</instanceId>
|
121
|
-
<shutdownState>
|
122
|
-
<code>32</code>
|
123
|
-
<name>shutting-down</name>
|
124
|
-
</shutdownState>
|
125
|
-
<previousState>
|
126
|
-
<code>0</code>
|
127
|
-
<name>pending</name>
|
128
|
-
</previousState>
|
129
|
-
</item>
|
130
|
-
</instancesSet>
|
115
|
+
<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
116
|
+
<instancesSet>
|
117
|
+
<item>
|
118
|
+
<instanceId>i-28a64341</instanceId>
|
119
|
+
<shutdownState>
|
120
|
+
<code>32</code>
|
121
|
+
<name>shutting-down</name>
|
122
|
+
</shutdownState>
|
123
|
+
<previousState>
|
124
|
+
<code>0</code>
|
125
|
+
<name>pending</name>
|
126
|
+
</previousState>
|
127
|
+
</item>
|
128
|
+
<item>
|
129
|
+
<instanceId>i-21a64348</instanceId>
|
130
|
+
<shutdownState>
|
131
|
+
<code>32</code>
|
132
|
+
<name>shutting-down</name>
|
133
|
+
</shutdownState>
|
134
|
+
<previousState>
|
135
|
+
<code>0</code>
|
136
|
+
<name>pending</name>
|
137
|
+
</previousState>
|
138
|
+
</item>
|
139
|
+
</instancesSet>
|
131
140
|
</TerminateInstancesResponse>
|
132
141
|
RESPONSE
|
133
142
|
end
|
134
|
-
|
135
|
-
|
143
|
+
|
144
|
+
|
136
145
|
specify "should be able to be run" do
|
137
|
-
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public').
|
146
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
138
147
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
139
|
-
|
148
|
+
|
140
149
|
@ec2.run_instances( :image_id => "ami-60a54009" ).should.be.an.instance_of EC2::Response
|
141
|
-
|
150
|
+
|
142
151
|
response = @ec2.run_instances( :image_id => "ami-60a54009" )
|
143
|
-
|
152
|
+
|
144
153
|
response.reservationId.should.equal "r-47a5402e"
|
145
154
|
response.ownerId.should.equal "495219933132"
|
146
|
-
|
155
|
+
|
147
156
|
response.groupSet.item[0].groupId.should.equal "default"
|
148
|
-
|
157
|
+
|
149
158
|
response.instancesSet.item.length.should.equal 3
|
150
|
-
|
159
|
+
|
151
160
|
response.instancesSet.item[0].instanceId.should.equal "i-2ba64342"
|
152
161
|
response.instancesSet.item[0].imageId.should.equal "ami-60a54009"
|
153
162
|
response.instancesSet.item[0].instanceState.code.should.equal "0"
|
@@ -155,7 +164,9 @@ context "EC2 instances " do
|
|
155
164
|
response.instancesSet.item[0].privateDnsName
|
156
165
|
response.instancesSet.item[0].dnsName.should.be.nil
|
157
166
|
response.instancesSet.item[0].keyName.should.equal "example-key-name"
|
158
|
-
|
167
|
+
response.instancesSet.item[0].instanceType.should.equal "m1.small"
|
168
|
+
response.instancesSet.item[0].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
169
|
+
|
159
170
|
response.instancesSet.item[1].instanceId.should.equal "i-2bc64242"
|
160
171
|
response.instancesSet.item[1].imageId.should.equal "ami-60a54009"
|
161
172
|
response.instancesSet.item[1].instanceState.code.should.equal "0"
|
@@ -163,7 +174,9 @@ context "EC2 instances " do
|
|
163
174
|
response.instancesSet.item[1].privateDnsName
|
164
175
|
response.instancesSet.item[1].dnsName.should.be.nil
|
165
176
|
response.instancesSet.item[1].keyName.should.equal "example-key-name"
|
166
|
-
|
177
|
+
response.instancesSet.item[1].instanceType.should.equal "m1.small"
|
178
|
+
response.instancesSet.item[1].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
179
|
+
|
167
180
|
response.instancesSet.item[2].instanceId.should.equal "i-2be64332"
|
168
181
|
response.instancesSet.item[2].imageId.should.equal "ami-60a54009"
|
169
182
|
response.instancesSet.item[2].instanceState.code.should.equal "0"
|
@@ -171,54 +184,56 @@ context "EC2 instances " do
|
|
171
184
|
response.instancesSet.item[2].privateDnsName
|
172
185
|
response.instancesSet.item[2].dnsName.should.be.nil
|
173
186
|
response.instancesSet.item[2].keyName.should.equal "example-key-name"
|
187
|
+
response.instancesSet.item[2].instanceType.should.equal "m1.small"
|
188
|
+
response.instancesSet.item[2].launchTime.should.equal "2007-08-07T11:51:50.000Z"
|
174
189
|
end
|
175
|
-
|
176
|
-
|
190
|
+
|
191
|
+
|
177
192
|
specify "method 'run_instances' should reject invalid arguments" do
|
178
|
-
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public').
|
193
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
179
194
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
180
|
-
|
195
|
+
|
181
196
|
lambda { @ec2.run_instances() }.should.raise(EC2::ArgumentError)
|
182
197
|
lambda { @ec2.run_instances( :image_id => "" ) }.should.raise(EC2::ArgumentError)
|
183
|
-
|
198
|
+
|
184
199
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1 ) }.should.not.raise(EC2::ArgumentError)
|
185
200
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => 0 ) }.should.raise(EC2::ArgumentError)
|
186
201
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => nil ) }.should.raise(EC2::ArgumentError)
|
187
202
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :min_count => "" ) }.should.raise(EC2::ArgumentError)
|
188
|
-
|
203
|
+
|
189
204
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 1 ) }.should.not.raise(EC2::ArgumentError)
|
190
205
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => 0 ) }.should.raise(EC2::ArgumentError)
|
191
206
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => nil ) }.should.raise(EC2::ArgumentError)
|
192
207
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :max_count => "" ) }.should.raise(EC2::ArgumentError)
|
193
|
-
|
208
|
+
|
194
209
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "public" ) }.should.not.raise(EC2::ArgumentError)
|
195
210
|
#lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "direct" ) }.should.not.raise(EC2::ArgumentError)
|
196
211
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => nil ) }.should.raise(EC2::ArgumentError)
|
197
212
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "" ) }.should.raise(EC2::ArgumentError)
|
198
213
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :addressing_type => "foo" ) }.should.raise(EC2::ArgumentError)
|
199
|
-
|
214
|
+
|
200
215
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => true ) }.should.not.raise(EC2::ArgumentError)
|
201
216
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => false ) }.should.not.raise(EC2::ArgumentError)
|
202
217
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => nil ) }.should.raise(EC2::ArgumentError)
|
203
218
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "" ) }.should.raise(EC2::ArgumentError)
|
204
219
|
lambda { @ec2.run_instances( :image_id => "ami-60a54009", :base64_encoded => "foo" ) }.should.raise(EC2::ArgumentError)
|
205
220
|
end
|
206
|
-
|
207
|
-
|
221
|
+
|
222
|
+
|
208
223
|
specify "should be able to call run_instances with :user_data and :base64_encoded => true (default is false)" do
|
209
|
-
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public').
|
224
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "foo", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
210
225
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
211
226
|
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => true ).should.be.an.instance_of EC2::Response
|
212
227
|
end
|
213
|
-
|
214
|
-
|
228
|
+
|
229
|
+
|
215
230
|
specify "should be able to call run_instances with :user_data and :base64_encoded => false" do
|
216
|
-
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public').
|
231
|
+
@ec2.stubs(:make_request).with('RunInstances', "ImageId" => "ami-60a54009", "MinCount" => '1', "MaxCount" => '1', "UserData" => "Zm9v", "AddressingType" => 'public', 'InstanceType' => 'm1.small').
|
217
232
|
returns stub(:body => @run_instances_response_body, :is_a? => true)
|
218
233
|
@ec2.run_instances( :image_id => "ami-60a54009", :min_count => 1, :max_count => 1, :group_id => [], :user_data => "foo", :base64_encoded => false ).should.be.an.instance_of EC2::Response
|
219
234
|
end
|
220
|
-
|
221
|
-
|
235
|
+
|
236
|
+
|
222
237
|
specify "should be able to be described and return the correct Ruby response class" do
|
223
238
|
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
224
239
|
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
@@ -226,8 +241,8 @@ context "EC2 instances " do
|
|
226
241
|
response = @ec2.describe_instances
|
227
242
|
response.reservationSet.item[0].reservationId.should.equal "r-44a5402d"
|
228
243
|
end
|
229
|
-
|
230
|
-
|
244
|
+
|
245
|
+
|
231
246
|
specify "should be able to be described with no params and return an array of Items" do
|
232
247
|
@ec2.stubs(:make_request).with('DescribeInstances', {}).
|
233
248
|
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
@@ -245,8 +260,8 @@ context "EC2 instances " do
|
|
245
260
|
response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
|
246
261
|
response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
|
247
262
|
end
|
248
|
-
|
249
|
-
|
263
|
+
|
264
|
+
|
250
265
|
specify "should be able to be described with params of Array of :instance_id's and return an array of Items" do
|
251
266
|
@ec2.stubs(:make_request).with('DescribeInstances', {"InstanceId.1" => "i-28a64341"}).
|
252
267
|
returns stub(:body => @describe_instances_response_body, :is_a? => true)
|
@@ -264,47 +279,47 @@ context "EC2 instances " do
|
|
264
279
|
response.reservationSet.item[0].instancesSet.item[0].keyName.should.equal "example-key-name"
|
265
280
|
response.reservationSet.item[0].instancesSet.item[0].productCodesSet.item[0].productCode.should.equal "774F4FF8"
|
266
281
|
end
|
267
|
-
|
268
|
-
|
282
|
+
|
283
|
+
|
269
284
|
specify "method reboot_instances should raise an exception when called without nil/empty string arguments" do
|
270
285
|
lambda { @ec2.reboot_instances() }.should.raise(EC2::ArgumentError)
|
271
286
|
lambda { @ec2.reboot_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
|
272
287
|
lambda { @ec2.reboot_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
|
273
288
|
end
|
274
|
-
|
275
|
-
|
289
|
+
|
290
|
+
|
276
291
|
specify "should be able to be rebooted when provided with an :instance_id" do
|
277
292
|
@ec2.expects(:make_request).with('RebootInstances', {"InstanceId.1"=>"i-2ea64347", "InstanceId.2"=>"i-21a64348"}).
|
278
293
|
returns stub(:body => @reboot_instances_response_body, :is_a? => true)
|
279
294
|
@ec2.reboot_instances( :instance_id => ["i-2ea64347", "i-21a64348"] ).class.should.equal EC2::Response
|
280
295
|
end
|
281
|
-
|
282
|
-
|
296
|
+
|
297
|
+
|
283
298
|
specify "method terminate_instances should raise an exception when called without nil/empty string arguments" do
|
284
299
|
lambda { @ec2.terminate_instances() }.should.raise(EC2::ArgumentError)
|
285
300
|
lambda { @ec2.terminate_instances( :instance_id => nil ) }.should.raise(EC2::ArgumentError)
|
286
301
|
lambda { @ec2.terminate_instances( :instance_id => "" ) }.should.raise(EC2::ArgumentError)
|
287
302
|
end
|
288
|
-
|
289
|
-
|
303
|
+
|
304
|
+
|
290
305
|
specify "should be able to be terminated when provided with an :instance_id" do
|
291
306
|
@ec2.stubs(:make_request).with('TerminateInstances', {"InstanceId.1"=>"i-28a64341", "InstanceId.2"=>"i-21a64348"}).
|
292
307
|
returns stub(:body => @terminate_instances_response_body, :is_a? => true)
|
293
308
|
@ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] ).class.should.equal EC2::Response
|
294
|
-
|
309
|
+
|
295
310
|
@response = @ec2.terminate_instances( :instance_id => ["i-28a64341", "i-21a64348"] )
|
296
|
-
|
311
|
+
|
297
312
|
@response.instancesSet.item[0].instanceId.should.equal "i-28a64341"
|
298
313
|
@response.instancesSet.item[0].shutdownState.code.should.equal "32"
|
299
314
|
@response.instancesSet.item[0].shutdownState.name.should.equal "shutting-down"
|
300
315
|
@response.instancesSet.item[0].previousState.code.should.equal "0"
|
301
316
|
@response.instancesSet.item[0].previousState.name.should.equal "pending"
|
302
|
-
|
317
|
+
|
303
318
|
@response.instancesSet.item[1].instanceId.should.equal "i-21a64348"
|
304
319
|
@response.instancesSet.item[1].shutdownState.code.should.equal "32"
|
305
320
|
@response.instancesSet.item[1].shutdownState.name.should.equal "shutting-down"
|
306
321
|
@response.instancesSet.item[1].previousState.code.should.equal "0"
|
307
322
|
@response.instancesSet.item[1].previousState.name.should.equal "pending"
|
308
323
|
end
|
309
|
-
|
324
|
+
|
310
325
|
end
|
data/test/test_EC2_keypairs.rb
CHANGED
@@ -11,14 +11,14 @@
|
|
11
11
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
12
12
|
|
13
13
|
context "EC2 keypairs " 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
|
@create_keypair_response_body = <<-RESPONSE
|
19
|
-
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
-
<keyName>example-key-name</keyName>
|
21
|
-
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
19
|
+
<CreateKeyPairResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
20
|
+
<keyName>example-key-name</keyName>
|
21
|
+
<keyFingerprint>1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f</keyFingerprint>
|
22
22
|
<keyMaterial>-----BEGIN RSA PRIVATE KEY-----
|
23
23
|
MIIEoQIBAAKCAQBuLFg5ujHrtm1jnutSuoO8Xe56LlT+HM8v/xkaa39EstM3/aFxTHgElQiJLChp
|
24
24
|
HungXQ29VTc8rc1bW0lkdi23OH5eqkMHGhvEwqa0HWASUMll4o3o/IX+0f2UcPoKCOVUR+jx71Sg
|
@@ -44,7 +44,7 @@ context "EC2 keypairs " do
|
|
44
44
|
-----END RSA PRIVATE KEY-----</keyMaterial>
|
45
45
|
</CreateKeyPairResponse>
|
46
46
|
RESPONSE
|
47
|
-
|
47
|
+
|
48
48
|
@describe_keypairs_response_body = <<-RESPONSE
|
49
49
|
<DescribeKeyPairsResponse xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
50
50
|
<keySet>
|
@@ -55,41 +55,41 @@ context "EC2 keypairs " do
|
|
55
55
|
</keySet>
|
56
56
|
</DescribeKeyPairsResponse>
|
57
57
|
RESPONSE
|
58
|
-
|
58
|
+
|
59
59
|
@delete_keypair_body = <<-RESPONSE
|
60
60
|
<DeleteKeyPair xmlns="http://ec2.amazonaws.com/doc/2007-03-01">
|
61
61
|
<return>true</return>
|
62
62
|
</DeleteKeyPair>
|
63
63
|
RESPONSE
|
64
|
-
|
64
|
+
|
65
65
|
end
|
66
|
-
|
67
|
-
|
66
|
+
|
67
|
+
|
68
68
|
specify "should be able to be created" do
|
69
69
|
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
70
70
|
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
71
|
-
|
71
|
+
|
72
72
|
@ec2.create_keypair( :key_name => "example-key-name" ).should.be.an.instance_of EC2::Response
|
73
|
-
|
73
|
+
|
74
74
|
response = @ec2.create_keypair( :key_name => "example-key-name" )
|
75
75
|
response.keyName.should.equal "example-key-name"
|
76
76
|
response.keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
77
77
|
response.keyMaterial.should.not.equal ""
|
78
78
|
response.keyMaterial.should.not.be.nil
|
79
79
|
end
|
80
|
-
|
81
|
-
|
80
|
+
|
81
|
+
|
82
82
|
specify "method create_keypair should reject bad arguments" do
|
83
83
|
@ec2.stubs(:make_request).with('CreateKeyPair', {"KeyName"=>"example-key-name"}).
|
84
84
|
returns stub(:body => @create_keypair_response_body, :is_a? => true)
|
85
|
-
|
85
|
+
|
86
86
|
lambda { @ec2.create_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
87
87
|
lambda { @ec2.create_keypair() }.should.raise(EC2::ArgumentError)
|
88
88
|
lambda { @ec2.create_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
89
89
|
lambda { @ec2.create_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
90
90
|
end
|
91
|
-
|
92
|
-
|
91
|
+
|
92
|
+
|
93
93
|
specify "should be able to be described with describe_keypairs" do
|
94
94
|
@ec2.stubs(:make_request).with('DescribeKeyPairs', {"KeyName.1"=>"example-key-name"}).
|
95
95
|
returns stub(:body => @describe_keypairs_response_body, :is_a? => true)
|
@@ -98,8 +98,8 @@ context "EC2 keypairs " do
|
|
98
98
|
response.keySet.item[0].keyName.should.equal "example-key-name"
|
99
99
|
response.keySet.item[0].keyFingerprint.should.equal "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f"
|
100
100
|
end
|
101
|
-
|
102
|
-
|
101
|
+
|
102
|
+
|
103
103
|
specify "should be able to be deleted with delete_keypairs" do
|
104
104
|
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
105
105
|
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
@@ -107,17 +107,17 @@ context "EC2 keypairs " do
|
|
107
107
|
response = @ec2.delete_keypair( :key_name => "example-key-name" )
|
108
108
|
response.return.should.equal "true"
|
109
109
|
end
|
110
|
-
|
111
|
-
|
110
|
+
|
111
|
+
|
112
112
|
specify "method delete_keypair should reject bad argument" do
|
113
113
|
@ec2.stubs(:make_request).with('DeleteKeyPair', {"KeyName"=>"example-key-name"}).
|
114
114
|
returns stub(:body => @delete_keypair_body, :is_a? => true)
|
115
|
-
|
115
|
+
|
116
116
|
lambda { @ec2.delete_keypair( :key_name => "example-key-name" ) }.should.not.raise(EC2::ArgumentError)
|
117
117
|
lambda { @ec2.delete_keypair() }.should.raise(EC2::ArgumentError)
|
118
118
|
lambda { @ec2.delete_keypair( :key_name => nil ) }.should.raise(EC2::ArgumentError)
|
119
119
|
lambda { @ec2.delete_keypair( :key_name => "" ) }.should.raise(EC2::ArgumentError)
|
120
120
|
end
|
121
|
-
|
122
|
-
|
121
|
+
|
122
|
+
|
123
123
|
end
|