From d00a5d2a8b3c3a97fb723f4a3a9d104079401063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8D=C3=B1igo=20Huguet?= Date: Fri, 21 Jul 2023 15:36:22 +0200 Subject: [PATCH] tools: nm-in-container: don't generate files from the script The script was generating the data-* files that later copies to the container. In order to the files being reusable for nm-in-vm, put them as separate files inside the data directory. However, some of the files need the full path to NetworkManager project, which varies for each user. Instead, make a sed replacement on them and generate the actual files that will be copied. Replacement: {{BASEDIR_NM}} -> $BASEDIR_NM Also, rename the files to more descriptive names, using some prefixes that give a hint of where those files will be put, and the .in extension to indicate that they will be processed. --- ...up.sh => bin-_nm-in-container-setup.sh.in} | 0 ...{data-nm-deploy.sh => bin-nm-deploy.sh.in} | 0 ...nv-prepare.sh => bin-nm-env-prepare.sh.in} | 0 tools/nm-guest-data/etc-bashrc.my.in | 48 ++++ tools/nm-guest-data/etc-motd-container.in | 75 ++++++ tools/nm-guest-data/etc-motd-vm.in | 63 +++++ .../{data-etc-rc.local => etc-rc.local.in} | 0 tools/nm-guest-data/home-bash_history.in | 31 +++ tools/nm-guest-data/home-behaverc.in | 2 + tools/nm-guest-data/home-gdb_history.in | 2 + tools/nm-guest-data/home-gdbinit.in | 2 + tools/nm-guest-data/nm-90-my.conf.in | 15 ++ tools/nm-guest-data/nm-95-user.conf.in | 0 ...ner.override => systemd-20-nm.override.in} | 0 tools/nm-in-container | 238 ++---------------- 15 files changed, 265 insertions(+), 211 deletions(-) rename tools/nm-guest-data/{data-_nm-in-container-setup.sh => bin-_nm-in-container-setup.sh.in} (100%) mode change 100755 => 100644 rename tools/nm-guest-data/{data-nm-deploy.sh => bin-nm-deploy.sh.in} (100%) mode change 100755 => 100644 rename tools/nm-guest-data/{data-nm-env-prepare.sh => bin-nm-env-prepare.sh.in} (100%) mode change 100755 => 100644 create mode 100644 tools/nm-guest-data/etc-bashrc.my.in create mode 100644 tools/nm-guest-data/etc-motd-container.in create mode 100644 tools/nm-guest-data/etc-motd-vm.in rename tools/nm-guest-data/{data-etc-rc.local => etc-rc.local.in} (100%) mode change 100755 => 100644 create mode 100644 tools/nm-guest-data/home-bash_history.in create mode 100644 tools/nm-guest-data/home-behaverc.in create mode 100644 tools/nm-guest-data/home-gdb_history.in create mode 100644 tools/nm-guest-data/home-gdbinit.in create mode 100644 tools/nm-guest-data/nm-90-my.conf.in create mode 100644 tools/nm-guest-data/nm-95-user.conf.in rename tools/nm-guest-data/{data-etc-systemd-20-nm-in-container.override => systemd-20-nm.override.in} (100%) diff --git a/tools/nm-guest-data/data-_nm-in-container-setup.sh b/tools/nm-guest-data/bin-_nm-in-container-setup.sh.in old mode 100755 new mode 100644 similarity index 100% rename from tools/nm-guest-data/data-_nm-in-container-setup.sh rename to tools/nm-guest-data/bin-_nm-in-container-setup.sh.in diff --git a/tools/nm-guest-data/data-nm-deploy.sh b/tools/nm-guest-data/bin-nm-deploy.sh.in old mode 100755 new mode 100644 similarity index 100% rename from tools/nm-guest-data/data-nm-deploy.sh rename to tools/nm-guest-data/bin-nm-deploy.sh.in diff --git a/tools/nm-guest-data/data-nm-env-prepare.sh b/tools/nm-guest-data/bin-nm-env-prepare.sh.in old mode 100755 new mode 100644 similarity index 100% rename from tools/nm-guest-data/data-nm-env-prepare.sh rename to tools/nm-guest-data/bin-nm-env-prepare.sh.in diff --git a/tools/nm-guest-data/etc-bashrc.my.in b/tools/nm-guest-data/etc-bashrc.my.in new file mode 100644 index 0000000000..db8598a05c --- /dev/null +++ b/tools/nm-guest-data/etc-bashrc.my.in @@ -0,0 +1,48 @@ +alias m="make -j 8" +alias n="ninja -C build" + +alias l='ls -l --color=auto' + +ulimit -c unlimited + +export G_DEBUG=fatal-warnings + +unset DEBUGINFOD_URLS + +export NMCI_DEBUG=1 + +Clean() { + systemctl stop NetworkManager + rm -i -rf /run/NetworkManager + nm-env-prepare.sh +} + +Cat-Timestamp() { + while IFS=$'\n' read line; do + printf "[%s]: %s\n" "1689938340.403232924" "$line" + done +} + +Journald-clear() { + rm -rf /var/log/journal/????????????????????????????????/* + systemctl restart systemd-journald +} + +nm_run_gdb() { + systemctl stop NetworkManager.service + gdb --args "${1:-/opt/test/sbin/NetworkManager}" --debug +} + +nm_run_normal() { + systemctl stop NetworkManager.service + "${1:-/opt/test/sbin/NetworkManager}" --debug 2>&1 | tee /tmp/nm-log.txt +} + +. /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 + export SHOW_MOTD=0 +fi diff --git a/tools/nm-guest-data/etc-motd-container.in b/tools/nm-guest-data/etc-motd-container.in new file mode 100644 index 0000000000..131f815c37 --- /dev/null +++ b/tools/nm-guest-data/etc-motd-container.in @@ -0,0 +1,75 @@ +*** nm-in-container: + +find NetworkManager bind mounted at {{BASEDIR_NM}} +run `nm-env-prepare.sh setup --idx 1` to setup test interfaces + +Coredumps: coredumps are not namespaced, so by default they will +be sent to coredumpctl of the outer host, which has no idea where +to get the debugging symbols from. A possible workaround is setting + + $ echo '/tmp/core.%e.%p' | sudo tee /proc/sys/kernel/core_pattern + +so that core dumps get written to file. Afterwards, restore with + + $ echo '|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h' | sudo tee /proc/sys/kernel/core_pattern + +from /usr/lib/sysctl.d/50-coredump.conf. + +For example, configure NetworkManager with + $ ./configure \ + --enable-address-sanitizer=no \ + --enable-compile-warnings=yes \ + --enable-concheck \ + --enable-config-plugin-ibft=yes \ + --enable-gtk-doc \ + --enable-ifcfg-rh=yes \ + --enable-ifcfg-suse \ + --enable-ifnet \ + --enable-ifupdown=yes \ + --enable-introspection \ + --enable-json-validation=yes \ + --enable-maintainer-mode \ + --enable-more-logging \ + --enable-more-warnings=error \ + --enable-ovs=yes \ + --enable-polkit=yes \ + --enable-teamdctl=yes \ + --enable-undefined-sanitizer=no \ + --enable-vala=yes \ + --enable-wimax \ + --localstatedir=/var \ + --prefix=/opt/test \ + --sysconfdir=/etc \ + --with-config-dhcp-default=internal \ + --with-config-dns-rc-manager-default=auto \ + --with-consolekit=yes \ + --with-consolekit=yes \ + --with-crypto=nss \ + --with-dhclient=yes \ + --with-dhcpcanon=yes \ + --with-dhcpcd=yes \ + --with-iwd=yes \ + --with-libnm-glib=yes \ + --with-modem-manager-1 \ + --with-netconfig=/bin/nowhere/netconfig \ + --with-nm-cloud-setup=yes \ + --with-nmcli=yes \ + --with-nmtui=yes \ + --with-ofono=yes \ + --with-resolvconf=/bin/nowhere/resolvconf \ + --with-session-tracking=systemd \ + --with-suspend-resume=systemd \ + --with-systemd-logind=yes \ + --with-valgrind=yes \ + --enable-tests="${NM_BUILD_TESTS:-yes}" \ + --with-more-asserts="${NM_BUILD_MORE_ASSERTS:-1000}" \ + "${NM_CONFIGURE_OTPS[@]}" +Test with: + $ systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a /tmp/nm-log.txt + +Or better, configure with `contrib/fedora/rpm/configure-for-system.sh`, +subsequent `make && make install` will overwrite your system's NetworkManager, +and you can test it with `systemctl daemon-reload ; systemctl restart NetworkManager`. + +Run NM-ci tests after creating eth1 with +`nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1`. diff --git a/tools/nm-guest-data/etc-motd-vm.in b/tools/nm-guest-data/etc-motd-vm.in new file mode 100644 index 0000000000..17332d5ea0 --- /dev/null +++ b/tools/nm-guest-data/etc-motd-vm.in @@ -0,0 +1,63 @@ +*** nm-in-vm: + +find NetworkManager bind mounted at {{BASEDIR_NM}} +run `nm-env-prepare.sh setup --idx 1` to setup test interfaces + +For example, configure NetworkManager with + $ ./configure \ + --enable-address-sanitizer=no \ + --enable-compile-warnings=yes \ + --enable-concheck \ + --enable-config-plugin-ibft=yes \ + --enable-gtk-doc \ + --enable-ifcfg-rh=yes \ + --enable-ifcfg-suse \ + --enable-ifnet \ + --enable-ifupdown=yes \ + --enable-introspection \ + --enable-json-validation=yes \ + --enable-maintainer-mode \ + --enable-more-logging \ + --enable-more-warnings=error \ + --enable-ovs=yes \ + --enable-polkit=yes \ + --enable-teamdctl=yes \ + --enable-undefined-sanitizer=no \ + --enable-vala=yes \ + --enable-wimax \ + --localstatedir=/var \ + --prefix=/opt/test \ + --sysconfdir=/etc \ + --with-config-dhcp-default=internal \ + --with-config-dns-rc-manager-default=auto \ + --with-consolekit=yes \ + --with-consolekit=yes \ + --with-crypto=nss \ + --with-dhclient=yes \ + --with-dhcpcanon=yes \ + --with-dhcpcd=yes \ + --with-iwd=yes \ + --with-libnm-glib=yes \ + --with-modem-manager-1 \ + --with-netconfig=/bin/nowhere/netconfig \ + --with-nm-cloud-setup=yes \ + --with-nmcli=yes \ + --with-nmtui=yes \ + --with-ofono=yes \ + --with-resolvconf=/bin/nowhere/resolvconf \ + --with-session-tracking=systemd \ + --with-suspend-resume=systemd \ + --with-systemd-logind=yes \ + --with-valgrind=yes \ + --enable-tests="${NM_BUILD_TESTS:-yes}" \ + --with-more-asserts="${NM_BUILD_MORE_ASSERTS:-1000}" \ + "${NM_CONFIGURE_OTPS[@]}" +Test with: + $ systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a /tmp/nm-log.txt + +Or better, configure with `contrib/fedora/rpm/configure-for-system.sh`, +subsequent `make && make install` will overwrite your system's NetworkManager, +and you can test it with `systemctl daemon-reload ; systemctl restart NetworkManager`. + +Run NM-ci tests after creating eth1 with +`nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1`. diff --git a/tools/nm-guest-data/data-etc-rc.local b/tools/nm-guest-data/etc-rc.local.in old mode 100755 new mode 100644 similarity index 100% rename from tools/nm-guest-data/data-etc-rc.local rename to tools/nm-guest-data/etc-rc.local.in diff --git a/tools/nm-guest-data/home-bash_history.in b/tools/nm-guest-data/home-bash_history.in new file mode 100644 index 0000000000..d97c561e18 --- /dev/null +++ b/tools/nm-guest-data/home-bash_history.in @@ -0,0 +1,31 @@ +NM-log +NM-log /tmp/nm-log.txt +behave -f html --stop -t ipv4_method_static_with_IP ./features/scenarios/ipv4.feature +behave -f html --stop ./features/scenarios/vrf.feature +cd {{BASEDIR_NM}} +cd /NetworkManager-ci +cd /NetworkManager +for i in {1..9}; do nm-env-prepare.sh --prefix eth -i $i; done +Journald-clear +journalctl | NM-log +journalctl --since '3 min ago' | NM-log +m +make +make install +n +nm-deploy.sh +nm-env-prepare.sh +nm-env-prepare.sh --prefix eth -i 1 +nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1 +nm_run_gdb +nm_run_normal +gdb /usr/sbin/NetworkManager /tmp/core.NetworkManager. +nmcli connection add type pppoe con-name ppp-net1 ifname ppp-net1 pppoe.parent net1 service isp username test password networkmanager autoconnect no +nmcli device connect eth1 +systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a ./nm-log.txt +systemctl stop NetworkManager; gdb -ex run --args /opt/test/sbin/NetworkManager --debug +systemctl stop NetworkManager +systemctl daemon-reload ; systemctl restart NetworkManager +(cd /NetworkManager && n && n install && systemctl daemon-reload && systemctl restart NetworkManager.service) +(cd /NetworkManager && m && m install && systemctl daemon-reload && systemctl restart NetworkManager.service) +systemctl status NetworkManager diff --git a/tools/nm-guest-data/home-behaverc.in b/tools/nm-guest-data/home-behaverc.in new file mode 100644 index 0000000000..ebb49fa7e4 --- /dev/null +++ b/tools/nm-guest-data/home-behaverc.in @@ -0,0 +1,2 @@ +[behave.formatters] +html = behave_html_formatter:HTMLFormatter diff --git a/tools/nm-guest-data/home-gdb_history.in b/tools/nm-guest-data/home-gdb_history.in new file mode 100644 index 0000000000..39fb9abf43 --- /dev/null +++ b/tools/nm-guest-data/home-gdb_history.in @@ -0,0 +1,2 @@ +run +run --debug 2>&1 | tee /tmp/nm-log.txt diff --git a/tools/nm-guest-data/home-gdbinit.in b/tools/nm-guest-data/home-gdbinit.in new file mode 100644 index 0000000000..f55a669a09 --- /dev/null +++ b/tools/nm-guest-data/home-gdbinit.in @@ -0,0 +1,2 @@ +set history save +set history filename ~/.gdb_history diff --git a/tools/nm-guest-data/nm-90-my.conf.in b/tools/nm-guest-data/nm-90-my.conf.in new file mode 100644 index 0000000000..fdc05b64d2 --- /dev/null +++ b/tools/nm-guest-data/nm-90-my.conf.in @@ -0,0 +1,15 @@ +[main] +no-auto-default=* +debug=RLIMIT_CORE,fatal-warnings + +[logging] +level=TRACE +domains=ALL,VPN_PLUGIN:TRACE + +[device-managed-0] +match-device=interface-name:d_*,interface-name:tap* +managed=0 + +[device-managed-1] +match-device=interface-name:net*,interface-name:eth* +managed=1 diff --git a/tools/nm-guest-data/nm-95-user.conf.in b/tools/nm-guest-data/nm-95-user.conf.in new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/nm-guest-data/data-etc-systemd-20-nm-in-container.override b/tools/nm-guest-data/systemd-20-nm.override.in similarity index 100% rename from tools/nm-guest-data/data-etc-systemd-20-nm-in-container.override rename to tools/nm-guest-data/systemd-20-nm.override.in diff --git a/tools/nm-in-container b/tools/nm-in-container index 39f7ab1b54..2b48ac3803 100755 --- a/tools/nm-in-container +++ b/tools/nm-in-container @@ -100,6 +100,13 @@ tmp_file() { test -z "$2" || chmod "$2" "$1" } +gen_file() { + local PERMS + [[ $1 =~ bin-* ]] && PERMS=755 || PERMS=644 + sed "s|{{BASEDIR_NM}}|$BASEDIR_NM|g" "$BASEDIR_DATA/$1.in" \ + | tmp_file "$BASEDIR_DATA/data-$1" $PERMS +} + bind_files() { VARIABLE_NAME="$1" @@ -123,208 +130,17 @@ create_dockerfile() { local CONTAINERFILE="$1" local BASE_IMAGE="$2" + local GEN_FILES="bin-nm-env-prepare.sh bin-nm-deploy.sh bin-_nm-in-container-setup.sh + etc-rc.local etc-motd-container etc-bashrc.my nm-90-my.conf nm-95-user.conf + home-bash_history home-gdbinit home-gdb_history home-behaverc systemd-20-nm.override" - cp "$BASEDIR_NM/contrib/scripts/NM-log" "$BASEDIR_DATA/data-NM-log" + cp "$BASEDIR_NM/contrib/scripts/NM-log" "$BASEDIR_DATA/data-bin-NM-log" CLEANUP_FILES+=( "$BASEDIR_DATA/data-NM-log" ) - cat <&1 | tee -a /tmp/nm-log.txt - -Or better, configure with \`contrib/fedora/rpm/configure-for-system.sh\`, -subsequent \`make && make install\` will overwrite your system's NetworkManager, -and you can test it with \`systemctl daemon-reload ; systemctl restart NetworkManager\`. - -Run NM-ci tests after creating eth1 with -\`nm-env-prepare.sh --prefix eth -i 1 && sleep 1 && nmcli device connect eth1\`. -EOF - - cat <&1 | tee /tmp/nm-log.txt -} - -. /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 - export SHOW_MOTD=0 -fi -EOF - - cat <&1 | tee -a ./nm-log.txt -systemctl stop NetworkManager; gdb -ex run --args /opt/test/sbin/NetworkManager --debug -systemctl stop NetworkManager -systemctl daemon-reload ; systemctl restart NetworkManager -(cd /NetworkManager && n && n install && systemctl daemon-reload && systemctl restart NetworkManager.service) -(cd /NetworkManager && m && m install && systemctl daemon-reload && systemctl restart NetworkManager.service) -systemctl status NetworkManager -EOF - - cat <&1 | tee /tmp/nm-log.txt -EOF - - cat <