]>
Commit | Line | Data |
---|---|---|
e12c5dbf DJ |
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 | ||
d7a63207 | 14 | # NOTE: not exhausive, reduced to actually required fields! |
e12c5dbf DJ |
15 | my $tree = { |
16 | nodes => [ | |
17 | { | |
18 | id => -3, | |
19 | name => 'pveA', | |
20 | children => [ 0,1,2,3 ], | |
d7a63207 TL |
21 | type => 'host', |
22 | }, | |
23 | { | |
e12c5dbf DJ |
24 | id => -5, |
25 | name => 'pveB', | |
26 | children => [ 4,5,6,7 ], | |
d7a63207 TL |
27 | type => 'host', |
28 | }, | |
29 | { | |
e12c5dbf DJ |
30 | id => -7, |
31 | name => 'pveC', | |
32 | children => [ 8,9,10,11 ], | |
d7a63207 | 33 | type => 'host', |
e12c5dbf DJ |
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', | |
d7a63207 | 62 | type => 'host', |
e12c5dbf DJ |
63 | }, |
64 | { | |
65 | name => 'pveA', | |
d7a63207 | 66 | type => 'host', |
e12c5dbf DJ |
67 | } |
68 | ] | |
69 | }; | |
70 | eval { PVE::API2::Ceph::OSD::osd_belongs_to_node($double_nodes_tree, 'pveA') }; | |
d7a63207 | 71 | like($@, qr/duplicate host name found/, "Die if node occurs too often"); |
e12c5dbf | 72 | |
d7a63207 TL |
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 | ); | |
e12c5dbf DJ |
78 | |
79 | ||
d7a63207 | 80 | done_testing(@belong_to_B + @not_belong_to_B + 2); |