automan 2.3.5 → 2.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -5
  3. data/automan.gemspec +3 -3
  4. data/lib/automan.rb +0 -1
  5. data/lib/automan/base.rb +3 -7
  6. data/lib/automan/beanstalk/deployer.rb +1 -1
  7. data/lib/automan/beanstalk/package.rb +1 -1
  8. data/lib/automan/beanstalk/router.rb +1 -1
  9. data/lib/automan/cli/snapper.rb +23 -3
  10. data/lib/automan/cli/stacker.rb +0 -19
  11. data/lib/automan/cloudformation/launcher.rb +3 -6
  12. data/lib/automan/cloudformation/replacer.rb +1 -1
  13. data/lib/automan/cloudformation/terminator.rb +1 -1
  14. data/lib/automan/ec2/image.rb +3 -3
  15. data/lib/automan/mixins/aws_caller.rb +7 -21
  16. data/lib/automan/rds/snapshot.rb +25 -35
  17. data/lib/automan/s3/downloader.rb +1 -10
  18. data/lib/automan/version.rb +1 -1
  19. data/spec/beanstalk/application_spec.rb +17 -17
  20. data/spec/beanstalk/configuration_spec.rb +24 -24
  21. data/spec/beanstalk/deployer_spec.rb +65 -65
  22. data/spec/beanstalk/router_spec.rb +19 -18
  23. data/spec/beanstalk/terminator_spec.rb +16 -16
  24. data/spec/beanstalk/uploader_spec.rb +13 -13
  25. data/spec/beanstalk/version_spec.rb +10 -8
  26. data/spec/cloudformation/launcher_spec.rb +65 -63
  27. data/spec/cloudformation/replacer_spec.rb +10 -10
  28. data/spec/cloudformation/terminator_spec.rb +23 -23
  29. data/spec/cloudformation/uploader_spec.rb +13 -13
  30. data/spec/ec2/image_spec.rb +55 -55
  31. data/spec/ec2/instance_spec.rb +17 -17
  32. data/spec/mixins/aws_caller_spec.rb +9 -9
  33. data/spec/mixins/utils_spec.rb +28 -27
  34. data/spec/rds/snapshot_spec.rb +46 -44
  35. metadata +9 -22
  36. data/.ruby-gemset +0 -1
  37. data/.ruby-version +0 -1
  38. data/.travis.yml +0 -5
  39. data/lib/automan/elasticache/router.rb +0 -79
  40. data/spec/elasticache/router_spec.rb +0 -29
  41. data/templates/stacker/.env.example +0 -14
  42. data/templates/stacker/.gitignore +0 -2
  43. data/templates/stacker/.ruby-gemset.tt +0 -1
  44. data/templates/stacker/.ruby-version +0 -1
  45. data/templates/stacker/Gemfile +0 -4
  46. data/templates/stacker/bin/%app_name%.tt +0 -62
  47. data/templates/stacker/bin/launch_%app_name%.sh.tt +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01c86c545002df8eeab70eaa5ed9d85383f7e5b3
4
- data.tar.gz: 3db10a2896e2200b1e11c036036e9c83e44909cc
3
+ metadata.gz: ba8bf0ad1d6385060e00b45ab199391f2520c179
4
+ data.tar.gz: 54e997202865573a99b4b21005869e79a3374977
5
5
  SHA512:
6
- metadata.gz: f39d57e90b286ab40593baf3a80230f09fd8cad9b7a1ffd47b8562accb15d1a630d694f1d8ad1593732d97c4a7f452cd441beb1684d882a7c2d0028193f4a842
7
- data.tar.gz: d00e9dd6958af11f067eeb8d3fb6a0ba3d6190640b605591a04433c56a7b671fc51778ad166243ce1d19f52a201076f93f560e84c3b54a691c1f17453ca0b7d2
6
+ metadata.gz: af5c94a4677e630eca5ef7e9d2d4fb47b306b7e7dec0ffaa23246f57009855947b6df6378b31748cb671a7110ed1051b7bbd1b76ac6be857e6f2675f38755713
7
+ data.tar.gz: a5ca5a4b040037645bd92541bc4e3c1c6800ca6faa3539b28f6cdd7854b192f2c7159a91a3afc39f62eaac25d37f5f52c450c7d45a700a3152f51e1c58362b91
data/Rakefile CHANGED
@@ -1,6 +1 @@
1
1
  require "bundler/gem_tasks"
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.3"
21
21
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "rspec-core", "~> 3"
23
- spec.add_development_dependency "rspec-mocks", "~> 3"
24
- spec.add_development_dependency "rspec-expectations", "~> 3"
22
+ spec.add_development_dependency "rspec-core", "~> 2.12.2"
23
+ spec.add_development_dependency "rspec-mocks", "~> 2.12.2"
24
+ spec.add_development_dependency "rspec-expectations", "~> 2.12.1"
25
25
  spec.add_dependency "aws-sdk", "< 2.0"
26
26
  spec.add_dependency "thor"
27
27
  spec.add_dependency "json"
@@ -19,7 +19,6 @@ require 'automan/cloudformation/terminator'
19
19
  require 'automan/cloudformation/replacer'
20
20
  require 'automan/cloudformation/uploader'
21
21
  require 'automan/cloudformation/errors'
22
- require 'automan/elasticache/router'
23
22
  require 'automan/rds/snapshot'
24
23
  require 'automan/rds/errors'
25
24
  require 'automan/ec2/instance'
@@ -12,9 +12,11 @@ module Automan
12
12
 
13
13
  include Automan::Mixins::AwsCaller
14
14
 
15
- def initialize(options={})
15
+ def initialize(options=nil)
16
16
  $stdout.sync = true
17
17
  @logger = Logger.new(STDOUT)
18
+ @log_aws_calls = false
19
+ #@wait = Wait.new(rescuer: WaitRescuer.new, logger: @logger)
18
20
 
19
21
  if !options.nil?
20
22
  options.each_pair do |k,v|
@@ -22,12 +24,6 @@ module Automan
22
24
  send(accessor, v) if respond_to? accessor
23
25
  end
24
26
  end
25
-
26
- aws_options = {}
27
- if options[:log_aws]
28
- aws_options[:logger] = @logger
29
- end
30
- configure_aws(aws_options)
31
27
  end
32
28
 
33
29
  def self.add_option(*args)
@@ -18,7 +18,7 @@ module Automan::Beanstalk
18
18
 
19
19
  include Automan::Mixins::Utils
20
20
 
21
- def initialize(options={})
21
+ def initialize(options=nil)
22
22
  @number_to_keep = 0
23
23
  super
24
24
  end
@@ -13,7 +13,7 @@ module Automan::Beanstalk
13
13
 
14
14
  # verify local package exists
15
15
  unless File.exists? source
16
- raise MissingPackageFileError, "package file #{source} does not exist"
16
+ raise MissingPackageFile, "package file #{source} does not exist"
17
17
  end
18
18
 
19
19
  logger.info "Uploading #{source} to #{destination}"
@@ -10,7 +10,7 @@ module Automan::Beanstalk
10
10
 
11
11
  attr_accessor :attempts_made
12
12
 
13
- def initialize(options={})
13
+ def initialize(options=nil)
14
14
  super
15
15
  @wait = Wait.new({
16
16
  attempts: 10,
@@ -37,9 +37,8 @@ module Automan::Cli
37
37
  exit 1
38
38
  end
39
39
 
40
- aws_opts = options.dup
41
- aws_opts[:log_aws] = true
42
- s = Automan::RDS::Snapshot.new(aws_opts)
40
+ s = Automan::RDS::Snapshot.new(options)
41
+ s.log_aws_calls = true
43
42
  s.prune_snapshots if options[:prune]
44
43
  s.create
45
44
  end
@@ -75,5 +74,26 @@ module Automan::Cli
75
74
  Automan::RDS::Snapshot.new(options).latest
76
75
  end
77
76
 
77
+ desc "count", "return the number of snapshots"
78
+
79
+ option :environment,
80
+ aliases: "-e",
81
+ desc: "environment of database to snapshot"
82
+
83
+ option :database,
84
+ aliases: "-d",
85
+ desc: "name of the database to snapshot"
86
+
87
+ def count
88
+
89
+ if options[:database].nil? && options[:environment].nil?
90
+ puts "Must specify either database or environment"
91
+ help "count"
92
+ exit 1
93
+ end
94
+
95
+ Automan::RDS::Snapshot.new(options).count_snapshots
96
+ end
97
+
78
98
  end
79
99
  end
@@ -102,24 +102,5 @@ module Automan::Cli
102
102
  h = Automan::Cloudformation::Launcher.new(options).parse_template_parameters
103
103
  say JSON.pretty_generate h
104
104
  end
105
-
106
- include Thor::Actions
107
- def self.source_root
108
- File.join(File.dirname(__FILE__),'..','..', '..')
109
- end
110
-
111
- desc "project APP_NAME", "create stacker project"
112
-
113
- attr_reader :app_name
114
-
115
- def project(app_name)
116
- @app_name = app_name
117
-
118
- say "\nCreating stacker project: #{app_name}\n", :yellow
119
- directory 'templates/stacker', app_name
120
- [app_name, "launch_#{app_name}.sh"].each do |file|
121
- chmod File.join(app_name, 'bin', file), 0755
122
- end
123
- end
124
105
  end
125
106
  end
@@ -16,7 +16,7 @@ module Automan::Cloudformation
16
16
 
17
17
  include Automan::Mixins::Utils
18
18
 
19
- def initialize(options={})
19
+ def initialize(options=nil)
20
20
  @wait_for_completion = false
21
21
  super
22
22
  @wait = Wait.new({
@@ -148,8 +148,6 @@ module Automan::Cloudformation
148
148
 
149
149
  logger.info "updating stack #{name}"
150
150
 
151
- no_updates_needed = false
152
-
153
151
  # if cfn determines that no updates are to be performed,
154
152
  # it raises a ValidationError
155
153
  begin
@@ -159,11 +157,10 @@ module Automan::Cloudformation
159
157
  raise e
160
158
  else
161
159
  logger.info e.message
162
- no_updates_needed = true
163
160
  end
164
161
  end
165
162
 
166
- if !no_updates_needed && wait_for_completion
163
+ if wait_for_completion
167
164
  logger.info "waiting for stack #{name} to update"
168
165
  wait_until { stack_update_complete? }
169
166
  end
@@ -196,4 +193,4 @@ module Automan::Cloudformation
196
193
  end
197
194
  end
198
195
 
199
- end
196
+ end
@@ -5,7 +5,7 @@ module Automan::Cloudformation
5
5
  class Replacer < Automan::Base
6
6
  add_option :name
7
7
 
8
- def initialize(options={})
8
+ def initialize(options=nil)
9
9
  super
10
10
  @wait = Wait.new({
11
11
  delay: 60,
@@ -4,7 +4,7 @@ module Automan::Cloudformation
4
4
  class Terminator < Automan::Base
5
5
  add_option :name, :wait_for_completion
6
6
 
7
- def initialize(options={})
7
+ def initialize(options=nil)
8
8
  @wait_for_completion = false
9
9
  super
10
10
  @wait = Wait.new({
@@ -7,7 +7,7 @@ module Automan::Ec2
7
7
 
8
8
  include Automan::Mixins::Utils
9
9
 
10
- def initialize(options={})
10
+ def initialize(options=nil)
11
11
  super
12
12
  @wait = Wait.new({
13
13
  delay: 5,
@@ -45,7 +45,7 @@ module Automan::Ec2
45
45
  end
46
46
 
47
47
  def default_image_name
48
- stime = Time.now.utc.iso8601.gsub(/[:+]/, '')
48
+ stime = Time.new.iso8601.gsub(/:/, '-')
49
49
  return name + "-" + stime
50
50
  end
51
51
 
@@ -134,4 +134,4 @@ module Automan::Ec2
134
134
  end
135
135
 
136
136
  end
137
- end
137
+ end
@@ -8,20 +8,14 @@ module Automan
8
8
  ENV['AWS_ACCOUNT_ID']
9
9
  end
10
10
 
11
- def configure_aws(options={})
12
- if ENV['AWS_ROLE']
13
- sts = AWS::STS.new
14
-
15
- @logger.info "Assuming role #{ENV['AWS_ROLE']}"
16
- provider = AWS::Core::CredentialProviders::AssumeRoleProvider.new(
17
- sts: sts,
18
- role_arn: ENV['AWS_ROLE'],
19
- role_session_name: "automan-aws-sdk"
20
- )
21
- options[:credential_provider] = provider
11
+ attr_reader :log_aws_calls
12
+ def log_aws_calls=(value)
13
+ if value == true
14
+ AWS.config(logger: @logger)
15
+ else
16
+ AWS.config(logger: nil)
22
17
  end
23
-
24
- AWS.config(options)
18
+ @log_aws_calls = value
25
19
  end
26
20
 
27
21
  attr_writer :eb
@@ -108,14 +102,6 @@ module Automan
108
102
  @rds
109
103
  end
110
104
 
111
- attr_writer :ec
112
- def ec
113
- if @ec.nil?
114
- @ec = AWS::ElastiCache.new
115
- end
116
- @ec
117
- end
118
-
119
105
  attr_writer :ec2
120
106
  def ec2
121
107
  if @ec2.nil?
@@ -12,7 +12,7 @@ module Automan::RDS
12
12
 
13
13
  attr_accessor :max_snapshots
14
14
 
15
- def initialize(options={})
15
+ def initialize(options=nil)
16
16
  @prune = true
17
17
  @wait_for_completion = false
18
18
  super
@@ -33,8 +33,6 @@ module Automan::RDS
33
33
 
34
34
  include Automan::Mixins::Utils
35
35
 
36
- # TODO move this and dependecies to an RDS utils class
37
- # so we can re-use it
38
36
  def find_db
39
37
  db = nil
40
38
  if !database.nil?
@@ -65,9 +63,7 @@ module Automan::RDS
65
63
  end
66
64
 
67
65
  def snapshot_count
68
- AWS.memoize do
69
- rds.db_instances[database].snapshots.count
70
- end
66
+ rds.db_instances[find_db.id].snapshots.count
71
67
  end
72
68
 
73
69
  def create
@@ -97,8 +93,8 @@ module Automan::RDS
97
93
  snap = db.create_snapshot(myname)
98
94
 
99
95
  if prune == true
100
- logger.info "Setting snapshot to be prunable and tagging environment"
101
- set_prunable_and_env(snap,environment)
96
+ logger.info "Setting snapshot to be prunable"
97
+ set_prunable(snap)
102
98
  end
103
99
 
104
100
  if wait_for_completion == true
@@ -124,7 +120,7 @@ module Automan::RDS
124
120
 
125
121
  def default_snapshot_name(db)
126
122
  env = db_environment db
127
- stime = Time.new.strftime("%Y-%m-%dT%H-%M")
123
+ stime = Time.new.iso8601.gsub(/:/,'-')
128
124
 
129
125
  return env + "-" + stime
130
126
  end
@@ -149,10 +145,10 @@ module Automan::RDS
149
145
  end
150
146
 
151
147
  # tag with CanPrune
152
- def set_prunable_and_env(snapshot,environment)
148
+ def set_prunable(snapshot)
153
149
  opts = {
154
150
  resource_name: snapshot_arn(snapshot),
155
- tags: [ {key: 'CanPrune', value: 'yes'}, {key: 'Environment', value: environment} ]
151
+ tags: [ {key: 'CanPrune', value: 'yes'} ]
156
152
  }
157
153
  response = rds.client.add_tags_to_resource opts
158
154
 
@@ -189,15 +185,6 @@ module Automan::RDS
189
185
  tagged_can_prune?(snapshot) && available?(snapshot) && manual?(snapshot)
190
186
  end
191
187
 
192
- def is_env?(snapshot,environment)
193
- tagged_env?(snapshot,environment) && available?(snapshot) && manual?(snapshot)
194
- end
195
-
196
- def tagged_env?(snapshot,environment)
197
- arn = snapshot_arn(snapshot)
198
- tags(arn)['Environment'] == environment
199
- end
200
-
201
188
  def tagged_can_prune?(snapshot)
202
189
  arn = snapshot_arn(snapshot)
203
190
  tags(arn)['CanPrune'] == 'yes'
@@ -217,12 +204,14 @@ module Automan::RDS
217
204
  end
218
205
 
219
206
  def get_all_snapshots
220
- rds.db_snapshots
207
+ rds.db_instances[find_db.id].snapshots
221
208
  end
222
209
 
223
210
  def prunable_snapshots
224
- snapshots = get_all_snapshots
225
- snapshots.select { |s| can_prune?(s) }
211
+ AWS.memoize do
212
+ snapshots = get_all_snapshots
213
+ snapshots.select { |s| can_prune?(s) }
214
+ end
226
215
  end
227
216
 
228
217
  def oldest_prunable_snapshot
@@ -246,22 +235,23 @@ module Automan::RDS
246
235
  end
247
236
  end
248
237
 
249
- def latest
238
+ def count_snapshots
250
239
  log_options
251
- logger.info "Finding most recent snapshot for #{environment}"
252
-
253
- allsnaps=get_all_snapshots
254
-
255
- envsnaps=[]
256
- allsnaps.each do |onesnap|
257
- if is_env?(onesnap,environment)
258
- envsnaps.push(onesnap)
259
- end
240
+ db = find_db
241
+ if db.nil?
242
+ logger.info "Database not found"
243
+ else
244
+ logger.info "Number of snapshots for database #{db.id} is #{snapshot_count}"
245
+ logger.info "Number of prunable snapshots for database #{db.id} is #{prunable_snapshots.count}"
260
246
  end
247
+ end
261
248
 
262
- s=envsnaps.sort_by {|i| i.created_at }.last
249
+ def latest
250
+ log_options
251
+ db = find_db
252
+ logger.info "Finding most recent snapshot for #{db.id}"
253
+ s = db.snapshots.sort_by {|i| i.created_at }.last
263
254
  logger.info "Most recent snapshot is #{s.id}"
264
- s.id
265
255
  end
266
256
  end
267
257
  end
@@ -9,7 +9,7 @@ module Automan::S3
9
9
  def download
10
10
  log_options
11
11
 
12
- logger.info "downloading #{s3file} to #{localfile}"
12
+ logger.info "uploading #{localfile} to #{s3file}"
13
13
 
14
14
  bucket, key = parse_s3_path s3file
15
15
 
@@ -18,16 +18,7 @@ module Automan::S3
18
18
  file.write(chunk)
19
19
  end
20
20
  end
21
- end
22
-
23
- def read
24
- log_options
25
-
26
- logger.info "returning contents of #{s3file} as string"
27
-
28
- bucket, key = parse_s3_path s3file
29
21
 
30
- s3.buckets[bucket].objects[key].read
31
22
  end
32
23
 
33
24
  end
@@ -1,3 +1,3 @@
1
1
  module Automan
2
- VERSION = "2.3.5"
2
+ VERSION = "2.3.6"
3
3
  end
@@ -1,12 +1,12 @@
1
1
  require "automan"
2
2
 
3
3
  describe Automan::Beanstalk::Application do
4
- it { is_expected.to respond_to :name }
5
- it { is_expected.to respond_to :create }
6
- it { is_expected.to respond_to :delete }
4
+ it { should respond_to :name }
5
+ it { should respond_to :create }
6
+ it { should respond_to :delete }
7
7
 
8
8
  describe '#create' do
9
- subject() do
9
+ subject(:a) do
10
10
  AWS.stub!
11
11
  a = Automan::Beanstalk::Application.new
12
12
  a.logger = Logger.new('/dev/null')
@@ -14,20 +14,20 @@ describe Automan::Beanstalk::Application do
14
14
  end
15
15
 
16
16
  it "does not create if the application already exists" do
17
- allow(subject).to receive(:application_exists?).and_return(true)
18
- expect(subject).to_not receive(:create_application)
19
- subject.create
17
+ a.stub(:application_exists?).and_return(true)
18
+ a.should_not_receive(:create_application)
19
+ a.create
20
20
  end
21
21
 
22
22
  it "does create if the application doesn't exist" do
23
- allow(subject).to receive(:application_exists?).and_return(false)
24
- expect(subject).to receive(:create_application)
25
- subject.create
23
+ a.stub(:application_exists?).and_return(false)
24
+ a.should_receive(:create_application)
25
+ a.create
26
26
  end
27
27
  end
28
28
 
29
29
  describe '#delete' do
30
- subject() do
30
+ subject(:a) do
31
31
  AWS.stub!
32
32
  a = Automan::Beanstalk::Application.new
33
33
  a.logger = Logger.new('/dev/null')
@@ -35,15 +35,15 @@ describe Automan::Beanstalk::Application do
35
35
  end
36
36
 
37
37
  it "does delete if the application already exists" do
38
- allow(subject).to receive(:application_exists?).and_return(true)
39
- expect(subject).to receive(:delete_application)
40
- subject.delete
38
+ a.stub(:application_exists?).and_return(true)
39
+ a.should_receive(:delete_application)
40
+ a.delete
41
41
  end
42
42
 
43
43
  it "does not delete if the application doesn't exist" do
44
- allow(subject).to receive(:application_exists?).and_return(false)
45
- expect(subject).to_not receive(:delete_application)
46
- subject.delete
44
+ a.stub(:application_exists?).and_return(false)
45
+ a.should_not_receive(:delete_application)
46
+ a.delete
47
47
  end
48
48
  end
49
49
  end