File: cache_cluster_tests.rb

package info (click to toggle)
ruby-fog-aws 3.33.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,180 kB
  • sloc: ruby: 75,405; javascript: 14; makefile: 9; sh: 4
file content (137 lines) | stat: -rw-r--r-- 4,988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
Shindo.tests('AWS::Elasticache | cache cluster requests', ['aws', 'elasticache']) do

  tests('success') do

    # 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   # Must be > 1, because one of the tests removes a node!

    tests(
    '#create_cache_cluster'
    ).formats(AWS::Elasticache::Formats::SINGLE_CACHE_CLUSTER) do
      body = Fog::AWS[:elasticache].create_cache_cluster(CLUSTER_ID,
        :num_nodes => NUM_NODES
      ).body
      cluster = body['CacheCluster']
      returns(CLUSTER_ID) { cluster['CacheClusterId'] }
      returns('creating') { cluster['CacheClusterStatus'] }
      body
    end

    tests(
    '#describe_cache_clusters without options'
    ).formats(AWS::Elasticache::Formats::DESCRIBE_CACHE_CLUSTERS) do
      body = Fog::AWS[:elasticache].describe_cache_clusters.body
      returns(true, "has #{CLUSTER_ID}") do
        body['CacheClusters'].any? do |cluster|
          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
      end
      body
    end

    tests(
    '#describe_cache_clusters with cluster ID'
    ).formats(AWS::Elasticache::Formats::DESCRIBE_CACHE_CLUSTERS) do
      body = Fog::AWS[:elasticache].describe_cache_clusters(CLUSTER_ID).body
      returns(1, "size of 1") { body['CacheClusters'].size }
      returns(CLUSTER_ID, "has #{CLUSTER_ID}") do
        body['CacheClusters'].first['CacheClusterId']
      end
      body
    end

    Fog::Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..."
    Fog::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 = Fog::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
      body = Fog::AWS[:elasticache].modify_cache_cluster(CLUSTER_ID,
        :auto_minor_version_upgrade => false
      ).body
      # now check that parameter change is in place
      returns('false')  { body['CacheCluster']['AutoMinorVersionUpgrade'] }
      body['CacheCluster']
    end

    tests(
    '#reboot_cache_cluster - reboot a node'
    ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
      c = Fog::AWS[:elasticache].clusters.get(CLUSTER_ID)
      node_id = c.nodes.last['CacheNodeId']
      Fog::Formatador.display_line "Rebooting node #{node_id}..."
      body = Fog::AWS[:elasticache].reboot_cache_cluster(c.id, [ node_id ]).body
      returns('rebooting cache cluster nodes') do
        body['CacheCluster']['CacheClusterStatus']
      end
      body['CacheCluster']
    end

    Fog::Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..."
    Fog::AWS[:elasticache].clusters.get(CLUSTER_ID).wait_for {ready?}

    tests(
    '#modify_cache_cluster - remove a node'
    ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
      c = Fog::AWS[:elasticache].clusters.get(CLUSTER_ID)
      node_id = c.nodes.last['CacheNodeId']
      Fog::Formatador.display_line "Removing node #{node_id}..."
      body = Fog::AWS[:elasticache].modify_cache_cluster(c.id,
      {
        :num_nodes          => NUM_NODES - 1,
        :nodes_to_remove    => [node_id],
        :apply_immediately  => true,
      }).body
      returns(node_id) {
        body['CacheCluster']['PendingModifiedValues']['CacheNodeId']
      }
      body['CacheCluster']
    end

    Fog::Formatador.display_line "Waiting for cluster #{CLUSTER_ID}..."
    Fog::AWS[:elasticache].clusters.get(CLUSTER_ID).wait_for {ready?}

    tests(
    '#delete_cache_clusters'
    ).formats(AWS::Elasticache::Formats::CACHE_CLUSTER_RUNNING) do
      body = Fog::AWS[:elasticache].delete_cache_cluster(CLUSTER_ID).body
      # make sure this particular cluster is in the returned list
      returns(true, "has #{CLUSTER_ID}") do
        body['CacheClusters'].any? do |cluster|
          cluster['CacheClusterId'] == CLUSTER_ID
        end
      end
      # now check that it reports itself as 'deleting'
      cluster = body['CacheClusters'].find do |cluster|
        cluster['CacheClusterId'] == CLUSTER_ID
      end
      returns('deleting')  { cluster['CacheClusterStatus'] }
      cluster
    end
  end

  tests('failure') do
    # TODO:
    # Create a duplicate cluster ID
    # List a missing cache cluster
    # Delete a missing cache cluster
  end
end