interferon 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +4 -0
  3. data/.rubocop_todo.yml +83 -0
  4. data/.travis.yml +4 -1
  5. data/bin/interferon +10 -9
  6. data/interferon.gemspec +18 -17
  7. data/lib/interferon/alert.rb +4 -10
  8. data/lib/interferon/alert_dsl.rb +12 -7
  9. data/lib/interferon/destinations/datadog.rb +103 -103
  10. data/lib/interferon/group_sources/filesystem.rb +5 -5
  11. data/lib/interferon/host_sources/aws_dynamo.rb +17 -19
  12. data/lib/interferon/host_sources/aws_elasticache.rb +20 -22
  13. data/lib/interferon/host_sources/aws_rds.rb +33 -33
  14. data/lib/interferon/host_sources/optica.rb +12 -10
  15. data/lib/interferon/host_sources/optica_services.rb +17 -15
  16. data/lib/interferon/host_sources/test_host_source.rb +1 -1
  17. data/lib/interferon/loaders.rb +4 -5
  18. data/lib/interferon/logging.rb +2 -3
  19. data/lib/interferon/version.rb +1 -1
  20. data/lib/interferon/work_hours_helper.rb +5 -5
  21. data/lib/interferon.rb +79 -80
  22. data/script/pre-commit +15 -20
  23. data/spec/fixtures/loaders/host_sources/test_host_source.rb +1 -1
  24. data/spec/fixtures/loaders/test_sources/order_test_source.rb +1 -1
  25. data/spec/fixtures/loaders/test_sources/test_source.rb +1 -1
  26. data/spec/fixtures/loaders2/test_sources/order_test_source.rb +1 -1
  27. data/spec/fixtures/loaders2/test_sources/secondary_source.rb +1 -1
  28. data/spec/fixtures/loaders2/test_sources/test_source.rb +1 -2
  29. data/spec/helpers/logging_helper.rb +2 -2
  30. data/spec/helpers/mock_alert.rb +1 -1
  31. data/spec/helpers/optica_helper.rb +70 -70
  32. data/spec/lib/interferon/destinations/datadog_spec.rb +58 -59
  33. data/spec/lib/interferon/group_sources/filesystem_spec.rb +29 -24
  34. data/spec/lib/interferon/host_sources/optica_services_spec.rb +11 -9
  35. data/spec/lib/interferon/host_sources/optica_spec.rb +6 -3
  36. data/spec/lib/interferon/loaders_spec.rb +19 -15
  37. data/spec/lib/interferon_spec.rb +61 -59
  38. data/spec/lib/work_hours_helper_spec.rb +15 -15
  39. data/spec/spec_helper.rb +1 -1
  40. metadata +61 -65
@@ -1,93 +1,93 @@
1
1
  class OpticaHelper
2
2
  def self.example_node_1
3
3
  {
4
- "ip" => "10.1.1.1",
5
- "environment" => "production",
6
- "role" => "role1",
7
- "hostname" => "box1",
8
- "uptime" => 37335310,
9
- "az" => "us-east-1a",
10
- "security_groups" => ["internal"],
11
- "instance_type" => "m1.large",
12
- "ami_id" => "ami-d9d6a6b0",
13
- "failed" => false,
14
- "roles" => ["role1"],
15
- "recipes" => ["airbnb-base","cookbook1"],
16
- "synapse_services" => ["service1","service2"],
17
- "nerve_services" => [],
18
- "ownership" => {
19
- "people" => ["test_user@example.com"],
20
- "groups" => ["admins"]
4
+ 'ip' => '10.1.1.1',
5
+ 'environment' => 'production',
6
+ 'role' => 'role1',
7
+ 'hostname' => 'box1',
8
+ 'uptime' => 37_335_310,
9
+ 'az' => 'us-east-1a',
10
+ 'security_groups' => ['internal'],
11
+ 'instance_type' => 'm1.large',
12
+ 'ami_id' => 'ami-d9d6a6b0',
13
+ 'failed' => false,
14
+ 'roles' => ['role1'],
15
+ 'recipes' => ['airbnb-base', 'cookbook1'],
16
+ 'synapse_services' => %w(service1 service2),
17
+ 'nerve_services' => [],
18
+ 'ownership' => {
19
+ 'people' => ['test_user@example.com'],
20
+ 'groups' => ['admins'],
21
21
  },
22
- "converger" => "ben_hughes"
22
+ 'converger' => 'ben_hughes',
23
23
  }
24
24
  end
25
25
 
26
26
  def self.example_node_2
27
27
  {
28
- "ip" => "10.1.1.2",
29
- "environment" => "production",
30
- "role" => "role2",
31
- "hostname" => "box2",
32
- "uptime" => 37335310,
33
- "az" => "us-east-1b",
34
- "security_groups" => ["internal"],
35
- "instance_type" => "m1.large",
36
- "ami_id" => "ami-d9d6a6b0",
37
- "failed" => false,
38
- "roles" => ["role2"],
39
- "recipes" => ["airbnb-base","cookbook2"],
40
- "synapse_services" => [],
41
- "nerve_services" => ["service1"],
42
- "ownership" => {
43
- "people" => ["test_user@example.com"],
44
- "groups" => ["admins"]
28
+ 'ip' => '10.1.1.2',
29
+ 'environment' => 'production',
30
+ 'role' => 'role2',
31
+ 'hostname' => 'box2',
32
+ 'uptime' => 37_335_310,
33
+ 'az' => 'us-east-1b',
34
+ 'security_groups' => ['internal'],
35
+ 'instance_type' => 'm1.large',
36
+ 'ami_id' => 'ami-d9d6a6b0',
37
+ 'failed' => false,
38
+ 'roles' => ['role2'],
39
+ 'recipes' => ['airbnb-base', 'cookbook2'],
40
+ 'synapse_services' => [],
41
+ 'nerve_services' => ['service1'],
42
+ 'ownership' => {
43
+ 'people' => ['test_user@example.com'],
44
+ 'groups' => ['admins'],
45
45
  },
46
- "converger" => "ben_hughes"
46
+ 'converger' => 'ben_hughes',
47
47
  }
48
48
  end
49
49
 
50
50
  def self.example_node_3
51
51
  {
52
- "ip" => "10.1.1.3",
53
- "environment" => "production",
54
- "role" => "role3",
55
- "hostname" => "box3",
56
- "uptime" => 37335310,
57
- "az" => "us-east-1b",
58
- "security_groups" => ["internal"],
59
- "instance_type" => "m1.large",
60
- "ami_id" => "ami-d9d6a6b0",
61
- "failed" => false,
62
- "roles" => ["role3"],
63
- "recipes" => ["airbnb-base","cookbook3"],
64
- "synapse_services" => [],
65
- "nerve_services" => ["service2"],
66
- "converger" => "ben_hughes"
52
+ 'ip' => '10.1.1.3',
53
+ 'environment' => 'production',
54
+ 'role' => 'role3',
55
+ 'hostname' => 'box3',
56
+ 'uptime' => 37_335_310,
57
+ 'az' => 'us-east-1b',
58
+ 'security_groups' => ['internal'],
59
+ 'instance_type' => 'm1.large',
60
+ 'ami_id' => 'ami-d9d6a6b0',
61
+ 'failed' => false,
62
+ 'roles' => ['role3'],
63
+ 'recipes' => ['airbnb-base', 'cookbook3'],
64
+ 'synapse_services' => [],
65
+ 'nerve_services' => ['service2'],
66
+ 'converger' => 'ben_hughes',
67
67
  }
68
68
  end
69
69
 
70
70
  def self.example_node_4
71
71
  {
72
- "ip" => "10.1.1.4",
73
- "environment" => "production",
74
- "role" => "role4",
75
- "hostname" => "box4",
76
- "uptime" => 37335310,
77
- "az" => "us-east-1e",
78
- "security_groups" => ["internal"],
79
- "instance_type" => "m1.large",
80
- "ami_id" => "ami-d9d6a6b0",
81
- "failed" => false,
82
- "roles" => ["role4"],
83
- "recipes" => ["airbnb-base","cookbook4"],
84
- "synapse_services" => [],
85
- "nerve_services" => ["service1"],
86
- "ownership" => {
87
- "people" => ["test_user2@example.com"],
88
- "groups" => ["engineers"]
72
+ 'ip' => '10.1.1.4',
73
+ 'environment' => 'production',
74
+ 'role' => 'role4',
75
+ 'hostname' => 'box4',
76
+ 'uptime' => 37_335_310,
77
+ 'az' => 'us-east-1e',
78
+ 'security_groups' => ['internal'],
79
+ 'instance_type' => 'm1.large',
80
+ 'ami_id' => 'ami-d9d6a6b0',
81
+ 'failed' => false,
82
+ 'roles' => ['role4'],
83
+ 'recipes' => ['airbnb-base', 'cookbook4'],
84
+ 'synapse_services' => [],
85
+ 'nerve_services' => ['service1'],
86
+ 'ownership' => {
87
+ 'people' => ['test_user2@example.com'],
88
+ 'groups' => ['engineers'],
89
89
  },
90
- "converger" => "ben_hughes"
90
+ 'converger' => 'ben_hughes',
91
91
  }
92
92
  end
93
93
 
@@ -104,7 +104,7 @@ class OpticaHelper
104
104
  {
105
105
  'examined' => 3,
106
106
  'returned' => 3,
107
- 'nodes' => example_nodes
107
+ 'nodes' => example_nodes,
108
108
  }
109
109
  end
110
110
  end
@@ -3,123 +3,122 @@ require 'interferon/destinations/datadog'
3
3
 
4
4
  describe Interferon::Destinations::Datadog do
5
5
  let(:retries) { 3 }
6
- let(:datadog) {
7
- Interferon::Destinations::Datadog.new({
6
+ let(:datadog) do
7
+ Interferon::Destinations::Datadog.new(
8
8
  'api_key' => 'TEST_API_KEY',
9
9
  'app_key' => 'TEST_APP_KEY',
10
- 'retries' => retries,
11
- })
12
- }
13
- let(:datadog_dry_run) {
14
- Interferon::Destinations::Datadog.new({
10
+ 'retries' => retries
11
+ )
12
+ end
13
+ let(:datadog_dry_run) do
14
+ Interferon::Destinations::Datadog.new(
15
15
  'api_key' => 'TEST_API_KEY',
16
16
  'app_key' => 'TEST_APP_KEY',
17
17
  'retries' => retries,
18
- 'dry_run' => true,
19
- })
20
- }
18
+ 'dry_run' => true
19
+ )
20
+ end
21
21
  let(:mock_alert_id) { 123 }
22
- let(:mock_alert) {
22
+ let(:mock_alert) do
23
23
  {
24
24
  'id' => [mock_alert_id],
25
25
  'name' => 'Test Alert',
26
- 'message' => "Test Message",
26
+ 'message' => 'Test Message',
27
27
  'metric' => { 'datadog_query' => 'avg:metric{*}' },
28
28
  'silenced' => {},
29
29
  'notify' => {},
30
30
  }
31
- }
32
- let(:mock_people) { ['foo', 'bar', 'baz'] }
33
- let(:mock_response) {
31
+ end
32
+ let(:mock_people) { %w(foo bar baz) }
33
+ let(:mock_response) do
34
34
  {
35
- "Test Alert" => {
36
- "id" => 567,
37
- "name" => 'Test Alert',
38
- 'message' => "Test Message",
39
- "query" => 'avg:metric{*}',
40
- "options" => {
41
- "silenced" => {}
42
- }
43
- }
35
+ 'Test Alert' => {
36
+ 'id' => 567,
37
+ 'name' => 'Test Alert',
38
+ 'message' => 'Test Message',
39
+ 'query' => 'avg:metric{*}',
40
+ 'options' => {
41
+ 'silenced' => {},
42
+ },
43
+ },
44
44
  }
45
- }
45
+ end
46
46
 
47
- describe ".get_existing_alerts" do
48
- it "calls dogapi get_all_monitors" do
47
+ describe '.fetch_existing_alerts' do
48
+ it 'calls dogapi get_all_monitors' do
49
49
  expect_any_instance_of(Dogapi::Client).to receive(:get_all_monitors).and_return([200, []])
50
- datadog.get_existing_alerts
50
+ datadog.fetch_existing_alerts
51
51
  end
52
52
  end
53
53
 
54
- describe ".existing_alerts" do
55
- it "retries dogapi get_all_monitors" do
56
- return_vals = [[400, ""]] * (retries + 1)
54
+ describe '.existing_alerts' do
55
+ it 'retries dogapi get_all_monitors' do
56
+ return_vals = [[400, '']] * (retries + 1)
57
57
  expect_any_instance_of(Dogapi::Client).to receive(:get_all_monitors).and_return(*return_vals)
58
58
  expect { datadog.existing_alerts }.to raise_error RuntimeError
59
59
  end
60
60
  end
61
61
 
62
- describe ".create_alert" do
63
- it "calls dogapi monitor" do
64
- expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ""])
62
+ describe '.create_alert' do
63
+ it 'calls dogapi monitor' do
64
+ expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ''])
65
65
  expect(datadog).to receive(:existing_alerts).and_return({})
66
66
  datadog.create_alert(mock_alert, mock_people)
67
67
  end
68
68
 
69
- it "calls dogapi update_monitor when alert name is found" do
70
- expect_any_instance_of(Dogapi::Client).to receive(:update_monitor).and_return([200, ""])
69
+ it 'calls dogapi update_monitor when alert name is found' do
70
+ expect_any_instance_of(Dogapi::Client).to receive(:update_monitor).and_return([200, ''])
71
71
  expect(datadog).to receive(:existing_alerts).and_return(mock_response)
72
72
  datadog.create_alert(mock_alert, mock_people)
73
73
  end
74
74
 
75
- it "calls dogapi to delete and recreate when alert name is found" do
76
- expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor).and_return([200, ""])
77
- expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ""])
78
- mock_response["Test Alert"]["type"] = "event_alert"
75
+ it 'calls dogapi to delete and recreate when alert name is found' do
76
+ expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor).and_return([200, ''])
77
+ expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ''])
78
+ mock_response['Test Alert']['type'] = 'event_alert'
79
79
  expect(datadog).to receive(:existing_alerts).and_return(mock_response)
80
80
  datadog.create_alert(mock_alert, mock_people)
81
81
  end
82
82
 
83
- it "calls dogapi to unmute when exiting alert is muted" do
84
- expect_any_instance_of(Dogapi::Client).to receive(:update_monitor).and_return([200, ""])
85
- expect_any_instance_of(Dogapi::Client).to receive(:unmute_monitor).and_return([200, ""])
86
- mock_response["Test Alert"]["options"]["silenced"] = { '*' => nil }
83
+ it 'calls dogapi to unmute when exiting alert is muted' do
84
+ expect_any_instance_of(Dogapi::Client).to receive(:update_monitor).and_return([200, ''])
85
+ expect_any_instance_of(Dogapi::Client).to receive(:unmute_monitor).and_return([200, ''])
86
+ mock_response['Test Alert']['options']['silenced'] = { '*' => nil }
87
87
  expect(datadog).to receive(:existing_alerts).and_return(mock_response)
88
88
  datadog.create_alert(mock_alert, mock_people)
89
89
  end
90
90
 
91
- it "always calls monitor in dry-run" do
92
- expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ""])
91
+ it 'always calls monitor in dry-run' do
92
+ expect_any_instance_of(Dogapi::Client).to receive(:monitor).and_return([200, ''])
93
93
  expect(datadog_dry_run).to receive(:existing_alerts).and_return(mock_response)
94
94
  datadog_dry_run.create_alert(mock_alert, mock_people)
95
95
  end
96
96
  end
97
97
 
98
- describe ".remove_alert" do
99
- it "calls dogapi delete_monitor with the correct alert id" do
100
- mock_alert["message"] += Interferon::Destinations::Datadog::ALERT_KEY
101
- expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor).
102
- with(mock_alert_id).and_return([200, ""])
98
+ describe '.remove_alert' do
99
+ it 'calls dogapi delete_monitor with the correct alert id' do
100
+ mock_alert['message'] += Interferon::Destinations::Datadog::ALERT_KEY
101
+ expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor)
102
+ .with(mock_alert_id).and_return([200, ''])
103
103
  datadog.remove_alert(mock_alert)
104
104
  end
105
105
 
106
- it "does not call dogapi delete_monitor in dry_run" do
107
- mock_alert["message"] += Interferon::Destinations::Datadog::ALERT_KEY
106
+ it 'does not call dogapi delete_monitor in dry_run' do
107
+ mock_alert['message'] += Interferon::Destinations::Datadog::ALERT_KEY
108
108
  expect_any_instance_of(Dogapi::Client).to_not receive(:delete_monitor)
109
109
  datadog_dry_run.remove_alert(mock_alert)
110
110
  end
111
111
 
112
- it "does not call dogapi delete_monitor when ALERT_KEY is missing" do
112
+ it 'does not call dogapi delete_monitor when ALERT_KEY is missing' do
113
113
  expect_any_instance_of(Dogapi::Client).to_not receive(:delete_monitor)
114
114
  datadog.remove_alert(mock_alert)
115
115
  end
116
-
117
116
  end
118
117
 
119
- describe ".remove_alert_by_id" do
120
- it "calls dogapi delete_monitor" do
121
- expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor).
122
- with(mock_alert_id).and_return([200, ""])
118
+ describe '.remove_alert_by_id' do
119
+ it 'calls dogapi delete_monitor' do
120
+ expect_any_instance_of(Dogapi::Client).to receive(:delete_monitor)
121
+ .with(mock_alert_id).and_return([200, ''])
123
122
  datadog.remove_alert_by_id(mock_alert_id)
124
123
  end
125
124
  end
@@ -2,56 +2,61 @@ require 'spec_helper'
2
2
  require 'interferon/group_sources/filesystem'
3
3
 
4
4
  describe Interferon::GroupSources::Filesystem do
5
- let (:fs_loader) { Interferon::GroupSources::Filesystem.new({'paths' => ['/tmp']}) }
5
+ let(:fs_loader) { Interferon::GroupSources::Filesystem.new('paths' => ['/tmp']) }
6
6
 
7
7
  describe 'list_groups' do
8
- context "with basic groups" do
8
+ context 'with basic groups' do
9
9
  before do
10
- group_a = double()
10
+ group_a = double
11
11
  expect(File).to receive(:read).with('group_a.yaml').and_return('group_a_text')
12
12
  expect(Psych).to receive(:parse).and_return(group_a)
13
- expect(group_a).to receive(:to_ruby).and_return({'name' => 'group_a',
14
- 'people' => ['Alice', 'Bob']})
13
+ expect(group_a).to receive(:to_ruby).and_return('name' => 'group_a',
14
+ 'people' => %w(Alice Bob))
15
15
 
16
- group_b = double()
16
+ group_b = double
17
17
  expect(File).to receive(:read).with('group_b.yaml').and_return('group_b_text')
18
18
  expect(Psych).to receive(:parse).and_return(group_b)
19
- expect(group_b).to receive(:to_ruby).and_return({'name' => 'group_b',
20
- 'people' => ['Carol', 'Dave']})
19
+ expect(group_b).to receive(:to_ruby).and_return('name' => 'group_b',
20
+ 'people' => %w(Carol Dave))
21
21
  end
22
22
 
23
23
  it 'loads groups defined by YAML' do
24
24
  expect(Dir).to receive(:glob).and_return(['group_a.yaml', 'group_b.yaml'].each)
25
25
 
26
- groups = fs_loader.list_groups()
27
- expect(groups).to eq({'group_a' => ['Alice', 'Bob'], 'group_b' => ['Carol', 'Dave']})
26
+ groups = fs_loader.list_groups
27
+ expect(groups).to eq('group_a' => %w(Alice Bob), 'group_b' => %w(Carol Dave))
28
28
  end
29
29
 
30
30
  it 'allows groups to be aliased in YAML' do
31
- expect(Dir).to receive(:glob).and_return(['group_a.yaml', 'group_b.yaml', 'group_c.yaml'].each)
32
- group_c = double()
31
+ expect(Dir).to receive(:glob).and_return(['group_a.yaml',
32
+ 'group_b.yaml',
33
+ 'group_c.yaml',].each)
34
+ group_c = double
33
35
  expect(File).to receive(:read).with('group_c.yaml').and_return('group_c_text')
34
36
  expect(Psych).to receive(:parse).and_return(group_c)
35
- expect(group_c).to receive(:to_ruby).and_return({'name' => 'group_c', 'alias_for' => 'group_b'})
37
+ expect(group_c).to receive(:to_ruby).and_return('name' => 'group_c',
38
+ 'alias_for' => 'group_b')
36
39
 
37
- groups = fs_loader.list_groups()
38
- expect(groups).to eq({'group_a' => ['Alice', 'Bob'],
39
- 'group_b' => ['Carol', 'Dave'],
40
- 'group_c' => ['Carol', 'Dave']})
40
+ groups = fs_loader.list_groups
41
+ expect(groups).to eq('group_a' => %w(Alice Bob),
42
+ 'group_b' => %w(Carol Dave),
43
+ 'group_c' => %w(Carol Dave))
41
44
  end
42
45
 
43
46
  it 'skips bad aliases in YAML' do
44
- expect(Dir).to receive(:glob).and_return(['group_a.yaml', 'group_b.yaml', 'group_c.yaml'].each)
45
- group_c = double()
47
+ expect(Dir).to receive(:glob).and_return(['group_a.yaml',
48
+ 'group_b.yaml',
49
+ 'group_c.yaml',].each)
50
+ group_c = double
46
51
  expect(File).to receive(:read).with('group_c.yaml').and_return('group_c_text')
47
52
  expect(Psych).to receive(:parse).and_return(group_c)
48
- expect(group_c).to receive(:to_ruby).and_return({'name' => 'group_c', 'alias_for' => 'group_d'})
53
+ expect(group_c).to receive(:to_ruby).and_return('name' => 'group_c',
54
+ 'alias_for' => 'group_d')
49
55
 
50
- groups = fs_loader.list_groups()
51
- expect(groups).to eq({'group_a' => ['Alice', 'Bob'],
52
- 'group_b' => ['Carol', 'Dave']})
56
+ groups = fs_loader.list_groups
57
+ expect(groups).to eq('group_a' => %w(Alice Bob),
58
+ 'group_b' => %w(Carol Dave))
53
59
  end
54
60
  end
55
61
  end
56
-
57
62
  end
@@ -3,7 +3,7 @@ require 'helpers/optica_helper'
3
3
  require 'interferon/host_sources/optica_services'
4
4
 
5
5
  describe Interferon::HostSources::OpticaServices do
6
- let(:optica_services) { Interferon::HostSources::OpticaServices.new({'host'=>'127.0.0.1'}) }
6
+ let(:optica_services) { Interferon::HostSources::OpticaServices.new('host' => '127.0.0.1') }
7
7
 
8
8
  describe '.list_hosts' do
9
9
  before do
@@ -11,8 +11,8 @@ describe Interferon::HostSources::OpticaServices do
11
11
  end
12
12
 
13
13
  let(:list) { optica_services.list_hosts }
14
- let(:service1) { list.select{|s| s[:service] == 'service1'}[0] }
15
- let(:service2) { list.select{|s| s[:service] == 'service2'}[0] }
14
+ let(:service1) { list.select { |s| s[:service] == 'service1' }[0] }
15
+ let(:service2) { list.select { |s| s[:service] == 'service2' }[0] }
16
16
 
17
17
  it 'returns both of the services we know about' do
18
18
  expect(list.length).to eq(2)
@@ -27,7 +27,7 @@ describe Interferon::HostSources::OpticaServices do
27
27
  :owner_groups,
28
28
  :consumer_roles,
29
29
  :consumer_machine_count,
30
- :provider_machine_count,
30
+ :provider_machine_count
31
31
  )
32
32
  end
33
33
  end
@@ -38,8 +38,11 @@ describe Interferon::HostSources::OpticaServices do
38
38
  end
39
39
 
40
40
  it 'knows that box1 is using both of the services' do
41
- expect(list).to satisfy{|l| l.all?{
42
- |s| s[:consumer_machine_count] == 1 && s[:consumer_roles] == ['role1']}}
41
+ expect(list).to satisfy do |l|
42
+ l.all? do |s|
43
+ s[:consumer_machine_count] == 1 && s[:consumer_roles] == ['role1']
44
+ end
45
+ end
43
46
  end
44
47
 
45
48
  it 'knows that service1 is provided by two machines' do
@@ -48,13 +51,12 @@ describe Interferon::HostSources::OpticaServices do
48
51
 
49
52
  it 'merges the ownership for all machines that provide service1' do
50
53
  all_owners = OpticaHelper.example_node_2['ownership']['people'] +
51
- OpticaHelper.example_node_4['ownership']['people']
54
+ OpticaHelper.example_node_4['ownership']['people']
52
55
  all_owner_groups = OpticaHelper.example_node_2['ownership']['groups'] +
53
- OpticaHelper.example_node_4['ownership']['groups']
56
+ OpticaHelper.example_node_4['ownership']['groups']
54
57
 
55
58
  expect(service1[:owners]).to contain_exactly(*all_owners)
56
59
  expect(service1[:owner_groups]).to contain_exactly(*all_owner_groups)
57
60
  end
58
61
  end
59
62
  end
60
-
@@ -3,7 +3,7 @@ require 'helpers/optica_helper'
3
3
  require 'interferon/host_sources/optica'
4
4
 
5
5
  describe Interferon::HostSources::Optica do
6
- let(:optica) { Interferon::HostSources::Optica.new({'host'=>'127.0.0.1'}) }
6
+ let(:optica) { Interferon::HostSources::Optica.new('host' => '127.0.0.1') }
7
7
 
8
8
  describe '.list_hosts' do
9
9
  before do
@@ -23,8 +23,11 @@ describe Interferon::HostSources::Optica do
23
23
  end
24
24
 
25
25
  it 'does not barf if ownership info is missing' do
26
- expect(list).to satisfy{|l| l.one?{|h| h[:owners].empty? && h[:owner_groups].empty?}}
26
+ expect(list).to satisfy do |l|
27
+ l.one? do |h|
28
+ h[:owners].empty? && h[:owner_groups].empty?
29
+ end
30
+ end
27
31
  end
28
32
  end
29
33
  end
30
-
@@ -1,5 +1,5 @@
1
- require "spec_helper"
2
- require "helpers/loader_helper"
1
+ require 'spec_helper'
2
+ require 'helpers/loader_helper'
3
3
 
4
4
  describe 'DynamicLoader' do
5
5
  describe 'custom class retrieval' do
@@ -10,7 +10,7 @@ describe 'DynamicLoader' do
10
10
 
11
11
  it 'throws an ArgumentError when the type cannot be found' do
12
12
  test_loader = TestLoader.new(['./spec/fixtures/loaders'])
13
- expect{test_loader.get_klass('unknown_source')}.to raise_error(ArgumentError)
13
+ expect { test_loader.get_klass('unknown_source') }.to raise_error(ArgumentError)
14
14
  end
15
15
 
16
16
  it 'looks at custom paths in order' do
@@ -53,22 +53,25 @@ describe 'DynamicLoader' do
53
53
  it 'returns an instance for each enabled source' do
54
54
  instances = loader.get_all(
55
55
  [
56
- {'type' => 'test_source', 'enabled' => true, 'options' => {}},
57
- {'type' => 'secondary_source', 'enabled' => true, 'options' => {}},
58
- ])
56
+ { 'type' => 'test_source', 'enabled' => true, 'options' => {} },
57
+ { 'type' => 'secondary_source', 'enabled' => true, 'options' => {} },
58
+ ]
59
+ )
59
60
 
60
61
  expect(instances.count).to eq(2)
61
62
  expect(instances).to contain_exactly(
62
63
  an_instance_of(Interferon::TestSources::TestSource),
63
- an_instance_of(Interferon::TestSources::SecondarySource))
64
+ an_instance_of(Interferon::TestSources::SecondarySource)
65
+ )
64
66
  end
65
67
 
66
68
  it 'ignores non-enabled sources' do
67
69
  instances = loader.get_all(
68
70
  [
69
- {'type' => 'test_source', 'enabled' => true, 'options' => {}},
70
- {'type' => 'secondary_source', 'enabled' => false, 'options' => {}},
71
- ])
71
+ { 'type' => 'test_source', 'enabled' => true, 'options' => {} },
72
+ { 'type' => 'secondary_source', 'enabled' => false, 'options' => {} },
73
+ ]
74
+ )
72
75
 
73
76
  expect(instances.count).to eq(1)
74
77
  expect(instances).to contain_exactly(an_instance_of(Interferon::TestSources::TestSource))
@@ -77,9 +80,10 @@ describe 'DynamicLoader' do
77
80
  it 'ignores sources with no type set' do
78
81
  instances = loader.get_all(
79
82
  [
80
- {'type' => 'test_source', 'enabled' => true, 'options' => {}},
81
- {'enabled' => true, 'options' => {}},
82
- ])
83
+ { 'type' => 'test_source', 'enabled' => true, 'options' => {} },
84
+ { 'enabled' => true, 'options' => {} },
85
+ ]
86
+ )
83
87
 
84
88
  expect(instances.count).to eq(1)
85
89
  expect(instances).to contain_exactly(an_instance_of(Interferon::TestSources::TestSource))
@@ -87,10 +91,10 @@ describe 'DynamicLoader' do
87
91
 
88
92
  it 'properly sets options on classes it instantiates' do
89
93
  instances = loader.get_all(
90
- [{'type' => 'test_source', 'enabled' => true, 'options' => {'testval' => 5}}])
94
+ [{ 'type' => 'test_source', 'enabled' => true, 'options' => { 'testval' => 5 } }]
95
+ )
91
96
 
92
97
  expect(instances[0].testval).to eq(5)
93
98
  end
94
99
  end
95
-
96
100
  end