]> git.proxmox.com Git - pve-manager.git/blob - test/OSD_test.pl
Add tests for OSD-belongs-to-node helper
[pve-manager.git] / test / OSD_test.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib ('.', '..');
7
8 use JSON;
9 use Test::More;
10 use PVE::API2::Ceph::OSD;
11
12 use Data::Dumper;
13
14 my $tree = {
15 nodes => [
16 {
17 id => -3,
18 name => 'pveA',
19 children => [ 0,1,2,3 ],
20 }, {
21 id => -5,
22 name => 'pveB',
23 children => [ 4,5,6,7 ],
24 }, {
25 id => -7,
26 name => 'pveC',
27 children => [ 8,9,10,11 ],
28 },
29 ],
30 };
31
32
33 # Check if all the grep and casts are correct
34 my @belong_to_B = ( 4,5 );
35 my @not_belong_to_B = ( -1,1,10,15 );
36 foreach (@belong_to_B) {
37 is (
38 PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
39 1,
40 "OSD $_ belongs to node pveB",
41 );
42 }
43 foreach (@not_belong_to_B) {
44 is (
45 PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
46 0,
47 "OSD $_ does not belong to node pveB",
48 );
49 }
50
51
52 my $double_nodes_tree = {
53 nodes => [
54 {
55 name => 'pveA',
56 },
57 {
58 name => 'pveA',
59 }
60 ]
61 };
62 eval { PVE::API2::Ceph::OSD::osd_belongs_to_node($double_nodes_tree, 'pveA') };
63 like($@, qr/not be more than one/, "Die if node occurs too often");
64
65 my $tree_without_nodes = {
66 dummy => 'dummy',
67 };
68 eval { PVE::API2::Ceph::OSD::osd_belongs_to_node(undef) };
69 like($@, qr/No tree nodes/, "Die if tree has no nodes");
70
71
72 done_testing(@belong_to_B + @not_belong_to_B + 2);