Skip to content

Commit 9205f3f

Browse files
committed
ncm-afsclt: add unit tests for cache configuration
1 parent 845fa03 commit 9205f3f

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 => 17;
10+
use Test::NoWarnings;
11+
use Test::Quattor qw(automatic automatic_nocachemount 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_AUTOMACTIC => '/afs:/afscache:AUTOMATIC
27+
';
28+
Readonly my $CACHEINFO_AUTOMACTIC_2 => '/afs::AUTOMATIC
29+
';
30+
Readonly my $CACHEINFO_EXPLICIT_SIZE => '/afs:/afscache:1422000
31+
';
32+
Readonly my $CACHEINFO_EXPLICIT_MOUNT => '/afsmnt:/var/afs/cache:1422000
33+
';
34+
Readonly my $FS_GETPARAMS_CMD => 'fs getcacheparms';
35+
Readonly my $FS_GETPARAMS_OUTPUT_1 => "AFS using 1229334 of the cache's available 1422000 1K byte blocks.";
36+
37+
#############
38+
# Main code #
39+
#############
40+
41+
42+
my $fh;
43+
my $status;
44+
45+
$CAF::Object::NoAction = 1;
46+
set_caf_file_close_diff(1);
47+
48+
my $comp = NCM::Component::afsclt->new('afsclt');
49+
50+
my $config_automatic = get_config_for_profile("automatic");
51+
my $config_no_cachemount = get_config_for_profile("automatic_nocachemount");
52+
my $config_explicit = get_config_for_profile("explicit");
53+
54+
set_desired_output($FS_GETPARAMS_CMD, $FS_GETPARAMS_OUTPUT_1);
55+
56+
# Initial cacheinfo file empty
57+
set_file_contents($CACHEINFO_FILE,"");
58+
$status = $comp->Configure_Cache($config_automatic);
59+
ok(!$status, "Configure_Cache returned no explicit error");
60+
$fh = get_file($CACHEINFO_FILE);
61+
ok(defined($fh), $CACHEINFO_FILE." was opened");
62+
is("$fh", $CACHEINFO_AUTOMACTIC, $CACHEINFO_FILE." (initially empty) has expected contents");
63+
$fh->close();
64+
65+
# Initial cacheinfo file empty and cache mount point undefined
66+
set_file_contents($CACHEINFO_FILE,"");
67+
$status = $comp->Configure_Cache($config_no_cachemount);
68+
ok(!$status, "Configure_Cache returned no explicit error");
69+
$fh = get_file($CACHEINFO_FILE);
70+
ok(defined($fh), $CACHEINFO_FILE." was opened");
71+
is("$fh", $CACHEINFO_AUTOMACTIC_2, $CACHEINFO_FILE." (cache mount undefined) has expected contents");
72+
$fh->close();
73+
74+
# Initial cacheinfo is the expected cacheinfo (size=AUTOMATIC)
75+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_AUTOMACTIC);
76+
$status = $comp->Configure_Cache($config_automatic);
77+
ok(!$status, "Configure_Cache returned no explicit error");
78+
$fh = get_file($CACHEINFO_FILE);
79+
ok(defined($fh), $CACHEINFO_FILE." was opened");
80+
is("$fh", $CACHEINFO_AUTOMACTIC, $CACHEINFO_FILE." (initially expected) has expected contents");
81+
$fh->close();
82+
83+
# Initial cacheinfo file with explicit size, expected AUTOMATIC
84+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_EXPLICIT_SIZE);
85+
$status = $comp->Configure_Cache($config_automatic);
86+
ok(!$status, "Configure_Cache returned no explicit error");
87+
$fh = get_file($CACHEINFO_FILE);
88+
ok(defined($fh), $CACHEINFO_FILE." was opened");
89+
is("$fh", $CACHEINFO_AUTOMACTIC, $CACHEINFO_FILE." (initially explicit size) has expected contents");
90+
$fh->close();
91+
92+
# Initial cacheinfo file with size=AUTOMATIC, expected explicit size
93+
set_file_contents($CACHEINFO_FILE,$CACHEINFO_AUTOMACTIC);
94+
$status = $comp->Configure_Cache($config_explicit);
95+
ok(!$status, "Configure_Cache returned no explicit error");
96+
$fh = get_file($CACHEINFO_FILE);
97+
ok(defined($fh), $CACHEINFO_FILE." was opened");
98+
is("$fh", $CACHEINFO_EXPLICIT_MOUNT, $CACHEINFO_FILE." (initially AUTOMATIC) has expected contents");
99+
$fh->close();
100+
101+
102+
103+
Test::NoWarnings::had_no_warnings();
104+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object template automatic;
2+
3+
# mock pkg_repl
4+
function pkg_repl = { null; };
5+
6+
include 'components/afsclt/config';
7+
8+
prefix '/software/components/afsclt';
9+
10+
# remove the dependencies that cannot be validated successfully
11+
'dependencies' = null;
12+
13+
'cachemount' = '/afscache';
14+
'cachesize' = 'AUTOMATIC';
15+
'cellservdb' = 'http://grand.central.org/dl/cellservdb/CellServDB';
16+
'dispatch' = true;
17+
'enabled' = 'yes';
18+
'thiscell' = 'in2p3.fr';
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
object template automatic_nocachemount;
2+
3+
# mock pkg_repl
4+
function pkg_repl = { null; };
5+
6+
include 'components/afsclt/config';
7+
8+
prefix '/software/components/afsclt';
9+
10+
# remove the dependencies that cannot be validated successfully
11+
'dependencies' = null;
12+
13+
'cachesize' = 'AUTOMATIC';
14+
'cellservdb' = 'http://grand.central.org/dl/cellservdb/CellServDB';
15+
'dispatch' = true;
16+
'enabled' = 'yes';
17+
'thiscell' = 'in2p3.fr';
18+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
object template explicit;
2+
3+
# mock pkg_repl
4+
function pkg_repl = { null; };
5+
6+
include 'components/afsclt/config';
7+
8+
prefix '/software/components/afsclt';
9+
10+
# remove the dependencies that cannot be validated successfully
11+
'dependencies' = null;
12+
13+
'afs_mount' = '/afsmnt';
14+
'cachemount' = '/var/afs/cache';
15+
'cachesize' = '1422000';
16+
'cellservdb' = 'http://grand.central.org/dl/cellservdb/CellServDB';
17+
'dispatch' = true;
18+
'enabled' = 'yes';
19+
'thiscell' = 'in2p3.fr';
20+

0 commit comments

Comments
 (0)