From f83629550b6e8968a3487731d76b4be4a2f57cf5 Mon Sep 17 00:00:00 2001 From: Efe Yardimci Date: Fri, 30 Aug 2013 17:28:43 -0400 Subject: [PATCH] Starting adding tests, some cleanup --- .../redshift/cluster_subnet_group_parser.rb | 51 +++++++++++++++ lib/fog/aws/redshift.rb | 22 +------ tests/aws/requests/redshift/cluster_tests.rb | 64 +++++++++++++++++++ 3 files changed, 116 insertions(+), 21 deletions(-) create mode 100644 lib/fog/aws/parsers/redshift/cluster_subnet_group_parser.rb create mode 100644 tests/aws/requests/redshift/cluster_tests.rb diff --git a/lib/fog/aws/parsers/redshift/cluster_subnet_group_parser.rb b/lib/fog/aws/parsers/redshift/cluster_subnet_group_parser.rb new file mode 100644 index 000000000..7d6e3ef20 --- /dev/null +++ b/lib/fog/aws/parsers/redshift/cluster_subnet_group_parser.rb @@ -0,0 +1,51 @@ +module Fog + module Parsers + module Redshift + module AWS + + class ClusterSubnetGroupParser < Fog::Parsers::Base + # :cluster_subnet_group_name - (String) + # :description - (String) + # :vpc_id - (String) + # :subnet_group_status - (String) + # :subnets - (Array) + # :subnet_identifier - (String) + # :subnet_availability_zone - (Hash) + # :name - (String) + # :subnet_status - (String) + + def reset + @response = { 'Subnets' => [] } + end + + def fresh_subnet + {'SubnetAvailabilityZone'=>{}} + end + + def start_element(name, attrs = []) + super + case name + when 'Subnets' + @subnet = fresh_subnet + end + end + + def end_element(name) + super + case name + when 'ClusterSubnetGroupName', 'Desciption', 'VpcId', 'SubnetGroupStatus' + @response[name] = value + when 'SubnetIdentifier', 'SubnetStatus' + @subnet[name] = value + when 'Name' + @subnet['SubnetAvailabilityZone'][name] = value + when 'Subnet' + @response['Subnets'] << @subnet + @subnet = fresh_subnet + end + end + end + end + end + end +end diff --git a/lib/fog/aws/redshift.rb b/lib/fog/aws/redshift.rb index c556b74bf..5df1d3d81 100644 --- a/lib/fog/aws/redshift.rb +++ b/lib/fog/aws/redshift.rb @@ -78,7 +78,7 @@ module Fog def initialize(options={}) - @use_redshift_profile = options[:use_redshift_profile] + @use_iam_profile = options[:use_iam_profile] @region = options[:region] || 'us-east-1' setup_credentials(options) @@ -96,15 +96,9 @@ module Fog private def setup_credentials(options) -<<<<<<< HEAD - @aws_access_key_id = options[:aws_access_key_id] - @aws_secret_access_key = options[:aws_secret_access_key] - @aws_session_token = options[:aws_session_token] -======= @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @aws_session_token = options[:aws_session_token] ->>>>>>> 6c5358b... Initial redshift setup, describe_clusters support @aws_credentials_expire_at = options[:aws_credentials_expire_at] @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'redshift') @@ -115,11 +109,6 @@ module Fog parser = params.delete(:parser) date = Fog::Time.now -<<<<<<< HEAD - -======= - ->>>>>>> 6c5358b... Initial redshift setup, describe_clusters support params[:headers]['Date'] = date.to_date_header params[:headers]['x-amz-date'] = date.to_iso8601_basic @@ -128,16 +117,7 @@ module Fog params[:headers]['x-amz-security-token'] = @aws_session_token if @aws_session_token params[:headers]['Authorization'] = @signer.sign params, date -<<<<<<< HEAD - begin - response = @connection.request(params.merge(:parser => parser), &block) - rescue Excon::Errors::HTTPStatusError => error - match = Fog::AWS::Errors.match_error(error) - end - -======= response = @connection.request(params.merge(:parser => parser), &block) ->>>>>>> 6c5358b... Initial redshift setup, describe_clusters support if response.headers['Content-Type'] == 'application/json' && response.body.size > 0 #body will be empty if the streaming form has been used response.body = Fog::JSON.decode(response.body) end diff --git a/tests/aws/requests/redshift/cluster_tests.rb b/tests/aws/requests/redshift/cluster_tests.rb new file mode 100644 index 000000000..7acba6cbf --- /dev/null +++ b/tests/aws/requests/redshift/cluster_tests.rb @@ -0,0 +1,64 @@ +Shindo.tests('Fog::Redshift[:aws] | cluster requests', ['aws']) do + + @describe_clusters_format = { + "ClusterSet" => [{ + "EndPoint" => { + "Port" => Integer, + "Address" => String, + "AutomatedSnapshotRetentionPeriod" => Integer, + "ClusterCreateTime" => Time + }, + "ClusterSecurityGroups" => [{ + "Status" => String, + "ClusterSecurityGroupName" => String + }], + "VpcSecurityGroups" => Fog::Nullable::Array, + "ClusterParameterGroups" => [{ + "ParameterApplyStatus" => String, + "ParameterGroupName" => String + }], + "PendingModifiedValues" => Fog::Nullable::Hash, + "RestoreStatus" => Fog::Nullable::Hash, + "ClusterVersion" => String, + "ClusterStatus" => String, + "Encrypted" => Fog::Boolean, + "NumberOfNodes" => Integer, + "PubliclyAccessible" => Fog::Boolean, + "DBName" => String, + "PreferredMaintenanceWindow" => String, + "AvailabilityZone" => String, + "NodeType" => String, + "ClusterIdentifier" => String, + "AllowVersionUpgrade" => Fog::Boolean, + "MasterUsername" => String + }] + } + + tests('success') do + tests("#describe_clusters").formats(@describe_clusters_format) do + body = Fog::AWS[:redshift].describe_clusters.body + body + end + end + + # tests('failure') do + + # tests("#get_console_output('i-00000000')").raises(Fog::Compute::AWS::NotFound) do + # Fog::Compute[:aws].get_console_output('i-00000000') + # end + + # tests("#get_password_data('i-00000000')").raises(Fog::Compute::AWS::NotFound) do + # Fog::Compute[:aws].get_password_data('i-00000000') + # end + + # tests("#reboot_instances('i-00000000')").raises(Fog::Compute::AWS::NotFound) do + # Fog::Compute[:aws].reboot_instances('i-00000000') + # end + + # tests("#terminate_instances('i-00000000')").raises(Fog::Compute::AWS::NotFound) do + # Fog::Compute[:aws].terminate_instances('i-00000000') + # end + + # end + +end