furnish 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d4afd9cd6de61bdd854e6d2f7a1a6872752f6f4
4
- data.tar.gz: 170882525003c0f981bd530c237eb6ff49833ce6
3
+ metadata.gz: 59696ae50785a0a803ebe6797e627c43230c6cfd
4
+ data.tar.gz: 3847e7e726cb5bd4a5791d5fb17e5fd00eae52ea
5
5
  SHA512:
6
- metadata.gz: 654feec56dab6dcdad88a5b5778188fa53930482000a88d0c67d98ed91b7cb6118ec30b6064ffb647e7a2a9a8b0e8c0ee6e91f7fc98d876188cf3fb8c8974445
7
- data.tar.gz: 5e3047a0556417cb61853a560cd7efa9c4cb75def76c9aa2a6585063a25092b3b90e00c60be2a5e61d22019f59642645575cde00b251d8029897cec2c11bcc26
6
+ metadata.gz: 231a68d0bb0550efd3c87d337a8f1cf0419bf9af577cfc649a3e6ace96dcb17a3a1fbcd08a578b7577d605f72c5c559a3a4c8c8e6b1bc6f8b3750e321222dc59
7
+ data.tar.gz: cfba9a6a29dbdbae88f561812309739cd8738c45f71618fbff262fefd7f0bb40ac682fddc6d9d46d1f5b03f9aaf32583490130623bc7ead743f6de8289b77389
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.1.2 (04/27/2013)
2
+ * Logger changes:
3
+ * Fixed: Certain situations with if_debug and the IO proxy would result in
4
+ surprising behavior with stdio.
5
+ * with_tag is a new call to prefix log messages in a block with a tag.
6
+ * redirect is a new call to temporarily redirect I/O in the logger.
7
+ * Furnish::Provisioners::API now includes the logger mixin by default.
8
+ * Provisioner properties now use strings instead of symbols -- resolves a
9
+ potential memory exhaustion issue.
10
+ * Failed provisions no longer log the failure twice.
11
+ * Furnish::Protocol#accepts_from_any? is a predicate to reflect the value as
12
+ true or false.
1
13
  # 0.1.1 (04/16/2013)
2
14
  * #wait_for would spin forever if something got flagged as needing recovery
3
15
  (threaded scheduler only). Now raises the first item's exception if
@@ -9,6 +21,7 @@
9
21
  * #teardown_group is aliased to #d and #down
10
22
  * New API: Furnish::Scheduler#groups can be used to more easily get at
11
23
  provisioner groups the scheduler knows about.
24
+
12
25
  # 0.1.0 (04/09/2013)
13
26
  * Furnish requires 1.9.3 or greater -- always has been the case, now rubygems enforces that for us.
14
27
  * Runtime performance increased significantly. No hard numbers, but test
@@ -45,6 +58,7 @@
45
58
  * `<<` is now an alias for `schedule_provisioner_group`
46
59
  * `s` and `sched` are now aliases for `schedule_provision`
47
60
  * Probably some other shit I don't remember now.
61
+
48
62
  # 0.0.4 (03/25/2013)
49
63
  * Support for FURNISH_DEBUG environment variable for test suites.
50
64
  * Ruby 2.0.0-p0 Compatibility Fixes
data/furnish.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'palsy', '~> 0.0.4'
22
22
 
23
23
  gem.add_development_dependency 'rake'
24
- gem.add_development_dependency 'minitest', '~> 4.5.0'
24
+ gem.add_development_dependency 'minitest', '~> 4.7'
25
25
  gem.add_development_dependency 'guard-minitest'
26
26
  gem.add_development_dependency 'guard-rake', '~> 0.0.8'
27
27
  gem.add_development_dependency 'rdoc', '~> 4'
@@ -45,11 +45,21 @@ module Furnish
45
45
  # with the standard logger object set as Furnish.logger.
46
46
  #
47
47
  module Mixins
48
- #
48
+ # :method: if_debug
49
49
  # Delegates to Furnish::Logger#if_debug.
50
- #
51
- def if_debug(*args, &block)
52
- Furnish.logger.if_debug(*args, &block)
50
+
51
+ # :method: redirect
52
+ # Delegates to Furnish::Logger#redirect.
53
+
54
+ # :method: with_tag
55
+ # Delegates to Furnish::Logger#with_tag.
56
+
57
+ %w[if_debug redirect with_tag].each do |meth|
58
+ module_eval <<-EOF
59
+ def #{meth}(*args, &block)
60
+ Furnish.logger.#{meth}(*args, &block)
61
+ end
62
+ EOF
53
63
  end
54
64
  end
55
65
 
@@ -62,7 +72,12 @@ module Furnish
62
72
  # The IO object. Probably best to not mess with this attribute directly,
63
73
  # most methods will be proxied to it.
64
74
  #
65
- attr_reader :io
75
+ attr_reader :io
76
+
77
+ #
78
+ # Optional tag. See #with_tag for an example.
79
+ #
80
+ attr_reader :tag
66
81
 
67
82
  #
68
83
  # Create a new Furnish::Logger. Takes an IO object and an Integer debug
@@ -89,17 +104,112 @@ module Furnish
89
104
  # if_debug is synchronized over the logger's mutex.
90
105
  #
91
106
  def if_debug(level=1, else_block=nil, &block)
92
- run = lambda do
93
- if debug_level >= level and block
94
- io.instance_eval(&block)
95
- elsif else_block
96
- io.instance_eval(&else_block)
107
+ hijack_stdio do
108
+ begin
109
+ run = lambda do
110
+ if debug_level >= level and block
111
+ instance_eval(&block)
112
+ elsif else_block
113
+ instance_eval(&else_block)
114
+ end
115
+ end
116
+
117
+ @write_mutex.synchronize { run.call }
118
+ rescue ThreadError
119
+ run.call
97
120
  end
98
121
  end
122
+ end
99
123
 
100
- @write_mutex.synchronize { run.call }
101
- rescue ThreadError
102
- run.call
124
+ #
125
+ # Makes stdio Furnish::Logger objects for the duration of the block. Used
126
+ # by #if_debug for the purposes of not breaking expectations.
127
+ #
128
+ def hijack_stdio
129
+ orig_stdout, orig_stderr = nil, nil
130
+
131
+ if io != $stdout
132
+ orig_stdout = $stdout
133
+ $stdout = self
134
+ end
135
+
136
+ if io != $stderr
137
+ orig_stderr = $stderr
138
+ $stderr = self
139
+ end
140
+
141
+ yield
142
+ ensure
143
+ $stdout = orig_stdout if orig_stdout
144
+ $stderr = orig_stderr if orig_stderr
145
+ end
146
+
147
+ #
148
+ # Temporarily redirects IO to a new IO object for the duration of the
149
+ # block. Example below:
150
+ #
151
+ # Furnish.logger.redirect($stdout) do
152
+ # Furnish.logger.if_debug do
153
+ # puts "herp" # prints to stdout
154
+ # end
155
+ # end
156
+ #
157
+ # # prints to original logger IO
158
+ # Furnish.logger.puts "hi"
159
+ #
160
+ def redirect(new_io, &block)
161
+ tmp_io = @io
162
+ @io = new_io
163
+ yield
164
+ @io = tmp_io
165
+ end
166
+
167
+ #
168
+ # Prefixes all 'puts' calls with a string of text (a "tag") provided for
169
+ # the duration of the block.
170
+ #
171
+ # Example:
172
+ #
173
+ #
174
+ # @logger.with_tag("hi") do
175
+ # @logger.if_debug do
176
+ # puts "hello" # "[hi] hello"
177
+ # end
178
+ # end
179
+ #
180
+ # @logger.puts "hello" # "hello"
181
+ #
182
+ def with_tag(new_tag, &block)
183
+ @tag = new_tag
184
+ yield
185
+ @tag = nil
186
+ end
187
+
188
+ #
189
+ # Hacky puts method to handle tags.
190
+ #
191
+ def puts(*args)
192
+ if tag
193
+ io.print("[#{tag}] ")
194
+ end
195
+
196
+ method_missing(:puts, *args)
197
+ end
198
+
199
+ #
200
+ # Makes it possible to assign this to $stdout and $stderr.
201
+ #
202
+ def write(*args)
203
+ method_missing(:write, *args)
204
+ end
205
+
206
+ #
207
+ # Hacky close method that keeps us from closing stdio.
208
+ #
209
+ def close
210
+ # XXX StringIO apparently overrides respond_to_missing for #to_i but
211
+ # doesn't implement #to_i
212
+ io.close unless io == $stdout or io == $stderr
103
213
  end
104
214
 
105
215
  #
@@ -139,6 +139,13 @@ module Furnish # :nodoc:
139
139
  @hash[:accepts_from_any] = val
140
140
  end
141
141
 
142
+ #
143
+ # Predicate for the value of #accepts_from_any.
144
+ #
145
+ def accepts_from_any?
146
+ !!@hash[:accepts_from_any]
147
+ end
148
+
142
149
  #
143
150
  # look up a rule set -- generally should not be used by consumers.
144
151
  #
@@ -93,10 +93,6 @@ module Furnish
93
93
  startup_args = args
94
94
 
95
95
  unless args = this_prov.startup(startup_args)
96
- if_debug do
97
- puts "Could not provision #{this_prov}"
98
- end
99
-
100
96
  set_recovery(this_prov, i, startup_args)
101
97
  raise "Could not provision #{this_prov}"
102
98
  end
@@ -1,5 +1,6 @@
1
1
  require 'furnish/provisioner'
2
2
  require 'furnish/protocol'
3
+ require 'furnish/logger'
3
4
 
4
5
  module Furnish # :nodoc:
5
6
  module Provisioner # :nodoc:
@@ -56,6 +57,8 @@ module Furnish # :nodoc:
56
57
  #
57
58
  class API
58
59
 
60
+ include Furnish::Logger::Mixins
61
+
59
62
  #
60
63
  # Ensures all properties are inherited by subclasses that inherit from API.
61
64
  #
@@ -126,7 +129,7 @@ module Furnish # :nodoc:
126
129
  # { :description => "does a foo", :type => Integer }
127
130
  #
128
131
  def self.furnish_property(name, description="", type=Object)
129
- name = name.to_sym unless name.kind_of?(Symbol)
132
+ name = name.to_s unless name.kind_of?(String)
130
133
 
131
134
  attr_accessor name
132
135
 
@@ -278,6 +281,7 @@ module Furnish # :nodoc:
278
281
  end
279
282
 
280
283
  args.each do |k, v|
284
+ k = k.to_s unless k.kind_of?(String)
281
285
  props = self.class.furnish_properties
282
286
 
283
287
  if props.has_key?(k)
@@ -90,6 +90,15 @@ module Furnish
90
90
 
91
91
  yield
92
92
  end
93
+
94
+ #
95
+ # Test the mixin functionality
96
+ #
97
+ def make_log
98
+ if_debug do
99
+ puts "hello from Dummy"
100
+ end
101
+ end
93
102
  end
94
103
  end
95
104
  end
@@ -1,4 +1,4 @@
1
1
  module Furnish
2
2
  # The current version of Furnish.
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
data/test/test_api.rb CHANGED
@@ -21,12 +21,12 @@ class TestAPI < Furnish::TestCase
21
21
  assert_respond_to(@klass, :furnish_property)
22
22
 
23
23
  assert_kind_of(Hash, @klass.furnish_properties)
24
- assert_includes(@klass.furnish_properties, :foo)
25
- assert_includes(@klass.furnish_properties, :a_string)
26
- refute_includes(@klass.furnish_properties, :bar)
27
- assert_kind_of(Hash, @klass.furnish_properties[:foo])
28
- assert_equal("does things with foo", @klass.furnish_properties[:foo][:description])
29
- assert_equal(Integer, @klass.furnish_properties[:foo][:type])
24
+ assert_includes(@klass.furnish_properties, "foo")
25
+ assert_includes(@klass.furnish_properties, "a_string")
26
+ refute_includes(@klass.furnish_properties, "bar")
27
+ assert_kind_of(Hash, @klass.furnish_properties["foo"])
28
+ assert_equal("does things with foo", @klass.furnish_properties["foo"][:description])
29
+ assert_equal(Integer, @klass.furnish_properties["foo"][:type])
30
30
 
31
31
  obj = @klass.new(:foo => 1)
32
32
 
data/test/test_logger.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'helper'
2
2
  require 'tempfile'
3
+ require 'stringio'
3
4
 
4
5
  class TestLogger < Furnish::TestCase
5
6
  def setup
@@ -60,6 +61,51 @@ class TestLogger < Furnish::TestCase
60
61
  assert_equal("foo\nquux\nlevel2\n", read_logfile, "debug level is 2 and if_debug checking for 1")
61
62
  end
62
63
 
64
+ def test_redirect
65
+ @logger.debug_level = 3
66
+ io = StringIO.new('', 'w')
67
+ @logger.redirect(io) do
68
+ @logger.if_debug do
69
+ puts "herp"
70
+ end
71
+ end
72
+
73
+ @logger.if_debug do
74
+ puts "derp"
75
+ end
76
+
77
+ assert_equal("derp\n", read_logfile)
78
+ assert_equal("herp\n", io.string)
79
+ end
80
+
81
+ def test_with_tag
82
+ @logger.debug_level = 3
83
+ @logger.with_tag("fart") do
84
+ @logger.if_debug do
85
+ puts "hello"
86
+ end
87
+ end
88
+
89
+ @logger.if_debug do
90
+ puts "hello"
91
+ end
92
+
93
+ assert_equal("[fart] hello\nhello\n", read_logfile)
94
+ end
95
+
96
+ def test_api_has_logger
97
+ old_logger = Furnish.logger
98
+ io = StringIO.new('', 'w')
99
+ Furnish.logger = Furnish::Logger.new(io, 3)
100
+
101
+ d = Furnish::Provisioner::Dummy.new
102
+ d.make_log
103
+
104
+ assert_equal("hello from Dummy\n", io.string)
105
+ ensure
106
+ Furnish.logger = old_logger
107
+ end
108
+
63
109
  def teardown
64
110
  @logger.close
65
111
  @logger_file.unlink
@@ -19,8 +19,10 @@ class TestProtocol < Furnish::TestCase
19
19
  end
20
20
 
21
21
  refute(proto[:accepts_from_any])
22
+ refute(proto.accepts_from_any?)
22
23
  proto.accepts_from_any(true)
23
24
  assert(proto[:accepts_from_any])
25
+ assert(proto.accepts_from_any?)
24
26
  end
25
27
 
26
28
  def test_configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furnish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Hollensbe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-16 00:00:00.000000000 Z
11
+ date: 2013-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: palsy
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 4.5.0
47
+ version: '4.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 4.5.0
54
+ version: '4.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard-minitest
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  requirements: []
181
181
  rubyforge_project:
182
- rubygems_version: 2.0.0
182
+ rubygems_version: 2.0.3
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: A novel way to do virtual machine provisioning