on init, connect to AWS and check for the AS group
This commit is contained in:
		
							parent
							
								
									2bdaca25bb
								
							
						
					
					
						commit
						4f466e1a19
					
				@ -25,3 +25,6 @@ if opts[:aws_access_key].nil? || opts[:aws_secret_key].nil?
 | 
				
			|||||||
  opts[:aws_access_key] = ENV['AWS_ACCESS_KEY']
 | 
					  opts[:aws_access_key] = ENV['AWS_ACCESS_KEY']
 | 
				
			||||||
  opts[:aws_secret_key] = ENV['AWS_SECRET_KEY']
 | 
					  opts[:aws_secret_key] = ENV['AWS_SECRET_KEY']
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require 'aws-missing-tools'
 | 
				
			||||||
 | 
					AwsHaRelease.new(opts)
 | 
				
			||||||
 | 
				
			|||||||
@ -1 +1,6 @@
 | 
				
			|||||||
require 'aruba/cucumber'
 | 
					require 'aruba/cucumber'
 | 
				
			||||||
 | 
					require 'aws-sdk'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Before do
 | 
				
			||||||
 | 
					  AWS.stub!
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -1,2 +1,12 @@
 | 
				
			|||||||
class AwsHaRelease
 | 
					class AwsHaRelease
 | 
				
			||||||
 | 
					  def initialize(opts)
 | 
				
			||||||
 | 
					    AWS.config(access_key_id: opts[:aws_access_key], secret_access_key: opts[:aws_secret_key], region: opts[:region])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @as = AWS::AutoScaling.new
 | 
				
			||||||
 | 
					    @group = @as.groups[opts[:as_group_name]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if @group.nil?
 | 
				
			||||||
 | 
					      raise ArgumentError, "The Auto Scaling Group named #{opts[:as_group_name]} does not exist in #{opts[:region]}."
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -10,13 +10,25 @@ describe 'aws-ha-release' do
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let(:as) { AWS::FakeAutoScaling.new }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  before do
 | 
					  before do
 | 
				
			||||||
    AWS.stub(:config)
 | 
					    AWS.stub(:config)
 | 
				
			||||||
    AWS::AutoScaling.stub(:new).and_return(AWS::FakeAutoScaling.new)
 | 
					    AWS::AutoScaling.stub(:new).and_return(as)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe '#initialize' do
 | 
					  describe '#initialize' do
 | 
				
			||||||
    it 'initializes the AWS connection'
 | 
					    it 'initializes the AWS connection' do
 | 
				
			||||||
    it 'ensures the as group exists'
 | 
					      as.groups.create 'test_group'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      AWS.should_receive(:config).with(access_key_id: 'testaccesskey', secret_access_key: 'testsecretkey', region: 'test-region')
 | 
				
			||||||
 | 
					      AwsHaRelease.new(opts)
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it 'ensures the as group exists' do
 | 
				
			||||||
 | 
					      lambda {
 | 
				
			||||||
 | 
					        AwsHaRelease.new(opts.merge!(as_group_name: 'fake_group'))
 | 
				
			||||||
 | 
					      }.should raise_error
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -2,5 +2,31 @@ module AWS
 | 
				
			|||||||
  class FakeAutoScaling
 | 
					  class FakeAutoScaling
 | 
				
			||||||
    def initialize
 | 
					    def initialize
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def groups
 | 
				
			||||||
 | 
					      @groups ||= GroupCollection.new
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class GroupCollection
 | 
				
			||||||
 | 
					      def initialize
 | 
				
			||||||
 | 
					        @groups = {}
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def [](name)
 | 
				
			||||||
 | 
					        @groups[name]
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def create(name, options = {})
 | 
				
			||||||
 | 
					        @groups[name] = Group.new name
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Group
 | 
				
			||||||
 | 
					      attr_reader :name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      def initialize(name)
 | 
				
			||||||
 | 
					        @name = name
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user