Skip to content

Instantly share code, notes, and snippets.

@marcy-terui
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcy-terui/9045056 to your computer and use it in GitHub Desktop.
Save marcy-terui/9045056 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'aws-sdk'
module Serverspec
module Type
class RdsParameters < Base
# AWS API Response Max Records Setting
MAX_RECORDS = 100
# _name_ :: RDS Paramater Group Name
def initialize(name)
@group_name = name
@parameters = {}
rds = AWS::RDS.new(
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:region => ENV['AWS_REGION'])
res = {}
marker = ""
while (res.length == 0) || (@paramaters.length % MAX_RECORDS == 0) do
if marker.empty? then
res = rds.client.describe_db_parameters(
:db_parameter_group_name => @group_name,
:max_records => MAX_RECORDS)
else
res = rds.client.describe_db_parameters(
:db_parameter_group_name => @group_name,
:max_records => MAX_RECORDS,
:marker => marker)
end
marker = res[:marker]
res[:parameters].each do |param|
@parameters[param[:parameter_name]] = param[:parameter_value]
end
end
end
# its(:paramater_name) { should eq paramater_value }
def method_missing(name)
if @parameters.has_key?(name.to_s) then
@parameters[name.to_s].to_s
else
super
end
end
end
# describe rds_parameters("hoge") do ... end
def rds_parameters(name)
RdsParameters.new(name)
end
end
end
# reload module
include Serverspec::Type
require 'spec_helper'
require 'rds_parameters'
describe rds_parameters('mysql56test') do
its('max_connections') { should eq '256' }
its('thread_cache_size') { should eq '256' }
its('character-set-client-handshake') { should eq '1' }
its('character_set_client') { should eq 'utf8' }
its('character_set_database') { should eq 'utf8' }
its('character_set_results') { should eq 'utf8' }
its('character_set_server') { should eq 'utf8' }
its('lock_wait_timeout') { should eq '60' }
its('interactive_timeout') { should eq '3600' }
its('log_output') { should eq 'FILE' }
its('max_allowed_packet') { should eq '33554432' }
its('query_cache_type') { should eq '1' }
its('skip_name_resolve') { should eq '1' }
its('wait_timeout') { should eq '3600' }
its('slow_query_log') { should eq '1' }
its('long_query_time') { should eq '2' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment