Tidied up nbd init test
This commit is contained in:
@@ -28,21 +28,19 @@ module FlexNBD
|
||||
@sock.close
|
||||
end
|
||||
|
||||
def read_hello
|
||||
timing_out(::FlexNBD::MS_HELLO_TIME_SECS,
|
||||
'Timed out waiting for hello.') do
|
||||
fail 'No hello.' unless (hello = @sock.read(152)) &&
|
||||
hello.length == 152
|
||||
|
||||
def read_hello()
|
||||
timing_out( ::FlexNBD::MS_HELLO_TIME_SECS,
|
||||
"Timed out waiting for hello." ) do
|
||||
fail "No hello." unless (hello = @sock.read( 152 )) &&
|
||||
hello.length==152
|
||||
passwd_s = hello[0..7]
|
||||
magic = hello[8..15].unpack('Q>').first
|
||||
size = hello[16..23].unpack('Q>').first
|
||||
flags = hello[24..27].unpack('L>').first
|
||||
reserved = hello[28..-1]
|
||||
|
||||
magic_s = hello[0..7]
|
||||
ignore_s= hello[8..15]
|
||||
size_s = hello[16..23]
|
||||
|
||||
size_h, size_l = size_s.unpack("NN")
|
||||
size = (size_h << 32) + size_l
|
||||
|
||||
return { :magic => magic_s, :size => size }
|
||||
return { passwd: passwd_s, magic: magic, size: size, flags: flags, reserved: reserved }
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -15,7 +15,7 @@ module ProxyTests
|
||||
begin
|
||||
|
||||
result = client.read_hello
|
||||
assert_equal "NBDMAGIC", result[:magic]
|
||||
assert_equal "NBDMAGIC", result[:passwd]
|
||||
assert_equal override_size || @env.file1.size, result[:size]
|
||||
|
||||
yield client
|
||||
|
@@ -1,6 +1,7 @@
|
||||
require 'test/unit'
|
||||
require 'environment'
|
||||
require 'flexnbd/fake_source'
|
||||
require 'pp'
|
||||
|
||||
class TestServeMode < Test::Unit::TestCase
|
||||
|
||||
@@ -21,8 +22,11 @@ class TestServeMode < Test::Unit::TestCase
|
||||
client = FlexNBD::FakeSource.new(@env.ip, @env.port1, "Connecting to server failed")
|
||||
begin
|
||||
result = client.read_hello
|
||||
assert_equal "NBDMAGIC", result[:magic]
|
||||
assert_equal 'NBDMAGIC', result[:passwd]
|
||||
assert_equal 0x00420281861253, result[:magic]
|
||||
assert_equal @env.file1.size, result[:size]
|
||||
assert_equal 13, result[:flags]
|
||||
assert_equal "\x0" * 124, result[:reserved]
|
||||
yield client
|
||||
ensure
|
||||
client.close rescue nil
|
||||
|
Reference in New Issue
Block a user