sport_ngin_aws_auditor 3.5.0 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.markdown +5 -0
- data/lib/sport_ngin_aws_auditor/cache_instance.rb +11 -2
- data/lib/sport_ngin_aws_auditor/ec2_instance.rb +14 -5
- data/lib/sport_ngin_aws_auditor/instance_helper.rb +10 -0
- data/lib/sport_ngin_aws_auditor/rds_instance.rb +11 -2
- data/lib/sport_ngin_aws_auditor/scripts/audit.rb +40 -17
- data/lib/sport_ngin_aws_auditor/version.rb +1 -1
- data/spec/sport_ngin_aws_auditor/cache_instance_spec.rb +48 -0
- data/spec/sport_ngin_aws_auditor/ec2_instance_spec.rb +65 -0
- data/spec/sport_ngin_aws_auditor/rds_instance_spec.rb +50 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 073cee3003356deb0134ca9da9b30f840114e29d
|
4
|
+
data.tar.gz: 9bf761c1afd8c271c1d99bafcbdf8aa26d01d49c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53e5ece55ea759b443d8bd965a22bc0413ba3934051bd1eb14d075e22945a31a6a6239a194d0617d078336640ae369f7f8f5555eee67506cf121cfe6483e796e
|
7
|
+
data.tar.gz: a97b0d51779933df9e489164d81ed85eeed70b0b29dae2bc2d522270cb29a9b071d650eec86bea943f5062930a17f437e256a5809bbb9905e7057174cd3a9ee6
|
data/CHANGELOG.markdown
CHANGED
@@ -7,7 +7,7 @@ module SportNginAwsAuditor
|
|
7
7
|
extend AWSWrapper
|
8
8
|
|
9
9
|
class << self
|
10
|
-
attr_accessor :instances, :reserved_instances
|
10
|
+
attr_accessor :instances, :reserved_instances, :retired_reserved_instances
|
11
11
|
|
12
12
|
def get_instances(tag_name=nil)
|
13
13
|
return @instances if @instances
|
@@ -25,9 +25,17 @@ module SportNginAwsAuditor
|
|
25
25
|
new(instance)
|
26
26
|
end.compact
|
27
27
|
end
|
28
|
+
|
29
|
+
def get_retired_reserved_instances
|
30
|
+
return @retired_reserved_instances if @retired_reserved_instances
|
31
|
+
@retired_reserved_instances = cache.describe_reserved_cache_nodes.reserved_cache_nodes.map do |instance|
|
32
|
+
next unless instance.state == 'retired'
|
33
|
+
new(instance)
|
34
|
+
end.compact
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
|
-
attr_accessor :id, :name, :instance_type, :engine, :count, :tag_value
|
38
|
+
attr_accessor :id, :name, :instance_type, :engine, :count, :tag_value, :expiration_date
|
31
39
|
def initialize(cache_instance, account_id=nil, tag_name=nil, cache=nil)
|
32
40
|
if cache_instance.class.to_s == "Aws::ElastiCache::Types::ReservedCacheNode"
|
33
41
|
self.id = cache_instance.reserved_cache_node_id
|
@@ -35,6 +43,7 @@ module SportNginAwsAuditor
|
|
35
43
|
self.instance_type = cache_instance.cache_node_type
|
36
44
|
self.engine = cache_instance.product_description
|
37
45
|
self.count = cache_instance.cache_node_count
|
46
|
+
self.expiration_date = cache_instance.start_time + cache_instance.duration if cache_instance.state == 'retired'
|
38
47
|
elsif cache_instance.class.to_s == "Aws::ElastiCache::Types::CacheCluster"
|
39
48
|
self.id = cache_instance.cache_cluster_id
|
40
49
|
self.name = cache_instance.cache_cluster_id
|
@@ -6,7 +6,7 @@ module SportNginAwsAuditor
|
|
6
6
|
extend EC2Wrapper
|
7
7
|
|
8
8
|
class << self
|
9
|
-
attr_accessor :instances, :reserved_instances
|
9
|
+
attr_accessor :instances, :reserved_instances, :retired_reserved_instances
|
10
10
|
|
11
11
|
def get_instances(tag_name=nil)
|
12
12
|
return @instances if @instances
|
@@ -21,9 +21,17 @@ module SportNginAwsAuditor
|
|
21
21
|
|
22
22
|
def get_reserved_instances
|
23
23
|
return @reserved_instances if @reserved_instances
|
24
|
-
@reserved_instances = ec2.describe_reserved_instances.reserved_instances.map do |
|
25
|
-
next unless
|
26
|
-
new(
|
24
|
+
@reserved_instances = ec2.describe_reserved_instances.reserved_instances.map do |instance|
|
25
|
+
next unless instance.state == 'active'
|
26
|
+
new(instance, nil, instance.instance_count)
|
27
|
+
end.compact
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_retired_reserved_instances
|
31
|
+
return @retired_reserved_instances if @retired_reserved_instances
|
32
|
+
@retired_reserved_instances = ec2.describe_reserved_instances.reserved_instances.map do |instance|
|
33
|
+
next unless instance.state == 'retired'
|
34
|
+
new(instance, nil, instance.instance_count)
|
27
35
|
end.compact
|
28
36
|
end
|
29
37
|
|
@@ -52,7 +60,7 @@ module SportNginAwsAuditor
|
|
52
60
|
private :get_more_info
|
53
61
|
end
|
54
62
|
|
55
|
-
attr_accessor :id, :name, :platform, :availability_zone, :instance_type, :count, :stack_name, :tag_value
|
63
|
+
attr_accessor :id, :name, :platform, :availability_zone, :instance_type, :count, :stack_name, :tag_value, :expiration_date
|
56
64
|
def initialize(ec2_instance, tag_name, count=1)
|
57
65
|
if ec2_instance.class.to_s == "Aws::EC2::Types::ReservedInstances"
|
58
66
|
self.id = ec2_instance.reserved_instances_id
|
@@ -62,6 +70,7 @@ module SportNginAwsAuditor
|
|
62
70
|
self.instance_type = ec2_instance.instance_type
|
63
71
|
self.count = count
|
64
72
|
self.stack_name = nil
|
73
|
+
self.expiration_date = ec2_instance.end if ec2_instance.state == 'retired'
|
65
74
|
elsif ec2_instance.class.to_s == "Aws::EC2::Types::Instance"
|
66
75
|
self.id = ec2_instance.instance_id
|
67
76
|
self.name = nil
|
@@ -34,15 +34,25 @@ module SportNginAwsAuditor
|
|
34
34
|
instances_without_tag = filter_instance_without_tags(instances)
|
35
35
|
instance_hash = instance_count_hash(instances_without_tag)
|
36
36
|
ris = instance_count_hash(get_reserved_instances)
|
37
|
+
|
37
38
|
instance_hash.keys.concat(ris.keys).uniq.each do |key|
|
38
39
|
instance_count = instance_hash.has_key?(key) ? instance_hash[key] : 0
|
39
40
|
ris_count = ris.has_key?(key) ? ris[key] : 0
|
40
41
|
differences[key] = ris_count - instance_count
|
41
42
|
end
|
43
|
+
|
42
44
|
add_instances_with_tag_to_hash(instances_with_tag, differences)
|
43
45
|
differences
|
44
46
|
end
|
45
47
|
|
48
|
+
# this gets all retired reserved instances and filters out only the ones that have expired
|
49
|
+
# within the past week
|
50
|
+
def get_recent_retired_reserved_instances
|
51
|
+
get_retired_reserved_instances.select do |ri|
|
52
|
+
ri.expiration_date > (Time.now - 604800)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
46
56
|
# assuming the value of the tag is in the form: 01/01/2000 like a date
|
47
57
|
def filter_instances_with_tags(instances)
|
48
58
|
instances.select do |instance|
|
@@ -7,7 +7,7 @@ module SportNginAwsAuditor
|
|
7
7
|
extend AWSWrapper
|
8
8
|
|
9
9
|
class << self
|
10
|
-
attr_accessor :instances, :reserved_instances
|
10
|
+
attr_accessor :instances, :reserved_instances, :retired_reserved_instances
|
11
11
|
|
12
12
|
def get_instances(tag_name=nil)
|
13
13
|
return @instances if @instances
|
@@ -25,9 +25,17 @@ module SportNginAwsAuditor
|
|
25
25
|
new(instance)
|
26
26
|
end.compact
|
27
27
|
end
|
28
|
+
|
29
|
+
def get_retired_reserved_instances
|
30
|
+
return @retired_reserved_instances if @retired_reserved_instances
|
31
|
+
@retired_reserved_instances = rds.describe_reserved_db_instances.reserved_db_instances.map do |instance|
|
32
|
+
next unless instance.state == 'retired'
|
33
|
+
new(instance)
|
34
|
+
end.compact
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
|
-
attr_accessor :id, :name, :multi_az, :instance_type, :engine, :count, :tag_value
|
38
|
+
attr_accessor :id, :name, :multi_az, :instance_type, :engine, :count, :tag_value, :expiration_date
|
31
39
|
def initialize(rds_instance, account_id=nil, tag_name=nil, rds=nil)
|
32
40
|
if rds_instance.class.to_s == "Aws::RDS::Types::ReservedDBInstance"
|
33
41
|
self.id = rds_instance.reserved_db_instances_offering_id
|
@@ -35,6 +43,7 @@ module SportNginAwsAuditor
|
|
35
43
|
self.instance_type = rds_instance.db_instance_class
|
36
44
|
self.engine = engine_helper(rds_instance.product_description)
|
37
45
|
self.count = rds_instance.db_instance_count
|
46
|
+
self.expiration_date = rds_instance.start_time + rds_instance.duration if rds_instance.state == 'retired'
|
38
47
|
elsif rds_instance.class.to_s == "Aws::RDS::Types::DBInstance"
|
39
48
|
self.id = rds_instance.db_instance_identifier
|
40
49
|
self.multi_az = rds_instance.multi_az ? "Multi-AZ" : "Single-AZ"
|
@@ -23,20 +23,22 @@ module SportNginAwsAuditor
|
|
23
23
|
tag_name = options[:tag]
|
24
24
|
end
|
25
25
|
|
26
|
+
cycle = [["EC2Instance", options[:ec2]],
|
27
|
+
["RDSInstance", options[:rds]],
|
28
|
+
["CacheInstance", options[:cache]]]
|
29
|
+
|
26
30
|
if !slack
|
27
31
|
print "Gathering info, please wait..."; print "\r"
|
28
32
|
else
|
29
33
|
puts "Condensed results from this audit will print into Slack instead of directly to an output."
|
30
34
|
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
data = gather_data("CacheInstance", tag_name) if options[:cache] || no_selection
|
39
|
-
print_data(slack, environment, data, "CacheInstance") if options[:cache] || no_selection
|
36
|
+
cycle.each do |c|
|
37
|
+
all_data = gather_data(c.first, tag_name) if (c.last || no_selection)
|
38
|
+
data = all_data.first unless all_data.nil?
|
39
|
+
retired_reserved_instances = all_data.last if (all_data.length == 2 && !all_data.nil?)
|
40
|
+
print_data(slack, environment, data, retired_reserved_instances, c.first) if (c.last || no_selection)
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def self.gather_data(class_type, tag_name)
|
@@ -52,26 +54,32 @@ module SportNginAwsAuditor
|
|
52
54
|
instance_hash = klass.instance_count_hash(klass.get_reserved_instances)
|
53
55
|
else
|
54
56
|
instance_hash = klass.compare(tag_name)
|
57
|
+
retired_reserved_instances = klass.get_recent_retired_reserved_instances
|
55
58
|
end
|
56
59
|
|
57
60
|
compared_array = []
|
58
61
|
instance_hash.each do |key, value|
|
59
62
|
compared_array.push(Instance.new(key, value))
|
60
63
|
end
|
61
|
-
|
64
|
+
|
65
|
+
[compared_array, retired_reserved_instances]
|
62
66
|
end
|
63
67
|
|
64
|
-
def self.print_data(slack, environment, data, class_type)
|
68
|
+
def self.print_data(slack, environment, data, retired_reserved_instances, class_type)
|
65
69
|
data.sort_by! { |instance| [instance.type, instance.name] }
|
66
70
|
|
67
71
|
if slack
|
68
|
-
print_to_slack(data, class_type, environment)
|
72
|
+
print_to_slack(data, retired_reserved_instances, class_type, environment)
|
69
73
|
elsif options[:reserved] || options[:instances]
|
70
74
|
puts header(class_type)
|
71
75
|
data.each{ |instance| say "<%= color('#{instance.name}: #{instance.count}', :white) %>" }
|
72
76
|
else
|
73
77
|
puts header(class_type)
|
74
78
|
data.each{ |instance| colorize(instance) }
|
79
|
+
unless retired_reserved_instances.empty?
|
80
|
+
say "The following reserved #{class_type}Instance have recently expired in #{environment}:"
|
81
|
+
retired_reserved_instances.each { |ri| say "#{ri.to_s} (#{ri.count}) on #{ri.expiration_date}"}
|
82
|
+
end
|
75
83
|
end
|
76
84
|
end
|
77
85
|
|
@@ -82,8 +90,9 @@ module SportNginAwsAuditor
|
|
82
90
|
say "<%= color('#{name}: #{count}', :#{color}) %>"
|
83
91
|
end
|
84
92
|
|
85
|
-
def self.print_to_slack(instances_array, class_type, environment)
|
93
|
+
def self.print_to_slack(instances_array, retired_instances_array, class_type, environment)
|
86
94
|
discrepancy_array = []
|
95
|
+
|
87
96
|
instances_array.each do |instance|
|
88
97
|
unless instance.matched?
|
89
98
|
discrepancy_array.push(instance)
|
@@ -93,22 +102,36 @@ module SportNginAwsAuditor
|
|
93
102
|
true_discrepancies = discrepancy_array.reject{ |instance| instance.tagged? }
|
94
103
|
|
95
104
|
unless true_discrepancies.empty?
|
96
|
-
print_discrepancies(discrepancy_array, class_type, environment)
|
105
|
+
print_discrepancies(discrepancy_array, retired_instances_array, class_type, environment)
|
97
106
|
end
|
98
107
|
end
|
99
108
|
|
100
|
-
def self.print_discrepancies(discrepancy_array, class_type, environment)
|
109
|
+
def self.print_discrepancies(discrepancy_array, retired_instances_array, class_type, environment)
|
101
110
|
title = "Some #{class_type} discrepancies for #{environment} exist:\n"
|
102
|
-
|
111
|
+
slack_instances = NotifySlack.new(title)
|
103
112
|
|
104
113
|
discrepancy_array.each do |discrepancy|
|
105
114
|
name = discrepancy.name
|
106
115
|
count = discrepancy.count
|
107
116
|
color, rgb = color_chooser(discrepancy)
|
108
|
-
|
117
|
+
slack_instances.attachments.push({"color" => rgb, "text" => "#{name}: #{count}", "mrkdwn_in" => ["text"]})
|
109
118
|
end
|
110
119
|
|
111
|
-
|
120
|
+
slack_instances.perform
|
121
|
+
|
122
|
+
unless retired_instances_array.empty?
|
123
|
+
message = "The following reserved #{class_type} have recently expired in #{environment}:\n"
|
124
|
+
|
125
|
+
retired_instances_array.each do |ri|
|
126
|
+
name = ri.to_s
|
127
|
+
count = ri.count
|
128
|
+
expiration_date = ri.expiration_date
|
129
|
+
message << "*#{name}* (#{count}) on *#{expiration_date}*\n"
|
130
|
+
end
|
131
|
+
|
132
|
+
slack_retired_instances = NotifySlack.new(message)
|
133
|
+
slack_retired_instances.perform
|
134
|
+
end
|
112
135
|
end
|
113
136
|
|
114
137
|
def self.color_chooser(instance)
|
@@ -99,6 +99,54 @@ module SportNginAwsAuditor
|
|
99
99
|
expect(reserved_instance.instance_type).to eq("cache.t2.small")
|
100
100
|
expect(reserved_instance.engine).to eq("redis")
|
101
101
|
end
|
102
|
+
|
103
|
+
context "for retired_reserved_cache_instances" do
|
104
|
+
before :each do
|
105
|
+
@time = Time.now
|
106
|
+
retired_reserved_cache_instance1 = double('reserved_cache_instance', reserved_cache_node_id: "job-queue-cluster",
|
107
|
+
cache_node_type: "cache.t2.small",
|
108
|
+
product_description: "redis",
|
109
|
+
state: "retired",
|
110
|
+
cache_node_count: 1,
|
111
|
+
class: "Aws::ElastiCache::Types::ReservedCacheNode",
|
112
|
+
start_time: @time - 31536000,
|
113
|
+
duration: 31536000)
|
114
|
+
retired_reserved_cache_instance2 = double('reserved_cache_instance', reserved_cache_node_id: "job-queue-cluster",
|
115
|
+
cache_node_type: "cache.t2.medium",
|
116
|
+
product_description: "mysql",
|
117
|
+
state: "retired",
|
118
|
+
cache_node_count: 1,
|
119
|
+
class: "Aws::ElastiCache::Types::ReservedCacheNode",
|
120
|
+
start_time: @time - 31536000,
|
121
|
+
duration: 31536000)
|
122
|
+
reserved_cache_nodes = double('cache_cluster', reserved_cache_nodes: [retired_reserved_cache_instance1,
|
123
|
+
retired_reserved_cache_instance2])
|
124
|
+
cache_client = double('cache_client', describe_reserved_cache_nodes: reserved_cache_nodes)
|
125
|
+
allow(CacheInstance).to receive(:cache).and_return(cache_client)
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should make a retired_reserved_cache_instance for each instance" do
|
129
|
+
retired_reserved_instances = CacheInstance.get_retired_reserved_instances
|
130
|
+
expect(retired_reserved_instances.first).to be_an_instance_of(CacheInstance)
|
131
|
+
expect(retired_reserved_instances.last).to be_an_instance_of(CacheInstance)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return an array of retired_reserved_cache_instances" do
|
135
|
+
retired_reserved_instances = CacheInstance.get_retired_reserved_instances
|
136
|
+
expect(retired_reserved_instances).not_to be_empty
|
137
|
+
expect(retired_reserved_instances.length).to eq(2)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should have proper variables set" do
|
141
|
+
retired_reserved_instances = CacheInstance.get_retired_reserved_instances
|
142
|
+
retired_reserved_instance = retired_reserved_instances.first
|
143
|
+
expect(retired_reserved_instance.id).to eq("job-queue-cluster")
|
144
|
+
expect(retired_reserved_instance.name).to eq("job-queue-cluster")
|
145
|
+
expect(retired_reserved_instance.instance_type).to eq("cache.t2.small")
|
146
|
+
expect(retired_reserved_instance.engine).to eq("redis")
|
147
|
+
expect(retired_reserved_instance.expiration_date).to be >= @time - 31536000
|
148
|
+
end
|
149
|
+
end
|
102
150
|
end
|
103
151
|
|
104
152
|
context "for returning pretty string formats" do
|
@@ -122,6 +122,71 @@ module SportNginAwsAuditor
|
|
122
122
|
expect(reserved_instance1.platform).to eq("Windows VPC")
|
123
123
|
expect(reserved_instance2.platform).to eq("Linux VPC")
|
124
124
|
end
|
125
|
+
|
126
|
+
context "for retired_reserved_ec2_instances" do
|
127
|
+
before :each do
|
128
|
+
@time = Time.now
|
129
|
+
retired_reserved_ec2_instance1 = double('reserved_ec2_instance', reserved_instances_id: "12345-dfas-1234-asdf-thisisfake!!",
|
130
|
+
instance_type: "t2.medium",
|
131
|
+
product_description: "Windows (Amazon VPC)",
|
132
|
+
state: "retired",
|
133
|
+
availability_zone: "us-east-1b",
|
134
|
+
instance_count: 4,
|
135
|
+
class: "Aws::EC2::Types::ReservedInstances",
|
136
|
+
end: @time - 86400)
|
137
|
+
retired_reserved_ec2_instance2 = double('reserved_ec2_instance', reserved_instances_id: "12345-dfas-1234-asdf-thisisalsofake",
|
138
|
+
instance_type: "t2.small",
|
139
|
+
product_description: "Linux/UNIX (Amazon VPC)",
|
140
|
+
state: "retired",
|
141
|
+
availability_zone: "us-east-1b",
|
142
|
+
instance_count: 2,
|
143
|
+
class: "Aws::EC2::Types::ReservedInstances",
|
144
|
+
end: @time - 86400)
|
145
|
+
reserved_ec2_instance1 = double('reserved_ec2_instance', reserved_instances_id: "12345-dfas-1234-asdf-thisisalsofake",
|
146
|
+
instance_type: "t2.small",
|
147
|
+
product_description: "Linux/UNIX (Amazon VPC)",
|
148
|
+
state: "active",
|
149
|
+
availability_zone: "us-east-1b",
|
150
|
+
instance_count: 2,
|
151
|
+
class: "Aws::EC2::Types::ReservedInstances")
|
152
|
+
reserved_ec2_instances = double('reserved_ec2_instances', reserved_instances: [retired_reserved_ec2_instance1,
|
153
|
+
retired_reserved_ec2_instance2,
|
154
|
+
reserved_ec2_instance1])
|
155
|
+
ec2_client = double('ec2_client', describe_reserved_instances: reserved_ec2_instances)
|
156
|
+
allow(EC2Instance).to receive(:ec2).and_return(ec2_client)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should make a retired_reserved_ec2_instance for each instance" do
|
160
|
+
retired_reserved_instances = EC2Instance.get_retired_reserved_instances
|
161
|
+
expect(retired_reserved_instances.first).to be_an_instance_of(EC2Instance)
|
162
|
+
expect(retired_reserved_instances.last).to be_an_instance_of(EC2Instance)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should return an array of retired_reserved_ec2_instances" do
|
166
|
+
retired_reserved_instances = EC2Instance.get_retired_reserved_instances
|
167
|
+
expect(retired_reserved_instances).not_to be_empty
|
168
|
+
expect(retired_reserved_instances.length).to eq(2)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should have proper variables set" do
|
172
|
+
retired_reserved_instances = EC2Instance.get_retired_reserved_instances
|
173
|
+
retired_reserved_instance = retired_reserved_instances.first
|
174
|
+
expect(retired_reserved_instance.id).to eq("12345-dfas-1234-asdf-thisisfake!!")
|
175
|
+
expect(retired_reserved_instance.platform).to eq("Windows VPC")
|
176
|
+
expect(retired_reserved_instance.availability_zone).to eq("us-east-1b")
|
177
|
+
expect(retired_reserved_instance.instance_type).to eq("t2.medium")
|
178
|
+
expect(retired_reserved_instance.count).to eq(4)
|
179
|
+
expect(retired_reserved_instance.expiration_date).to be >= @time - 86500
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should recognize Windows vs. Linux" do
|
183
|
+
retired_reserved_instances = EC2Instance.get_retired_reserved_instances
|
184
|
+
retired_reserved_instance1 = retired_reserved_instances.first
|
185
|
+
retired_reserved_instance2 = retired_reserved_instances.last
|
186
|
+
expect(retired_reserved_instance1.platform).to eq("Windows VPC")
|
187
|
+
expect(retired_reserved_instance2.platform).to eq("Linux VPC")
|
188
|
+
end
|
189
|
+
end
|
125
190
|
end
|
126
191
|
|
127
192
|
context "for returning pretty string formats" do
|
@@ -101,6 +101,56 @@ module SportNginAwsAuditor
|
|
101
101
|
expect(reserved_instance.instance_type).to eq("db.t2.small")
|
102
102
|
expect(reserved_instance.engine).to eq("Oracle SE Two")
|
103
103
|
end
|
104
|
+
|
105
|
+
context "for retired_reserved_rds_instances" do
|
106
|
+
before :each do
|
107
|
+
@time = Time.now
|
108
|
+
retired_reserved_rds_instance1 = double('reserved_rds_instance', reserved_db_instances_offering_id: "555te4yy-1234-555c-5678-thisisafake!!",
|
109
|
+
multi_az: false,
|
110
|
+
db_instance_class: "db.t2.small",
|
111
|
+
state: "retired",
|
112
|
+
product_description: "oracle-se2 (byol)",
|
113
|
+
db_instance_count: 1,
|
114
|
+
class: "Aws::RDS::Types::ReservedDBInstance",
|
115
|
+
start_time: @time - 31536000,
|
116
|
+
duration: 31536000)
|
117
|
+
retired_reserved_rds_instance2 = double('reserved_rds_instance', reserved_db_instances_offering_id: "555te4yy-1234-555c-5678-thisisafake!!",
|
118
|
+
multi_az: false,
|
119
|
+
db_instance_class: "db.m3.large",
|
120
|
+
state: "retired",
|
121
|
+
product_description: "postgresql",
|
122
|
+
db_instance_count: 2,
|
123
|
+
class: "Aws::RDS::Types::ReservedDBInstance",
|
124
|
+
start_time: @time - 31536000,
|
125
|
+
duration: 31536000)
|
126
|
+
reserved_db_instances = double('db_instances', reserved_db_instances: [retired_reserved_rds_instance1,
|
127
|
+
retired_reserved_rds_instance2])
|
128
|
+
rds_client = double('rds_client', describe_reserved_db_instances: reserved_db_instances)
|
129
|
+
allow(RDSInstance).to receive(:rds).and_return(rds_client)
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should make a retired_reserved_rds_instance for each instance" do
|
133
|
+
retired_reserved_instances = RDSInstance.get_retired_reserved_instances
|
134
|
+
expect(retired_reserved_instances.first).to be_an_instance_of(RDSInstance)
|
135
|
+
expect(retired_reserved_instances.last).to be_an_instance_of(RDSInstance)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should return an array of retired_reserved_rds_instances" do
|
139
|
+
retired_reserved_instances = RDSInstance.get_retired_reserved_instances
|
140
|
+
expect(retired_reserved_instances).not_to be_empty
|
141
|
+
expect(retired_reserved_instances.length).to eq(2)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should have proper variables set" do
|
145
|
+
retired_reserved_instances = RDSInstance.get_retired_reserved_instances
|
146
|
+
retired_reserved_instance = retired_reserved_instances.first
|
147
|
+
expect(retired_reserved_instance.id).to eq("555te4yy-1234-555c-5678-thisisafake!!")
|
148
|
+
expect(retired_reserved_instance.multi_az).to eq("Single-AZ")
|
149
|
+
expect(retired_reserved_instance.instance_type).to eq("db.t2.small")
|
150
|
+
expect(retired_reserved_instance.engine).to eq("Oracle SE Two")
|
151
|
+
expect(retired_reserved_instance.expiration_date).to be >= @time - 31536000
|
152
|
+
end
|
153
|
+
end
|
104
154
|
end
|
105
155
|
|
106
156
|
context "for returning pretty string formats" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sport_ngin_aws_auditor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elliot Hursh
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-08-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: aws-sdk
|