9 find_mogclient_or_skip();
12 my $sto = eval { temp_store(); };
14 plan skip_all => "Can't create temporary test database: $@";
20 $mogroot{1} = File::Temp::tempdir( CLEANUP => 1 );
21 $mogroot{2} = File::Temp::tempdir( CLEANUP => 1 );
22 my $dev2host = { 1 => 1, 2 => 2, };
23 foreach (sort { $a <=> $b } keys %$dev2host) {
24 my $root = $mogroot{$dev2host->{$_}};
25 mkdir("$root/dev$_") or die "Failed to create dev$_ dir: $!";
28 my $ms1 = create_mogstored("127.0.1.1", $mogroot{1});
29 ok($ms1, "got mogstored1");
30 my $ms2 = create_mogstored("127.0.1.2", $mogroot{2});
31 ok($ms1, "got mogstored2");
34 print "Waiting on usage...\n";
35 -e "$mogroot{1}/dev1/usage" && -e "$mogroot{2}/dev2/usage";
38 my $tmptrack = create_temp_tracker($sto);
41 my $admin = IO::Socket::INET->new(PeerAddr => '127.0.0.1:7001');
42 $admin or die "failed to create admin socket: $!";
43 my $moga = MogileFS::Admin->new(hosts => [ "127.0.0.1:7001" ]);
44 my $mogc = MogileFS::Client->new(
46 hosts => [ "127.0.0.1:7001" ],
48 my $be = $mogc->{backend}; # gross, reaching inside of MogileFS::Client
50 # test some basic commands to backend
51 ok($tmptrack->mogadm("domain", "add", "testdom"), "created test domain");
52 ok($tmptrack->mogadm("class", "add", "testdom", "changer", "--mindevcount=2", "--hashtype=MD5"), "created changer class in testdom with hashtype=MD5");
54 ok($tmptrack->mogadm("host", "add", "hostA", "--ip=127.0.1.1", "--status=alive"), "created hostA");
55 ok($tmptrack->mogadm("host", "add", "hostB", "--ip=127.0.1.2", "--status=alive"), "created hostB");
57 ok($tmptrack->mogadm("device", "add", "hostA", 1), "created dev1 on hostA");
58 ok($tmptrack->mogadm("device", "add", "hostB", 2), "created dev2 on hostB");
60 sub wait_for_monitor {
62 my $was = $be->{timeout}; # can't use local on phash :(
64 ok($be->do_request("clear_cache", {}), "waited for monitor")
65 or die "Failed to wait for monitor";
66 ok($be->do_request("clear_cache", {}), "waited for monitor")
67 or die "Failed to wait for monitor";
68 $be->{timeout} = $was;
71 wait_for_monitor($be);
72 want($admin, 0, "replicate");
74 my ($req, $rv, %opts, @paths, @fsck_log);
75 my $ua = LWP::UserAgent->new;
78 use Digest::MD5 qw/md5_hex/;
82 %opts = ( domain => "testdom", class => "changer", key => $key );
83 $rv = $be->do_request("create_open", \%opts);
85 ok($rv && $rv->{path}, "create_open succeeded");
86 $req = HTTP::Request->new(PUT => $rv->{path});
87 $req->content("blah");
88 $rv = $ua->request($req);
89 ok($rv->is_success, "PUT successful");
91 $opts{domain} = "testdom";
92 $opts{checksum} = "MD5:".md5_hex('blah');
93 $opts{checksumverify} = 1;
94 $rv = $be->do_request("create_close", \%opts);
95 ok($rv, "checksum verified successfully");
96 ok($sto->get_checksum($opts{fid}), "checksum saved");
97 ok($mogc->file_info($key), "file_info($key) is sane");
100 # disable MD5 checksums in "changer" class
102 %opts = ( domain => "testdom", class => "changer",
103 hashtype => "NONE", mindevcount => 2);
104 ok($be->do_request("update_class", \%opts), "update class");
105 wait_for_monitor($be);
108 # replicate should work even if we have, but don't need a checksum anymore
110 want($admin, 1, "replicate");
112 # wait for replicate to recreate checksum
114 @paths = $mogc->get_paths($key);
117 is(scalar(@paths), 2, "replicated successfully");
118 want($admin, 0, "replicate");
121 # switch to SHA-1 checksums in "changer" class
123 %opts = ( domain => "testdom", class => "changer",
124 hashtype => "SHA-1", mindevcount => 2);
125 ok($be->do_request("update_class", \%opts), "update class");
126 wait_for_monitor($be);
130 ok($tmptrack->mogadm("fsck", "stop"), "stop fsck");
131 ok($tmptrack->mogadm("fsck", "clearlog"), "clear fsck log");
132 ok($tmptrack->mogadm("fsck", "reset"), "reset fsck");
133 ok($tmptrack->mogadm("fsck", "start"), "started fsck");
135 try_for(30, sub { @fsck_log = $sto->fsck_log_rows; });
136 is($fsck_log[0]->{evcode}, "BALG", "bad checksum algorithm logged");