jamie 0.1.0.beta2 → 0.1.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/jamie.rb CHANGED
@@ -58,11 +58,20 @@ module Jamie
58
58
  end
59
59
 
60
60
  def default_logger
61
- env_log = ENV['JAMIE_LOG'] && ENV['JAMIE_LOG'].downcase.to_sym
62
- env_log = Util.to_logger_level(env_log) unless env_log.nil?
63
-
64
61
  Logger.new(:stdout => STDOUT, :level => env_log)
65
62
  end
63
+
64
+ def default_file_logger
65
+ logfile = File.expand_path(File.join(".jamie", "logs", "jamie.log"))
66
+ Logger.new(:stdout => STDOUT, :logdev => logfile, :level => env_log)
67
+ end
68
+
69
+ private
70
+
71
+ def env_log
72
+ level = ENV['JAMIE_LOG'] && ENV['JAMIE_LOG'].downcase.to_sym
73
+ level = Util.to_logger_level(level) unless level.nil?
74
+ end
66
75
  end
67
76
 
68
77
  module Error ; end
@@ -256,7 +265,6 @@ module Jamie
256
265
  :logger => new_instance_logger(index)
257
266
  }
258
267
 
259
- FileUtils.mkdir_p(log_root)
260
268
  new_instance_supervised_or_not(actor_name, opts)
261
269
  end
262
270
 
@@ -389,11 +397,13 @@ module Jamie
389
397
 
390
398
  include ::Logger::Severity
391
399
 
400
+ attr_reader :logdev
401
+
392
402
  def initialize(options = {})
393
403
  color = options[:color] || :bright_white
394
404
 
395
405
  @loggers = []
396
- @loggers << logdev_logger(options[:logdev]) if options[:logdev]
406
+ @loggers << @logdev = logdev_logger(options[:logdev]) if options[:logdev]
397
407
  @loggers << stdout_logger(options[:stdout], color) if options[:stdout]
398
408
  @loggers << stdout_logger(STDOUT, color) if @loggers.empty?
399
409
 
@@ -433,11 +443,12 @@ module Jamie
433
443
  end
434
444
 
435
445
  def logdev_logger(filepath_or_logdev)
436
- LogdevLogger.new(logdev(filepath_or_logdev))
446
+ LogdevLogger.new(resolve_logdev(filepath_or_logdev))
437
447
  end
438
448
 
439
- def logdev(filepath_or_logdev)
449
+ def resolve_logdev(filepath_or_logdev)
440
450
  if filepath_or_logdev.is_a? String
451
+ FileUtils.mkdir_p(File.dirname(filepath_or_logdev))
441
452
  file = File.open(File.expand_path(filepath_or_logdev), "ab")
442
453
  file.sync = true
443
454
  file
@@ -754,7 +765,7 @@ module Jamie
754
765
  verify
755
766
  destroy if destroy_mode == :passing
756
767
  end
757
- info "Finished testing #{to_str} (#{elapsed.real} seconds)."
768
+ info "Finished testing #{to_str} #{Util.duration(elapsed.real)}."
758
769
  Actor.current
759
770
  ensure
760
771
  destroy if destroy_mode == :always
@@ -827,7 +838,7 @@ module Jamie
827
838
  banner "#{output_verb} #{to_str}"
828
839
  elapsed = action(verb) { |state| driver.public_send(verb, state) }
829
840
  info("Finished #{output_verb.downcase} #{to_str}" +
830
- " (#{elapsed.real} seconds).")
841
+ " #{Util.duration(elapsed.real)}.")
831
842
  yield if block_given?
832
843
  Actor.current
833
844
  end
@@ -884,6 +895,11 @@ module Jamie
884
895
  ))
885
896
  end
886
897
 
898
+ def banner(*args)
899
+ Jamie.logger.logdev && Jamie.logger.logdev.banner(*args)
900
+ super
901
+ end
902
+
887
903
  # The simplest finite state machine pseudo-implementation needed to manage
888
904
  # an Instance.
889
905
  #
@@ -1106,6 +1122,12 @@ module Jamie
1106
1122
  obj
1107
1123
  end
1108
1124
  end
1125
+
1126
+ def self.duration(total)
1127
+ minutes = (total / 60).to_i
1128
+ seconds = (total - (minutes * 60))
1129
+ "(%dm%.2fs)" % [ minutes, seconds ]
1130
+ end
1109
1131
  end
1110
1132
 
1111
1133
  # Mixin that wraps a command shell out invocation, providing a #run_command
@@ -1132,7 +1154,7 @@ module Jamie
1132
1154
  info("#{subject} BEGIN (#{display_cmd(cmd)})")
1133
1155
  sh = Mixlib::ShellOut.new(cmd, :live_stream => logger, :timeout => 60000)
1134
1156
  sh.run_command
1135
- info("#{subject} END (#{sh.execution_time} seconds)")
1157
+ info("#{subject} END #{Util.duration(sh.execution_time)}")
1136
1158
  sh.error!
1137
1159
  rescue Mixlib::ShellOut::ShellCommandFailed => ex
1138
1160
  raise ShellCommandFailed, ex.message
@@ -1164,10 +1186,10 @@ module Jamie
1164
1186
  str_const = Util.to_camel_case(plugin)
1165
1187
  klass = self.const_get(str_const)
1166
1188
  klass.new(config)
1189
+ rescue UserError
1190
+ raise
1167
1191
  rescue LoadError
1168
1192
  raise ClientError, "Could not require '#{plugin}' plugin from load path"
1169
- rescue NameError
1170
- raise ClientError, "No class 'Jamie::Driver::#{str_const}' could be found"
1171
1193
  rescue
1172
1194
  raise ClientError, "Failed to create a driver for '#{plugin}' plugin"
1173
1195
  end
@@ -1193,6 +1215,9 @@ module Jamie
1193
1215
  self.class.defaults.each do |attr, value|
1194
1216
  @config[attr] = value unless @config[attr]
1195
1217
  end
1218
+ Array(self.class.validations).each do |tuple|
1219
+ tuple.last.call(tuple.first, config[tuple.first])
1220
+ end
1196
1221
  end
1197
1222
 
1198
1223
  # Provides hash-like access to configuration keys.
@@ -1277,6 +1302,23 @@ module Jamie
1277
1302
  defaults[attr] = value
1278
1303
  end
1279
1304
 
1305
+ def self.validations
1306
+ @validations
1307
+ end
1308
+
1309
+ def self.required_config(attr, &block)
1310
+ @validations = [] if @validations.nil?
1311
+ if ! block_given?
1312
+ klass = self
1313
+ block = lambda do |attr, value|
1314
+ if value.nil? || value.to_s.empty?
1315
+ raise UserError, "#{klass}#config[:#{attr}] cannot be blank"
1316
+ end
1317
+ end
1318
+ end
1319
+ @validations << [ attr, block ]
1320
+ end
1321
+
1280
1322
  def self.no_parallel_for(*methods)
1281
1323
  Array(methods).each do |meth|
1282
1324
  if ! ACTION_METHODS.include?(meth)
@@ -1357,9 +1399,13 @@ module Jamie
1357
1399
  end
1358
1400
 
1359
1401
  def install_omnibus(ssh_args)
1402
+ flag = config[:require_chef_omnibus]
1403
+ version = flag.is_a?(String) ? "-s -- -v #{flag}" : ""
1404
+
1360
1405
  ssh(ssh_args, <<-INSTALL.gsub(/^ {10}/, ''))
1361
1406
  if [ ! -d "/opt/chef" ] ; then
1362
- curl -sSL https://www.opscode.com/chef/install.sh | sudo bash
1407
+ curl -sSL https://www.opscode.com/chef/install.sh \
1408
+ | sudo bash #{version}
1363
1409
  fi
1364
1410
  INSTALL
1365
1411
  end
@@ -1608,7 +1654,7 @@ Celluloid.logger = Jamie.logger
1608
1654
  Jamie.crashes = []
1609
1655
  Celluloid.exception_handler do |exception|
1610
1656
  Jamie.logger.debug("An instance crashed because of #{exception.inspect}")
1611
- Jamie.crashes << exception
1657
+ Jamie.mutex.synchronize { Jamie.crashes << exception }
1612
1658
  end
1613
1659
 
1614
1660
  Jamie.mutex = Mutex.new
data/lib/jamie/cli.rb CHANGED
@@ -38,6 +38,7 @@ module Jamie
38
38
  $stdout.sync = true
39
39
  @config = Jamie::Config.new(ENV['JAMIE_YAML'])
40
40
  @config.supervised = false
41
+ Jamie.logger = Jamie.default_file_logger
41
42
  end
42
43
 
43
44
  desc "list [(all|<REGEX>)]", "List all instances"
@@ -98,7 +99,7 @@ module Jamie
98
99
  run_serial(results, destroy_mode)
99
100
  end
100
101
  end
101
- banner "Jamie is finished. (#{elapsed.real} seconds)"
102
+ banner "Jamie is finished. #{Util.duration(elapsed.real)}"
102
103
  end
103
104
 
104
105
  desc "login (['REGEX']|[INSTANCE])", "Log in to one instance"
@@ -158,7 +159,7 @@ module Jamie
158
159
  results = parse_subcommand(args.first)
159
160
  options[:parallel] ? run_parallel(results) : run_serial(results)
160
161
  end
161
- banner "Jamie is finished. (#{elapsed.real} seconds)"
162
+ banner "Jamie is finished. #{Util.duration(elapsed.real)}"
162
163
  end
163
164
 
164
165
  def run_serial(instances, *args)
@@ -458,7 +459,8 @@ module Jamie
458
459
  :license => license_comments)
459
460
  create_template("plugin/driver.rb",
460
461
  "lib/jamie/driver/#{plugin_name}.rb",
461
- :klass_name => klass_name, :license => license_comments)
462
+ :klass_name => klass_name, :license => license_comments,
463
+ :author => author, :email => email)
462
464
  end
463
465
 
464
466
  def rendered_license
@@ -33,6 +33,7 @@ module Jamie
33
33
  def initialize
34
34
  @config = Jamie::Config.new
35
35
  @config.supervised = false
36
+ Jamie.logger = Jamie.default_file_logger
36
37
  yield self if block_given?
37
38
  define
38
39
  end
@@ -45,7 +46,9 @@ module Jamie
45
46
  namespace "jamie" do
46
47
  config.instances.each do |instance|
47
48
  desc "Run #{instance.name} test instance"
48
- task instance.name { instance.test(:always) }
49
+ task instance.name do
50
+ instance.test(:always)
51
+ end
49
52
  end
50
53
 
51
54
  desc "Run all test instances"
@@ -36,6 +36,7 @@ module Jamie
36
36
  super
37
37
  @config = Jamie::Config.new
38
38
  @config.supervised = false
39
+ Jamie.logger = Jamie.default_file_logger
39
40
  yield self if block_given?
40
41
  define
41
42
  end
data/lib/jamie/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Jamie
20
20
 
21
- VERSION = "0.1.0.beta2"
21
+ VERSION = "0.1.0.beta3"
22
22
  end
@@ -9,12 +9,14 @@ module Jamie
9
9
  module Driver
10
10
 
11
11
  # <%= klass_name %> driver for Jamie.
12
+ #
13
+ # @author <%= author %> <<%= email %>>
12
14
  class <%= klass_name %> < Jamie::Driver::SSHBase
13
15
 
14
- def create(instance, state)
16
+ def create(state)
15
17
  end
16
18
 
17
- def destroy(instance, state)
19
+ def destroy(state)
18
20
  end
19
21
  end
20
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jamie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta2
4
+ version: 0.1.0.beta3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-13 00:00:00.000000000 Z
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: celluloid