]> git.proxmox.com Git - pve-manager.git/blob - test/OSD_test.pl
ui: guest import: fine-tune text on labels and button
[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 # NOTE: not exhausive, reduced to actually required fields!
15 my $tree = {
16 nodes => [
17 {
18 id => -3,
19 name => 'pveA',
20 children => [ 0,1,2,3 ],
21 type => 'host',
22 },
23 {
24 id => -5,
25 name => 'pveB',
26 children => [ 4,5,6,7 ],
27 type => 'host',
28 },
29 {
30 id => -7,
31 name => 'pveC',
32 children => [ 8,9,10,11 ],
33 type => 'host',
34 },
35 ],
36 };
37
38
39 # Check if all the grep and casts are correct
40 my @belong_to_B = ( 4,5 );
41 my @not_belong_to_B = ( -1,1,10,15 );
42 foreach (@belong_to_B) {
43 is (
44 PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
45 1,
46 "OSD $_ belongs to node pveB",
47 );
48 }
49 foreach (@not_belong_to_B) {
50 is (
51 PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
52 0,
53 "OSD $_ does not belong to node pveB",
54 );
55 }
56
57
58 my $double_nodes_tree = {
59 nodes => [
60 {
61 name => 'pveA',
62 type => 'host',
63 },
64 {
65 name => 'pveA',
66 type => 'host',
67 }
68 ]
69 };
70 eval { PVE::API2::Ceph::OSD::osd_belongs_to_node($double_nodes_tree, 'pveA') };
71 like($@, qr/duplicate host name found/, "Die if node occurs too often");
72
73 is (
74 PVE::API2::Ceph::OSD::osd_belongs_to_node(undef),
75 0,
76 "Early-return false if there's no/empty node tree",
77 );
78
79
80 done_testing(@belong_to_B + @not_belong_to_B + 2);