contrib: improve nm-in-container.sh script

This commit is contained in:
Thomas Haller 2021-09-13 20:33:50 +02:00
parent 549424273a
commit d7c0dcc7b4
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 59 additions and 2 deletions

View file

@ -1 +1,3 @@
/data-NM-log
/data-motd
/dockerfile.*

View file

@ -11,7 +11,12 @@ cleanup() {
local IDX="$1"
pkill -F "/tmp/nm-dnsmasq-d_$IDX.pid" dnsmasq &>/dev/null || :
: > "/tmp/nm-dnsmasq-d_$IDX.pid"
rm -rf "/tmp/nm-dnsmasq-d_$IDX.pid"
pkill -F "/tmp/nm-radvd-d_$IDX.pid" radvd &>/dev/null || :
rm -rf "/tmp/nm-radvd-d_$IDX.pid"
rm -rf "/tmp/nm-radvd-d_$IDX.conf"
ip link del "d_$IDX" &>/dev/null || :
}
@ -25,6 +30,7 @@ setup() {
ip link set "d_$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"
dnsmasq \
--conf-file=/dev/null \
@ -38,6 +44,22 @@ setup() {
--dhcp-range="192.168.$((120 + $IDX)).100,192.168.$((120 + $IDX)).150" \
--no-ping \
&
cat <<EOF > "/tmp/nm-radvd-d_$IDX.conf"
interface d_$IDX
{
AdvSendAdvert on;
prefix 192:168:$((120 + IDX))::/64
{
AdvOnLink on;
};
};
EOF
radvd \
--config "/tmp/nm-radvd-d_$IDX.conf" \
--pidfile "/tmp/nm-radvd-d_$IDX.pid" \
&
}
IDX=1

View file

@ -42,6 +42,7 @@ bind_files() {
H=~
for f in ~/.gitconfig* ~/.vim* ; do
test -f "$f" || continue
f2="${f#$H/}"
[[ "$f2" = .viminf* ]] && continue
[[ "$f2" = *.tmp ]] && continue
@ -58,6 +59,22 @@ create_dockerfile() {
DOCKERFILE="$1"
BASE_IMAGE="$2"
cp "$BASEDIR_NM/contrib/scripts/NM-log" "$BASEDIR/data-NM-log"
CLEANUP_FILES+=( "$BASEDIR/data-NM-log" )
cat <<EOF > "$BASEDIR/data-motd"
*** nm-in-container:
find NetworkManager bind mounted at $BASEDIR_NM
run \`nm-env-prepare.sh setup --idx 1\` to setup test interfaces
Configure NetworkManager with
\$ ./configure --enable-maintainer-mode --enable-more-warnings=error --with-more-asserts="\${NM_BUILD_MORE_ASSERTS:-1000}" --with-nm-cloud-setup=yes --prefix=/opt/test --localstatedir=/var --sysconfdir=/etc --enable-gtk-doc --enable-introspection --with-ofono=yes --with-dhclient=yes --with-dhcpcanon=yes --with-dhcpcd=yes --enable-more-logging --enable-compile-warnings=yes --enable-address-sanitizer=no --enable-undefined-sanitizer=no --with-valgrind=yes --enable-concheck --enable-wimax --enable-ifcfg-rh=yes --enable-config-plugin-ibft=yes --enable-ifcfg-suse --enable-ifupdown=yes --enable-ifnet --enable-vala=yes --enable-polkit=yes --with-libnm-glib=yes --with-nmcli=yes --with-nmtui=yes --with-modem-manager-1 --with-suspend-resume=systemd --enable-teamdctl=yes --enable-ovs=yes --enable-tests=${NM_BUILD_TESTS} --with-netconfig=/bin/nowhere/netconfig --with-resolvconf=/bin/nowhere/resolvconf --with-crypto=nss --with-session-tracking=systemd --with-consolekit=yes --with-systemd-logind=yes --with-iwd=yes --enable-json-validation=yes --with-consolekit=yes --with-config-dns-rc-manager-default=auto --with-config-dhcp-default=internal "\${NM_CONFIGURE_OTPS[@]}"
Test with:
\$ systemctl stop NetworkManager; /opt/test/sbin/NetworkManager --debug 2>&1 | tee -a /tmp/nm-log.txt
EOF
CLEANUP_FILES+=( "$BASEDIR/data-motd" )
cat <<EOF > "$DOCKERFILE"
FROM $BASE_IMAGE
@ -110,6 +127,7 @@ RUN dnf install -y \\
python3-gobject \\
python3-pip \\
python3-pip \\
radvd \\
readline-devel \\
rpm-build \\
strace \\
@ -126,21 +144,36 @@ RUN pip install gdbgui
RUN systemctl enable NetworkManager
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
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-veths-1]\nmatch-device=interface-name:d_*\nmanaged=0\n' >> /etc/NetworkManager/conf.d/90-my.conf
RUN echo -e '[device-veths-2]\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
@ -207,7 +240,7 @@ do_run() {
do_exec() {
do_run
podman exec -it "$CONTAINER_NAME_NAME" /bin/bash -c "cd \"$BASEDIR_NM\"; exec /bin/bash"
podman exec --workdir "$BASEDIR_NM" -it "$CONTAINER_NAME_NAME" bash
}
###############################################################################