Permalink
Browse files

1. Doc fixes

2. Tests for some of the existing functionality in Route 53.
3. Specify source in Gemfile to make it work with more versions of bundler.
4. Tests for existing ELB functionality.
5. README for developers.
6. Updated ELB to API version 2011-04-05 to display CanonicalHostedZoneNameID. Ignore SourceSecurityGroup for now.
7. Updated Route 53 to API version 2011-05-05 which handles A(Alias) records.
  • Loading branch information...
1 parent 2eb840d commit a1b7682fc2246d8d1994b8b4c79b9cb42ae64978 @dvrensk dvrensk committed with konstantin-dzreev Aug 18, 2011
View
@@ -1,3 +1,5 @@
+source "http://rubygems.org"
+
gem 'right_http_connection', '1.2.5', :git => 'git@github.com:rightscale/right_http_connection.git'
gem 'libxml-ruby', '~> 0.5.2'
View
@@ -5,6 +5,7 @@ GIT
right_http_connection (1.2.5)
GEM
+ remote: http://rubygems.org/
specs:
libxml-ruby (0.5.2.0)
rake (0.8.7)
View
@@ -12,7 +12,7 @@ begin
rescue LoadError => e
STDERR.puts("Bundler is not available, some rake tasks will not be defined: #{e.message}")
else
- Bundler::GemHelper.install_tasks
+ Bundler::GemHelper.install_tasks :name => 'right_aws'
end
begin
@@ -113,4 +113,18 @@ task :testsns do
require 'test/sns/test_right_sns.rb'
end
+desc "Test Route 53 interface"
+task :testroute53 do
+ require 'test/test_credentials'
+ TestCredentials.get_credentials
+ require 'test/route_53/test_right_route_53'
+end
+
+desc "Test ELB interface"
+task :testelb do
+ require 'test/test_credentials'
+ TestCredentials.get_credentials
+ require 'test/elb/test_right_elb'
+end
+
# vim: syntax=Ruby
@@ -62,7 +62,7 @@ class ElbInterface < RightAwsBase
include RightAwsBaseInterface
# Amazon ELB API version being used
- API_VERSION = "2010-07-01"
+ API_VERSION = "2011-04-05"
DEFAULT_HOST = "elasticloadbalancing.amazonaws.com"
DEFAULT_PATH = '/'
DEFAULT_PROTOCOL = 'https'
@@ -460,6 +460,8 @@ def tagend(name)
when 'LoadBalancerPort' then @listener[:load_balancer_port] = @text
when 'InstancePort' then @listener[:instance_port] = @text
when 'SSLCertificateId' then @listener[:ssl_certificate_id] = @text
+ when 'CanonicalHostedZoneName' then @item[:canonical_hosted_zone_name] = @text
+ when 'CanonicalHostedZoneNameID' then @item[:canonical_hosted_zone_name_id] = @text
end
case full_tag_name
when %r{AvailabilityZones/member$} then @item[:availability_zones] << @text
@@ -158,7 +158,7 @@ class Route53Interface < RightAwsBase
include RightAwsBaseInterface
- API_VERSION = "2010-10-01"
+ API_VERSION = "2011-05-05"
DEFAULT_HOST = "route53.amazonaws.com"
DEFAULT_PATH = '/'
DEFAULT_PROTOCOL = 'https'
@@ -295,11 +295,22 @@ def resource_record_sets_to_xml(resource_record_changes, comment) # :nodoc:
" <Action>#{AwsUtils::xml_escape(change[:action].to_s.upcase)}</Action>\n" +
" <ResourceRecordSet>\n" +
" <Name>#{AwsUtils::xml_escape(change[:name])}</Name>\n" +
- " <Type>#{AwsUtils::xml_escape(change[:type].to_s.upcase)}</Type>\n" +
+ " <Type>#{AwsUtils::xml_escape(change[:type].to_s.upcase)}</Type>\n"
+ if change[:alias_target]
+ alias_target = change[:alias_target]
+ xml_changes +=
+ " <AliasTarget>\n" +
+ " <HostedZoneId>#{AwsUtils::xml_escape(alias_target[:hosted_zone_id].to_s)}</HostedZoneId>\n" +
+ " <DNSName>#{AwsUtils::xml_escape(alias_target[:dns_name].to_s)}</DNSName>\n" +
+ " </AliasTarget>\n"
+ else
+ xml_changes +=
" <TTL>#{AwsUtils::xml_escape(change[:ttl].to_s)}</TTL>\n" +
" <ResourceRecords>\n" +
xml_resource_records +
- " </ResourceRecords>\n" +
+ " </ResourceRecords>\n"
+ end
+ xml_changes +=
" </ResourceRecordSet>\n" +
" </Change>\n"
end
@@ -416,7 +427,6 @@ def delete_hosted_zone(hosted_zone_aws_id)
# Options: :type, :name, :max_items
#
# r53.list_resource_record_sets("/hostedzone/ZWEC7PPVACGQ4") #=>
- # {:items=>
# [{:type=>"NS",
# :ttl=>172800,
# :name=>"mysite.patch-island.com.",
@@ -433,9 +443,7 @@ def delete_hosted_zone(hosted_zone_aws_id)
# {:type=>"NS",
# :ttl=>600,
# :resource_records=>["xxx.mysite.com"],
- # :name=>"m1.mysite.patch-island.com."}],
- # :is_truncated=>false,
- # :max_items=>100}
+ # :name=>"m1.mysite.patch-island.com."}]
#
# PS: http://docs.amazonwebservices.com/Route53/latest/APIReference/API_ListResourceRecordSets.html
#
@@ -451,7 +459,7 @@ def list_resource_record_sets(hosted_zone_aws_id, options={})
# Create or delete DNS records.
#
- # resource_record_sets = { :action => :create,
+ # resource_record_sets = [{ :action => :create,
# :name => 'm3.mysite.patch-island.com',
# :type => 'NS',
# :ttl => 600,
@@ -460,7 +468,7 @@ def list_resource_record_sets(hosted_zone_aws_id, options={})
# :name => 'm2.mysite.patch-island.com',
# :type => 'A',
# :ttl => 600,
- # :resource_records => ['10.0.0.1'] }
+ # :resource_records => ['10.0.0.1'] }]
# r53.change_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
# {:status=>"PENDING",
# :submitted_at=>"2011-01-18T20:21:56.828Z",
@@ -476,14 +484,14 @@ def change_resource_record_sets(hosted_zone_aws_id, resource_record_sets, commen
# Create DNS records.
#
- # resource_record_sets = { :name => 'm3.mysite.patch-island.com',
+ # resource_record_sets = [{ :name => 'm3.mysite.patch-island.com',
# :type => 'NS',
# :ttl => 600,
# :resource_records => 'xxx.mysite.com' },
# { :name => 'm2.mysite.patch-island.com',
# :type => 'A',
# :ttl => 600,
- # :resource_records => ['10.0.0.1'] }
+ # :resource_records => ['10.0.0.1'] }]
# r53.create_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
# {:status=>"PENDING",
# :submitted_at=>"2011-01-18T20:21:56.828Z",
@@ -498,14 +506,14 @@ def create_resource_record_sets(hosted_zone_aws_id, resource_record_sets, commen
# Delete DNS records.
#
- # resource_record_sets = { :name => 'm3.mysite.patch-island.com',
+ # resource_record_sets = [{ :name => 'm3.mysite.patch-island.com',
# :type => 'NS',
# :ttl => 600,
# :resource_records => 'xxx.mysite.com' },
# { :name => 'm2.mysite.patch-island.com',
# :type => 'A',
# :ttl => 600,
- # :resource_records => ['10.0.0.1'] }
+ # :resource_records => ['10.0.0.1'] }]
# r53.create_resource_record_sets("/hostedzone/Z1K6NCF0EB26FB", resource_record_sets, 'KD: Comment#1') #=>
# {:status=>"PENDING",
# :submitted_at=>"2011-01-18T20:21:56.828Z",
@@ -606,7 +614,9 @@ def tagend(name)
when 'ResourceRecordSet' then @result[:items] << @item
else
case full_tag_name
- when %r{/ResourceRecord/Value} then (@item[:resource_records] ||= []) << @text
+ when %r{/ResourceRecord/Value} then (@item[:resource_records] ||= []) << @text
+ when %r{/AliasTarget/DNSName} then (@item[:alias_target] ||= {})[:dns_name] = @text
+ when %r{/AliasTarget/HostedZoneId} then (@item[:alias_target] ||= {})[:hosted_zone_id] = @text
end
end
end
View
@@ -0,0 +1,39 @@
+# Notes and tips for developers
+
+## Setting up credentials for testing
+
+Before you can run any tests, you need to set up credentials (API key and secret) that
+will be used when talking to AWS. The credentials are loaded in `test/test_credentials.rb`
+and are expected to be found in `~/.rightscale/testcredentials.rb` and look like this:
+
+ TestCredentials.aws_access_key_id= 'AAAAAAAAAAAAAAAAAAAA'
+ TestCredentials.aws_secret_access_key= 'asdfasdfsadf'
+ TestCredentials.account_number= '???'
+
+If you prefer to store your secret key in the OS X keychain, you can do this:
+
+ def secret_access_key_from_keychain (key_id)
+ dump = `security -q find-generic-password -a "#{key_id}" -g 2>&1`
+ dump[/password: "(.*)"/, 1]
+ end
+
+ TestCredentials.aws_access_key_id= 'AAAAAAAAAAAAAAAAAAAA'
+ TestCredentials.aws_secret_access_key= secret_access_key_from_keychain(TestCredentials.aws_access_key_id)
+ TestCredentials.account_number= '???'
+
+## Running tests
+
+There is no test suite that runs all tests. Each module is tested separately. E.g.,
+to run the Load Balancer tests, run `rake testelb`. Run `rake -T` for a full list.
+
+Some tests need to launch services on AWS to have something to test. This means two things:
+
+1. Running all the tests will cost you money.
+2. You will need to shut down some services separately once you are done, or things
+ will keep running and cost you money.
+
+As an example, the ELB and Route 53 tests need a load balancer for testing. Starting a load balancer
+for every test would make every test case cost as much as running the LB for one hour, so it makes
+more sense to leave it running until it's no longer needed.
+
+The ELB tests contain instructions for shutting down the load balancer.
View
@@ -0,0 +1,2 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/right_aws'
View
@@ -0,0 +1,43 @@
+require File.dirname(__FILE__) + '/test_helper.rb'
+
+class TestElb < Test::Unit::TestCase
+
+ STDOUT.sync = true
+ BALANCER_NAME = 'right-aws-test-lb'
+
+ def setup
+ @elb = Rightscale::ElbInterface.new(TestCredentials.aws_access_key_id, TestCredentials.aws_secret_access_key, :logger => Logger.new('/dev/null'))
+
+ unless @elb.describe_load_balancers.detect { |lb| lb[:load_balancer_name] == BALANCER_NAME }
+ @elb.create_load_balancer(BALANCER_NAME, %w[us-east-1b], [])
+ end
+ @lb = @elb.describe_load_balancers.detect { |lb| lb[:load_balancer_name] == BALANCER_NAME }
+ end
+
+ # At the end of the day when you want to shut down the test balancer:
+ # * Uncomment this method.
+ # * Comment out all test except one.
+ # * Run this test file.
+ #
+ # def teardown
+ # @elb.delete_load_balancer BALANCER_NAME
+ # end
+
+ def test_00_describe_load_balancers
+ items = @elb.describe_load_balancers
+ assert items.is_a?(Array)
+ end
+
+ def test_description
+ assert_match /^#{BALANCER_NAME}-\d+\.us-east-1\.elb\.amazonaws\.com$/, @lb[:dns_name]
+ end
+
+ def test_description_has_canonical_hosted_zone_name
+ assert_match /^#{BALANCER_NAME}-\d+\.us-east-1\.elb\.amazonaws\.com$/, @lb[:canonical_hosted_zone_name]
+ end
+
+ def test_description_has_canonical_hosted_zone_name_id
+ assert_match /^[A-Z0-9]+$/, @lb[:canonical_hosted_zone_name_id]
+ end
+
+end
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">
+ <ChangeBatch>
+ <Changes>
+ <Change>
+ <Action>CREATE</Action>
+ <ResourceRecordSet>
+ <Name>host.right-aws.example.com.</Name>
+ <Type>A</Type>
+ <TTL>600</TTL>
+ <ResourceRecords>
+ <ResourceRecord><Value>10.0.0.1</Value></ResourceRecord>
+ </ResourceRecords>
+ </ResourceRecordSet>
+ </Change>
+ </Changes>
+ </ChangeBatch>
+</ChangeResourceRecordSetsRequest>
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ChangeResourceRecordSetsRequest xmlns="https://route53.amazonaws.com/doc/2011-05-05/">
+ <ChangeBatch>
+ <Changes>
+ <Change>
+ <Action>CREATE</Action>
+ <ResourceRecordSet>
+ <Name>right-aws.example.com.</Name>
+ <Type>A</Type>
+ <AliasTarget>
+ <HostedZoneId>Z1234567890123</HostedZoneId>
+ <DNSName>example-load-balancer-1111111111.us-east-1.elb.amazonaws.com.</DNSName>
+ </AliasTarget>
+ </ResourceRecordSet>
+ </Change>
+ </Changes>
+ </ChangeBatch>
+</ChangeResourceRecordSetsRequest>
@@ -0,0 +1,2 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/right_aws'
Oops, something went wrong.

0 comments on commit a1b7682

Please sign in to comment.