]> git.proxmox.com Git - pve-manager.git/blame - test/OSD_test.pl
api: ceph ec pools: make add_storages overridable default
[pve-manager.git] / test / OSD_test.pl
CommitLineData
e12c5dbf
DJ
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use lib ('.', '..');
7
8use JSON;
9use Test::More;
10use PVE::API2::Ceph::OSD;
11
12use Data::Dumper;
13
d7a63207 14# NOTE: not exhausive, reduced to actually required fields!
e12c5dbf
DJ
15my $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
40my @belong_to_B = ( 4,5 );
41my @not_belong_to_B = ( -1,1,10,15 );
42foreach (@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}
49foreach (@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
58my $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};
70eval { PVE::API2::Ceph::OSD::osd_belongs_to_node($double_nodes_tree, 'pveA') };
d7a63207 71like($@, qr/duplicate host name found/, "Die if node occurs too often");
e12c5dbf 72
d7a63207
TL
73is (
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 80done_testing(@belong_to_B + @not_belong_to_B + 2);