1 # Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 18;
24 use File::Path qw(mkpath);
27 use lib "@amperldir@";
28 use Installcheck::Config;
29 use Amanda::Config qw( :init :getconf config_dir_relative );
30 use Amanda::Util qw( slurp burp sanitise_filename );
33 use Amanda::Curinfo::Info;
38 eval "use Text::Diff;";
42 my $testconf = Installcheck::Config->new();
45 my $infodir = "$Installcheck::TMP/infodir";
47 config_init( $CONFIG_INIT_EXPLICIT_NAME, "TESTCONF" ) == $CFGERR_OK
48 or die("config_init failed");
53 full-rate: 2974.060606 2886.529412 2973.878788
54 full-comp: 0.471483 0.471497 0.471477
55 incr-rate: 27.800000 3062.406250 1.000000
56 incr-comp: 0.133333 0.133333 0.133333
57 stats: 0 208160 98144 33 1211438831 16 S3012
58 stats: 1 30 4 0 1212380683 8 S3023
60 history: 1 30 4 1212380683 0
61 history: 1 30 4 1212294141 0
62 history: 1 30 4 1212207722 0
63 history: 1 30 4 1212121208 0
64 history: 1 30 4 1212034786 0
65 history: 1 30 4 1211948729 0
66 history: 1 30 4 1211862004 0
67 history: 1 30 4 1211775583 0
68 history: 1 30 4 1211690046 0
69 history: 1 30 4 1211603671 0
70 history: 1 30 4 1211526232 0
71 history: 0 208160 98144 1211438831 33
72 history: 1 50 5 1211344512 0
73 history: 1 30 4 1210912587 0
74 history: 1 30 4 1210826040 0
75 history: 1 30 4 1210739734 0
76 history: 1 30 4 1210653066 0
77 history: 1 30 4 1210567105 0
78 history: 1 30 4 1210480489 0
79 history: 1 30 4 1210393557 0
80 history: 1 30 4 1210307156 0
81 history: 1 30 4 1210220759 0
82 history: 1 30 4 1210134427 0
83 history: 1 30 4 1210047948 0
84 history: 1 30 4 1209961521 0
85 history: 1 30 4 1209875114 0
86 history: 1 30 4 1209788730 0
87 history: 1 30 4 1209702327 0
88 history: 1 30 4 1209615918 0
89 history: 1 30 4 1209529659 0
90 history: 1 30 4 1209443026 0
91 history: 1 30 4 1209356534 0
92 history: 1 30 4 1209270139 0
93 history: 1 30 4 1209183732 0
94 history: 1 30 4 1209097323 0
95 history: 1 30 4 1209010914 0
96 history: 1 30 4 1208924687 0
97 history: 1 30 4 1208838244 0
98 history: 1 30 4 1208751683 0
99 history: 1 30 4 1208665357 0
100 history: 0 208150 98142 1208579385 34
101 history: 1 50 10 1208492851 0
102 history: 1 50 10 1208406237 0
103 history: 1 50 10 1208319724 0
104 history: 1 50 10 1208233394 0
105 history: 1 50 10 1208146982 0
106 history: 1 50 10 1208060529 0
107 history: 1 50 10 1207974095 0
108 history: 1 50 10 1207887693 0
109 history: 1 50 10 1207801290 0
110 history: 1 50 10 1207714857 0
111 history: 1 50 10 1207628549 0
112 history: 1 50 10 1207541982 0
113 history: 1 50 10 1207455648 0
114 history: 1 50 10 1207369359 0
115 history: 1 50 10 1207282921 0
116 history: 1 50 10 1207196370 0
117 history: 1 50 10 1207109992 0
118 history: 1 50 10 1207023639 0
119 history: 1 50 10 1206937266 0
120 history: 1 50 10 1206850809 0
121 history: 1 50 10 1206764417 0
122 history: 1 50 10 1206678095 0
123 history: 1 50 10 1206591577 0
124 history: 1 50 10 1206505188 0
125 history: 1 50 10 1206418784 0
126 history: 1 30 4 1206332424 0
127 history: 1 30 4 1206245966 0
128 history: 1 30 4 1206159612 0
129 history: 0 208150 98138 1206073398 33
130 history: 1 70 11 1205986945 0
131 history: 1 70 11 1205900387 0
132 history: 1 70 11 1205814007 0
133 history: 1 70 11 1205727544 0
134 history: 1 70 11 1205641330 0
135 history: 1 70 11 1205554904 0
136 history: 1 70 11 1205468423 0
137 history: 1 70 11 1205381996 0
138 history: 1 70 11 1205295616 0
139 history: 1 70 11 1205209178 0
140 history: 1 70 11 1205122964 0
141 history: 1 70 11 1205039969 0
142 history: 1 70 11 1204953604 0
143 history: 1 70 11 1204867108 0
144 history: 1 70 11 1204780854 0
145 history: 1 70 11 1204694432 0
146 history: 1 70 11 1204608080 0
147 history: 1 70 11 1204521528 0
148 history: 1 30 4 1204435294 0
149 history: 1 30 4 1204348825 0
150 history: 1 30 4 1204176062 0
151 history: 1 30 4 1204003405 0
152 history: 1 30 4 1203916794 0
153 history: 1 30 4 1203830409 0
154 history: 1 30 4 1203744032 0
155 history: 1 30 4 1203657632 0
156 history: 0 208120 98130 1203571350 33
157 history: 2 220 139 1203312046 0
158 history: 2 220 139 1203139220 0
159 history: 2 220 139 1203053015 0
163 ## set up the temporary infofile to read from
164 my $tmp_infofile = "$Installcheck::TMP/temporary-infofile";
165 burp $tmp_infofile, $data;
167 my $host = "fakehost";
168 my $disk = "/home/fakeuser/disk";
169 my $host_q = sanitise_filename($host);
170 my $disk_q = sanitise_filename($disk);
172 my $curinfo_file = "$infodir/$host_q/$disk_q/info";
174 ## start running tests
175 ok(my $ci = Amanda::Curinfo->new($infodir),
176 "create the Amanda::Curinfo object");
180 bless({ 'infodir' => $infodir }, 'Amanda::Curinfo'),
181 "Amanda::Curinfo object check"
184 ok(my $info = Amanda::Curinfo::Info->new($tmp_infofile),
185 "create the Amanda::Curinfo::Info object");
186 ok($ci->put_info($host, $disk, $info),
187 "test writing the Info object to the Curinfo database");
188 ok(-f $curinfo_file, "Info object installed in the correct location");
190 ## re-load Amanda::Curinfo::Info and check each field separately
193 ok($info = $ci->get_info($host, $disk),
194 "Amanda::Curinfo::Info constructor check");
196 ## Test components of Amanda::Curinfo::Info separately
198 is( $info->{command}, "0", "Amanda::Curinfo::Info->command check" );
204 'rate' => [ '27.800000', '3062.406250', '1.000000' ],
205 'comp' => [ '0.133333', '0.133333', '0.133333' ]
207 'Amanda::Curinfo::Perf'
209 'Amanda::Curinfo::Perf ($info->{incr}) check'
216 'rate' => [ '2974.060606', '2886.529412', '2973.878788' ],
217 'comp' => [ '0.471483', '0.471497', '0.471477' ]
219 'Amanda::Curinfo::Perf'
221 'Amanda::Curinfo::Perf ($info->{full}) check'
230 'date' => '1211438831',
237 'Amanda::Curinfo::Stats'
242 'date' => '1212380683',
249 'Amanda::Curinfo::Stats'
252 'Amanda::Curinfo::Stats ($info->{inf}) check'
261 'date' => '1212380683',
266 'Amanda::Curinfo::History'
271 'date' => '1212294141',
276 'Amanda::Curinfo::History'
281 'date' => '1212207722',
286 'Amanda::Curinfo::History'
291 'date' => '1212121208',
296 'Amanda::Curinfo::History'
301 'date' => '1212034786',
306 'Amanda::Curinfo::History'
311 'date' => '1211948729',
316 'Amanda::Curinfo::History'
321 'date' => '1211862004',
326 'Amanda::Curinfo::History'
331 'date' => '1211775583',
336 'Amanda::Curinfo::History'
341 'date' => '1211690046',
346 'Amanda::Curinfo::History'
351 'date' => '1211603671',
356 'Amanda::Curinfo::History'
361 'date' => '1211526232',
366 'Amanda::Curinfo::History'
371 'date' => '1211438831',
376 'Amanda::Curinfo::History'
381 'date' => '1211344512',
386 'Amanda::Curinfo::History'
391 'date' => '1210912587',
396 'Amanda::Curinfo::History'
401 'date' => '1210826040',
406 'Amanda::Curinfo::History'
411 'date' => '1210739734',
416 'Amanda::Curinfo::History'
421 'date' => '1210653066',
426 'Amanda::Curinfo::History'
431 'date' => '1210567105',
436 'Amanda::Curinfo::History'
441 'date' => '1210480489',
446 'Amanda::Curinfo::History'
451 'date' => '1210393557',
456 'Amanda::Curinfo::History'
461 'date' => '1210307156',
466 'Amanda::Curinfo::History'
471 'date' => '1210220759',
476 'Amanda::Curinfo::History'
481 'date' => '1210134427',
486 'Amanda::Curinfo::History'
491 'date' => '1210047948',
496 'Amanda::Curinfo::History'
501 'date' => '1209961521',
506 'Amanda::Curinfo::History'
511 'date' => '1209875114',
516 'Amanda::Curinfo::History'
521 'date' => '1209788730',
526 'Amanda::Curinfo::History'
531 'date' => '1209702327',
536 'Amanda::Curinfo::History'
541 'date' => '1209615918',
546 'Amanda::Curinfo::History'
551 'date' => '1209529659',
556 'Amanda::Curinfo::History'
561 'date' => '1209443026',
566 'Amanda::Curinfo::History'
571 'date' => '1209356534',
576 'Amanda::Curinfo::History'
581 'date' => '1209270139',
586 'Amanda::Curinfo::History'
591 'date' => '1209183732',
596 'Amanda::Curinfo::History'
601 'date' => '1209097323',
606 'Amanda::Curinfo::History'
611 'date' => '1209010914',
616 'Amanda::Curinfo::History'
621 'date' => '1208924687',
626 'Amanda::Curinfo::History'
631 'date' => '1208838244',
636 'Amanda::Curinfo::History'
641 'date' => '1208751683',
646 'Amanda::Curinfo::History'
651 'date' => '1208665357',
656 'Amanda::Curinfo::History'
661 'date' => '1208579385',
666 'Amanda::Curinfo::History'
671 'date' => '1208492851',
676 'Amanda::Curinfo::History'
681 'date' => '1208406237',
686 'Amanda::Curinfo::History'
691 'date' => '1208319724',
696 'Amanda::Curinfo::History'
701 'date' => '1208233394',
706 'Amanda::Curinfo::History'
711 'date' => '1208146982',
716 'Amanda::Curinfo::History'
721 'date' => '1208060529',
726 'Amanda::Curinfo::History'
731 'date' => '1207974095',
736 'Amanda::Curinfo::History'
741 'date' => '1207887693',
746 'Amanda::Curinfo::History'
751 'date' => '1207801290',
756 'Amanda::Curinfo::History'
761 'date' => '1207714857',
766 'Amanda::Curinfo::History'
771 'date' => '1207628549',
776 'Amanda::Curinfo::History'
781 'date' => '1207541982',
786 'Amanda::Curinfo::History'
791 'date' => '1207455648',
796 'Amanda::Curinfo::History'
801 'date' => '1207369359',
806 'Amanda::Curinfo::History'
811 'date' => '1207282921',
816 'Amanda::Curinfo::History'
821 'date' => '1207196370',
826 'Amanda::Curinfo::History'
831 'date' => '1207109992',
836 'Amanda::Curinfo::History'
841 'date' => '1207023639',
846 'Amanda::Curinfo::History'
851 'date' => '1206937266',
856 'Amanda::Curinfo::History'
861 'date' => '1206850809',
866 'Amanda::Curinfo::History'
871 'date' => '1206764417',
876 'Amanda::Curinfo::History'
881 'date' => '1206678095',
886 'Amanda::Curinfo::History'
891 'date' => '1206591577',
896 'Amanda::Curinfo::History'
901 'date' => '1206505188',
906 'Amanda::Curinfo::History'
911 'date' => '1206418784',
916 'Amanda::Curinfo::History'
921 'date' => '1206332424',
926 'Amanda::Curinfo::History'
931 'date' => '1206245966',
936 'Amanda::Curinfo::History'
941 'date' => '1206159612',
946 'Amanda::Curinfo::History'
951 'date' => '1206073398',
956 'Amanda::Curinfo::History'
961 'date' => '1205986945',
966 'Amanda::Curinfo::History'
971 'date' => '1205900387',
976 'Amanda::Curinfo::History'
981 'date' => '1205814007',
986 'Amanda::Curinfo::History'
991 'date' => '1205727544',
996 'Amanda::Curinfo::History'
1001 'date' => '1205641330',
1006 'Amanda::Curinfo::History'
1011 'date' => '1205554904',
1016 'Amanda::Curinfo::History'
1021 'date' => '1205468423',
1026 'Amanda::Curinfo::History'
1031 'date' => '1205381996',
1036 'Amanda::Curinfo::History'
1041 'date' => '1205295616',
1046 'Amanda::Curinfo::History'
1051 'date' => '1205209178',
1056 'Amanda::Curinfo::History'
1061 'date' => '1205122964',
1066 'Amanda::Curinfo::History'
1071 'date' => '1205039969',
1076 'Amanda::Curinfo::History'
1081 'date' => '1204953604',
1086 'Amanda::Curinfo::History'
1091 'date' => '1204867108',
1096 'Amanda::Curinfo::History'
1101 'date' => '1204780854',
1106 'Amanda::Curinfo::History'
1111 'date' => '1204694432',
1116 'Amanda::Curinfo::History'
1121 'date' => '1204608080',
1126 'Amanda::Curinfo::History'
1131 'date' => '1204521528',
1136 'Amanda::Curinfo::History'
1141 'date' => '1204435294',
1146 'Amanda::Curinfo::History'
1151 'date' => '1204348825',
1156 'Amanda::Curinfo::History'
1161 'date' => '1204176062',
1166 'Amanda::Curinfo::History'
1171 'date' => '1204003405',
1176 'Amanda::Curinfo::History'
1181 'date' => '1203916794',
1186 'Amanda::Curinfo::History'
1191 'date' => '1203830409',
1196 'Amanda::Curinfo::History'
1201 'date' => '1203744032',
1206 'Amanda::Curinfo::History'
1211 'date' => '1203657632',
1216 'Amanda::Curinfo::History'
1221 'date' => '1203571350',
1226 'Amanda::Curinfo::History'
1231 'date' => '1203312046',
1236 'Amanda::Curinfo::History'
1241 'date' => '1203139220',
1246 'Amanda::Curinfo::History'
1251 'date' => '1203053015',
1256 'Amanda::Curinfo::History'
1259 'Amanda::Curinfo::history ($info->{history}) check'
1262 is( $info->{last_level}, 1, "Amanda::Curinfo::Info last_level check" );
1264 is( $info->{consecutive_runs},
1265 11, "Amanda::Curinfo::Info consecutive_runs check" );
1267 ## test the accessor functions
1268 is( $info->get_dumpdate(2),
1269 "2008:6:2:4:24:43", 'Amanda::Curinfo::Info->get_dumpdate check' );
1271 is( $info->get_dumpdate(1),
1272 "2008:5:22:6:47:11", 'Amanda::Curinfo::Info->get_dumpdate check' );
1276 $ci->del_info($host, $disk);
1277 ok(!-f "$infodir/$host_q/$disk_q/info", "infofile successfully deleted");
1279 ## rewrite it using the built-in
1281 ok( $ci->put_info($host, $disk, $info), "Amanda::Curinfo->put_info check");
1283 ## compare the two files
1287 my ( $from, $to ) = @_;
1289 $$from =~ s{\s+}{ }g;
1292 return diff($from, $to);
1295 my $filedata = slurp $curinfo_file;
1299 my $diff_txt = diff_wi(\$filedata, \$data);
1301 is($diff_txt, "", "file writing functional.")
1302 or diag("original and written infofile different. diff:\n"
1303 . diff_wi(\$filedata, \$data));
1307 $filedata =~ s{\s+}{ }g;
1308 $data =~ s{\s+}{ }g;
1310 is($filedata, $data, "file writing functional. ")
1311 or diag("original and written infofile different.");