diff --git a/lib/fog/aws/models/rds/parameters.rb b/lib/fog/aws/models/rds/parameters.rb index ca88a9a02..5f960006a 100644 --- a/lib/fog/aws/models/rds/parameters.rb +++ b/lib/fog/aws/models/rds/parameters.rb @@ -29,6 +29,12 @@ module Fog end load(result) # data is an array of attribute hashes end + + def defaults(family) + data = service.describe_engine_default_parameters(family).body['DescribeEngineDefaultParametersResult']['Parameters'] + + load(data) + end end end end diff --git a/lib/fog/aws/parsers/rds/db_parameter_parser.rb b/lib/fog/aws/parsers/rds/db_parameter_parser.rb new file mode 100644 index 000000000..c53e1cfcf --- /dev/null +++ b/lib/fog/aws/parsers/rds/db_parameter_parser.rb @@ -0,0 +1,30 @@ +module Fog + module Parsers + module AWS + module RDS + class DBParameterParser < Fog::Parsers::Base + def reset + @db_parameter = new_db_parameter + end + + def new_db_parameter + {} + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'IsModifiable' + @value == "true" ? true : false + else + @db_parameter[name] = @value.strip + end + end + end + end + end + end +end diff --git a/lib/fog/aws/parsers/rds/describe_engine_default_parameters.rb b/lib/fog/aws/parsers/rds/describe_engine_default_parameters.rb new file mode 100644 index 000000000..6b2d842b0 --- /dev/null +++ b/lib/fog/aws/parsers/rds/describe_engine_default_parameters.rb @@ -0,0 +1,34 @@ +module Fog + module Parsers + module AWS + module RDS + require 'fog/aws/parsers/rds/db_parameter_parser' + + class DescribeEngineDefaultParameters < Fog::Parsers::AWS::RDS::DBParameterParser + def reset + @response = {'DescribeEngineDefaultParametersResult' => {'Parameters' => []}, 'ResponseMetadata' => {}} + super + end + + def start_element(name, attrs = []) + super + end + + def end_element(name) + case name + when 'Parameter' + @response['DescribeEngineDefaultParametersResult']['Parameters'] << @db_parameter + @db_parameter = new_db_parameter + when 'Marker' + @response['DescribeEngineDefaultParametersResult']['Marker'] = @value + when 'RequestId' + @response['ResponseMetadata'][name] = @value + else + super + end + end + end + end + end + end +end diff --git a/lib/fog/aws/rds.rb b/lib/fog/aws/rds.rb index aa05fd5f0..583a7a8db 100644 --- a/lib/fog/aws/rds.rb +++ b/lib/fog/aws/rds.rb @@ -62,6 +62,8 @@ module Fog request :create_event_subscription request :delete_event_subscription + request :describe_engine_default_parameters + model_path 'fog/aws/models/rds' model :server collection :servers @@ -100,6 +102,18 @@ module Fog :subnet_groups => {}, :snapshots => {}, :event_subscriptions => {}, + :default_parameters => { + "mysql5.5" => [ + { + "DataType" => "integer", + "Source" => "engine-default", + "Description" => "Intended for use with master-to-master replication, and can be used to control the operation of AUTO_INCREMENT columns", + "ApplyType" => "dynamic", + "AllowedValues" => "1-65535", + "ParameterName" => "auto_increment_increment" + } + ], + }, :db_engine_versions => [ { 'Engine' => "mysql", diff --git a/lib/fog/aws/requests/rds/create_db_instance.rb b/lib/fog/aws/requests/rds/create_db_instance.rb index 1bfccbc41..8b41796e3 100644 --- a/lib/fog/aws/requests/rds/create_db_instance.rb +++ b/lib/fog/aws/requests/rds/create_db_instance.rb @@ -84,6 +84,16 @@ module Fog ec2 = Fog::Compute::AWS::Mock.data[@region][@aws_access_key_id] + db_parameter_groups = if pg_name = options.delete("DBParameterGroupName") + group = self.data[:parameter_groups][pg_name] + if group + [{"DBParameterGroupName" => pg_name, "ParameterApplyStatus" => "in-sync" }] + else + raise Fog::AWS::RDS::NotFound.new("Parameter group does not exist") + end + else + [{ "DBParameterGroupName" => "default.mysql5.5", "ParameterApplyStatus" => "in-sync" }] + end db_security_group_names = Array(options.delete("DBSecurityGroups")) rds_security_groups = self.data[:security_groups].values ec2_security_groups = ec2[:security_groups].values @@ -119,7 +129,7 @@ module Fog "DBInstanceIdentifier" => db_name, "DBInstanceStatus" =>"creating", "DBName" => options["DBName"], - "DBParameterGroups" => [{ "DBParameterGroupName" => "default.mysql5.5", "ParameterApplyStatus" => "in-sync" }], + "DBParameterGroups" => db_parameter_groups, "DBSecurityGroups" => db_security_groups, "DBSubnetGroupName" => options["DBSubnetGroupName"], "Endpoint" =>{}, diff --git a/lib/fog/aws/requests/rds/describe_db_parameters.rb b/lib/fog/aws/requests/rds/describe_db_parameters.rb index 5b51da422..7b8e0de4a 100644 --- a/lib/fog/aws/requests/rds/describe_db_parameters.rb +++ b/lib/fog/aws/requests/rds/describe_db_parameters.rb @@ -34,7 +34,21 @@ module Fog class Mock def describe_db_parameters(name, opts={}) - Fog::Mock.not_implemented + group = self.data[:parameter_groups][name] + + unless group + raise Fog::AWS::RDS::NotFound.new("parameter group does not exist") + end + + parameters = group[:parameters] + + response = Excon::Response.new + response.body = { + "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id }, + "DescribeDBParametersResult" => { "Parameters" => parameters } + } + response.status = 200 + response end end end diff --git a/lib/fog/aws/requests/rds/describe_engine_default_parameters.rb b/lib/fog/aws/requests/rds/describe_engine_default_parameters.rb new file mode 100644 index 000000000..46ecca0c7 --- /dev/null +++ b/lib/fog/aws/requests/rds/describe_engine_default_parameters.rb @@ -0,0 +1,30 @@ +module Fog + module AWS + class RDS + class Real + require 'fog/aws/parsers/rds/describe_engine_default_parameters' + + def describe_engine_default_parameters(family, opts={}) + request({ + 'Action' => 'DescribeEngineDefaultParameters', + 'DBParameterGroupFamily' => family, + :parser => Fog::Parsers::AWS::RDS::DescribeEngineDefaultParameters.new, + }.merge(opts)) + end + end + + class Mock + def describe_engine_default_parameters(family, opts={}) + response = Excon::Response.new + + response.status = 200 + response.body = { + "ResponseMetadata" => { "RequestId" => Fog::AWS::Mock.request_id }, + "DescribeEngineDefaultParametersResult" => { "Parameters" => self.data[:default_parameters][family]} + } + response + end + end + end + end +end diff --git a/lib/fog/aws/requests/rds/modify_db_parameter_group.rb b/lib/fog/aws/requests/rds/modify_db_parameter_group.rb index 9a03bac27..3e9827172 100644 --- a/lib/fog/aws/requests/rds/modify_db_parameter_group.rb +++ b/lib/fog/aws/requests/rds/modify_db_parameter_group.rb @@ -42,7 +42,34 @@ module Fog class Mock def modify_db_parameter_group(group_name, parameters) - Fog::Mock.not_implemented + group = self.data[:parameter_groups][group_name] + + unless group + raise Fog::AWS::RDS::NotFound.new("Parameter group not found") + end + + parameters.each do |p| + p.merge!( + "Source" => "user", + "IsModifiable" => true, + "Description" => "some string", + "DataType" => "string", + "AllowedValues" => p["ParameterValue"], + "ApplyType" => "dynamic" + ) + end + + group[:parameters] = parameters + + self.data[:parameter_groups][group_name] = group + + response = Excon::Response.new + response.body = { + "ResponseMetadata" => {"RequestId" => Fog::AWS::Mock.request_id}, + "ModifyDBParameterGroupResult" => {"DBParameterGroupName" => group_name} + } + response.status = 200 + response end end end diff --git a/tests/requests/rds/parameter_group_tests.rb b/tests/requests/rds/parameter_group_tests.rb index 0b120d802..b29760d4b 100644 --- a/tests/requests/rds/parameter_group_tests.rb +++ b/tests/requests/rds/parameter_group_tests.rb @@ -21,7 +21,7 @@ Shindo.tests('AWS::RDS | parameter group requests', ['aws', 'rds']) do body end - tests("#describe_db_parameter_groups('fog-group)").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do + tests("#describe_db_parameter_groups('fog-group')").formats(AWS::RDS::Formats::DESCRIBE_DB_PARAMETER_GROUP) do body = Fog::AWS[:rds].describe_db_parameter_groups('fog-group').body diff --git a/tests/requests/rds/parameter_request_tests.rb b/tests/requests/rds/parameter_request_tests.rb index 8c35082c2..6f65030b9 100644 --- a/tests/requests/rds/parameter_request_tests.rb +++ b/tests/requests/rds/parameter_request_tests.rb @@ -1,7 +1,5 @@ Shindo.tests('AWS::RDS | parameter requests', ['aws', 'rds']) do tests('success') do - pending if Fog.mocking? - Fog::AWS[:rds].create_db_parameter_group('fog-group', 'MySQL5.1', 'Some description') tests('#modify_db_parameter_group').formats(AWS::RDS::Formats::MODIFY_PARAMETER_GROUP) do