Skip to content

Commit 01f4e91

Browse files
committed
ncm-afsclt: add unit tests for cache configuration
1 parent 56af89a commit 01f4e91

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# -*- mode: cperl -*-
2+
# ${license-info}
3+
# ${author-info}
4+
# ${build-info}
5+
6+
use strict;
7+
use warnings;
8+
9+
use Test::More tests => 14;
10+
use Test::NoWarnings;
11+
use Test::Quattor qw(automatic explicit);
12+
use NCM::Component::afsclt;
13+
use Readonly;
14+
use CAF::Object;
15+
Test::NoWarnings::clear_warnings();
16+
17+
=pod
18+
19+
=head1 SYNOPSIS
20+
21+
Tests for AFS client cache configuration
22+
23+
=cut
24+
25+
Readonly my $CACHEINFO_FILE => '/usr/vice/etc/cacheinfo';
26+
Readonly my $CACHEINFO_EXPECTED_1 => '/afs:/afscache:AUTOMATIC
27+
';
28+
Readonly my $CACHEINFO_EXPECTED_2 => '/afs:/afscache:1422000
29+
';
30+
Readonly my $FS_GETPARAMS_CMD => 'fs getcacheparms';
31+
Readonly my $FS_GETPARAMS_OUTPUT_1 => "AFS using 1229334 of the cache's available 1422000 1K byte blocks.";
32+
33+
#############
34+
# Main code #
35+
#############
36+
37+
$CAF::Object::NoAction = 1;
38+
set_caf_file_close_diff(1);
39+
40+
my $comp = NCM::Component::afsclt->new('afsclt');
41+
42+
my $config = get_config_for_profile("automatic");
43+
44+
# Initial cacheinfo file empty
45+
set_file_contents($CACHEINFO_FILE,"");
46+
set_desired_output($FS_GETPARAMS_CMD, $FS_GETPARAMS_OUTPUT_1);
47+
my $status = $comp->Configure_Cache($config);
48+
ok(!$status, "Configure_Cache returned no explicit error");
49+
my $fh = get_file($CACHEINFO_FILE);
50+
ok(defined($fh), $CACHEINFO_FILE." was opened");
51+
is("$fh", $CACHEINFO_EXPECTED_1, $CACHEINFO_FILE." (nitially empty) has expected contents");
52+
$fh->close();
53+
54+
# Initial cacheinfo is the expected cacheinfo (size=AUTOMATIC)
55+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_EXPECTED_1);
56+
set_desired_output($FS_GETPARAMS_CMD, $FS_GETPARAMS_OUTPUT_1);
57+
my $status = $comp->Configure_Cache($config);
58+
ok(!$status, "Configure_Cache returned no explicit error");
59+
my $fh = get_file($CACHEINFO_FILE);
60+
ok(defined($fh), $CACHEINFO_FILE." was opened");
61+
is("$fh", $CACHEINFO_EXPECTED_1, $CACHEINFO_FILE." (initially expected) has expected contents");
62+
$fh->close();
63+
64+
# Initial cacheinfo file with explicit size, expected AUTOMATIC
65+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_EXPECTED_2);
66+
set_desired_output($FS_GETPARAMS_CMD, $FS_GETPARAMS_OUTPUT_1);
67+
my $status = $comp->Configure_Cache($config);
68+
ok(!$status, "Configure_Cache returned no explicit error");
69+
my $fh = get_file($CACHEINFO_FILE);
70+
ok(defined($fh), $CACHEINFO_FILE." was opened");
71+
is("$fh", $CACHEINFO_EXPECTED_1, $CACHEINFO_FILE." (initially explicit size) has expected contents");
72+
$fh->close();
73+
74+
# Initial cacheinfo file with size=AUTOMATIC, expected explicit size
75+
$config = get_config_for_profile("explicit");
76+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_EXPECTED_1);
77+
set_desired_output($FS_GETPARAMS_CMD, $FS_GETPARAMS_OUTPUT_1);
78+
my $status = $comp->Configure_Cache($config);
79+
ok(!$status, "Configure_Cache returned no explicit error");
80+
my $fh = get_file($CACHEINFO_FILE);
81+
ok(defined($fh), $CACHEINFO_FILE." was opened");
82+
is("$fh", $CACHEINFO_EXPECTED_2, $CACHEINFO_FILE." (initially AUTOMATIC) has expected contents");
83+
$fh->close();
84+
85+
86+
87+
Test::NoWarnings::had_no_warnings();
88+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object template automatic;
2+
3+
"/software/components/afsclt/cachemount" = "/afscache";
4+
"/software/components/afsclt/cachesize" = "AUTOMATIC";
5+
"/software/components/afsclt/cellservdb" = "http://grand.central.org/dl/cellservdb/CellServDB";
6+
"/software/components/afsclt/dispatch" = true;
7+
"/software/components/afsclt/enabled" = "yes";
8+
"/software/components/afsclt/thiscell" = "in2p3.fr";
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object template explicit;
2+
3+
"/software/components/afsclt/cachemount" = "/afscache";
4+
"/software/components/afsclt/cachesize" = "1422000";
5+
"/software/components/afsclt/cellservdb" = "http://grand.central.org/dl/cellservdb/CellServDB";
6+
"/software/components/afsclt/dispatch" = true;
7+
"/software/components/afsclt/enabled" = "yes";
8+
"/software/components/afsclt/thiscell" = "in2p3.fr";
9+

0 commit comments

Comments
 (0)