1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
| | # -*- encoding: binary -*-
require "./test/exec"
require "tmpdir"
require "fileutils"
class TestMogFresh < Test::Unit::TestCase
include TestExec
def setup
@test_host = "127.0.0.1"
@tracker = TCPServer.new(@test_host, 0)
@tracker_port = @tracker.addr[1]
@mogstored_mgmt = TCPServer.new(@test_host, 0)
@mogstored_http = TCPServer.new(@test_host, 0)
@mogstored_mgmt_port = @mogstored_mgmt.addr[1]
@mogstored_http_port = @mogstored_http.addr[1]
@dbname = Tempfile.new(["mogfresh", "sqlite3"])
@docroot = Dir.mktmpdir(["mogfresh", "docroot"])
@mogstored_conf = Tempfile.new(["mogstored", "conf"])
@mogilefsd_conf = Tempfile.new(["mogilefsd", "conf"])
@mogstored_pid = Tempfile.new(["mogstored", "pid"])
@mogilefsd_pid = Tempfile.new(["mogilefsd", "pid"])
cmd = %w(mogdbsetup --yes --type=SQLite --dbname) << @dbname.path
x!(*cmd)
@mogilefsd_conf.puts "db_dsn DBI:SQLite:#{@dbname.path}"
@mogilefsd_conf.write <<EOF
conf_port #@tracker_port
listen #@test_host
pidfile #{@mogilefsd_pid.path}
replicate_jobs 1
fsck_jobs 1
query_jobs 1
mogstored_stream_port #{@mogstored_mgmt_port}
node_timeout 10
EOF
@mogilefsd_conf.flush
@mogstored_conf.write <<EOF
pidfile = #{@mogstored_pid.path}
maxconns = 1000
httplisten = #@test_host:#{@mogstored_http_port}
mgmtlisten = #@test_host:#{@mogstored_mgmt_port}
docroot = #@docroot
EOF
@mogstored_conf.flush
@hosts = [ "#@test_host:#@tracker_port" ]
@mogstored_mgmt.close
@mogstored_http.close
@tracker.close
x!("mogstored", "--daemon", "--config=#{@mogstored_conf.path}")
wait_for_port @mogstored_http_port
wait_for_port @mogstored_mgmt_port
x!("mogilefsd", "--daemon", "--config=#{@mogilefsd_conf.path}")
wait_for_port @tracker_port
@admin = MogileFS::Admin.new(:hosts => @hosts)
10.times do
break if @mogstored_pid.size > 0
sleep 0.1
end
end
def wait_for_port(port)
tries = 50
begin
TCPSocket.new(@test_host, port).close
return
rescue
sleep 0.1
end while (tries -= 1) > 0
raise "#@test_host:#{port} never became ready"
end
def test_admin_setup_new_host_and_devices
assert_equal [], @admin.get_hosts
args = { :ip => @test_host, :port => @mogstored_http_port }
@admin.create_host("me", args)
yield_for_monitor_update { @admin.get_hosts.empty? or break }
hosts = @admin.get_hosts
assert_equal 1, hosts.size
host = @admin.get_hosts[0]
assert_equal "me", host["hostname"]
assert_equal @mogstored_http_port, host["http_port"].to_i
assert_equal @test_host, host["hostip"]
assert_equal hosts, @admin.get_hosts(host["hostid"])
assert_equal [], @admin.get_devices
end
def test_create_update_delete_class
domain = "rbmogtest#{Time.now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
@admin.create_domain(domain)
yield_for_monitor_update { @admin.get_domains.include?(domain) and break }
assert_nothing_raised do
@admin.create_class(domain, "klassy", 1)
end
assert_raises(MogileFS::Backend::ClassExistsError) do
@admin.create_class(domain, "klassy", 1)
end
assert_nothing_raised do
@admin.update_class(domain, "klassy",
:mindevcount => 1, :replpolicy => "MultipleHosts(1)")
end
tmp = nil
yield_for_monitor_update do
tmp = @admin.get_domains[domain]["klassy"]
break if tmp && tmp["replpolicy"] == "MultipleHosts(1)"
end
assert tmp, "domain did not show up"
assert_equal 1, tmp["mindevcount"]
assert_equal "MultipleHosts(1)", tmp["replpolicy"]
assert_nothing_raised { @admin.update_class(domain, "klassy", 2) }
ensure
@admin.delete_class(domain, "klassy") rescue nil
end
def teardown
if @mogstored_pid && @mogstored_pid.size > 0
Process.kill(:TERM, @mogstored_pid.read.to_i)
end
if @mogilefsd_pid
s = TCPSocket.new(@test_host, @tracker_port)
s.write "!shutdown\r\n"
s.close
end
FileUtils.rmtree(@docroot)
end
end
|