Browse code

Add service to tcpdump during run

This adds a service to run a tcpdump during the run. This can be
useful to capture various network traffic for post analysis.

There didn't seem to quite be an appropriate place to document it, so
a new debugging file is started, with some terse explaination of our
various system-wide debugging services.

Change-Id: I09aaa57611c5047d09a9bce7932d34e9d50b30e6

Ian Wienand authored on 2019/02/11 10:25:38
Showing 4 changed files
... ...
@@ -232,6 +232,7 @@
232 232
         '{{ devstack_log_dir }}/dstat-csv.log': logs
233 233
         '{{ devstack_log_dir }}/devstacklog.txt': logs
234 234
         '{{ devstack_log_dir }}/devstacklog.txt.summary': logs
235
+        '{{ devstack_log_dir }}/tcpdump.pcap': logs
235 236
         '{{ devstack_full_log}}': logs
236 237
         '{{ stage_dir }}/verify_tempest_conf.log': logs
237 238
         '{{ stage_dir }}/apache': logs
238 239
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+=====================
1
+System-wide debugging
2
+=====================
3
+
4
+A lot can go wrong during a devstack run, and there are a few inbuilt
5
+tools to help you.
6
+
7
+dstat
8
+-----
9
+
10
+Enable the ``dstat`` service to produce performance logs during the
11
+devstack run.  These will be logged to the journal and also as a CSV
12
+file.
13
+
14
+memory_tracker
15
+--------------
16
+
17
+The ``memory_tracker`` service periodically monitors RAM usage and
18
+provides consumption output when available memory is seen to be
19
+falling (i.e. processes are consuming memory).  It also provides
20
+output showing locked (unswappable) memory.
21
+
22
+tcpdump
23
+-------
24
+
25
+Enable the ``tcpdump`` service to run a background tcpdump.  You must
26
+set the ``TCPDUMP_ARGS`` variable to something suitable (there is no
27
+default).  For example, to trace iSCSI communication during a job in
28
+the OpenStack gate and copy the result into the log output, you might
29
+use:
30
+
31
+.. code-block:: yaml
32
+
33
+   job:
34
+     name: devstack-job
35
+     parent: devstack
36
+     vars:
37
+       devstack_services:
38
+         tcpdump: true
39
+       devstack_localrc:
40
+         TCPDUMP_ARGS: "-i any tcp port 3260"
41
+       zuul_copy_output:
42
+         '{{ devstack_log_dir }}/tcpdump.pcap': logs
43
+
44
+
45
+
0 46
new file mode 100644
... ...
@@ -0,0 +1,43 @@
0
+#!/bin/bash
1
+#
2
+# lib/tcpdump
3
+# Functions to start and stop a tcpdump
4
+
5
+# Dependencies:
6
+#
7
+# - ``functions`` file
8
+
9
+# ``stack.sh`` calls the entry points in this order:
10
+#
11
+# - start_tcpdump
12
+# - stop_tcpdump
13
+
14
+# Save trace setting
15
+_XTRACE_TCPDUMP=$(set +o | grep xtrace)
16
+set +o xtrace
17
+
18
+TCPDUMP_OUTPUT=${TCPDUMP_OUTPUT:-$LOGDIR/tcpdump.pcap}
19
+
20
+# e.g. for iscsi
21
+#  "-i any tcp port 3260"
22
+TCPDUMP_ARGS=${TCPDUMP_ARGS:-""}
23
+
24
+# start_tcpdump() - Start running processes
25
+function start_tcpdump {
26
+    # Run a tcpdump with given arguments and save the packet capture
27
+    if is_service_enabled tcpdump; then
28
+        if [[ -z "${TCPDUMP_ARGS}" ]]; then
29
+            die $LINENO "The tcpdump service requires TCPDUMP_ARGS to be set"
30
+        fi
31
+        touch ${TCPDUMP_OUTPUT}
32
+        run_process tcpdump "/usr/sbin/tcpdump -w $TCPDUMP_OUTPUT $TCPDUMP_ARGS" root root
33
+    fi
34
+}
35
+
36
+# stop_tcpdump() stop tcpdump process
37
+function stop_tcpdump {
38
+    stop_process tcpdump
39
+}
40
+
41
+# Restore xtrace
42
+$_XTRACE_TCPDUMP
... ...
@@ -614,6 +614,7 @@ source $TOP_DIR/lib/swift
614 614
 source $TOP_DIR/lib/neutron
615 615
 source $TOP_DIR/lib/ldap
616 616
 source $TOP_DIR/lib/dstat
617
+source $TOP_DIR/lib/tcpdump
617 618
 source $TOP_DIR/lib/etcd3
618 619
 
619 620
 # Extras Source
... ...
@@ -1053,6 +1054,12 @@ fi
1053 1053
 # A better kind of sysstat, with the top process per time slice
1054 1054
 start_dstat
1055 1055
 
1056
+# Run a background tcpdump for debugging
1057
+# Note: must set TCPDUMP_ARGS with the enabled service
1058
+if is_service_enabled tcpdump; then
1059
+    start_tcpdump
1060
+fi
1061
+
1056 1062
 # Etcd
1057 1063
 # -----
1058 1064