newrelic-amazon-ec2 0.6.2

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.
Files changed (62) hide show
  1. data/.gitignore +8 -0
  2. data/.yardopts +1 -0
  3. data/ChangeLog +293 -0
  4. data/LICENSE +66 -0
  5. data/README.rdoc +354 -0
  6. data/README_dev.rdoc +12 -0
  7. data/Rakefile +101 -0
  8. data/VERSION +1 -0
  9. data/amazon-ec2.gemspec +134 -0
  10. data/bin/ec2-gem-example.rb +137 -0
  11. data/bin/ec2-gem-profile.rb +10 -0
  12. data/bin/ec2sh +62 -0
  13. data/bin/setup.rb +28 -0
  14. data/deps.rip +1 -0
  15. data/lib/AWS.rb +292 -0
  16. data/lib/AWS/Autoscaling.rb +70 -0
  17. data/lib/AWS/Autoscaling/autoscaling.rb +273 -0
  18. data/lib/AWS/Cloudwatch.rb +32 -0
  19. data/lib/AWS/Cloudwatch/monitoring.rb +89 -0
  20. data/lib/AWS/EC2.rb +33 -0
  21. data/lib/AWS/EC2/availability_zones.rb +21 -0
  22. data/lib/AWS/EC2/console.rb +23 -0
  23. data/lib/AWS/EC2/elastic_ips.rb +81 -0
  24. data/lib/AWS/EC2/image_attributes.rb +133 -0
  25. data/lib/AWS/EC2/images.rb +101 -0
  26. data/lib/AWS/EC2/instances.rb +212 -0
  27. data/lib/AWS/EC2/keypairs.rb +61 -0
  28. data/lib/AWS/EC2/products.rb +21 -0
  29. data/lib/AWS/EC2/security_groups.rb +183 -0
  30. data/lib/AWS/EC2/snapshots.rb +59 -0
  31. data/lib/AWS/EC2/volumes.rb +115 -0
  32. data/lib/AWS/ELB.rb +71 -0
  33. data/lib/AWS/ELB/load_balancers.rb +178 -0
  34. data/lib/AWS/exceptions.rb +122 -0
  35. data/lib/AWS/responses.rb +21 -0
  36. data/newrelic-amazon-ec2.gemspec +136 -0
  37. data/perftools/ec2prof +0 -0
  38. data/perftools/ec2prof-results.dot +132 -0
  39. data/perftools/ec2prof-results.txt +100 -0
  40. data/perftools/ec2prof.symbols +102 -0
  41. data/test/test_Autoscaling_groups.rb +336 -0
  42. data/test/test_EC2.rb +68 -0
  43. data/test/test_EC2_availability_zones.rb +49 -0
  44. data/test/test_EC2_console.rb +54 -0
  45. data/test/test_EC2_elastic_ips.rb +144 -0
  46. data/test/test_EC2_image_attributes.rb +238 -0
  47. data/test/test_EC2_images.rb +197 -0
  48. data/test/test_EC2_instances.rb +429 -0
  49. data/test/test_EC2_keypairs.rb +123 -0
  50. data/test/test_EC2_products.rb +48 -0
  51. data/test/test_EC2_responses.rb +53 -0
  52. data/test/test_EC2_s3_xmlsimple.rb +80 -0
  53. data/test/test_EC2_security_groups.rb +205 -0
  54. data/test/test_EC2_snapshots.rb +83 -0
  55. data/test/test_EC2_volumes.rb +142 -0
  56. data/test/test_ELB_load_balancers.rb +239 -0
  57. data/test/test_helper.rb +23 -0
  58. data/wsdl/2007-08-29.ec2.wsdl +1269 -0
  59. data/wsdl/2008-02-01.ec2.wsdl +1614 -0
  60. data/wsdl/2008-05-05.ec2.wsdl +2052 -0
  61. data/wsdl/2008-12-01.ec2.wsdl +2354 -0
  62. metadata +218 -0
@@ -0,0 +1,336 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ context "autoscaling " do
4
+ before do
5
+ @as = AWS::Autoscaling::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
6
+
7
+ @valid_create_launch_configuration_params = {
8
+ :image_id => "ami-ed46a784",
9
+ :launch_configuration_name => "TestAutoscalingGroupName",
10
+ :instance_type => "m1.small"
11
+ }
12
+
13
+ @error_response_for_creation = <<-RESPONSE
14
+ <ErrorResponse xmlns="http://autoscaling.amazonaws.com/doc/2009-05-15/">
15
+ <Error>
16
+ <Type>Sender</Type>
17
+ <Code>AlreadyExists</Code>
18
+ <Message>Launch Configuration by this name already exists - A launch configuration already exists with the name TestAutoscalingGroupName</Message>
19
+ </Error>
20
+ <RequestId>31d00b03-ad6a-11de-a47f-a5c562feca13</RequestId>
21
+ </ErrorResponse>
22
+ RESPONSE
23
+
24
+ @delete_launch_configuration_response = <<-RESPONSE
25
+ <DeleteLaunchConfigurationResponse xmlns="http://autoscaling.amazonaws.com/doc/2009-05-15/">
26
+ <ResponseMetadata>
27
+ <RequestId>5f5717d3-ad6c-11de-b1c0-1b00aadc5f72</RequestId>
28
+ </ResponseMetadata>
29
+ </DeleteLaunchConfigurationResponse>
30
+ RESPONSE
31
+
32
+ @create_launch_configuration_response = "<CreateLaunchConfigurationResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">\n <ResponseMetadata>\n <RequestId>6062466f-ad6c-11de-b82f-996c936914c5</RequestId>\n </ResponseMetadata>\n</CreateLaunchConfigurationResponse>\n"
33
+
34
+ @create_autoscaling_group_response = "<CreateAutoScalingGroupResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">\n <ResponseMetadata>\n <RequestId>cc4f9960-ad6e-11de-b82f-996c936914c5</RequestId>\n </ResponseMetadata>\n</CreateAutoScalingGroupResponse>\n"
35
+
36
+ @delete_autoscaling_group = "<DeleteAutoScalingGroupResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
37
+ <ResponseMetadata><RequestId>e64fc4c3-e10b-11dd-a73e-2d774d6aee71</RequestId></ResponseMetadata></DeleteAutoScalingGroupResponse>"
38
+ @create_or_update_trigger_response = "<CreateOrUpdateScalingTriggerResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
39
+ <ResponseMetadata>
40
+ <RequestId>503d309d-e10b-11dd-a73e-2d774d6aee71</RequestId>
41
+ </ResponseMetadata>
42
+ </CreateOrUpdateScalingTriggerResponse>"
43
+ end
44
+
45
+ specify "AWS::Autoscaling::Base should give back a nice response if there is an error" do
46
+ @as.stubs(:make_request).with('CreateLaunchConfiguration', {
47
+ 'ImageId' => 'ami-ed46a784',
48
+ 'LaunchConfigurationName' => 'TestAutoscalingGroupName',
49
+ 'InstanceType' => "m1.small"
50
+ }).returns stub(:body => @error_response_for_creation, :is_a? => true)
51
+
52
+ response = @as.create_launch_configuration( :image_id => "ami-ed46a784", :launch_configuration_name => "TestAutoscalingGroupName", :instance_type => "m1.small")
53
+ response.should.be.an.instance_of Hash
54
+ response["Error"]["Message"].should.equal "Launch Configuration by this name already exists - A launch configuration already exists with the name TestAutoscalingGroupName"
55
+ end
56
+
57
+ specify "AWS::Autoscaling::Base should destroy a launch configuration just fine" do
58
+ @as.stubs(:make_request).with('DeleteLaunchConfiguration', {
59
+ 'LaunchConfigurationName' => 'TestAutoscalingGroupName1'
60
+ }).returns stub(:body => @delete_launch_configuration_response, :is_a? => true)
61
+
62
+ response = @as.delete_launch_configuration( :launch_configuration_name => "TestAutoscalingGroupName1" )
63
+ response.should.be.an.instance_of Hash
64
+ end
65
+
66
+ specify "AWS::Autoscaling::Base should create a launch configuration" do
67
+ @as.stubs(:make_request).with('CreateLaunchConfiguration', {
68
+ 'ImageId' => 'ami-ed46a784',
69
+ 'LaunchConfigurationName' => 'CustomTestAutoscalingGroupName',
70
+ 'InstanceType' => "m1.small"
71
+ }).returns stub(:body => @create_launch_configuration_response, :is_a? => true)
72
+
73
+ response = @as.create_launch_configuration( :image_id => "ami-ed46a784", :launch_configuration_name => "CustomTestAutoscalingGroupName", :instance_type => "m1.small")
74
+ response.should.be.an.instance_of Hash
75
+ end
76
+
77
+ specify "AWS::Autoscaling::Base should be able to create a new autoscaling group" do
78
+ @as.stubs(:make_request).with("CreateAutoScalingGroup", {
79
+ 'AutoScalingGroupName' => 'CloudteamTestAutoscalingGroup1',
80
+ 'AvailabilityZones.member.1' => 'us-east-1a',
81
+ 'LoadBalancerNames' => 'TestLoadBalancerName',
82
+ 'LaunchConfigurationName' => 'CloudteamTestAutoscaling',
83
+ 'MinSize' => "1", 'MaxSize' => "3"
84
+ }).returns stub(:body => @create_autoscaling_group_response, :is_a? => true)
85
+ response = @as.create_autoscaling_group(:autoscaling_group_name => "CloudteamTestAutoscalingGroup1", :availability_zones => "us-east-1a", :load_balancer_names => "TestLoadBalancerName", :launch_configuration_name => "CloudteamTestAutoscaling", :min_size => 1, :max_size => 3)
86
+ response.should.be.an.instance_of Hash
87
+ end
88
+
89
+ specify "AWS::Autoscaling::Base should destroy an autoscaling group" do
90
+ @as.stubs(:make_request).with('DeleteAutoScalingGroup', {
91
+ 'AutoScalingGroupName' => 'TestAutoscalingGroupName1'
92
+ }).returns stub(:body => @delete_autoscaling_group, :is_a? => true)
93
+
94
+ response = @as.delete_autoscaling_group( :autoscaling_group_name => "TestAutoscalingGroupName1" )
95
+ response.should.be.an.instance_of Hash
96
+ end
97
+
98
+ specify "AWS::Autoscaling::Base should be able to create a new scaling trigger" do
99
+ @as.stubs(:make_request).with("CreateOrUpdateScalingTrigger", {
100
+ 'AutoScalingGroupName' => 'AutoScalingGroupName',
101
+ 'Unit' => "Seconds",
102
+ 'Dimensions.member.1.Name' => "AutoScalingGroupName",
103
+ 'Dimensions.member.1.Value' => "Bob",
104
+ 'MeasureName' => "CPUUtilization",
105
+ 'Statistic' => 'Average',
106
+ 'Period' => '120',
107
+ 'TriggerName' => "AFunNameForATrigger",
108
+ 'LowerThreshold' => "0.2",
109
+ 'LowerBreachScaleIncrement' => "-1",
110
+ 'UpperThreshold' => "1.5",
111
+ 'UpperBreachScaleIncrement' => "1",
112
+ 'BreachDuration' => "120"
113
+ }).returns stub(:body => @create_or_update_trigger_response, :is_a? => true)
114
+
115
+ valid_create_or_update_scaling_trigger_params = {:autoscaling_group_name => "AutoScalingGroupName", :dimensions => {:name => "AutoScalingGroupName", :value => "Bob"}, :unit => "Seconds", :measure_name => "CPUUtilization", :statistic => "Average", :period => 120, :trigger_name => "AFunNameForATrigger", :lower_threshold => 0.2, :lower_breach_scale_increment => "-1", :upper_threshold => 1.5, :upper_breach_scale_increment => 1, :breach_duration => 120}
116
+
117
+ %w(dimensions autoscaling_group_name measure_name statistic period trigger_name lower_threshold lower_breach_scale_increment upper_threshold upper_breach_scale_increment breach_duration).each do |meth_str|
118
+ lambda { @as.create_or_updated_scaling_trigger(valid_create_or_update_scaling_trigger_params.merge(meth_str.to_sym=>nil)) }.should.raise(AWS::ArgumentError)
119
+ end
120
+
121
+ response = @as.create_or_updated_scaling_trigger(valid_create_or_update_scaling_trigger_params)
122
+ response.should.be.an.instance_of Hash
123
+ end
124
+
125
+ specify "AWS::Autoscaling::Base should destroy a launch configuration group" do
126
+ @as.stubs(:make_request).with('DeleteLaunchConfiguration', {
127
+ 'LaunchConfigurationName' => 'LaunchConfiguration'
128
+ }).returns stub(:body => " <DeleteLaunchConfigurationResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
129
+ <ResponseMetadata><RequestId>e64fc4c3-e10b-11dd-a73e-2d774d6aee71</RequestId></ResponseMetadata>
130
+ </DeleteLaunchConfigurationResponse>", :is_a? => true)
131
+
132
+ response = @as.delete_launch_configuration( :launch_configuration_name => "LaunchConfiguration" )
133
+ response.should.be.an.instance_of Hash
134
+ end
135
+
136
+ specify "AWS::Autoscaling::Base should destroy a scaling trigger" do
137
+ @as.stubs(:make_request).with('DeleteTrigger', {
138
+ 'TriggerName' => 'DeletingTrigger', 'AutoScalingGroupName' => "Name"
139
+ }).returns stub(:body => " <DeleteTriggerResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
140
+ <ResponseMetadata>
141
+ <RequestId>cca38097-e10b-11dd-a73e-2d774d6aee71</RequestId>
142
+ </ResponseMetadata>
143
+ </DeleteTriggerResponse>", :is_a? => true)
144
+
145
+ response = @as.delete_trigger( :trigger_name => "DeletingTrigger", :autoscaling_group_name => "Name" )
146
+ response.should.be.an.instance_of Hash
147
+ end
148
+
149
+ specify "AWS::Autoscaling::Base should describe the autoscaling groups" do
150
+ @as.stubs(:make_request).with('DescribeAutoScalingGroups', {
151
+ 'AutoScalingGroupNames.member.1' => "webtier"
152
+ }).returns stub(:body => "<DescribeAutoScalingGroupsResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
153
+ <DescribeAutoScalingGroupsResult>
154
+ <AutoScalingGroups>
155
+ <member>
156
+ <MinSize>0</MinSize>
157
+ <CreatedTime>2009-01-13T00:38:54Z</CreatedTime>
158
+ <AvailabilityZones>
159
+ <member>us-east-1c</member>
160
+ </AvailabilityZones>
161
+ <Cooldown>0</Cooldown>
162
+ <LaunchConfigurationName>wt20080929</LaunchConfigurationName>
163
+ <AutoScalingGroupName>webtier</AutoScalingGroupName>
164
+ <DesiredCapacity>1</DesiredCapacity>
165
+ <Instances>
166
+ <member>
167
+ <InstanceId>i-8fa224e6</InstanceId>
168
+ <LifecycleState>InService</LifecycleState>
169
+ <AvailabilityZone>us-east-1c</AvailabilityZone>
170
+ </member>
171
+ </Instances>
172
+ <MaxSize>1</MaxSize>
173
+ </member>
174
+ </AutoScalingGroups>
175
+ </DescribeAutoScalingGroupsResult>
176
+ <ResponseMetadata>
177
+ <RequestId>70f2e8af-e10b-11dd-a73e-2d774d6aee71</RequestId>
178
+ </ResponseMetadata>
179
+ </DescribeAutoScalingGroupsResponse>", :is_a? => true)
180
+
181
+ response = @as.describe_autoscaling_groups( :autoscaling_group_names => ["webtier"] )
182
+ response.should.be.an.instance_of Hash
183
+ end
184
+
185
+ specify "AWS::Autoscaling::Base should describe the launch configurations" do
186
+ @as.stubs(:make_request).with('DescribeLaunchConfigurations', {
187
+ 'AutoScalingGroupNames.member.1' => "webtier"
188
+ }).returns stub(:body => "<DescribeLaunchConfigurationsResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
189
+ <DescribeLaunchConfigurationsResult>
190
+ <LaunchConfigurations>
191
+ <member>
192
+ <InstanceType>m1.small</InstanceType>
193
+ <BlockDeviceMappings/>
194
+ <KeyName/>
195
+ <SecurityGroups/>
196
+ <ImageId>ami-f7c5219e</ImageId>
197
+ <RamdiskId/>
198
+ <CreatedTime>2009-01-13T00:35:31Z</CreatedTime>
199
+ <KernelId/>
200
+ <LaunchConfigurationName>wt20080929</LaunchConfigurationName>
201
+ <UserData/>
202
+ </member>
203
+ </LaunchConfigurations>
204
+ </DescribeLaunchConfigurationsResult>
205
+ <ResponseMetadata>
206
+ <RequestId>2e14cb6c-e10a-11dd-a73e-2d774d6aee71</RequestId>
207
+ </ResponseMetadata>
208
+ </DescribeLaunchConfigurationsResponse>", :is_a? => true)
209
+
210
+ response = @as.describe_launch_configurations( :launch_configuration_names => ["webtier"] )
211
+ response.should.be.an.instance_of Hash
212
+ end
213
+
214
+
215
+ specify "AWS::Autoscaling::Base should describe the launch configurations" do
216
+ @as.stubs(:make_request).with('DescribeScalingActivities', {
217
+ 'AutoScalingGroupName' => "webtier"
218
+ }).returns stub(:body => "<DescribeScalingActivitiesResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
219
+ <DescribeScalingActivitiesResult>
220
+ <Activities>
221
+ <member>
222
+ <ActivityId>885b2900-0f2e-497a-8ec6-b1b90a9ddee0</ActivityId>
223
+ <StartTime>2009-03-29T04:07:07Z</StartTime>
224
+ <Progress>0</Progress>
225
+ <StatusCode>InProgress</StatusCode>
226
+ <Cause>Automated Capacity Adjustment</Cause>
227
+ <Description>Launching a new EC2 instance</Description>
228
+ </member>
229
+ </Activities>
230
+ </DescribeScalingActivitiesResult>
231
+ <ResponseMetadata>
232
+ <RequestId>f0321780-e10a-11dd-a73e-2d774d6aee71</RequestId>
233
+ </ResponseMetadata>
234
+ </DescribeScalingActivitiesResponse>", :is_a? => true)
235
+
236
+ response = @as.describe_scaling_activities( :autoscaling_group_name => "webtier" )
237
+ response.should.be.an.instance_of Hash
238
+ end
239
+
240
+ specify "AWS::Autoscaling::Base should describe triggers" do
241
+ @as.stubs(:make_request).with('DescribeTriggers', {
242
+ 'AutoScalingGroupName' => "webtier"
243
+ }).returns stub(:body => " <DescribeTriggersResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
244
+ <DescribeTriggersResult>
245
+ <Triggers>
246
+ <member>
247
+ <BreachDuration>300</BreachDuration>
248
+ <UpperBreachScaleIncrement>1</UpperBreachScaleIncrement>
249
+ <CreatedTime>2009-01-13T00:44:19Z</CreatedTime>
250
+ <UpperThreshold>60.0</UpperThreshold>
251
+ <Status>NoData</Status>
252
+ <LowerThreshold>0.0</LowerThreshold>
253
+ <Period>60</Period>
254
+ <LowerBreachScaleIncrement>-1</LowerBreachScaleIncrement>
255
+ <TriggerName>tenpct</TriggerName>
256
+ <Statistic>Average</Statistic>
257
+ <Unit>None</Unit>
258
+ <Namespace>AWS/EC2</Namespace>
259
+ <Dimensions>
260
+
261
+ <member>
262
+ <Name>AutoScalingGroupName</Name>
263
+ <Value>webtier</Value>
264
+ </member>
265
+ </Dimensions>
266
+ <AutoScalingGroupName>webtier</AutoScalingGroupName>
267
+ <MeasureName>CPUUtilization</MeasureName>
268
+ </member>
269
+ </Triggers>
270
+ </DescribeTriggersResult>
271
+ <ResponseMetadata>
272
+ <RequestId>5c33c82a-e10b-11dd-a73e-2d774d6aee71</RequestId>
273
+ </ResponseMetadata>
274
+ </DescribeTriggersResponse>", :is_a? => true)
275
+
276
+ response = @as.describe_triggers( :autoscaling_group_name => "webtier" )
277
+ response.should.be.an.instance_of Hash
278
+ end
279
+
280
+ specify "AWS::Autoscaling::Base should describe triggers" do
281
+ @as.stubs(:make_request).with('SetDesiredCapacity', {
282
+ 'AutoScalingGroupName' => "name", 'DesiredCapacity' => '10'
283
+ }).returns stub(:body => " <SetDesiredCapacityResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
284
+ <ResponseMetadata>
285
+ <RequestId>d3f2091c-e10a-11dd-a73e- 2d774d6aee71</RequestId>
286
+ </ResponseMetadata>
287
+ </SetDesiredCapacityResponse>
288
+ ", :is_a? => true)
289
+
290
+ response = @as.set_desired_capacity( :autoscaling_group_name => "name", :desired_capacity => "10" )
291
+ response.should.be.an.instance_of Hash
292
+ end
293
+
294
+
295
+ specify "AWS::Autoscaling::Base should terminate an instance in an autoscaling group" do
296
+ @as.stubs(:make_request).with('TerminateInstanceInAutoScalingGroup', {
297
+ 'InstanceId' => "i-instance1"
298
+ }).returns stub(:body => " <DescribeTriggersResponse xmlns=\"http://autoscaling.amazonaws.com/doc/2009-05-15/\">
299
+ <DescribeTriggersResult>
300
+ <Triggers>
301
+ <member>
302
+ <BreachDuration>300</BreachDuration>
303
+ <UpperBreachScaleIncrement>1</UpperBreachScaleIncrement>
304
+ <CreatedTime>2009-01-13T00:44:19Z</CreatedTime>
305
+ <UpperThreshold>60.0</UpperThreshold>
306
+ <Status>NoData</Status>
307
+ <LowerThreshold>0.0</LowerThreshold>
308
+ <Period>60</Period>
309
+ <LowerBreachScaleIncrement>-1</LowerBreachScaleIncrement>
310
+ <TriggerName>tenpct</TriggerName>
311
+ <Statistic>Average</Statistic>
312
+ <Unit>None</Unit>
313
+ <Namespace>AWS/EC2</Namespace>
314
+ <Dimensions>
315
+
316
+ <member>
317
+ <Name>AutoScalingGroupName</Name>
318
+ <Value>webtier</Value>
319
+ </member>
320
+ </Dimensions>
321
+ <AutoScalingGroupName>webtier</AutoScalingGroupName>
322
+ <MeasureName>CPUUtilization</MeasureName>
323
+ </member>
324
+ </Triggers>
325
+ </DescribeTriggersResult>
326
+ <ResponseMetadata>
327
+ <RequestId>5c33c82a-e10b-11dd-a73e-2d774d6aee71</RequestId>
328
+ </ResponseMetadata>
329
+ </DescribeTriggersResponse>", :is_a? => true)
330
+
331
+ response = @as.terminate_instance_in_autoscaling_group( :instance_id => "i-instance1" )
332
+ response.should.be.an.instance_of Hash
333
+ end
334
+
335
+
336
+ end
@@ -0,0 +1,68 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "The EC2 method " do
14
+
15
+ before do
16
+ end
17
+
18
+ specify "AWS::EC2::Base attribute readers should be available" do
19
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
20
+ :secret_access_key => "not a secret",
21
+ :use_ssl => true,
22
+ :server => "foo.example.com" )
23
+
24
+ @ec2.use_ssl.should.equal true
25
+ @ec2.port.should.equal 443
26
+ @ec2.server.should.equal "foo.example.com"
27
+ end
28
+
29
+ specify "AWS::EC2::Base should work with insecure connections as well" do
30
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
31
+ :secret_access_key => "not a secret",
32
+ :use_ssl => false,
33
+ :server => "foo.example.com" )
34
+
35
+ @ec2.use_ssl.should.equal false
36
+ @ec2.port.should.equal 80
37
+ @ec2.server.should.equal "foo.example.com"
38
+ end
39
+
40
+ specify "AWS::EC2::Base should allow specification of port" do
41
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key",
42
+ :secret_access_key => "not a secret",
43
+ :use_ssl => true,
44
+ :server => "foo.example.com",
45
+ :port => 8443 )
46
+
47
+ @ec2.use_ssl.should.equal true
48
+ @ec2.port.should.equal 8443
49
+ @ec2.server.should.equal "foo.example.com"
50
+ end
51
+
52
+ specify "AWS.canonical_string(path) should conform to Amazon's requirements " do
53
+ path = {"name1" => "value1", "name2" => "value2", "name3" => "value3"}
54
+ if ENV['EC2_URL'].nil? || ENV['EC2_URL'] == 'https://ec2.amazonaws.com'
55
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\nec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
56
+ elsif ENV['EC2_URL'] == 'https://us-east-1.ec2.amazonaws.com'
57
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\nus-east-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
58
+ elsif ENV['EC2_URL'] == 'https://eu-west-1.ec2.amazonaws.com'
59
+ AWS.canonical_string(path, 'ec2.amazonaws.com').should.equal "POST\neu-west-1.ec2.amazonaws.com\n/\nname1=value1&name2=value2&name3=value3"
60
+ end
61
+ end
62
+
63
+ specify "AWS.encode should return the expected string" do
64
+ AWS.encode("secretaccesskey", "foobar123", urlencode=true).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g%3D"
65
+ AWS.encode("secretaccesskey", "foobar123", urlencode=false).should.equal "e3jeuDc3DIX2mW8cVqWiByj4j5g="
66
+ end
67
+
68
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Amazon Web Services EC2 Query API Ruby library
3
+ #
4
+ # Ruby Gem Name:: amazon-ec2
5
+ # Author:: Glenn Rempe (mailto:glenn@rempe.us)
6
+ # Copyright:: Copyright (c) 2007-2008 Glenn Rempe
7
+ # License:: Distributes under the same terms as Ruby
8
+ # Home:: http://github.com/grempe/amazon-ec2/tree/master
9
+ #++
10
+
11
+ require File.dirname(__FILE__) + '/test_helper.rb'
12
+
13
+ context "EC2 availability zones" do
14
+
15
+ before do
16
+ @ec2 = AWS::EC2::Base.new( :access_key_id => "not a key", :secret_access_key => "not a secret" )
17
+
18
+ @describe_availability_zones_response_body = <<-RESPONSE
19
+ <DescribeAvailabilityZonesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01/">
20
+ <availabilityZoneInfo>
21
+ <item>
22
+ <zoneName>us-east-1a</zoneName>
23
+ <zoneState>available</zoneState>
24
+ </item>
25
+ <item>
26
+ <zoneName>us-east-1b</zoneName>
27
+ <zoneState>available</zoneState>
28
+ </item>
29
+ </availabilityZoneInfo>
30
+ </DescribeAvailabilityZonesResponse>
31
+ RESPONSE
32
+
33
+ end
34
+
35
+ specify "should be able to be described with describe_availability_zones" do
36
+ @ec2.stubs(:make_request).with('DescribeAvailabilityZones', { "ZoneName.1" => "us-east-1a", "ZoneName.2" => "us-east-1b" }).
37
+ returns stub(:body => @describe_availability_zones_response_body, :is_a? => true)
38
+ @ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] ).should.be.an.instance_of Hash
39
+
40
+ response = @ec2.describe_availability_zones( :zone_name => ["us-east-1a", "us-east-1b"] )
41
+
42
+ response.availabilityZoneInfo.item[0].zoneName.should.equal "us-east-1a"
43
+ response.availabilityZoneInfo.item[0].zoneState.should.equal "available"
44
+
45
+ response.availabilityZoneInfo.item[1].zoneName.should.equal "us-east-1b"
46
+ response.availabilityZoneInfo.item[1].zoneState.should.equal "available"
47
+ end
48
+
49
+ end