From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <root@dev.dominic.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 0DA366706A
 for <pve-devel@lists.proxmox.com>; Mon, 11 Jan 2021 12:43:04 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 0BE4119D4C
 for <pve-devel@lists.proxmox.com>; Mon, 11 Jan 2021 12:43:04 +0100 (CET)
Received: from dev.dominic.proxmox.com (212-186-127-178.static.upcbusiness.at
 [212.186.127.178])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 8C23D19D42
 for <pve-devel@lists.proxmox.com>; Mon, 11 Jan 2021 12:43:03 +0100 (CET)
Received: by dev.dominic.proxmox.com (Postfix, from userid 0)
 id 77C2821608; Mon, 11 Jan 2021 12:43:03 +0100 (CET)
From: =?UTF-8?q?Dominic=20J=C3=A4ger?= <d.jaeger@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 11 Jan 2021 12:42:59 +0100
Message-Id: <20210111114259.121999-2-d.jaeger@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210111114259.121999-1-d.jaeger@proxmox.com>
References: <20210111114259.121999-1-d.jaeger@proxmox.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  1
 AWL -0.372 Adjusted score from AWL reputation of From: address
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery
 methods
 KHOP_HELO_FCRDNS        0.398 Relay HELO differs from its IP's reverse DNS
 NO_DNS_FOR_FROM         0.379 Envelope sender has no MX or A DNS records
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_NONE                0.001 SPF: sender does not publish an SPF Record
Subject: [pve-devel] [PATCH manager 2/2] Add tests for OSD-belongs-to-node
 helper
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 11 Jan 2021 11:43:04 -0000

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
---
 test/Makefile    |  5 +++-
 test/OSD_test.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100755 test/OSD_test.pl

diff --git a/test/Makefile b/test/Makefile
index d383e89f..3c4d2f2a 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -5,7 +5,7 @@ all:
 export PERLLIB=..
 
 .PHONY: check balloon-test replication-test mail-test vzdump-test
-check: test-replication test-balloon test-mail test-vzdump
+check: test-replication test-balloon test-mail test-vzdump test-osd
 
 test-balloon:
 	./balloontest.pl
@@ -27,6 +27,9 @@ test-vzdump-guest-included:
 test-vzdump-retention:
 	./vzdump_new_retention_test.pl
 
+test-osd:
+	./OSD_test.pl
+
 .PHONY: install
 install:
 
diff --git a/test/OSD_test.pl b/test/OSD_test.pl
new file mode 100755
index 00000000..df8c7881
--- /dev/null
+++ b/test/OSD_test.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib ('.', '..');
+
+use JSON;
+use Test::More;
+use PVE::API2::Ceph::OSD;
+
+use Data::Dumper;
+
+my $tree = {
+    nodes => [
+	{
+	    id => -3,
+	    name => 'pveA',
+	    children => [ 0,1,2,3 ],
+	}, {
+	    id => -5,
+	    name => 'pveB',
+	    children => [ 4,5,6,7 ],
+	}, {
+	    id => -7,
+	    name => 'pveC',
+	    children => [ 8,9,10,11 ],
+	},
+    ],
+};
+
+
+# Check if all the grep and casts are correct
+my @belong_to_B = ( 4,5 );
+my @not_belong_to_B = ( -1,1,10,15 );
+foreach (@belong_to_B) {
+    is (
+	PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
+	1,
+	"OSD $_ belongs to node pveB",
+    );
+}
+foreach (@not_belong_to_B) {
+    is (
+	PVE::API2::Ceph::OSD::osd_belongs_to_node($tree, 'pveB', $_),
+	0,
+	"OSD $_ does not belong to node pveB",
+    );
+}
+
+
+my $double_nodes_tree = {
+    nodes => [
+	{
+	    name => 'pveA',
+	},
+	{
+	    name => 'pveA',
+	}
+    ]
+};
+eval { PVE::API2::Ceph::OSD::osd_belongs_to_node($double_nodes_tree, 'pveA') };
+like($@, qr/not be more than one/, "Die if node occurs too often");
+
+my $tree_without_nodes = {
+    dummy => 'dummy',
+};
+eval { PVE::API2::Ceph::OSD::osd_belongs_to_node(undef) };
+like($@, qr/No tree nodes/, "Die if tree has no nodes");
+
+
+done_testing(@belong_to_B + @not_belong_to_B + 2);
\ No newline at end of file
-- 
2.20.1