Statistics
| Branch: | Tag: | Revision:

root / devel / check-split-query @ 74685117

History | View | Annotate | Download (2.2 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2013 Google Inc.
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19

    
20
# Checks query equivalence between masterd and confd
21
#
22
# This is not (currently) run automatically during QA, but you can run
23
# it manually on a test cluster. It will force all queries known to be
24
# converted via both paths and check the difference, via both 'list'
25
# and 'list-fields'. For best results, it should be run on a non-empty
26
# cluster.
27
#
28
# Also note that this is not expected to show 100% perfect matches,
29
# since the JSON output differs slightly for complex data types
30
# (e.g. dictionaries with different sort order for keys, etc.).
31
#
32
# Current known delta:
33
# - all dicts, sort order
34
# - ctime is always defined in Haskell as epoch 0 if missing
35

    
36
MA=`mktemp master.XXXXXX`
37
CF=`mktemp confd.XXXXXX`
38
trap 'rm -f "$MA" "$CF"' EXIT
39
trap 'exit 1' SIGINT
40

    
41
RET=0
42
SEP="--separator=,"
43
ENABLED_QUERIES="node group network backup"
44

    
45
test_cmd() {
46
  cmd="$1"
47
  desc="$2"
48
  FORCE_LUXI_SOCKET=master $cmd > "$MA"
49
  FORCE_LUXI_SOCKET=query  $cmd > "$CF"
50
  diff -u "$MA" "$CF" || {
51
    echo "Mismatch in $desc, see above."
52
    RET=1
53
  }
54
}
55

    
56
for kind in $ENABLED_QUERIES; do
57
  all_fields=$(FORCE_LUXI_SOCKET=master gnt-$kind list-fields \
58
    --no-headers --separator=,|cut -d, -f1)
59
  comma_fields=$(echo $all_fields|tr ' ' ,|sed -e 's/,$//')
60
  for op in list list-fields; do
61
    test_cmd "gnt-$kind $op $SEP" "$kind $op"
62
  done
63
  #test_cmd "gnt-$kind list $SEP -o$comma_fields" "$kind list with all fields"
64
  for field in $all_fields; do
65
    test_cmd "gnt-$kind list $SEP -o$field" "$kind list for field $field"
66
  done
67
done
68

    
69
exit $RET