mirror of
https://github.com/puppetlabs/vmpooler-provider-vsphere.git
synced 2026-01-26 03:18:41 -05:00
Merge pull request #30 from puppetlabs/update_timeout_method
(maint) Use timeout builtin to TCPSocket when opening sockets.
This commit is contained in:
commit
f7c797a4f4
6 changed files with 31 additions and 35 deletions
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
|
@ -73,7 +73,7 @@ jobs:
|
|||
- name: Install Ruby jruby-9.3.6.0
|
||||
uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 'jruby-9.3.6.0'
|
||||
ruby-version: 'jruby-9.4.1.0'
|
||||
|
||||
- name: Build gem
|
||||
run: gem build *.gemspec
|
||||
|
|
|
|||
6
.github/workflows/testing.yml
vendored
6
.github/workflows/testing.yml
vendored
|
|
@ -18,8 +18,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- 'jruby-9.3.6.0'
|
||||
- 'jruby-9.4.0.0'
|
||||
- 'jruby-9.4.1.0'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Ruby
|
||||
|
|
@ -35,8 +34,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
ruby-version:
|
||||
- 'jruby-9.3.6.0'
|
||||
- 'jruby-9.4.0.0'
|
||||
- 'jruby-9.4.1.0'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Ruby
|
||||
|
|
|
|||
24
Gemfile.lock
24
Gemfile.lock
|
|
@ -9,11 +9,11 @@ GEM
|
|||
remote: https://rubygems.org/
|
||||
specs:
|
||||
ast (2.4.2)
|
||||
bindata (2.4.14)
|
||||
bindata (2.4.15)
|
||||
builder (3.2.4)
|
||||
climate_control (1.2.0)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.2.0)
|
||||
concurrent-ruby (1.2.2)
|
||||
connection_pool (2.3.0)
|
||||
deep_merge (1.2.2)
|
||||
diff-lcs (1.5.0)
|
||||
|
|
@ -33,7 +33,7 @@ GEM
|
|||
ruby2_keywords (~> 0.0.1)
|
||||
net-ldap (0.17.1)
|
||||
nio4r (2.5.8-java)
|
||||
nokogiri (1.13.10-java)
|
||||
nokogiri (1.14.2-java)
|
||||
racc (~> 1.4)
|
||||
opentelemetry-api (1.1.0)
|
||||
opentelemetry-common (0.19.6)
|
||||
|
|
@ -74,7 +74,7 @@ GEM
|
|||
opentelemetry-api (~> 1.0)
|
||||
optimist (3.0.1)
|
||||
parallel (1.22.1)
|
||||
parser (3.2.0.0)
|
||||
parser (3.2.1.0)
|
||||
ast (~> 2.4.1)
|
||||
pickup (0.0.11)
|
||||
prometheus-client (2.1.0)
|
||||
|
|
@ -97,14 +97,14 @@ GEM
|
|||
json (~> 2.3)
|
||||
nokogiri (~> 1.12, >= 1.12.5)
|
||||
optimist (~> 3.0)
|
||||
redis (4.8.0)
|
||||
regexp_parser (2.6.2)
|
||||
redis (4.8.1)
|
||||
regexp_parser (2.7.0)
|
||||
rexml (3.2.5)
|
||||
rspec (3.12.0)
|
||||
rspec-core (~> 3.12.0)
|
||||
rspec-expectations (~> 3.12.0)
|
||||
rspec-mocks (~> 3.12.0)
|
||||
rspec-core (3.12.0)
|
||||
rspec-core (3.12.1)
|
||||
rspec-support (~> 3.12.0)
|
||||
rspec-expectations (3.12.2)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
|
|
@ -122,9 +122,9 @@ GEM
|
|||
rubocop-ast (>= 1.17.0, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 1.4.0, < 3.0)
|
||||
rubocop-ast (1.24.1)
|
||||
parser (>= 3.1.1.0)
|
||||
ruby-progressbar (1.11.0)
|
||||
rubocop-ast (1.27.0)
|
||||
parser (>= 3.2.1.0)
|
||||
ruby-progressbar (1.12.0)
|
||||
ruby2_keywords (0.0.5)
|
||||
simplecov (0.22.0)
|
||||
docile (~> 1.1)
|
||||
|
|
@ -143,8 +143,8 @@ GEM
|
|||
ffi
|
||||
statsd-ruby (1.5.0)
|
||||
thor (1.2.1)
|
||||
thrift (0.17.0)
|
||||
tilt (2.0.11)
|
||||
thrift (0.18.1)
|
||||
tilt (2.1.0)
|
||||
unicode-display_width (2.4.2)
|
||||
vmpooler (2.4.0)
|
||||
concurrent-ruby (~> 1.1)
|
||||
|
|
|
|||
|
|
@ -632,17 +632,15 @@ module Vmpooler
|
|||
|
||||
# This should supercede the open_socket method in the Pool Manager
|
||||
def open_socket(host, domain = nil, timeout = 5, port = 22, &_block)
|
||||
Timeout.timeout(timeout) do
|
||||
target_host = host
|
||||
target_host = "#{host}.#{domain}" if domain
|
||||
sock = TCPSocket.new target_host, port
|
||||
sock = TCPSocket.new(target_host, port, connect_timeout: timeout)
|
||||
begin
|
||||
yield sock if block_given?
|
||||
ensure
|
||||
sock.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_vm_folder_path(vm_object)
|
||||
# This gives an array starting from the root Datacenters folder all the way to the VM
|
||||
|
|
|
|||
|
|
@ -1399,44 +1399,44 @@ EOT
|
|||
end
|
||||
|
||||
it 'opens socket with defaults' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 5}).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'yields the socket if a block is given' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: nil}).and_return(socket)
|
||||
|
||||
expect{ |socket| subject.open_socket(hostname,nil,nil,default_socket,&socket) }.to yield_control.exactly(1).times
|
||||
end
|
||||
|
||||
it 'closes the opened socket' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_return(socket)
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 5}).and_return(socket)
|
||||
expect(socket).to receive(:close)
|
||||
|
||||
expect(subject.open_socket(hostname)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'opens a specific socket' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,80).and_return(socket)
|
||||
expect(TCPSocket).to receive(:new).with(hostname,80,{connect_timeout: nil}).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname,nil,nil,80)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'uses a specific domain with the hostname' do
|
||||
expect(TCPSocket).to receive(:new).with("#{hostname}.#{domain}",default_socket).and_return(socket)
|
||||
expect(TCPSocket).to receive(:new).with("#{hostname}.#{domain}",default_socket,{connect_timeout: 5}).and_return(socket)
|
||||
|
||||
expect(subject.open_socket(hostname,domain)).to eq(nil)
|
||||
end
|
||||
|
||||
it 'raises error if host is not resolvable' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'getaddrinfo: No such host is known')
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 1}).and_raise(SocketError,'getaddrinfo: No such host is known')
|
||||
|
||||
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
|
||||
end
|
||||
|
||||
it 'raises error if socket is not listening' do
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket).and_raise(SocketError,'No connection could be made because the target machine actively refused it')
|
||||
expect(TCPSocket).to receive(:new).with(hostname,default_socket,{connect_timeout: 1}).and_raise(SocketError,'No connection could be made because the target machine actively refused it')
|
||||
|
||||
expect { subject.open_socket(hostname,nil,1) }.to raise_error(SocketError)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,5 +3,5 @@
|
|||
# The container tag should closely match what is used in `docker/Dockerfile` in vmpooler-deployment
|
||||
docker run -it --rm \
|
||||
-v $(pwd):/app \
|
||||
jruby:9.3.6-jdk \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends make git && cd /app && gem install bundler && bundle install --jobs 3 && bundle update; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
jruby:9.4.1.0-jdk11 \
|
||||
/bin/bash -c 'apt-get update -qq && apt-get install -y --no-install-recommends git make netbase && cd /app && gem install bundler && bundle install --jobs 3 && bundle update; echo "LOCK_FILE_UPDATE_EXIT_CODE=$?"'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue