File: common.discovery

package info (click to toggle)
pcp 7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 252,748 kB
  • sloc: ansic: 1,483,656; sh: 182,366; xml: 160,462; cpp: 83,813; python: 24,980; perl: 18,327; yacc: 6,877; lex: 2,864; makefile: 2,738; awk: 165; fortran: 60; java: 52
file content (199 lines) | stat: -rw-r--r-- 5,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#
# Common shell routines for testing service discovery
# Copyright (c) 2014 Red Hat.
#

. ./common.product
. ./common.filter
. ./common.check

_filter_discovery_sought()
{
    # Only pmcd is guaranteed to be running, but other services may also be.
    # Transform two cases - no servers vs found servers - into deterministic
    # output for the --all invocations.
    sed \
	-e 's/No \(pmproxy servers\) discovered/Sought \1/g' \
	-e 's/Discovered \(pmproxy servers\):/Sought \1/g' \
    # end
}

_filter_discovery_unresolved()
{
    tee -a $seq_full \
    | sed -e '/  pcp:/d;
	    /  proxy:/d;
	    /  http:/d' \
    | _filter_discovery_sought
}

_filter_discovery_resolved()
{
    # Pass unresolved urls, filter the resolved ones.
    tee -a $seq_full \
    | sed -e '/  pcp:\/\/[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/{p;b};
	    /  proxy:\/\/[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/{p;b};
	    /  http:\/\/[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+/{p;b};
	    /  pcp:/d;
	    /  proxy:/d;
	    /  http:/d' \
    | _filter_discovery_sought \
    | _filter_discovery_unresolvable
}

_filter_discovery_unresolvable()
{
    # For each unresolved address in the response, see if we can resolve
    # it using dig(1). If not, filter it out as an unresolvable result.
    # Oherwise, leave it in as an erroneous result.
    while read __line
    do
	# If the line is an unresolved service, then see if we can resolve it
	# using dig(1).
	if echo $__line | grep -q -e '^pcp://' -e '^proxy://' -e '^http://';
	then
	    __addr=`echo $__line |
                  sed -e 's|pcp://\(.*\):[0-9]\+|\1|'`

	    # If dig(1) can not resolve this address, then it is a correctly
	    # unresolved address. Filter it out. Otherwise keep it as an
	    # erroneously unresolved address.
	    __dug=`dig -x $__addr +short`
	    [ -z "$__dug" ] && continue
	fi

	# Keep this line
	echo $__line
    done
}

_control_service_discovery()
{
    echo "*** Initial service status ***" >> $seq_full
    $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID|[p]mproxy|[p]mcd' \
	>> $seq_full
    cat $PCP_LOG_DIR/pmproxy/pmproxy.log >> $seq_full
    cat $PCP_LOG_DIR/pmcd/pmcd.log >> $seq_full
    echo "*** End status information ***" >> $seq_full
}

_check_service_discovery()
{
    _get_libpcp_config
    $service_discovery || _notrun "No support for service discovery"

    avahi-daemon --check 2>/dev/null || _notrun "avahi-daemon is unavailable"
}

_check_avahi_service()
{
    _check_service_discovery
    which avahi-browse >/dev/null 2>&1 || _notrun "avahi-browse not installed"
}

_cleanup_avahi_service()
{
    cd $here
    echo "avahi_cleanup: before pmsignal" >>$seq_full
    __grep_service=`echo "$service" | sed -e 's/./[&]/'`
    $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID|$__grep_service |$__grep_service$' >>$seq_full
    $sudo $PCP_BINADM_DIR/pmsignal -a "$service" >>$seq_full 2>&1
    pmsleep 0.5
    echo "avahi_cleanup: after pmsignal" >>$seq_full
    $PCP_PS_PROG $PCP_PS_ALL_FLAGS | grep -E '[P]PID|$__grep_service |$__grep_service$' >>$seq_full
    _restore_config $PCP_PMCDOPTIONS_PATH
    _restore_config $PCP_PMPROXYOPTIONS_PATH
    if $__service_was_running
    then
	echo "Restart $service ..." >>$seq_full
	_service $service restart >>$seq_full 2>&1
	case "$service"
	in
	pmcd)
	    _wait_for_pmcd
	    ;;
	pmproxy)
	    _wait_for_pmproxy
	    ;;
	esac
    else
	echo "Stopping $service ..." >>$seq_full
	_service $service stop >>$seq_full 2>&1
    fi
    $sudo rm -rf $tmp $tmp.*
}

_control_avahi_service()
{
    _save_config $PCP_PMPROXYOPTIONS_PATH
    cp $PCP_PMPROXYOPTIONS_PATH $tmp.options
    echo "# edited for PCP QA test $seq" >$tmp.options
    sed <$PCP_PMPROXYOPTIONS_PATH >>$tmp.options \
	-e '/^-A/s/.*/# for PCP QA -A/'
    $sudo cp $tmp.options $PCP_PMPROXYOPTIONS_PATH

    _save_config $PCP_PMCDOPTIONS_PATH
    cp $PCP_PMCDOPTIONS_PATH $tmp.options
    echo "# edited for PCP QA test $seq" >$tmp.options
    sed <$PCP_PMCDOPTIONS_PATH >>$tmp.options \
	-e '/^-A/s/.*/# for PCP QA -A/'
    $sudo cp $tmp.options $PCP_PMCDOPTIONS_PATH

    __service_was_running=false
    [ -f $PCP_RUN_DIR/$service.pid ] && __service_was_running=true
    echo "__service_was_running=$__service_was_running" >>$seq_full
    _stop_auto_restart $service
    $sudo "$PCP_RC_DIR/$service" restart >>$seq_full 2>&1
    case "$service"
    in
    pmcd)
	_wait_for_pmcd
	;;
    pmproxy)
	_wait_for_pmproxy
	;;
    esac
    _restore_auto_restart $service

    _control_service_discovery
}

_verify_avahi_service()
{
    __msg="$@"

    [ "X$__msg" = "X" ] && __msg="Verify $service avahi service advertising"
    echo $__msg | tee -a $seq_full

    # strip any domain part ... e.g. if hostname is vm08.localdomain,
    # avahi reports this as vm08.local
    # look for a line like this ...
    # = eth0 IPv4 PCP pmproxy on vm04.localdomain _pmproxy._tcp local
    # + eth0 IPv6 PCP pmproxy on vm30 _pmroxy._tcp local
    #
    __hostname=`hostname | sed -e 's/\..*//'`
    echo "__hostname=$__hostname" >>$seq_full
    echo "avahi-browse -rt -d local _$service._tcp" >> $seq_full
    avahi-browse -rt -d local "_$service._tcp" > $tmp.out 2> $tmp.err
    # sometimes we need a fair bit of time for avahi to register
    for __i in 0.1 0.3 1 2 3
    do
	[ -s $tmp.out ] && break
	pmsleep $__i
	avahi-browse -rt -d local "_$service._tcp" > $tmp.out 2> $tmp.err
    done
    cat $tmp.err >>$seq_full
    cat $tmp.out | \
	tee -a $seq_full | \
	sed -n \
	    -e '/ '"$__hostname"'[ .]/{
s/  */ /g
s/'"$__hostname"'[^ ]*/HOSTNAME/
s/[=+] [^ ]* /. <interface> /
s/ IPv[46] / <protocol> /
s/ \#[0-9] / /
p
q
}'

}