mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|elasticache] add test for removing a cache node
This commit is contained in:
parent
6f3f9d29bf
commit
7bf0fa6157
3 changed files with 51 additions and 25 deletions
|
@ -44,9 +44,12 @@ module Fog
|
|||
@security_group[name] = value
|
||||
when 'CacheNode'
|
||||
@cache_cluster["#{name}s"] << @cache_node unless @cache_node.empty?
|
||||
when 'CacheNodeCreateTime', 'CacheNodeId', 'CacheNodeStatus',
|
||||
'Address', 'ParameterGroupStatus', 'Port'
|
||||
@cache_node[name] = value ? value.strip : name
|
||||
@cache_node = nil
|
||||
when 'CacheNodeCreateTime', 'CacheNodeStatus', 'Address',
|
||||
'ParameterGroupStatus', 'Port', 'CacheNodeId'
|
||||
if @cache_node
|
||||
@cache_node[name] = value ? value.strip : name
|
||||
end
|
||||
when 'CacheNodeIdsToReboots', 'CacheParameterGroupName', 'ParameterApplyStatus'
|
||||
@cache_cluster['CacheParameterGroup'][name] = value
|
||||
else
|
||||
|
|
|
@ -37,9 +37,9 @@ module Fog
|
|||
# Construct CacheNodeIdsToRemove parameters in the format:
|
||||
# CacheNodeIdsToRemove.member.N => "node_id"
|
||||
node_ids = options[:nodes_to_remove] || []
|
||||
node_id_params = node_ids.inject({}) do |node_hash, id|
|
||||
index = node_ids.index(name) + 1
|
||||
node_hash["CacheNodeIdsToRemove.member.#{index}"] = id
|
||||
node_id_params = node_ids.inject({}) do |node_hash, node_id|
|
||||
index = node_ids.index(node_id) + 1
|
||||
node_hash["CacheNodeIdsToRemove.member.#{index}"] = node_id
|
||||
node_hash
|
||||
end
|
||||
# Merge the Cache Security Group parameters with the normal options
|
||||
|
|
|
@ -4,17 +4,17 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
pending if Fog.mocking?
|
||||
|
||||
# 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
|
||||
CLUSTER_ID = "fog-test-cluster-#{rand(999).to_s}" # 20 chars max!
|
||||
NUM_NODES = 2 # Must be > 1, because one of the tests reomves a node!
|
||||
|
||||
tests(
|
||||
'#create_cache_cluster'
|
||||
).formats(AWS::Elasticache::Formats::SINGLE_CACHE_CLUSTER) do
|
||||
body = AWS[:elasticache].create_cache_cluster(cluster_id,
|
||||
:num_nodes => num_nodes
|
||||
body = AWS[:elasticache].create_cache_cluster(CLUSTER_ID,
|
||||
:num_nodes => NUM_NODES
|
||||
).body
|
||||
cluster = body['CacheCluster']
|
||||
returns(cluster_id) { cluster['CacheClusterId'] }
|
||||
returns(CLUSTER_ID) { cluster['CacheClusterId'] }
|
||||
returns('creating') { cluster['CacheClusterStatus'] }
|
||||
body
|
||||
end
|
||||
|
@ -23,15 +23,15 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
'#describe_cache_clusters without options'
|
||||
).formats(AWS::Elasticache::Formats::DESCRIBE_CACHE_CLUSTERS) do
|
||||
body = AWS[:elasticache].describe_cache_clusters.body
|
||||
returns(true, "has #{cluster_id}") do
|
||||
returns(true, "has #{CLUSTER_ID}") do
|
||||
body['CacheClusters'].any? do |cluster|
|
||||
cluster['CacheClusterId'] == cluster_id
|
||||
cluster['CacheClusterId'] == CLUSTER_ID
|
||||
end
|
||||
end
|
||||
# The DESCRIBE_CACHE_CLUSTERS format must include only one cluster
|
||||
# So remove all but the relevant cluster from the response body
|
||||
test_cluster = body['CacheClusters'].delete_if do |cluster|
|
||||
cluster['CacheClusterId'] != cluster_id
|
||||
cluster['CacheClusterId'] != CLUSTER_ID
|
||||
end
|
||||
body
|
||||
end
|
||||
|
@ -39,24 +39,24 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
tests(
|
||||
'#describe_cache_clusters with cluster ID'
|
||||
).formats(AWS::Elasticache::Formats::DESCRIBE_CACHE_CLUSTERS) do
|
||||
body = AWS[:elasticache].describe_cache_clusters(cluster_id).body
|
||||
body = AWS[:elasticache].describe_cache_clusters(CLUSTER_ID).body
|
||||
returns(1, "size of 1") { body['CacheClusters'].size }
|
||||
returns(cluster_id, "has #{cluster_id}") do
|
||||
returns(CLUSTER_ID, "has #{CLUSTER_ID}") do
|
||||
body['CacheClusters'].first['CacheClusterId']
|
||||
end
|
||||
body
|
||||
end
|
||||
|
||||
Formatador.display_line "Waiting for cluster #{cluster_id}..."
|
||||
AWS[:elasticache].clusters.get(cluster_id).wait_for {ready?}
|
||||
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,
|
||||
cluster = AWS[:elasticache].describe_cache_clusters(CLUSTER_ID,
|
||||
:show_node_info => true
|
||||
).body['CacheClusters'].first
|
||||
returns(num_nodes, "has #{num_nodes} nodes") do
|
||||
returns(NUM_NODES, "has #{NUM_NODES} nodes") do
|
||||
cluster['CacheNodes'].count
|
||||
end
|
||||
cluster
|
||||
|
@ -65,7 +65,7 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
tests(
|
||||
'#modify_cache_cluster - change a non-pending cluster attribute'
|
||||
).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
|
||||
body = AWS[:elasticache].modify_cache_cluster(cluster_id,
|
||||
body = AWS[:elasticache].modify_cache_cluster(CLUSTER_ID,
|
||||
:auto_minor_version_upgrade => false
|
||||
).body
|
||||
# now check that parameter change is in place
|
||||
|
@ -73,19 +73,42 @@ Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']
|
|||
body['CacheCluster']
|
||||
end
|
||||
|
||||
tests(
|
||||
'#modify_cache_cluster - remove a node'
|
||||
).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
|
||||
c = AWS[:elasticache].clusters.get(CLUSTER_ID)
|
||||
node_id = c.nodes.last['CacheNodeId']
|
||||
Formatador.display_line "Removing node #{node_id}..."
|
||||
body = AWS[:elasticache].modify_cache_cluster(c.id,
|
||||
{
|
||||
:num_nodes => NUM_NODES - 1,
|
||||
:nodes_to_remove => node_id,
|
||||
:apply_immediately => true,
|
||||
}).body
|
||||
Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..."
|
||||
AWS[:elasticache].clusters.get(CLUSTER_ID).wait_for {ready?}
|
||||
c.reload
|
||||
node = c.nodes.find {|n| n['CacheNodeId'] == node_id}
|
||||
#returns('deleting') { node['CacheNodeStatus'] }
|
||||
body['CacheCluster']
|
||||
end
|
||||
|
||||
Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..."
|
||||
AWS[:elasticache].clusters.get(CLUSTER_ID).wait_for {ready?}
|
||||
|
||||
tests(
|
||||
'#delete_cache_clusters'
|
||||
).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
|
||||
body = AWS[:elasticache].delete_cache_cluster(cluster_id).body
|
||||
body = AWS[:elasticache].delete_cache_cluster(CLUSTER_ID).body
|
||||
# make sure this particular cluster is in the returned list
|
||||
returns(true, "has #{cluster_id}") do
|
||||
returns(true, "has #{CLUSTER_ID}") do
|
||||
body['CacheClusters'].any? do |cluster|
|
||||
cluster['CacheClusterId'] == cluster_id
|
||||
cluster['CacheClusterId'] == CLUSTER_ID
|
||||
end
|
||||
end
|
||||
# now check that it reports itself as 'deleting'
|
||||
cluster = body['CacheClusters'].find do |cluster|
|
||||
cluster['CacheClusterId'] == cluster_id
|
||||
cluster['CacheClusterId'] == CLUSTER_ID
|
||||
end
|
||||
returns('deleting') { cluster['CacheClusterStatus'] }
|
||||
cluster
|
||||
|
|
Loading…
Add table
Reference in a new issue