| 51 |
rodolico |
1 |
#! /usr/bin/env perl
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use warnings;
|
|
|
5 |
use FindBin;
|
|
|
6 |
use lib "$FindBin::Bin";
|
|
|
7 |
use lib "$FindBin::Bin/.."; # ensure module path
|
|
|
8 |
|
|
|
9 |
use ZFS_Utils qw(runCmd loadConfig logMsg makeReplicateCommands $logFileName $displayLogsOnConsole);
|
|
|
10 |
|
|
|
11 |
# Test script for ZFS_Utils (dry-run safe)
|
|
|
12 |
|
|
|
13 |
$displayLogsOnConsole = 1;
|
|
|
14 |
$logFileName = '/tmp/zfs_utils_test.log';
|
|
|
15 |
unlink $logFileName if -f $logFileName;
|
|
|
16 |
|
|
|
17 |
print "Running ZFS_Utils smoke tests (dry-run safe)\n";
|
|
|
18 |
|
|
|
19 |
# 1) runCmd in scalar context
|
|
|
20 |
my $echo_out = runCmd('printf', 'hello_from_runCmd');
|
|
|
21 |
print "runCmd scalar output: [$echo_out]\n";
|
|
|
22 |
|
|
|
23 |
# 2) runCmd in list context
|
|
|
24 |
my @ls = runCmd('printf', "line1\nline2\n");
|
|
|
25 |
print "runCmd list output: ". join('|', @ls) ."\n";
|
|
|
26 |
|
|
|
27 |
# 3) loadConfig using a temporary YAML file
|
|
|
28 |
my $tmp_yaml = '/tmp/test_zfs_utils.conf.yaml';
|
|
|
29 |
open my $yh, '>', $tmp_yaml or die "Cannot write $tmp_yaml: $!";
|
|
|
30 |
print $yh "transport:\n mount_point: /tmp/mount_point_test\n dryrun: 1\n";
|
|
|
31 |
print $yh "datasets:\n demo:\n source: pool\n target: backup\n";
|
|
|
32 |
close $yh;
|
|
|
33 |
|
|
|
34 |
my $loaded = loadConfig($tmp_yaml, { default_key => 'default_value' });
|
|
|
35 |
print "Loaded config keys: ". join(', ', sort keys %$loaded) ."\n";
|
|
|
36 |
print "transport.mount_point = " . ($loaded->{transport}{mount_point} // '(undef)') ."\n";
|
|
|
37 |
|
|
|
38 |
# 4) makeReplicateCommands - sample snapshot lines
|
|
|
39 |
my @snaplines = (
|
|
|
40 |
'tank/home@2025-12-01-1d extra',
|
|
|
41 |
'tank/home@2025-12-07-1d extra',
|
|
|
42 |
'tank/data@2025-11-01-7d',
|
|
|
43 |
);
|
|
|
44 |
my @status = ('tank/home@2025-11-30-1d');
|
|
|
45 |
my @newstatus;
|
|
|
46 |
my $cmds = makeReplicateCommands(\@snaplines, \@status, \@newstatus);
|
|
|
47 |
print "Generated replicate commands:\n";
|
|
|
48 |
for my $fs (sort keys %$cmds) {
|
|
|
49 |
print " $fs => $cmds->{$fs}\n";
|
|
|
50 |
}
|
|
|
51 |
print "New status entries: ". join(', ', @newstatus) ."\n";
|
|
|
52 |
|
|
|
53 |
# 5) logMsg test
|
|
|
54 |
logMsg("Test log entry from test_zfs_utils.pl");
|
|
|
55 |
print "Log file written to $logFileName (if enabled).\n";
|
|
|
56 |
|
|
|
57 |
print "Smoke tests complete.\n";
|
|
|
58 |
|
|
|
59 |
# Clean up temporary YAML
|
|
|
60 |
unlink $tmp_yaml;
|
|
|
61 |
|
|
|
62 |
1;
|