From dbcbb45224243865d6b93105b722485233f34426 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 14 Sep 2021 13:23:26 +0200 Subject: [PATCH] contrib: improve nm-in-container.sh script --- contrib/scripts/nm-in-container.d/.gitignore | 3 +- .../nm-in-container.d/data-nm-env-prepare.sh | 6 +- contrib/scripts/nm-in-container.sh | 79 ++++++++++++------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/contrib/scripts/nm-in-container.d/.gitignore b/contrib/scripts/nm-in-container.d/.gitignore index 047b879b7b..3ed62b52fa 100644 --- a/contrib/scripts/nm-in-container.d/.gitignore +++ b/contrib/scripts/nm-in-container.d/.gitignore @@ -1,3 +1,2 @@ -/data-NM-log -/data-motd +/data-* /dockerfile.* 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 4f84413a2d..3996749829 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 @@ -24,7 +24,7 @@ do_cleanup() { do_setup() { local IDX="$1" - cleanup "$IDX" + do_cleanup "$IDX" ip link add "net$IDX" type veth peer "d_$IDX" ip link set "d_$IDX" up @@ -63,8 +63,8 @@ EOF } do_redo() { - cleanup "$1" - setup "$1" + do_cleanup "$1" + do_setup "$1" } ############################################################################### diff --git a/contrib/scripts/nm-in-container.sh b/contrib/scripts/nm-in-container.sh index 3e1e55a309..da7e4d87fb 100755 --- a/contrib/scripts/nm-in-container.sh +++ b/contrib/scripts/nm-in-container.sh @@ -18,7 +18,7 @@ set -e # # It bind mounts the current working directory inside the container. # You can run `make install` and run tests. -# There is a script nm-env-prepare to generate a net1 interface for testing. +# There is a script nm-env-prepare.sh to generate a net1 interface for testing. ############################################################################### BASE_IMAGE="${BASE_IMAGE:-fedora:latest}" @@ -63,6 +63,12 @@ trap cleanup EXIT ############################################################################### +tmp_file() { + cat > "$1" + CLEANUP_FILES+=( "$1" ) + test -z "$2" || chmod "$2" "$1" +} + bind_files() { VARIABLE_NAME="$1" @@ -90,7 +96,7 @@ create_dockerfile() { cp "$BASEDIR_NM/contrib/scripts/NM-log" "$BASEDIR/data-NM-log" CLEANUP_FILES+=( "$BASEDIR/data-NM-log" ) - cat < "$BASEDIR/data-motd" + cat <&1 | tee -a /tmp/nm-log.txt EOF - CLEANUP_FILES+=( "$BASEDIR/data-motd" ) + + cat <&1 | tee -a /tmp/nm-log.txt +systemctl stop NetworkManager; gdb --args /opt/test/sbin/NetworkManager --debug +NM-log +NM-log /tmp/nm-log.txt +EOF cat < "$DOCKERFILE" FROM $BASE_IMAGE @@ -175,34 +220,14 @@ RUN dnf clean all COPY data-NM-log "/usr/bin/NM-log" COPY data-nm-env-prepare.sh "/usr/bin/nm-env-prepare.sh" COPY data-motd /etc/motd +COPY data-bashrc.my /etc/bashrc.my +COPY data-90-my.conf /etc/NetworkManager/conf.d/90-my.conf +COPY data-bash_history /root/.bash_history RUN sed 's/.*RateLimitBurst=.*/RateLimitBurst=0/' /etc/systemd/journald.conf -i -RUN echo -e '[logging]\nlevel=TRACE\ndomains=ALL,VPN_PLUGIN:TRACE\n' >> /etc/NetworkManager/conf.d/90-my.conf -RUN echo -e '[main]\nno-auto-default=*\ndebug=RLIMIT_CORE,fatal-warnings\n' >> /etc/NetworkManager/conf.d/90-my.conf -RUN echo -e '[device-managed-0]\nmatch-device=interface-name:d_*,interface-name:tap*\nmanaged=0\n' >> /etc/NetworkManager/conf.d/90-my.conf -RUN echo -e '[device-managed-1]\nmatch-device=interface-name:net*\nmanaged=1\n' >> /etc/NetworkManager/conf.d/90-my.conf - RUN rm -rf /etc/NetworkManager/system-connections/* -RUN echo 'cd $BASEDIR_NM' >> /root/.bash_history -RUN echo 'nm-env-prepare.sh setup --idx 1' >> /root/.bash_history -RUN echo 'systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a /tmp/nm-log.txt' >> /root/.bash_history -RUN echo 'NM-log' >> /root/.bash_history -RUN echo 'NM-log /tmp/nm-log.txt' >> /root/.bash_history -RUN chmod 600 /root/.bash_history - -RUN echo 'alias m="make -j 8"' >> /etc/bashrc.my -RUN echo 'alias n="ninja -C build"' >> /etc/bashrc.my -RUN echo '' >> /etc/bashrc.my -RUN echo '. /usr/share/git-core/contrib/completion/git-prompt.sh' >> /etc/bashrc.my -RUN echo 'PS1="\[\\033[01;36m\]\u@\h\[\\033[00m\]:\\t:\[\\033[01;34m\]\w\\\$(__git_ps1 \\" \[\\033[01;36m\](%s)\[\\033[00m\]\\")\[\\033[00m\]\$ "' >> /etc/bashrc.my -RUN echo '' >> /etc/bashrc.my -RUN echo 'if test "\$SHOW_MOTD" != 0; then' >> /etc/bashrc.my -RUN echo ' cat /etc/motd' >> /etc/bashrc.my -RUN echo ' export SHOW_MOTD=0' >> /etc/bashrc.my -RUN echo 'fi' >> /etc/bashrc.my - RUN echo -e '\n. /etc/bashrc.my\n' >> /etc/bashrc EOF } @@ -210,7 +235,7 @@ EOF ############################################################################### container_image_exists() { - podman image exists my:nm || return 1 + podman image exists "$1" || return 1 } container_exists() {