From: "Dominic Jäger" <d.jaeger@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 2/2] Add tests for OSD-belongs-to-node helper
Date: Mon, 11 Jan 2021 12:42:59 +0100 [thread overview]
Message-ID: <20210111114259.121999-2-d.jaeger@proxmox.com> (raw)
In-Reply-To: <20210111114259.121999-1-d.jaeger@proxmox.com>
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
next prev parent reply other threads:[~2021-01-11 11:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 11:42 [pve-devel] [PATCH manager 1/2] Fix #2053: OSD destroy only on specified node Dominic Jäger
2021-01-11 11:42 ` Dominic Jäger [this message]
2021-04-20 16:10 ` [pve-devel] applied-series: " Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210111114259.121999-2-d.jaeger@proxmox.com \
--to=d.jaeger@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox