chef-provisioning-vra 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +0 -1
- data/README.md +13 -0
- data/lib/chef/provisioning/vra_driver/driver.rb +16 -1
- data/lib/chef/provisioning/vra_driver/version.rb +1 -1
- data/spec/unit/chef/provisioning/vra_driver/driver_spec.rb +77 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f46d3e01ef741106c72a6f3ca7d95ff868e132ae
|
4
|
+
data.tar.gz: b1d172a0eee394d504886690d688a895126566c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b03355e6a996baf1a96530dac85937536ef8ff5000963921dd38e11864cf908d28934b0cfae37a12f7c079f0597a2e6cfe3cd1fcb764502a6eba15de6cb47aa
|
7
|
+
data.tar.gz: c641d8830df10e30286a14c42992d87cf216eb52ac76ccba3c149fcda9d966fd58b16c34453f7b54ec8d55bb099a3cf7b9f7228e03485c84ed1ea9b2eb29bfc8
|
data/CHANGELOG.md
CHANGED
@@ -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
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
|
-
|
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" \
|
@@ -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.
|
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
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef-provisioning
|