This commit is contained in:
Patrick J Cherry
2018-02-02 21:34:14 +00:00
parent 1b7b688f7a
commit 9c48da82cc
40 changed files with 666 additions and 858 deletions

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a server, accept a client, then cancel the migration by issuing
# a break command.
@@ -8,28 +6,27 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid, sock = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
ctrl = UNIXSocket.open( sock )
ctrl = UNIXSocket.open(sock)
Process.kill("STOP", src_pid.to_i)
ctrl.write( "break\n" )
Process.kill('STOP', src_pid.to_i)
ctrl.write("break\n")
ctrl.close_write
client.write_hello
Process.kill("CONT", src_pid.to_i)
Process.kill('CONT', src_pid.to_i)
fail "Unexpected control response" unless
raise 'Unexpected control response' unless
ctrl.read =~ /0: mirror stopped/
client2 = nil
begin
client2 = server.accept( "Expected timeout" )
fail "Unexpected reconnection"
client2 = server.accept('Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end
client.close
exit(0)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Receive a mirror, and disconnect after sending the entrust reply but
# before it can send the disconnect signal.
#
@@ -11,26 +9,25 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
while (req = client.read_request; req[:type] == 1)
client.read_data( req[:len] )
client.write_reply( req[:handle] )
while req = client.read_request; req[:type] == 1
client.read_data(req[:len])
client.write_reply(req[:handle])
end
system "kill -STOP #{src_pid}"
client.write_reply( req[:handle] )
client.write_reply(req[:handle])
client.close
system "kill -CONT #{src_pid}"
sleep( 0.25 )
client2 = server.accept( "Timed out waiting for a reconnection" )
sleep(0.25)
client2 = server.accept('Timed out waiting for a reconnection')
client2.close
server.close
$stderr.puts "done"
warn 'done'
exit(0)

View File

@@ -10,12 +10,12 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
client = server.accept('Timed out waiting for a connection')
client.write_hello
client.close
new_client = server.accept( "Timed out waiting for a reconnection" )
new_client = server.accept('Timed out waiting for a reconnection')
new_client.close
server.close

View File

@@ -11,13 +11,13 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
client = server.accept('Timed out waiting for a connection')
client.write_hello
client.read_request
client.close
new_client = server.accept( "Timed out waiting for a reconnection" )
new_client = server.accept('Timed out waiting for a reconnection')
new_client.close
server.close

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a server, accept a client, then we expect a single write
# followed by an entrust. However, we disconnect after the write so
# the entrust will fail. We don't expect a reconnection: the sender
@@ -10,16 +8,16 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
req = client.read_request
data = client.read_data( req[:len] )
data = client.read_data(req[:len])
Process.kill("STOP", src_pid.to_i)
client.write_reply( req[:handle], 0 )
Process.kill('STOP', src_pid.to_i)
client.write_reply(req[:handle], 0)
client.close
Process.kill("CONT", src_pid.to_i)
Process.kill('CONT', src_pid.to_i)
exit(0)

View File

@@ -1,19 +1,16 @@
#!/usr/bin/env ruby
# encoding: utf-8
require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
handle = client.read_request[:handle]
client.write_error( handle )
client.write_error(handle)
client2 = server.accept( "Timed out waiting for a reconnection" )
client2 = server.accept('Timed out waiting for a reconnection')
client.close
client2.close

View File

@@ -14,8 +14,8 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Client didn't make a connection" )
server = FakeDest.new(addr, port)
client = server.accept("Client didn't make a connection")
# Sleep for one second past the timeout (a bit of slop in case ruby
# doesn't launch things quickly)
@@ -26,10 +26,10 @@ client.close
# Invert the sense of the timeout exception, since we *don't* want a
# connection attempt
begin
server.accept( "Expected timeout" )
fail "Unexpected reconnection"
server.accept('Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
# expected
end
server.close

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Open a socket, say hello, receive a write, then sleep for >
# MS_REQUEST_LIMIT_SECS seconds. This should tell the source that the
# write has gone MIA, and we expect a reconnect.
@@ -9,24 +7,24 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
client1 = server.accept( server )
server = FakeDest.new(addr, port)
client1 = server.accept(server)
client1.write_hello
client1.read_request
t = Thread.start do
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_REQUEST_LIMIT_SECS + 2 )
client2 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_REQUEST_LIMIT_SECS + 2)
client2.close
end
sleep_time = if ENV.has_key?('FLEXNBD_MS_REQUEST_LIMIT_SECS')
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'].to_f
else
FlexNBD::MS_REQUEST_LIMIT_SECS
sleep_time = if ENV.key?('FLEXNBD_MS_REQUEST_LIMIT_SECS')
ENV['FLEXNBD_MS_REQUEST_LIMIT_SECS'].to_f
else
FlexNBD::MS_REQUEST_LIMIT_SECS
end
sleep( sleep_time + 2.0 )
sleep(sleep_time + 2.0)
client1.close
t.join

View File

@@ -7,21 +7,21 @@ include FlexNBD
Thread.abort_on_exception
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client1 = server.accept
# We don't expect a reconnection attempt.
t = Thread.new do
begin
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
fail "Unexpected reconnection"
client2 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_RETRY_DELAY_SECS + 1)
raise 'Unexpected reconnection'
rescue Timeout::Error
#expected
# expected
end
end
client1.write_hello( :magic => :wrong )
client1.write_hello(magic: :wrong)
t.join

View File

@@ -9,7 +9,7 @@ include FlexNBD
Thread.abort_on_exception = true
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
t = Thread.new do
@@ -18,21 +18,21 @@ t = Thread.new do
# so it makes no sense to continue. This means we have to invert the
# sense of the exception.
begin
client2 = server.accept( "Timed out waiting for a reconnection",
FlexNBD::MS_RETRY_DELAY_SECS + 1 )
client2 = server.accept('Timed out waiting for a reconnection',
FlexNBD::MS_RETRY_DELAY_SECS + 1)
client2.close
fail "Unexpected reconnection."
raise 'Unexpected reconnection.'
rescue Timeout::Error
end
end
client.write_hello( :size => :wrong )
client.write_hello(size: :wrong)
t.join
# Now check that the source closed the first socket (yes, this was an
# actual bug)
fail "Didn't close socket" unless client.disconnected?
raise "Didn't close socket" unless client.disconnected?
exit 0

View File

@@ -7,18 +7,16 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
server.accept.close
begin
server.accept
fail "Unexpected reconnection"
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end
server.close
exit(0)

View File

@@ -8,8 +8,8 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port, pid = *ARGV
server = FakeDest.new( addr, port )
client = server.accept( "Timed out waiting for a connection" )
server = FakeDest.new(addr, port)
client = server.accept('Timed out waiting for a connection')
client.write_hello
Process.kill(15, pid.to_i)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Accept a connection, write hello, wait for a write request, read the
# data, then write back a reply with a bad magic field. We then
# expect a reconnect.
@@ -9,13 +7,13 @@ require 'flexnbd/fake_dest'
include FlexNBD
addr, port = *ARGV
server = FakeDest.new( addr, port )
server = FakeDest.new(addr, port)
client = server.accept
client.write_hello
req = client.read_request
client.read_data( req[:len] )
client.write_reply( req[:handle], 0, :magic => :wrong )
client.read_data(req[:len])
client.write_reply(req[:handle], 0, magic: :wrong)
client2 = server.accept
client.close

View File

@@ -11,13 +11,13 @@ include FlexNBD
addr, port = *ARGV
FakeSource.new( addr, port, "Failed to connect" ).close
# Sleep to be sure we don't try to connect too soon. That wouldn't
# be a problem for the destination, but it would prevent us from
# determining success or failure here in the case where we try to
# reconnect before the destination has tidied up after the first
# thread went away.
FakeSource.new(addr, port, 'Failed to connect').close
# Sleep to be sure we don't try to connect too soon. That wouldn't
# be a problem for the destination, but it would prevent us from
# determining success or failure here in the case where we try to
# reconnect before the destination has tidied up after the first
# thread went away.
sleep(0.5)
FakeSource.new( addr, port, "Failed to reconnect" ).close
FakeSource.new(addr, port, 'Failed to reconnect').close
exit 0

View File

@@ -11,10 +11,10 @@ include FlexNBD
addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.read_hello
client.write_write_request( 0, 8 )
client.write_data( "12345678" )
client.write_write_request(0, 8)
client.write_data('12345678')
# Use system "kill" rather than Process.kill because Process.kill
# doesn't seem to work
@@ -25,12 +25,11 @@ client.close
system "kill -CONT #{srv_pid}"
sleep(0.25)
begin
client2 = FakeSource.new( addr, port, "Expected timeout" )
fail "Unexpected reconnection"
client2 = FakeSource.new(addr, port, 'Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end

View File

@@ -10,10 +10,10 @@ include FlexNBD
addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.read_hello
client.write_write_request( 0, 8 )
client.write_data( "12345678" )
client.write_write_request(0, 8)
client.write_data('12345678')
client.write_entrust_request
client.read_response
@@ -21,13 +21,11 @@ client.close
sleep(0.25)
begin
client2 = FakeSource.new( addr, port, "Expected timeout" )
fail "Unexpected reconnection"
client2 = FakeSource.new(addr, port, 'Expected timeout')
raise 'Unexpected reconnection'
rescue Timeout::Error
# expected
end
exit(0)

View File

@@ -12,13 +12,12 @@ include FlexNBD
addr, port = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting." )
client = FakeSource.new(addr, port, 'Timed out connecting.')
client.read_hello
client.close
sleep(0.2)
FakeSource.new( addr, port, "Timed out reconnecting." )
FakeSource.new(addr, port, 'Timed out reconnecting.')
exit(0)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# We connect, pause the server, issue a write request, disconnect,
# then cont the server. This ensures that our disconnect happens
# while the server is trying to read the write data.
@@ -10,11 +8,11 @@ include FlexNBD
addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.read_hello
system "kill -STOP #{srv_pid}"
client.write_write_request( 0, 8 )
client.write_write_request(0, 8)
client.close
system "kill -CONT #{srv_pid}"
@@ -24,7 +22,7 @@ system "kill -CONT #{srv_pid}"
sleep(0.25)
# ...and can we reconnect?
client2 = FakeSource.new( addr, port, "Timed out connecting" )
client2 = FakeSource.new(addr, port, 'Timed out connecting')
client2.close
exit(0)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# We connect, pause the server, issue a write request, send data,
# disconnect, then cont the server. This ensures that our disconnect
# happens before the server can try to write the reply.
@@ -10,13 +8,13 @@ include FlexNBD
addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.read_hello
system "kill -STOP #{srv_pid}"
client.write_write_request( 0, 8 )
client.write_data( "12345678" )
client.write_write_request(0, 8)
client.write_data('12345678')
client.close
system "kill -CONT #{srv_pid}"
@@ -27,7 +25,7 @@ system "kill -CONT #{srv_pid}"
sleep(0.25)
# ...and can we reconnect?
client2 = FakeSource.new( addr, port, "Timed out reconnecting" )
client2 = FakeSource.new(addr, port, 'Timed out reconnecting')
client2.close
exit(0)

View File

@@ -8,10 +8,9 @@ include FlexNBD
addr, port, srv_pid, newaddr, newport = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client.write_read_request( 0, 8 )
client.read_raw( 4 )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.write_read_request(0, 8)
client.read_raw(4)
client.close
exit(0)

View File

@@ -10,9 +10,9 @@ include FlexNBD
addr, port = *ARGV
client1 = FakeSource.new( addr, port, "Timed out connecting" )
client1 = FakeSource.new(addr, port, 'Timed out connecting')
sleep(0.25)
client2 = FakeSource.new( addr, port, "Timed out connecting a second time" )
client2 = FakeSource.new(addr, port, 'Timed out connecting a second time')
# This is the expected source crashing after connect
client1.close

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# We connect from a local address which should be blocked, sleep for a
# bit, then try to read from the socket. We should get an instant EOF
# as we've been cut off by the destination.
@@ -11,10 +9,9 @@ include FlexNBD
addr, port = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting", "127.0.0.6" )
sleep( 0.25 )
client = FakeSource.new(addr, port, 'Timed out connecting', '127.0.0.6')
sleep(0.25)
rsp = client.disconnected? ? 0 : 1
client.close
exit(rsp)

View File

@@ -7,10 +7,10 @@
# listening for an incoming migration.
addr, port = *ARGV
require "flexnbd/fake_source"
require 'flexnbd/fake_source'
include FlexNBD
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
client.read_hello
# Now we do two things:
@@ -24,16 +24,16 @@ client.read_hello
kidpid = fork do
client.close
new_client = nil
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 1 )
new_client = FakeSource.new( addr, port, "Timed out reconnecting." )
sleep(FlexNBD::CLIENT_MAX_WAIT_SECS + 1)
new_client = FakeSource.new(addr, port, 'Timed out reconnecting.')
new_client.read_hello
exit 0
end
# Sleep for longer than the child, to give the flexnbd process a bit
# of slop
sleep( FlexNBD::CLIENT_MAX_WAIT_SECS + 3 )
sleep(FlexNBD::CLIENT_MAX_WAIT_SECS + 3)
client.close
_,status = Process.waitpid2( kidpid )
_, status = Process.waitpid2(kidpid)
exit status.exitstatus

View File

@@ -9,10 +9,10 @@ include FlexNBD
addr, port, pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting." )
client = FakeSource.new(addr, port, 'Timed out connecting.')
client.read_hello
Process.kill( "TERM", pid.to_i )
Process.kill('TERM', pid.to_i)
sleep(0.2)
client.close

View File

@@ -9,10 +9,9 @@ include FlexNBD
addr, port, srv_pid, newaddr, newport = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client.send_mirror()
client = FakeSource.new(addr, port, 'Timed out connecting')
client.send_mirror
sleep(1)
exit( 0 )
exit(0)

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env ruby
# encoding: utf-8
# Connect, read the hello then make a write request with an impossible
# (from,len) pair. We expect an error response, and not to be
# disconnected.
@@ -13,20 +11,20 @@ include FlexNBD
addr, port = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client = FakeSource.new(addr, port, 'Timed out connecting')
hello = client.read_hello
client.write_write_request( hello[:size]+1, 32, "myhandle" )
client.write_data("1"*32)
client.write_write_request(hello[:size] + 1, 32, 'myhandle')
client.write_data('1' * 32)
response = client.read_response
fail "Not an error" if response[:error] == 0
fail "Wrong handle" unless "myhandle" == response[:handle]
raise 'Not an error' if response[:error] == 0
raise 'Wrong handle' unless response[:handle] == 'myhandle'
client.write_write_request( 0, 32 )
client.write_data( "2"*32 )
client.write_write_request(0, 32)
client.write_data('2' * 32)
success_response = client.read_response
fail "Second write failed" unless success_response[:error] == 0
raise 'Second write failed' unless success_response[:error] == 0
client.close
exit(0)