chef-provisioning-vra 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24ec90bf7c616780c06ad82ec5e23070b4e4c388
4
- data.tar.gz: ea67c1833771612241790aa650bdaf60c13cf50b
3
+ metadata.gz: f46d3e01ef741106c72a6f3ca7d95ff868e132ae
4
+ data.tar.gz: b1d172a0eee394d504886690d688a895126566c2
5
5
  SHA512:
6
- metadata.gz: fea45711fe93dfda82a6052ba22df4e2f9794d095fd7607bf007a8bbc7013926806bcf5d3b0348cbb56445dd8a8c8cceb880b63e854751ab3fd1c9dee11525e7
7
- data.tar.gz: d70b63e72dc7f7731968283a594a684246b15a4357c87bddb30c17f2d0f024bf77fc1dc7f53f881172614190cf97adaf16490bd341b5de7b2904068983a5623b
6
+ metadata.gz: 7b03355e6a996baf1a96530dac85937536ef8ff5000963921dd38e11864cf908d28934b0cfae37a12f7c079f0597a2e6cfe3cd1fcb764502a6eba15de6cb47aa
7
+ data.tar.gz: c641d8830df10e30286a14c42992d87cf216eb52ac76ccba3c149fcda9d966fd58b16c34453f7b54ec8d55bb099a3cf7b9f7228e03485c84ed1ea9b2eb29bfc8
@@ -1,5 +1,8 @@
1
1
  # chef-provisioning-vra CHANGELOG
2
2
 
3
+ ## v0.2.0 (2015-12-15)
4
+ * [pr#5](https://github.com/chef-partners/chef-provisioning-vra/pull/5) Adding retry logic in wait_for method if an exception is encountered
5
+
3
6
  ## v0.1.1 (2015-11-18)
4
7
  * [pr#3](https://github.com/chef-partners/chef-provisioning-vra/pull/3) Loosen version constraing on vmware-vra-gem
5
8
 
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in chef-provisioning-vra.gemspec
4
4
  gemspec
5
-
data/README.md CHANGED
@@ -80,6 +80,19 @@ bootstrap_options: {
80
80
  }
81
81
  ```
82
82
 
83
+ If your parameter name contains a hyphen, such as when you're passing in "provider" parameters, you will need to use the older "hash rocket" syntax:
84
+
85
+ ```ruby
86
+ bootstrap_options: {
87
+ extra_parameters: {
88
+ 'provider-MyCustomProperty' => {
89
+ type: 'string',
90
+ value: 'my value'
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
83
96
  ### Transport Options
84
97
 
85
98
  All transport options are optional.
@@ -225,13 +225,28 @@ class Chef
225
225
  driver_options.fetch(:max_wait_time, 600).to_i
226
226
  end
227
227
 
228
+ def max_retries
229
+ driver_options.fetch(:max_retries, 1).to_i
230
+ end
231
+
228
232
  def wait_for(action_handler, &block)
229
233
  sleep_time = 5
230
234
  start_time = Time.now.utc.to_i
235
+ try = 0
231
236
 
232
237
  Timeout.timeout(max_wait_time) do
233
238
  loop do
234
- return if block.call == true
239
+ begin
240
+ return if block.call == true
241
+ rescue => e
242
+ action_handler.report_progress("Error encountered: #{e.class} - #{e.message}")
243
+
244
+ try += 1
245
+ if try > max_retries
246
+ action_handler.report_progress('Retries exceeded, aborting...')
247
+ raise
248
+ end
249
+ end
235
250
 
236
251
  time_elapsed = Time.now.utc.to_i - start_time
237
252
  action_handler.report_progress("been waiting #{time_elapsed}/#{max_wait_time} seconds" \
@@ -19,7 +19,7 @@
19
19
  class Chef
20
20
  module Provisioning
21
21
  module VraDriver
22
- VERSION = '0.1.1'
22
+ VERSION = '0.2.0'
23
23
  end
24
24
  end
25
25
  end
@@ -568,6 +568,83 @@ describe Chef::Provisioning::VraDriver::Driver do
568
568
  end
569
569
  end
570
570
 
571
+ describe '#max_retries' do
572
+ it 'returns the configured value in driver_options' do
573
+ allow(driver).to receive(:driver_options).and_return(max_retries: 3)
574
+
575
+ expect(driver.max_retries).to eq(3)
576
+ end
577
+
578
+ it 'returns the default value if there is no value in driver_options' do
579
+ allow(driver).to receive(:driver_options).and_return({})
580
+
581
+ expect(driver.max_retries).to eq(1)
582
+ end
583
+ end
584
+
585
+ describe '#wait_for' do
586
+ before do
587
+ allow(driver).to receive(:sleep)
588
+ end
589
+
590
+ context 'when the block returns true immediately' do
591
+ it 'does not retry' do
592
+ expect(driver).not_to receive(:sleep)
593
+ driver.wait_for(action_handler) { true }
594
+ end
595
+ end
596
+
597
+ context 'when the block returns true after 3 tries' do
598
+ it 'retries twice' do
599
+ expect(driver).to receive(:sleep).twice
600
+
601
+ @loop_count = 0
602
+ driver.wait_for(action_handler) do
603
+ @loop_count += 1
604
+ @loop_count == 3
605
+ end
606
+ end
607
+ end
608
+
609
+ context 'when an exception is raised on first try but not second' do
610
+ it 'does not raise an exception' do
611
+ allow(driver).to receive(:max_retries).and_return(1)
612
+ expect do
613
+ driver.wait_for(action_handler) do
614
+ if @raised_exception
615
+ true
616
+ else
617
+ @raised_exception = true
618
+ raise 'Raising exception on first loop'
619
+ end
620
+ end
621
+ end.not_to raise_error
622
+ end
623
+ end
624
+
625
+ context 'when an exception is raised on both tries' do
626
+ it 'raises an exception' do
627
+ allow(driver).to receive(:max_retries).and_return(1)
628
+ expect { driver.wait_for(action_handler) { raise RuntimeError } }.to raise_error(RuntimeError)
629
+ end
630
+ end
631
+
632
+ context 'when max_retries is 5 and the block raises exceptions' do
633
+ it 'tries the block 6 times' do
634
+ allow(driver).to receive(:max_retries).and_return(5)
635
+
636
+ @loop_count = 0
637
+ expect do
638
+ driver.wait_for(action_handler) do
639
+ @loop_count += 1
640
+ raise RuntimeError
641
+ end
642
+ end.to raise_error(RuntimeError)
643
+ expect(@loop_count).to eq(6)
644
+ end
645
+ end
646
+ end
647
+
571
648
  describe '#username_for' do
572
649
  context 'when machine_spec reference entry exists' do
573
650
  it 'returns the correct username' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-vra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Partner Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-18 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-provisioning