rubix 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -38,7 +38,7 @@ module Rubix
38
38
  # script.
39
39
  class ClusterMonitor < ChefMonitor
40
40
 
41
- attr_reader :private_ips_by_cluster, :nodes_by_cluster
41
+ attr_reader :all_private_ips_by_cluster, :private_ips_by_cluster, :all_nodes_by_cluster, :nodes_by_cluster
42
42
 
43
43
  def initialize settings
44
44
  super(settings)
@@ -54,14 +54,23 @@ module Rubix
54
54
  end
55
55
 
56
56
  def group_nodes_by_cluster
57
- @private_ips_by_cluster = {}
58
- @nodes_by_cluster = {}
57
+ @all_private_ips_by_cluster = {}
58
+ @private_ips_by_cluster = {}
59
+ @all_nodes_by_cluster = {}
60
+ @nodes_by_cluster = {}
59
61
  matching_chef_nodes.first.each do |node|
60
- @nodes_by_cluster[node['cluster_name']] ||= []
61
- @nodes_by_cluster[node['cluster_name']] << node
62
+ @all_nodes_by_cluster[node['cluster_name']] ||= []
63
+ @nodes_by_cluster[node['cluster_name']] ||= []
62
64
 
63
- @private_ips_by_cluster[node['cluster_name']] ||= []
64
- @private_ips_by_cluster[node['cluster_name']] << node['ipaddress']
65
+ @all_nodes_by_cluster[node['cluster_name']] << node
66
+ @nodes_by_cluster[node['cluster_name']] << node unless %w[stopped].include?(node['state'])
67
+
68
+
69
+ @all_private_ips_by_cluster[node['cluster_name']] ||= []
70
+ @private_ips_by_cluster[node['cluster_name']] ||= []
71
+
72
+ @all_private_ips_by_cluster[node['cluster_name']] << node['ipaddress']
73
+ @private_ips_by_cluster[node['cluster_name']] << node['ipaddress'] unless %w[stopped].include?(node['state'])
65
74
  end
66
75
  end
67
76
 
@@ -5,6 +5,7 @@ describe Rubix::ChefMonitor do
5
5
  before do
6
6
  @wrapper = Class.new(Rubix::ChefMonitor)
7
7
  end
8
+
8
9
 
9
10
  end
10
11
 
@@ -2,9 +2,33 @@ require 'spec_helper'
2
2
 
3
3
  describe Rubix::ClusterMonitor do
4
4
 
5
- before do
6
- @wrapper = Class.new(Rubix::ClusterMonitor)
5
+ def mock_chef_query nodes
6
+ query = mock("Chef::Search::Query")
7
+ require 'chef'
8
+ ::Chef::Search::Query.should_receive(:new).and_return(query)
9
+ query.should_receive(:search).and_return([nodes, nodes.size])
7
10
  end
8
11
 
12
+ it "should correctly carve up a group of nodes into clusters" do
13
+ mock_chef_query([
14
+ { 'cluster_name' => 'foo', 'state' => 'started', 'ipaddress' => '123' },
15
+ { 'cluster_name' => 'foo', 'state' => 'stopped', 'ipaddress' => '456' },
16
+ { 'cluster_name' => 'bar', 'state' => 'started', 'ipaddress' => '789' },
17
+ { 'cluster_name' => 'bar', 'state' => 'stopped', 'ipaddress' => '321' }
18
+ ])
19
+ cm = Rubix::ClusterMonitor.new({})
20
+ cm.clusters.should include('foo', 'bar')
21
+ cm.private_ips_by_cluster.should == { 'foo' => ['123'], 'bar' => ['789'] }
22
+ cm.all_private_ips_by_cluster.should == { 'foo' => ['123', '456'], 'bar' => ['789', '321'] }
23
+
24
+ cm.nodes_by_cluster['foo'].size.should == 1
25
+ cm.nodes_by_cluster['bar'].size.should == 1
26
+
27
+ cm.all_nodes_by_cluster['foo'].size.should == 2
28
+ cm.all_nodes_by_cluster['bar'].size.should == 2
29
+
30
+ end
31
+
32
+
9
33
  end
10
34
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dhruv Bansal