ebs_snapper 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ebs_snapper.gemspec +7 -4
- data/lib/ebs_snapper/version.rb +4 -4
- data/spec/lib/ebs_spec.rb +68 -68
- metadata +46 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cb6f5bd627a4e313748244d4b636a7cf304123b5
|
4
|
+
data.tar.gz: a7e27644727f54cfde5dc9068df90141319f0371
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f507337479c0be1df17d56e3bc922d004422ac89b3e25a3a1522c46f6ab4c511d532de431b61b9fc21080f08656e99aaa255dbb4b9a07f47b3533a8e1c7807c5
|
7
|
+
data.tar.gz: c6d1d8a4c14526bbbf04a272cf2eb5c4f8846467c420172c847ea337e45be660efe2a2f780da70e4800af1e45025683690dc73609a9681082af37d7efb1897c7
|
data/ebs_snapper.gemspec
CHANGED
@@ -15,11 +15,14 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.name = "ebs_snapper"
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.version = EbsSnapper::VERSION
|
18
|
-
|
19
|
-
s.add_runtime_dependency "aws-sdk", "~>
|
20
|
-
|
18
|
+
|
19
|
+
# s.add_runtime_dependency "aws-sdk", "~> 2.0"
|
20
|
+
s.add_runtime_dependency "aws-sdk", '~> 1.57.0'
|
21
|
+
s.add_runtime_dependency "aws-sdk-v1"
|
22
|
+
|
21
23
|
s.add_development_dependency "rake"
|
22
24
|
s.add_development_dependency "rspec"
|
25
|
+
s.add_development_dependency "rspec-mocks"
|
23
26
|
s.add_development_dependency "fakeweb"
|
24
|
-
|
27
|
+
|
25
28
|
end
|
data/lib/ebs_snapper/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Copyright 2012 NeuStar, Inc. All rights reserved.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -13,5 +13,5 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module EbsSnapper
|
16
|
-
VERSION = "0.0.
|
16
|
+
VERSION = "0.0.10"
|
17
17
|
end
|
data/spec/lib/ebs_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Copyright 2012 NeuStar, Inc. All rights reserved.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
5
5
|
# You may obtain a copy of the License at
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Unless required by applicable law or agreed to in writing, software
|
10
10
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -16,106 +16,106 @@ require 'spec_helper'
|
|
16
16
|
require 'fakeweb'
|
17
17
|
require 'ostruct'
|
18
18
|
|
19
|
-
describe EbsSnapper::Ebs do
|
19
|
+
describe EbsSnapper::Ebs do
|
20
20
|
DEFAULT_TAG_NAME = EbsSnapper::Ebs::DEFAULT_TAG_NAME
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
|
23
23
|
it "should run purge_old_snapshots in dry mode" do
|
24
24
|
ebs = EbsSnapper::Ebs.new({}, true)
|
25
25
|
ttl = EbsSnapper::Ebs::TTL.new("1.day") # 1 day
|
26
26
|
region = OpenStruct.new
|
27
|
-
|
27
|
+
|
28
28
|
snapshot_old = OpenStruct.new
|
29
29
|
snapshot_old.status = :complete
|
30
30
|
snapshot_old.tags = {DEFAULT_TAG_NAME => Time.now.utc.to_i - (86400 * 2)}
|
31
|
-
snapshot_old.
|
32
|
-
|
31
|
+
expect(snapshot_old).to_not receive(:delete)
|
32
|
+
|
33
33
|
region.snapshots = [snapshot_old]
|
34
34
|
region.snapshots.stub(:filter).and_return(region.snapshots)
|
35
|
-
|
35
|
+
|
36
36
|
ebs.purge_old_snapshots(ttl, region, 2)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should run snapshot_volume in dry mode" do
|
40
40
|
ebs = EbsSnapper::Ebs.new({}, true)
|
41
|
-
|
41
|
+
|
42
42
|
region = OpenStruct.new
|
43
43
|
region.tags = []
|
44
44
|
region.id = '999'
|
45
|
-
|
45
|
+
|
46
46
|
volume = OpenStruct.new
|
47
47
|
volume.should_not_receive(:create_snapshot)
|
48
48
|
region.volumes = {3 => volume}
|
49
|
-
|
50
|
-
ebs.snapshot_volume(region, 3).
|
49
|
+
|
50
|
+
expect(ebs.snapshot_volume(region, 3)).to eql(true)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should find tagged volumes in a region" do
|
54
54
|
ebs = EbsSnapper::Ebs.new
|
55
|
-
|
55
|
+
|
56
56
|
tag = OpenStruct.new
|
57
57
|
tag.resource = OpenStruct.new(:id => 1)
|
58
|
-
|
58
|
+
|
59
59
|
tags = [tag]
|
60
60
|
tags.stub(:filter).and_return(tags)
|
61
|
-
|
61
|
+
|
62
62
|
region = OpenStruct.new
|
63
63
|
region.tags = tags
|
64
64
|
region.id = '999'
|
65
|
-
|
65
|
+
|
66
66
|
ebs.stub(:each_region).and_yield(region)
|
67
|
-
|
67
|
+
|
68
68
|
vols = ebs.tagged_volumes
|
69
|
-
vols.size.
|
69
|
+
expect(vols.size).to eql(1)
|
70
|
+
|
71
|
+
expect(vols[0][:region].id).to eql(region.id)
|
72
|
+
expect(vols[0][:volume_id]).to be == tag.resource.id
|
73
|
+
expect(vols[0][:ttl]).to_not be == nil
|
70
74
|
|
71
|
-
vols[0][:region].id.should == region.id
|
72
|
-
vols[0][:volume_id].should == tag.resource.id
|
73
|
-
vols[0][:ttl].should_not == nil
|
74
|
-
|
75
75
|
two_days_secs = EbsSnapper::Ebs::TTL.new().convert_to_seconds(0).to_i
|
76
76
|
span_begin = (Time.now.utc.to_i - two_days_secs) - 10
|
77
77
|
span_end = (Time.now.utc.to_i - two_days_secs) + 1
|
78
|
-
vols[0][:ttl].cut_off.
|
79
|
-
vols[0][:ttl].cut_off.
|
78
|
+
expect(vols[0][:ttl].cut_off).to be > span_begin
|
79
|
+
expect(vols[0][:ttl].cut_off).to be < span_end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should use retention from the tag in a volume in a region" do
|
83
83
|
ebs = EbsSnapper::Ebs.new
|
84
|
-
|
84
|
+
|
85
85
|
tag = OpenStruct.new
|
86
86
|
tag.resource = OpenStruct.new(:id => 1)
|
87
87
|
tag.value = "2.days"
|
88
|
-
|
88
|
+
|
89
89
|
tags = [tag]
|
90
90
|
tags.stub(:filter).and_return(tags)
|
91
|
-
|
91
|
+
|
92
92
|
region = OpenStruct.new
|
93
93
|
region.tags = tags
|
94
94
|
region.id = '999'
|
95
|
-
|
95
|
+
|
96
96
|
ebs.stub(:each_region).and_yield(region)
|
97
|
-
|
97
|
+
|
98
98
|
vols = ebs.tagged_volumes
|
99
99
|
vols.size.should == 1
|
100
100
|
|
101
101
|
vols[0][:region].id.should == region.id
|
102
102
|
vols[0][:volume_id].should == tag.resource.id
|
103
103
|
vols[0][:ttl].should_not == nil
|
104
|
-
|
104
|
+
|
105
105
|
two_days_secs = EbsSnapper::Ebs::TTL.new().convert_to_seconds('2.days').to_i
|
106
106
|
span_begin = (Time.now.utc.to_i - two_days_secs) - 10
|
107
107
|
span_end = (Time.now.utc.to_i - two_days_secs) + 1
|
108
108
|
vols[0][:ttl].cut_off.should > span_begin
|
109
109
|
vols[0][:ttl].cut_off.should < span_end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
it "should pruge old timestamps" do
|
113
113
|
ttl = EbsSnapper::Ebs::TTL.new("1.day") # 1 day
|
114
114
|
ttl.purge?(Time.now.utc.to_i - (86400 * 3)).should == true
|
115
115
|
ttl.purge?(Time.now.utc.to_i - (86400 + 3601)).should == true
|
116
116
|
ttl.purge?("#{Time.now.utc.to_i - (86400 + 3601)}").should == true
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
it "shouldn't pruge new timestamps" do
|
120
120
|
ttl = EbsSnapper::Ebs::TTL.new("1.day") # 1 day
|
121
121
|
ttl.purge?(Time.now.utc.to_i - (3600)).should == false
|
@@ -124,19 +124,19 @@ describe EbsSnapper::Ebs do
|
|
124
124
|
# we give it 1 hr around the timestamp
|
125
125
|
ttl.purge?(Time.now.utc.to_i - 86400).should == false
|
126
126
|
end
|
127
|
-
|
127
|
+
|
128
128
|
it "should convert day ttls to seconds" do
|
129
129
|
ttl = EbsSnapper::Ebs::TTL.new("1.day") # 1 day
|
130
130
|
ttl.convert_to_seconds("1.day").should == 86400 + 3600
|
131
131
|
cut_off_10 = ttl.convert_to_seconds("10.days")
|
132
|
-
cut_off_10.should == (86400 * 10) + 3600
|
132
|
+
cut_off_10.should == (86400 * 10) + 3600
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
it "should convert hour ttls to seconds" do
|
136
|
-
ttl = EbsSnapper::Ebs::TTL.new()
|
136
|
+
ttl = EbsSnapper::Ebs::TTL.new()
|
137
137
|
ttl.convert_to_seconds("3.hours").should == (3600 * 3)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
it "should set default ttl to seconds" do
|
141
141
|
ten_days_secs = (86400 * 10) + 3600
|
142
142
|
between_a = Time.now.utc.to_i - ten_days_secs
|
@@ -145,69 +145,69 @@ describe EbsSnapper::Ebs do
|
|
145
145
|
between_b = tm - ten_days_secs
|
146
146
|
ttl.cut_off.should >= between_a
|
147
147
|
ttl.cut_off.should <= between_b
|
148
|
-
|
148
|
+
|
149
149
|
ttl.convert_to_seconds("asfljasdfjl").should == ten_days_secs
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it "should snapshot a volume" do
|
153
|
-
|
153
|
+
|
154
154
|
ebs = EbsSnapper::Ebs.new
|
155
|
-
|
155
|
+
|
156
156
|
tag = OpenStruct.new
|
157
157
|
tag.resource = OpenStruct.new(:id => 1)
|
158
|
-
|
158
|
+
|
159
159
|
tags = [tag]
|
160
160
|
tags.stub(:filter).and_return(tags)
|
161
|
-
|
161
|
+
|
162
162
|
region = OpenStruct.new
|
163
163
|
region.tags = tags
|
164
164
|
region.id = '999'
|
165
|
-
|
165
|
+
|
166
166
|
snapshot = Object.new
|
167
|
-
snapshot.
|
168
|
-
hash_including(:value =>
|
169
|
-
|
167
|
+
expect(snapshot).to receive(:tag).with(DEFAULT_TAG_NAME,
|
168
|
+
hash_including(:value => match(/^\d+/))) {true}
|
169
|
+
|
170
170
|
volume = OpenStruct.new
|
171
|
-
volume.
|
171
|
+
expect(volume).to receive(:create_snapshot) {snapshot}
|
172
172
|
region.volumes = {3 => volume}
|
173
173
|
ebs.snapshot_volume(region, 3).should == true
|
174
174
|
|
175
175
|
# id 1 is not found (nil)
|
176
176
|
ebs.snapshot_volume(region, 1).should == true
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
it "should purge old snapshots" do
|
180
180
|
ebs = EbsSnapper::Ebs.new
|
181
181
|
ttl = EbsSnapper::Ebs::TTL.new("1.day") # 1 day
|
182
182
|
region = OpenStruct.new
|
183
|
-
|
183
|
+
|
184
184
|
snapshot_old = OpenStruct.new
|
185
185
|
snapshot_old.status = :complete
|
186
186
|
snapshot_old.tags = {DEFAULT_TAG_NAME => Time.now.utc.to_i - (86400 * 2)}
|
187
|
-
snapshot_old.
|
187
|
+
expect(snapshot_old).to receive(:delete)
|
188
188
|
|
189
189
|
snapshot_old_error = OpenStruct.new
|
190
190
|
snapshot_old_error.status = :error
|
191
191
|
snapshot_old_error.tags = {DEFAULT_TAG_NAME => Time.now.utc.to_i - (86400 * 2)}
|
192
|
-
snapshot_old_error.
|
193
|
-
|
194
|
-
|
192
|
+
expect(snapshot_old_error).to receive(:delete)
|
193
|
+
|
194
|
+
|
195
195
|
snapshot_new = OpenStruct.new
|
196
196
|
snapshot_new.status = :complete
|
197
197
|
snapshot_new.tags = {DEFAULT_TAG_NAME => Time.now.utc.to_i - (3600 * 3)}
|
198
|
-
snapshot_new.
|
199
|
-
|
198
|
+
expect(snapshot_new).to_not receive(:delete)
|
199
|
+
|
200
200
|
snapshot_pending = OpenStruct.new
|
201
201
|
snapshot_pending.status = :pending
|
202
202
|
snapshot_pending.tags = {DEFAULT_TAG_NAME => Time.now.utc.to_i - (86400 * 3)}
|
203
|
-
snapshot_pending.
|
204
|
-
|
203
|
+
expect(snapshot_pending).to_not receive(:delete)
|
204
|
+
|
205
205
|
region.snapshots = [snapshot_old, snapshot_new, snapshot_pending, snapshot_old_error]
|
206
206
|
region.snapshots.stub(:filter).and_return(region.snapshots)
|
207
|
-
|
207
|
+
|
208
208
|
ebs.purge_old_snapshots(ttl, region, 2)
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it "should flow through snapshot and purge" do
|
212
212
|
ebs = EbsSnapper::Ebs.new
|
213
213
|
ebs.stub(:tagged_volumes).and_return([{
|
@@ -215,9 +215,9 @@ describe EbsSnapper::Ebs do
|
|
215
215
|
:region => 'us-east-1',
|
216
216
|
:volume_id => 1
|
217
217
|
}])
|
218
|
-
|
219
|
-
ebs.
|
220
|
-
ebs.
|
218
|
+
|
219
|
+
expect(ebs).to receive(:snapshot_volume).with(anything(), anything()).once
|
220
|
+
expect(ebs).to receive(:purge_old_snapshots).with(anything(), anything(), anything()).once
|
221
221
|
|
222
222
|
ebs.snapshot_and_purge()
|
223
223
|
end
|
metadata
CHANGED
@@ -1,78 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebs_snapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.10
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- ultradns
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-10-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: aws-sdk
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
19
|
+
version: 1.57.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
26
|
+
version: 1.57.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-v1
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
30
41
|
- !ruby/object:Gem::Dependency
|
31
42
|
name: rake
|
32
43
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
44
|
requirements:
|
35
|
-
- -
|
45
|
+
- - ">="
|
36
46
|
- !ruby/object:Gem::Version
|
37
47
|
version: '0'
|
38
48
|
type: :development
|
39
49
|
prerelease: false
|
40
50
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
51
|
requirements:
|
43
|
-
- -
|
52
|
+
- - ">="
|
44
53
|
- !ruby/object:Gem::Version
|
45
54
|
version: '0'
|
46
55
|
- !ruby/object:Gem::Dependency
|
47
56
|
name: rspec
|
48
57
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
58
|
requirements:
|
51
|
-
- -
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-mocks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
52
74
|
- !ruby/object:Gem::Version
|
53
75
|
version: '0'
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - ">="
|
60
81
|
- !ruby/object:Gem::Version
|
61
82
|
version: '0'
|
62
83
|
- !ruby/object:Gem::Dependency
|
63
84
|
name: fakeweb
|
64
85
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
86
|
requirements:
|
67
|
-
- -
|
87
|
+
- - ">="
|
68
88
|
- !ruby/object:Gem::Version
|
69
89
|
version: '0'
|
70
90
|
type: :development
|
71
91
|
prerelease: false
|
72
92
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
93
|
requirements:
|
75
|
-
- -
|
94
|
+
- - ">="
|
76
95
|
- !ruby/object:Gem::Version
|
77
96
|
version: '0'
|
78
97
|
description: Manage snapshots of EBS volumes
|
@@ -83,7 +102,7 @@ executables:
|
|
83
102
|
extensions: []
|
84
103
|
extra_rdoc_files: []
|
85
104
|
files:
|
86
|
-
- .gitignore
|
105
|
+
- ".gitignore"
|
87
106
|
- Gemfile
|
88
107
|
- LICENSE
|
89
108
|
- README.md
|
@@ -99,33 +118,26 @@ files:
|
|
99
118
|
- spec/spec_helper.rb
|
100
119
|
homepage: https://github.com/ultradns/ebs_snapper
|
101
120
|
licenses: []
|
121
|
+
metadata: {}
|
102
122
|
post_install_message:
|
103
123
|
rdoc_options: []
|
104
124
|
require_paths:
|
105
125
|
- lib
|
106
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
127
|
requirements:
|
109
|
-
- -
|
128
|
+
- - ">="
|
110
129
|
- !ruby/object:Gem::Version
|
111
130
|
version: '0'
|
112
|
-
segments:
|
113
|
-
- 0
|
114
|
-
hash: 1635891677389619037
|
115
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
132
|
requirements:
|
118
|
-
- -
|
133
|
+
- - ">="
|
119
134
|
- !ruby/object:Gem::Version
|
120
135
|
version: '0'
|
121
|
-
segments:
|
122
|
-
- 0
|
123
|
-
hash: 1635891677389619037
|
124
136
|
requirements: []
|
125
137
|
rubyforge_project:
|
126
|
-
rubygems_version:
|
138
|
+
rubygems_version: 2.2.2
|
127
139
|
signing_key:
|
128
|
-
specification_version:
|
140
|
+
specification_version: 4
|
129
141
|
summary: Manage snapshots of EBS volumes
|
130
142
|
test_files:
|
131
143
|
- spec/lib/ebs_spec.rb
|