diff options
author | Thomas Haller <thaller@redhat.com> | 2021-09-20 19:03:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-09-21 13:56:37 +0200 |
commit | 48691a2101dcf1ab0e71a6afc8cf30c5b0101dd3 (patch) | |
tree | f99b8084b79edf04f7987bb57a87156fcd0c8ee4 /contrib/scripts | |
parent | bf6d5f355e4e31ab4c899b35b8afaa495562a456 (diff) | |
download | NetworkManager-48691a2101dcf1ab0e71a6afc8cf30c5b0101dd3.tar.gz |
contrib: improve nm-in-container.sh script (7)
Diffstat (limited to 'contrib/scripts')
-rwxr-xr-x | contrib/scripts/nm-in-container.d/data-nm-env-prepare.sh | 60 | ||||
-rwxr-xr-x | contrib/scripts/nm-in-container.sh | 28 |
2 files changed, 69 insertions, 19 deletions
diff --git a/contrib/scripts/nm-in-container.d/data-nm-env-prepare.sh b/contrib/scripts/nm-in-container.d/data-nm-env-prepare.sh index 3996749829..5b536b82c0 100755 --- a/contrib/scripts/nm-in-container.d/data-nm-env-prepare.sh +++ b/contrib/scripts/nm-in-container.d/data-nm-env-prepare.sh @@ -9,32 +9,36 @@ die() { do_cleanup() { local IDX="$1" + local NAME_PREFIX="${2:-net}" + local PEER_PREFIX="${3:-d_}" - pkill -F "/tmp/nm-dnsmasq-d_$IDX.pid" dnsmasq &>/dev/null || : - rm -rf "/tmp/nm-dnsmasq-d_$IDX.pid" + pkill -F "/tmp/nm-dnsmasq-$PEER_PREFIX$IDX.pid" dnsmasq &>/dev/null || : + rm -rf "/tmp/nm-dnsmasq-$PEER_PREFIX$IDX.pid" - pkill -F "/tmp/nm-radvd-d_$IDX.pid" radvd &>/dev/null || : - rm -rf "/tmp/nm-radvd-d_$IDX.pid" + pkill -F "/tmp/nm-radvd-$PEER_PREFIX$IDX.pid" radvd &>/dev/null || : + rm -rf "/tmp/nm-radvd-$PEER_PREFIX$IDX.pid" - rm -rf "/tmp/nm-radvd-d_$IDX.conf" + rm -rf "/tmp/nm-radvd-$PEER_PREFIX$IDX.conf" - ip link del "d_$IDX" &>/dev/null || : + ip link del "$PEER_PREFIX$IDX" &>/dev/null || : } do_setup() { local IDX="$1" + local NAME_PREFIX="${2:-net}" + local PEER_PREFIX="${3:-d_}" do_cleanup "$IDX" - ip link add "net$IDX" type veth peer "d_$IDX" - ip link set "d_$IDX" up + ip link add "$NAME_PREFIX$IDX" type veth peer "$PEER_PREFIX$IDX" + ip link set "$PEER_PREFIX$IDX" up - ip addr add "192.168.$((120 + $IDX)).1/23" dev "d_$IDX" - ip addr add "192:168:$((120 + IDX))::1/64" dev "d_$IDX" + ip addr add "192.168.$((120 + $IDX)).1/23" dev "$PEER_PREFIX$IDX" + ip addr add "192:168:$((120 + IDX))::1/64" dev "$PEER_PREFIX$IDX" dnsmasq \ --conf-file=/dev/null \ - --pid-file="/tmp/nm-dnsmasq-d_$IDX.pid" \ + --pid-file="/tmp/nm-dnsmasq-$PEER_PREFIX$IDX.pid" \ --no-hosts \ --keep-in-foreground \ --bind-interfaces \ @@ -45,8 +49,8 @@ do_setup() { --no-ping \ & - cat <<EOF > "/tmp/nm-radvd-d_$IDX.conf" -interface d_$IDX + cat <<EOF > "/tmp/nm-radvd-$PEER_PREFIX$IDX.conf" +interface $PEER_PREFIX$IDX { AdvSendAdvert on; prefix 192:168:$((120 + IDX))::/64 @@ -57,19 +61,21 @@ interface d_$IDX }; EOF radvd \ - --config "/tmp/nm-radvd-d_$IDX.conf" \ - --pidfile "/tmp/nm-radvd-d_$IDX.pid" \ + --config "/tmp/nm-radvd-$PEER_PREFIX$IDX.conf" \ + --pidfile "/tmp/nm-radvd-$PEER_PREFIX$IDX.pid" \ & } do_redo() { - do_cleanup "$1" - do_setup "$1" + do_cleanup "$@" + do_setup "$@" } ############################################################################### IDX=1 +NAME_PREFIX=net +PEER_PREFIX= CMD=redo for (( i=1 ; i<="$#" ; )) ; do c="${@:$i:1}" @@ -78,6 +84,16 @@ for (( i=1 ; i<="$#" ; )) ; do redo|setup|cleanup) CMD="$c" ;; + --prefix|-p) + NAME_PREFIX="${@:$i:1}" + test -n "$NAME_PREFIX" || die "missing argument to --prefix" + i=$((i+1)) + ;; + --peer-prefix) + PEER_PREFIX="${@:$i:1}" + test -n "$PEER_PREFIX" || die "missing argument to --peer-prefix" + i=$((i+1)) + ;; --idx|-i) test $i -le "$#" || die "missing argument to --idx" IDX="${@:$i:1}" @@ -89,4 +105,12 @@ for (( i=1 ; i<="$#" ; )) ; do esac done -do_$CMD "$IDX" +if [ -z "$PEER_PREFIX" ]; then + if [ "$NAME_PREFIX" = net ]; then + PEER_PREFIX=d_ + else + PEER_PREFIX="d_${NAME_PREFIX}_" + fi +fi + +do_$CMD "$IDX" "$NAME_PREFIX" "$PEER_PREFIX" diff --git a/contrib/scripts/nm-in-container.sh b/contrib/scripts/nm-in-container.sh index 83a6124993..cb12991e53 100755 --- a/contrib/scripts/nm-in-container.sh +++ b/contrib/scripts/nm-in-container.sh @@ -126,6 +126,12 @@ Clean() { nm-env-prepare.sh } +Cat-Timestamp() { + while IFS=$'\n' read line; do + printf "[%s]: %s\n" "$(date '+%s.%N')" "$line" + done +} + nm_run_gdb() { systemctl stop NetworkManager.service gdb --args "\${1:-/opt/test/sbin/NetworkManager}" --debug @@ -138,6 +144,7 @@ nm_run_normal() { . /usr/share/git-core/contrib/completion/git-prompt.sh PS1="\[\\033[01;36m\]\u@\h\[\\033[00m\]:\\t:\[\\033[01;34m\]\w\\\$(__git_ps1 \\" \[\\033[01;36m\](%s)\[\\033[00m\]\\")\[\\033[00m\]\$ " +export GIT_PS1_SHOWDIRTYSTATE=1 if test "\$SHOW_MOTD" != 0; then cat /etc/motd @@ -159,18 +166,22 @@ match-device=interface-name:d_*,interface-name:tap* managed=0 [device-managed-1] -match-device=interface-name:net* +match-device=interface-name:net*,interface-name:eth* managed=1 EOF cat <<EOF | tmp_file "$BASEDIR/data-bash_history" 600 NM-log NM-log /tmp/nm-log.txt +behave -f html --stop ./features/scenarios/vrf.feature +behave -f html --stop -t ipv4_method_static_with_IP ./features/scenarios/ipv4.feature cd $BASEDIR_NM journalctl | NM-log nm-env-prepare.sh +nm-env-prepare.sh --prefix eth -i 4 nm_run_gdb nm_run_normal +for i in {1..9}; do nm-env-prepare.sh --prefix eth -i \$i; done systemctl status NetworkManager systemctl stop NetworkManager systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a /tmp/nm-log.txt @@ -183,9 +194,15 @@ set history filename ~/.gdb_history EOF cat <<EOF | tmp_file "$BASEDIR/data-gdb_history" 600 +run run --debug 2>&1 | tee /tmp/nm-log.txt EOF + cat <<EOF | tmp_file "$BASEDIR/data-behaverc" 600 +[behave.formatters] +html = behave_html_formatter:HTMLFormatter +EOF + cat <<EOF | tmp_file "$CONTAINERFILE" FROM $BASE_IMAGE @@ -197,6 +214,7 @@ RUN dnf install -y \\ NetworkManager \\ audit-libs-devel \\ bash-completion \\ + bind-utils \\ bluez-libs-devel \\ cscope \\ dbus-devel \\ @@ -234,10 +252,14 @@ RUN dnf install -y \\ ppp \\ ppp-devel \\ procps \\ + python3-behave \\ python3-dbus \\ python3-devel \\ python3-gobject \\ + python3-pexpect \\ python3-pip \\ + python3-pyte \\ + python3-pyyaml \\ radvd \\ readline-devel \\ rpm-build \\ @@ -253,6 +275,9 @@ RUN dnf install -y \\ RUN dnf debuginfo-install --skip-broken \$(ldd /usr/sbin/NetworkManager | sed -n 's/.* => \\(.*\\) (0x[0-9A-Fa-f]*)$/\1/p' | xargs -n1 readlink -f) -y +RUN pip3 install --user \\ + behave_html_formatter + RUN systemctl enable NetworkManager COPY data-NM-log "/usr/bin/NM-log" @@ -263,6 +288,7 @@ COPY data-90-my.conf /etc/NetworkManager/conf.d/90-my.conf COPY data-bash_history /root/.bash_history COPY data-gdbinit /root/.gdbinit COPY data-gdb_history /root/.gdb_history +COPY data-behaverc /root/.behaverc # Generate a stable machine id. RUN echo "10001000100010001000100010001000" > /etc/machine-id |