Remove listen mode

Changing behaviour so that instead of rebinding after a successful
migration and continuing as an ordinary server, we simply quit with a
0 exit code and let our caller restart us as a server if they want to.
This means that everything in listen.c, listen.h, and anything making
reference to a rebind address is unneeded.
This commit is contained in:
Alex Young
2012-07-23 09:48:50 +01:00
parent 77f4ac29c6
commit 4790912750
19 changed files with 122 additions and 551 deletions

View File

@@ -17,8 +17,8 @@ class Environment
@rebind_port1 = @available_ports.shift
@port2 = @available_ports.shift
@rebind_port2 = @available_ports.shift
@nbd1 = FlexNBD.new("../../build/flexnbd", @ip, @port1, @ip, @rebind_port1)
@nbd2 = FlexNBD.new("../../build/flexnbd", @ip, @port2, @ip, @rebind_port2)
@nbd1 = FlexNBD.new("../../build/flexnbd", @ip, @port1)
@nbd2 = FlexNBD.new("../../build/flexnbd", @ip, @port2)
@fake_pid = nil
end
@@ -115,7 +115,7 @@ class Environment
end
def run_fake( name, addr, port, rebind_addr = addr, rebind_port = port, sock=nil )
def run_fake( name, addr, port, sock=nil )
fakedir = File.join( File.dirname( __FILE__ ), "fakes" )
fake = Dir[File.join( fakedir, name ) + "*"].sort.find { |fn|
File.executable?( fn )
@@ -124,11 +124,9 @@ class Environment
raise "no fake executable" unless fake
raise "no addr" unless addr
raise "no port" unless port
raise "no rebind_addr" unless rebind_addr
raise "no rebind_port" unless rebind_port
@fake_pid = fork do
exec [fake, addr, port, @nbd1.pid, rebind_addr, rebind_port, sock].map{|x| x.to_s}.join(" ")
exec [fake, addr, port, @nbd1.pid, sock].map{|x| x.to_s}.join(" ")
end
sleep(0.5)
end

View File

@@ -7,7 +7,7 @@
require 'flexnbd/fake_dest'
include FlexNBD
addr, port, src_pid, _, _, sock = *ARGV
addr, port, src_pid, sock = *ARGV
server = FakeDest.new( addr, port )
client = server.accept

View File

@@ -3,8 +3,8 @@
# Connect, send a migration, entrust then *immediately* disconnect.
# This simulates a client which fails while the client is blocked.
#
# We attempt to reconnect immediately afterwards to prove that we can
# retry the mirroring.
# In this situation we expect the destination to quit with an error
# status.
require 'flexnbd/fake_source'
include FlexNBD
@@ -28,7 +28,11 @@ system "kill -CONT #{srv_pid}"
sleep(0.25)
client2 = FakeSource.new( addr, port, "Timed out reconnecting" )
client2.close
begin
client2 = FakeSource.new( addr, port, "Expected timeout" )
fail "Unexpected reconnection"
rescue Timeout::Error
# expected
end
exit(0)

View File

@@ -1,10 +1,9 @@
#!/usr/bin/env ruby
# Connect, send a migration, entrust then *immediately* disconnect.
# Connect, send a migration, entrust, read the reply, then disconnect.
# This simulates a client which fails while the client is blocked.
#
# We attempt to reconnect immediately afterwards to prove that we can
# retry the mirroring.
# We expect the destination to quit with an error status.
require 'flexnbd/fake_source'
include FlexNBD
@@ -22,11 +21,12 @@ client.close
sleep(0.25)
client2 = FakeSource.new( addr, port, "Timed out reconnecting to mirror" )
client2.send_mirror
sleep(1)
client3 = FakeSource.new( rebind_addr, rebind_port, "Timed out reconnecting to read" )
client3.close
begin
client2 = FakeSource.new( addr, port, "Expected timeout" )
fail "Unexpected reconnection"
rescue Timeout::Error
# expected
end
exit(0)

View File

@@ -12,10 +12,11 @@ addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client.read_hello
Process.kill( "STOP", srv_pid.to_i )
system "kill -STOP #{srv_pid}"
client.write_write_request( 0, 8 )
client.close
Process.kill( "CONT", srv_pid.to_i )
system "kill -CONT #{srv_pid}"
# This sleep ensures that we don't return control to the test runner
# too soon, giving the flexnbd process time to fall over if it's going

View File

@@ -13,13 +13,13 @@ addr, port, srv_pid = *ARGV
client = FakeSource.new( addr, port, "Timed out connecting" )
client.read_hello
Process.kill( "STOP", srv_pid.to_i )
system "kill -STOP #{srv_pid}"
client.write_write_request( 0, 8 )
client.write_data( "12345678" )
client.close
Process.kill( "CONT", srv_pid.to_i )
system "kill -CONT #{srv_pid}"
# This sleep ensures that we don't return control to the test runner
# too soon, giving the flexnbd process time to fall over if it's going

View File

@@ -1,17 +1,14 @@
#!/usr/bin/env ruby
# Successfully send a migration, but squat on the IP and port which
# the destination wants to rebind to. The destination should retry
# every second, so we give it up then attempt to connect to the new
# server.
# Successfully send a migration. This test just makes sure that the
# happy path is covered. We expect the destination to quit with a
# success status.
require 'flexnbd/fake_source'
include FlexNBD
addr, port, srv_pid, newaddr, newport = *ARGV
squatter = TCPServer.open( newaddr, newport.to_i )
client = FakeSource.new( addr, port, "Timed out connecting" )
client.send_mirror()

View File

@@ -166,7 +166,7 @@ end # class ValgrindExecutor
# Noddy test class to exercise FlexNBD from the outside for testing.
#
class FlexNBD
attr_reader :bin, :ctrl, :pid, :ip, :port, :rebind_ip, :rebind_port
attr_reader :bin, :ctrl, :pid, :ip, :port
class << self
def counter
@@ -195,7 +195,7 @@ class FlexNBD
end
end
def initialize(bin, ip, port, rebind_ip = ip, rebind_port = port)
def initialize(bin, ip, port)
@bin = bin
@do_debug = ENV['DEBUG']
@debug = build_debug_opt
@@ -204,8 +204,6 @@ class FlexNBD
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
@ip = ip
@port = port
@rebind_ip = rebind_ip
@rebind_port = rebind_port
@kill = []
end
@@ -235,8 +233,6 @@ class FlexNBD
"--addr #{ip} "\
"--port #{port} "\
"--file #{file} "\
"--rebind-addr #{rebind_ip} " \
"--rebind-port #{rebind_port} " \
"--sock #{ctrl} "\
"#{@debug} "\
"#{acl.join(' ')}"

View File

@@ -80,15 +80,15 @@ class TestDestErrorHandling < Test::Unit::TestCase
end
def test_cant_rebind_dies
@env.nbd1.can_die(6)
def test_straight_migration
@env.nbd1.can_die(0)
run_fake( "source/successful_transfer" )
end
private
def run_fake( name )
@env.run_fake( name, @env.ip, @env.port1, @env.ip, @env.rebind_port1 )
@env.run_fake( name, @env.ip, @env.port1 )
assert @env.fake_reports_success, "#{name} failed."
end

View File

@@ -97,7 +97,7 @@ class TestSourceErrorHandling < Test::Unit::TestCase
private
def run_fake(name, opts = {})
@env.run_fake( name, @env.ip, @env.port2, @env.ip, @env.port2, @env.nbd1.ctrl )
@env.run_fake( name, @env.ip, @env.port2, @env.nbd1.ctrl )
stdout, stderr = @env.mirror12_unchecked
assert_success
assert_match( opts[:err], stderr ) if opts[:err]