Skip to content

Commit

Permalink
1. Doc fixes
Browse files Browse the repository at this point in the history
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
dvrensk authored and konstantin committed Oct 26, 2011
1 parent 2eb840d commit a1b7682
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 15 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion lib/elb/right_elb_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
38 changes: 24 additions & 14 deletions lib/route_53/right_route_53_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.",
Expand All @@ -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
#
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions test/README.mdown
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions test/elb/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/right_aws'
43 changes: 43 additions & 0 deletions test/elb/test_right_elb.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions test/route_53/fixtures/a_record.xml
Original file line number Diff line number Diff line change
@@ -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>
18 changes: 18 additions & 0 deletions test/route_53/fixtures/alias_record.xml
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 2 additions & 0 deletions test/route_53/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'test/unit'
require File.dirname(__FILE__) + '/../../lib/right_aws'
Loading

0 comments on commit a1b7682

Please sign in to comment.