From 7d19d43117a3f102428a5e6e8114ee01a7d331f3 Mon Sep 17 00:00:00 2001 From: Benton Roberts Date: Tue, 13 Sep 2011 05:00:45 -0400 Subject: [PATCH] [aws|elasticache] add cache node info to describe_cache_clusters --- .../parsers/elasticache/cache_cluster_parser.rb | 7 +++++++ .../requests/elasticache/cache_cluster_tests.rb | 17 ++++++++++++++++- tests/aws/requests/elasticache/helper.rb | 13 +++++++------ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb b/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb index 8ac2998f3..e23e390f8 100644 --- a/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb +++ b/lib/fog/aws/parsers/elasticache/cache_cluster_parser.rb @@ -14,6 +14,7 @@ module Fog def reset_cache_cluster @cache_cluster = { 'CacheSecurityGroups' => [], + 'CacheNodes' => [], 'CacheParameterGroup' => {} } end @@ -22,6 +23,7 @@ module Fog super case name when 'CacheSecurityGroup'; then @security_group = {} + when 'CacheNode'; then @cache_node = {} end end @@ -40,6 +42,11 @@ module Fog @cache_cluster["#{name}s"] << @security_group unless @security_group.empty? when 'CacheSecurityGroupName', 'Status' @security_group[name] = value + when 'CacheNode' + @cache_cluster["#{name}s"] << @cache_node unless @cache_node.empty? + when 'CacheNodeCreateTime', 'CacheNodeId', 'CacheNodeStatus', + 'Endpoint', 'ParameterGroupStatus' + @cache_node[name] = value.strip when 'CacheNodeIdsToReboots', 'CacheParameterGroupName', 'ParameterApplyStatus' @cache_cluster['CacheParameterGroup'][name] = value else diff --git a/tests/aws/requests/elasticache/cache_cluster_tests.rb b/tests/aws/requests/elasticache/cache_cluster_tests.rb index 7394c4ec0..b5fdb7c70 100644 --- a/tests/aws/requests/elasticache/cache_cluster_tests.rb +++ b/tests/aws/requests/elasticache/cache_cluster_tests.rb @@ -5,11 +5,14 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache'] # Randomize the cluster ID so tests can be fequently re-run cluster_id = "fog-test-cluster-#{rand(999).to_s}" # 20 chars max! + num_nodes = 2 tests( '#create_cache_cluster' ).formats(AWS::Elasticache::Formats::SINGLE_CACHE_CLUSTER) do - body = AWS[:elasticache].create_cache_cluster(cluster_id).body + body = AWS[:elasticache].create_cache_cluster(cluster_id, + :num_nodes => num_nodes + ).body cluster = body['CacheCluster'] returns(cluster_id) { cluster['CacheClusterId'] } returns('creating') { cluster['CacheClusterStatus'] } @@ -47,6 +50,18 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache'] Formatador.display_line "Waiting for cluster #{cluster_id}..." AWS[:elasticache].clusters.get(cluster_id).wait_for {ready?} + tests( + '#describe_cache_clusters with node info' + ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do + cluster = AWS[:elasticache].describe_cache_clusters(cluster_id, + :show_node_info => true + ).body['CacheClusters'].first + returns(num_nodes, "has #{num_nodes} nodes") do + cluster['CacheNodes'].count + end + cluster + end + tests( '#modify_cache_cluster - change a non-pending cluster attribute' ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do diff --git a/tests/aws/requests/elasticache/helper.rb b/tests/aws/requests/elasticache/helper.rb index f9be7d75a..4b386c771 100644 --- a/tests/aws/requests/elasticache/helper.rb +++ b/tests/aws/requests/elasticache/helper.rb @@ -28,15 +28,16 @@ class AWS 'CacheParameterGroup' => Hash, 'NumCacheNodes' => Integer, 'PreferredMaintenanceWindow' => String, + 'CacheNodes' => Array, } - CACHE_CLUSTER_RUNNING = CACHE_CLUSTER.merge( + CACHE_CLUSTER_RUNNING = CACHE_CLUSTER.merge({ 'CacheClusterCreateTime' => DateTime, - 'PreferredAvailabilityZone' => String - ) - CACHE_CLUSTER_MODIFIED = CACHE_CLUSTER_RUNNING.merge( + 'PreferredAvailabilityZone' => String, + }) + CACHE_CLUSTER_MODIFIED = CACHE_CLUSTER_RUNNING.merge({ 'NotificationConfiguration' => Hash, - 'PendingModifiedValues' => Hash - ) + 'PendingModifiedValues' => Hash, + }) SINGLE_CACHE_CLUSTER = BASIC.merge('CacheCluster' => CACHE_CLUSTER) DESCRIBE_CACHE_CLUSTERS = BASIC.merge('CacheClusters' => [CACHE_CLUSTER]) end