rds-rotate-db-snapshots 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rds_rotate_db_snapshots/action_wrappers.rb +4 -1
- data/lib/rds_rotate_db_snapshots/options_parser.rb +7 -7
- data/rds-rotate-db-snapshots.gemspec +7 -3
- data/spec/helper.rb +1 -1
- data/spec/lib/rds_rotate_db_snapshots/action_wrappers_spec.rb +45 -0
- data/spec/lib/rds_rotate_db_snapshots/actions_spec.rb +96 -0
- data/spec/lib/rds_rotate_db_snapshots/options_parser_spec.rb +33 -0
- data/spec/lib/rds_rotate_db_snapshots/rds_client_spec.rb +32 -0
- data/spec/{rds_rotate_db_snapshots_spec.rb → lib/rds_rotate_db_snapshots_spec.rb} +0 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca82ea61b9da51d2888c98f21fda30ce73850b265dcb01b75c2e99c0b84d597d
|
4
|
+
data.tar.gz: 778fc695f23d0c713bedad76b2ce4893401c50d270df596c1324b52dcd0546b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8bca5be1bb1d4324ae674677f574707782f92cb9717ec66010a8686ceca450d0127017c109289738c487f25131f6cf355ad60d4a33d8c71d0b2c2278ea24b68
|
7
|
+
data.tar.gz: b00fe71aab391fa82e64b52f1de28bfc68632f0ae5a7961b5e1358fb55a28d19f1d9dd44dbcd59e81ce06204b8d26f290c2c253e303386144b0525c75ff1c3ec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
@@ -9,7 +9,10 @@ class RdsRotateDbSnapshots
|
|
9
9
|
reset_backoff
|
10
10
|
begin
|
11
11
|
super *args
|
12
|
-
rescue Aws::RDS::Errors => e
|
12
|
+
rescue Aws::RDS::Errors::ServiceError => e
|
13
|
+
raise if e.is_a? Aws::RDS::Errors::ExpiredToken
|
14
|
+
# TODO: re-work
|
15
|
+
puts "Error: #{e}"
|
13
16
|
backoff
|
14
17
|
retry
|
15
18
|
end
|
@@ -95,15 +95,15 @@ class RdsRotateDbSnapshots
|
|
95
95
|
@options[:dry_run] = true
|
96
96
|
end
|
97
97
|
end
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
hash[tag] = value
|
100
|
+
def split_tag(hash,v)
|
101
|
+
v.split(',').each do |pair|
|
102
|
+
tag, value = pair.split('=',2)
|
103
|
+
if value.nil?
|
104
|
+
raise InvalidArgument, "invalid tag=value format"
|
106
105
|
end
|
106
|
+
hash[tag] = value
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: rds-rotate-db-snapshots 0.5.
|
5
|
+
# stub: rds-rotate-db-snapshots 0.5.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "rds-rotate-db-snapshots".freeze
|
9
|
-
s.version = "0.5.
|
9
|
+
s.version = "0.5.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -38,7 +38,11 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/rds_rotate_db_snapshots/rds_client.rb",
|
39
39
|
"rds-rotate-db-snapshots.gemspec",
|
40
40
|
"spec/helper.rb",
|
41
|
-
"spec/
|
41
|
+
"spec/lib/rds_rotate_db_snapshots/action_wrappers_spec.rb",
|
42
|
+
"spec/lib/rds_rotate_db_snapshots/actions_spec.rb",
|
43
|
+
"spec/lib/rds_rotate_db_snapshots/options_parser_spec.rb",
|
44
|
+
"spec/lib/rds_rotate_db_snapshots/rds_client_spec.rb",
|
45
|
+
"spec/lib/rds_rotate_db_snapshots_spec.rb"
|
42
46
|
]
|
43
47
|
s.homepage = "http://github.com/serg-kovalev/rds-rotate-db-snapshots".freeze
|
44
48
|
s.licenses = ["MIT".freeze]
|
data/spec/helper.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestClass
|
4
|
+
def initialize
|
5
|
+
@backoff_counter = 0
|
6
|
+
@options = { backoff_limit: 5 }
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_method
|
10
|
+
raise Aws::RDS::Errors::ServiceError.new(nil, 'service error')
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset_backoff
|
14
|
+
@backoff_counter = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def backoff
|
18
|
+
@backoff_counter = @backoff_counter + 1
|
19
|
+
|
20
|
+
raise StandardError, 'gave up' if @options[:backoff_limit] > 0 && @options[:backoff_limit] < @backoff_counter
|
21
|
+
end
|
22
|
+
|
23
|
+
extend RdsRotateDbSnapshots::ActionWrappers
|
24
|
+
|
25
|
+
with_backoff :test_method
|
26
|
+
end
|
27
|
+
|
28
|
+
describe RdsRotateDbSnapshots::ActionWrappers do
|
29
|
+
subject { TestClass.new }
|
30
|
+
|
31
|
+
describe "#with_backoff" do
|
32
|
+
it "does not retry if the exception raised is Aws::RDS::Errors::ExpiredToken" do
|
33
|
+
allow(subject).to receive(:test_method).and_raise(Aws::RDS::Errors::ExpiredToken.new(nil, 'token expired'))
|
34
|
+
expect(subject).not_to receive(:reset_backoff)
|
35
|
+
expect(subject).not_to receive(:backoff)
|
36
|
+
expect{subject.test_method}.to raise_error(Aws::RDS::Errors::ExpiredToken)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "retries if the exception raised is Aws::RDS::Errors::ServiceError" do
|
40
|
+
expect(subject).to receive(:backoff).exactly(6).and_call_original
|
41
|
+
|
42
|
+
expect{ subject.test_method }.to raise_error(StandardError, 'gave up')
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples 'rds_rotate_db_snapshots actions' do
|
4
|
+
let(:rds_client) { instance_double(RdsRotateDbSnapshots::RdsClient) }
|
5
|
+
let(:client) { rds_client }
|
6
|
+
let(:options) do
|
7
|
+
{
|
8
|
+
aws_access_key: 'ACCESS_KEY',
|
9
|
+
aws_secret_access_key: 'SECRET_KEY',
|
10
|
+
aws_region: 'REGION',
|
11
|
+
pattern: 'test',
|
12
|
+
dry_run: true,
|
13
|
+
backoff_limit: 15
|
14
|
+
}
|
15
|
+
end
|
16
|
+
let(:rds_snapshots) do
|
17
|
+
[
|
18
|
+
{ snapshot_create_time: Time.now, db_instance_identifier: 'test_db', db_snapshot_identifier: 'test_snapshot' }
|
19
|
+
]
|
20
|
+
end
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(subject).to receive(:client).and_return(rds_client)
|
24
|
+
allow(rds_client).to receive(:describe_db_snapshots).and_return(rds_snapshots)
|
25
|
+
allow(rds_client).to receive(:create_db_snapshot)
|
26
|
+
allow(rds_client).to receive(:delete_db_snapshot)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#rotate_em" do
|
30
|
+
it "deletes the snapshots that are not part of the specified time periods" do
|
31
|
+
expect(rds_client).to receive(:delete_db_snapshot)
|
32
|
+
subject.rotate_em(rds_snapshots)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#create_snapshot" do
|
37
|
+
it "creates a snapshot with the specified name" do
|
38
|
+
expect(rds_client).to receive(:create_db_snapshot)
|
39
|
+
subject.create_snapshot('test', ['test_db'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#get_db_snapshots" do
|
44
|
+
let(:snapshots) { double('snapshots', db_snapshots: rds_snapshots) }
|
45
|
+
|
46
|
+
it "returns the list of snapshots from the client" do
|
47
|
+
allow(snapshots).to receive(:[]).with(:marker).and_return(nil)
|
48
|
+
expect(rds_client).to receive(:describe_db_snapshots).and_return(snapshots)
|
49
|
+
snapshots = subject.get_db_snapshots(options)
|
50
|
+
expect(snapshots).to eq(rds_snapshots)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
class Test
|
57
|
+
include RdsRotateDbSnapshots::Actions
|
58
|
+
|
59
|
+
attr_reader :options
|
60
|
+
|
61
|
+
def initialize(script_name: nil, cli: false, options: {})
|
62
|
+
@script_name = script_name
|
63
|
+
@options = options
|
64
|
+
@cli = cli
|
65
|
+
parse_options if cli?
|
66
|
+
@backoff_counter = 0
|
67
|
+
end
|
68
|
+
|
69
|
+
def reset_backoff
|
70
|
+
@backoff_counter = 0
|
71
|
+
end
|
72
|
+
|
73
|
+
def time_periods
|
74
|
+
@options[:time_periods] || {}
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def cli?
|
80
|
+
!!@cli
|
81
|
+
end
|
82
|
+
|
83
|
+
def parse_options
|
84
|
+
@options = RdsRotateDbSnapshots::OptionsParser.new(script_name: @script_name, cli: @cli).parse!
|
85
|
+
end
|
86
|
+
|
87
|
+
def backoff
|
88
|
+
@backoff_counter = @backoff_counter + 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe RdsRotateDbSnapshots::Actions do
|
93
|
+
subject { Test.new }
|
94
|
+
|
95
|
+
it_behaves_like 'rds_rotate_db_snapshots actions'
|
96
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe RdsRotateDbSnapshots::OptionsParser do
|
4
|
+
let(:script_name) { "rds_rotate_snapshots.rb" }
|
5
|
+
subject { RdsRotateDbSnapshots::OptionsParser.new(script_name: script_name, cli: true).parse! }
|
6
|
+
|
7
|
+
describe "#parse!" do
|
8
|
+
before { ARGV.clear }
|
9
|
+
|
10
|
+
it "parses options correctly" do
|
11
|
+
ARGV.concat(["--aws-access-key", "ACCESS_KEY",
|
12
|
+
"--aws-secret-access-key", "SECRET_KEY",
|
13
|
+
"--aws-region", "REGION",
|
14
|
+
"--pattern", "PATTERN",
|
15
|
+
"--backoff-limit", "20",
|
16
|
+
"--create-snapshot", "snapshot"])
|
17
|
+
options = subject
|
18
|
+
|
19
|
+
expect(options[:aws_access_key]).to eq("ACCESS_KEY")
|
20
|
+
expect(options[:aws_secret_access_key]).to eq("SECRET_KEY")
|
21
|
+
expect(options[:aws_region]).to eq("REGION")
|
22
|
+
expect(options[:pattern]).to eq("PATTERN")
|
23
|
+
expect(options[:backoff_limit]).to eq("20")
|
24
|
+
expect(options[:create_snapshot]).to eq("snapshot")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises NotImplementedError when by-tags option is passed and it is not implemented" do
|
28
|
+
ARGV.concat(["--by-tags", "tag=value,tag2=value"])
|
29
|
+
|
30
|
+
expect { subject }.to raise_error(RdsRotateDbSnapshots::OptionsParser::NotImplementedError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe RdsRotateDbSnapshots::RdsClient do
|
4
|
+
let(:options) { {
|
5
|
+
:aws_access_key => "ACCESS_KEY",
|
6
|
+
:aws_secret_access_key => "SECRET_KEY",
|
7
|
+
:aws_session_token => "SESSION_TOKEN",
|
8
|
+
:aws_region => "REGION"
|
9
|
+
} }
|
10
|
+
let(:rds_client) { RdsRotateDbSnapshots::RdsClient.new(options) }
|
11
|
+
|
12
|
+
it 'configures the client with the correct credentials and region' do
|
13
|
+
expect(rds_client.instance_variable_get(:@client).config.credentials).
|
14
|
+
to have_attributes(access_key_id: "ACCESS_KEY", secret_access_key: "SECRET_KEY", session_token: "SESSION_TOKEN")
|
15
|
+
expect(rds_client.instance_variable_get(:@client).config.region).to eq("REGION")
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'delegates describe_db_snapshots method to the @client object' do
|
19
|
+
expect(rds_client.instance_variable_get(:@client)).to receive(:describe_db_snapshots)
|
20
|
+
rds_client.describe_db_snapshots
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'delegates create_db_snapshot method to the @client object' do
|
24
|
+
expect(rds_client.instance_variable_get(:@client)).to receive(:create_db_snapshot)
|
25
|
+
rds_client.create_db_snapshot("test-snapshot")
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'delegates delete_db_snapshot method to the @client object' do
|
29
|
+
expect(rds_client.instance_variable_get(:@client)).to receive(:delete_db_snapshot)
|
30
|
+
rds_client.delete_db_snapshot("test-snapshot")
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rds-rotate-db-snapshots
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siarhei Kavaliou
|
@@ -108,7 +108,11 @@ files:
|
|
108
108
|
- lib/rds_rotate_db_snapshots/rds_client.rb
|
109
109
|
- rds-rotate-db-snapshots.gemspec
|
110
110
|
- spec/helper.rb
|
111
|
-
- spec/
|
111
|
+
- spec/lib/rds_rotate_db_snapshots/action_wrappers_spec.rb
|
112
|
+
- spec/lib/rds_rotate_db_snapshots/actions_spec.rb
|
113
|
+
- spec/lib/rds_rotate_db_snapshots/options_parser_spec.rb
|
114
|
+
- spec/lib/rds_rotate_db_snapshots/rds_client_spec.rb
|
115
|
+
- spec/lib/rds_rotate_db_snapshots_spec.rb
|
112
116
|
homepage: http://github.com/serg-kovalev/rds-rotate-db-snapshots
|
113
117
|
licenses:
|
114
118
|
- MIT
|