From 970a79753dc52d82d2abf29ffe6f88adac678eb0 Mon Sep 17 00:00:00 2001 From: Xiaoxi Chen Date: Wed, 20 Aug 2014 15:35:44 +0800 Subject: [PATCH] CrushWrapper: pick a ruleset same as rule_id Originally in the add_simple_ruleset funtion, the ruleset_id is not reused but rule_id is reused. So after some add/remove against rules, the newly created rule likely to have ruleset!=rule_id. We dont want this happen because we are trying to hold the constraint that ruleset == rule_id. Signed-off-by: Xiaoxi Chen (cherry picked from commit 78e84f34da83abf5a62ae97bb84ab70774b164a6) --- src/test/mon/osd-crush.sh | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/test/mon/osd-crush.sh b/src/test/mon/osd-crush.sh index 56c85735df2f9..8aae18db6c037 100755 --- a/src/test/mon/osd-crush.sh +++ b/src/test/mon/osd-crush.sh @@ -175,6 +175,61 @@ EOF } +function Check_ruleset_id_match_rule_id() { + local rule_name=$1 + rule_id=`./ceph osd crush rule dump $rule_name | grep "\"rule_id\":" | awk -F ":|," '{print int($2)}'` + ruleset_id=`./ceph osd crush rule dump $rule_name | grep "\"ruleset\":"| awk -F ":|," '{print int($2)}'` + test $ruleset_id = $rule_id || return 1 +} + +function generate_manipulated_rules() { + local dir=$1 + ./ceph osd crush add-bucket $root host + ./ceph osd crush rule create-simple test_rule1 $root osd firstn || return 1 + ./ceph osd crush rule create-simple test_rule2 $root osd firstn || return 1 + ./ceph osd getcrushmap -o $dir/original_map + ./crushtool -d $dir/original_map -o $dir/decoded_original_map + #manipulate the rulesets , to make the rule_id != ruleset_id + sed -i 's/ruleset 0/ruleset 3/' $dir/decoded_original_map + sed -i 's/ruleset 2/ruleset 0/' $dir/decoded_original_map + sed -i 's/ruleset 1/ruleset 2/' $dir/decoded_original_map + + ./crushtool -c $dir/decoded_original_map -o $dir/new_map + ./ceph osd setcrushmap -i $dir/new_map + + ./ceph osd crush rule dump +} + +function TEST_crush_ruleset_match_rule_when_creating() { + local dir=$1 + local root=host1 + + generate_manipulated_rules $dir + + ./ceph osd crush rule create-simple special_rule_simple $root osd firstn || return 1 + + ./ceph osd crush rule dump + #show special_rule_simple has same rule_id and ruleset_id + Check_ruleset_id_match_rule_id special_rule_simple || return 1 +} + +function TEST_add_ruleset_failed() { + local dir=$1 + local root=host1 + + ./ceph osd crush add-bucket $root host + ./ceph osd crush rule create-simple test_rule1 $root osd firstn || return 1 + ./ceph osd crush rule create-simple test_rule2 $root osd firstn || return 1 + #./ceph osd crush rule rm test_rule1 + for i in `seq 3 255` + do + ./ceph osd crush rule create-simple test_rule$i $root osd firstn || return 1 + Check_ruleset_id_match_rule_id test_rule$i || return 1 + done + + ./ceph osd crush rule create-simple test_rule_nospace $root osd firstn 2>&1 | grep "Error ENOSPC" || return 1 + +} main osd-crush # Local Variables: -- 2.39.5