Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / standalone / osd / osd-config.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2014 Cloudwatt <libre.licensing@cloudwatt.com>
4 # Copyright (C) 2014, 2015 Red Hat <contact@redhat.com>
5 #
6 # Author: Loic Dachary <loic@dachary.org>
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU Library Public License for more details.
17 #
18
19 source $CEPH_ROOT/qa/standalone/ceph-helpers.sh
20
21 function run() {
22     local dir=$1
23     shift
24
25     export CEPH_MON="127.0.0.1:7100" # git grep '\<7100\>' : there must be only one
26     export CEPH_ARGS
27     CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
28     CEPH_ARGS+="--mon-host=$CEPH_MON "
29
30     local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
31     for func in $funcs ; do
32         setup $dir || return 1
33         $func $dir || return 1
34         teardown $dir || return 1
35     done
36 }
37
38 function TEST_config_init() {
39     local dir=$1
40
41     run_mon $dir a || return 1
42     run_mgr $dir x || return 1
43     local advance=1000
44     local stale=1000
45     local cache=500
46     run_osd $dir 0 \
47         --osd-map-max-advance $advance \
48         --osd-map-cache-size $cache \
49         --osd-pg-epoch-persisted-max-stale $stale \
50         || return 1
51     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log flush || return 1
52     grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
53     grep 'is not > osd_pg_epoch_persisted_max_stale' $dir/osd.0.log || return 1
54 }
55
56 function TEST_config_track() {
57     local dir=$1
58
59     run_mon $dir a || return 1
60     run_mgr $dir x || return 1
61     run_osd $dir 0 || return 1
62
63     local osd_map_cache_size=$(CEPH_ARGS='' ceph-conf \
64         --show-config-value osd_map_cache_size)
65     local osd_map_max_advance=$(CEPH_ARGS='' ceph-conf \
66         --show-config-value osd_map_max_advance)
67     local osd_pg_epoch_persisted_max_stale=$(CEPH_ARGS='' ceph-conf \
68         --show-config-value osd_pg_epoch_persisted_max_stale)
69     #
70     # lower cache_size under max_advance to trigger the warning
71     #
72     ! grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
73     local cache=$(($osd_map_max_advance / 2))
74     ceph tell osd.0 injectargs "--osd-map-cache-size $cache" || return 1
75     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log flush || return 1
76     grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
77     rm $dir/osd.0.log
78     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log reopen || return 1
79
80     #
81     # reset cache_size to the default and assert that it does not trigger the warning
82     #
83     ! grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
84     local cache=$osd_map_cache_size
85     ceph tell osd.0 injectargs "--osd-map-cache-size $cache" || return 1
86     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log flush || return 1
87     ! grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
88     rm $dir/osd.0.log
89     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log reopen || return 1
90
91     #
92     # increase the osd_map_max_advance above the default cache_size
93     #
94     ! grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
95     local advance=$(($osd_map_cache_size * 2))
96     ceph tell osd.0 injectargs "--osd-map-max-advance $advance" || return 1
97     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log flush || return 1
98     grep 'is not > osd_map_max_advance' $dir/osd.0.log || return 1
99     rm $dir/osd.0.log
100     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log reopen || return 1
101
102     #
103     # increase the osd_pg_epoch_persisted_max_stale above the default cache_size
104     #
105     ! grep 'is not > osd_pg_epoch_persisted_max_stale' $dir/osd.0.log || return 1
106     local stale=$(($osd_map_cache_size * 2))
107     ceph tell osd.0 injectargs "--osd-pg-epoch-persisted-max-stale $stale" || return 1
108     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log flush || return 1
109     grep 'is not > osd_pg_epoch_persisted_max_stale' $dir/osd.0.log || return 1
110     rm $dir/osd.0.log
111     CEPH_ARGS='' ceph --admin-daemon $(get_asok_path osd.0) log reopen || return 1
112 }
113
114 main osd-config "$@"
115
116 # Local Variables:
117 # compile-command: "cd ../.. ; make -j4 && test/osd/osd-config.sh"
118 # End: