Module: check_mk
Branch: master
Commit: e7a603920097332532c4b237cb528b03ea456860
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e7a60392009733…
Author: Jukka Aro <ja(a)mathias-kettner.de>
Date: Fri Dec 1 16:44:34 2017 +0100
Windows agent: add build target integrationtest
Update chroot jail with necessary additional packages for pytest and
SSH. Copy existing SSH RSA key pair from SUDO_USER to chroot jail.
Prerequisite: the ssh keys must be generated without passphrase and
named correctly (id_rsa_windows_test).
Change-Id: I95e99458fa6c69c42260fa487cf5c168c6f9182d
---
agents/windows/Makefile.am | 5 +++++
agents/windows/build-agent | 17 ++++++++++++++---
agents/windows/build.sh | 2 +-
agents/windows/chroot_version | 2 +-
agents/windows/make-agent | 13 ++++++++++---
agents/windows/make-chroot | 10 ++++++++--
agents/windows/setup-ssh | 38 ++++++++++++++++++++++++++++++++++++++
7 files changed, 77 insertions(+), 10 deletions(-)
diff --git a/agents/windows/Makefile.am b/agents/windows/Makefile.am
index a658312..4e0df39 100644
--- a/agents/windows/Makefile.am
+++ b/agents/windows/Makefile.am
@@ -34,6 +34,11 @@ check_mk_agent.res: check_mk_agent.rc $(VPATH)/check_mk_agent.ico
unittest: WindowsAgentTest$(EXEEXT)
DISPLAY="$$DISPLAY xterm" wine WindowsAgentTest$(EXEEXT) 2>/dev/null
+integrationtest: install-strip
+ cd $(bindir)/it ; \
+ pytest --maxfail=10 ; \
+ cd -
+
libcheck_mk_agent_a_SOURCES = \
Configuration.cc \
CrashHandler.cc \
diff --git a/agents/windows/build-agent b/agents/windows/build-agent
index 3f9847e..b64c4d9 100755
--- a/agents/windows/build-agent
+++ b/agents/windows/build-agent
@@ -24,8 +24,14 @@ cd /$CHROOT_BUILD_DIR/agents/windows
autoreconf --install
build_archs=(32 64)
-if [[ "$targets" == unittest ]] ; then
- # Only unittest
+
+if [[ " $targets " =~ " integrationtest " &&
"$targets" != integrationtest ]] ; then
+ echo "integrationtest cannot be combined with other targets"
+ exit 1
+fi
+
+if [[ "$targets" == unittest || "$targets" == integrationtest ]] ;
then
+ # Only unittest or integrationtest
build_archs=()
elif [[ " $targets " =~ " unittest " ]] ; then
# unittest together with other target(s)
@@ -54,8 +60,13 @@ if [[ -z "$targets" ]] ; then
cd -
fi
-if [[ ! "$targets" =~ clean ]] ; then
+if [[ ! "$targets" =~ clean && "$targets" != integrationtest
]] ; then
# Run unittest only in 64 bit
targets=unittest
build 64
fi
+
+if [[ " $targets " =~ " integrationtest " ]] ; then
+ targets=integrationtest
+ build 64
+fi
diff --git a/agents/windows/build.sh b/agents/windows/build.sh
index 4c18a4c..45136f0 100644
--- a/agents/windows/build.sh
+++ b/agents/windows/build.sh
@@ -75,5 +75,5 @@ function build {
# If special targets given, do just them.
make -j${njobs} "$targets" || return 1
fi
- cd -
+ cd ..
}
diff --git a/agents/windows/chroot_version b/agents/windows/chroot_version
index 7f8f011..45a4fb7 100644
--- a/agents/windows/chroot_version
+++ b/agents/windows/chroot_version
@@ -1 +1 @@
-7
+8
diff --git a/agents/windows/make-agent b/agents/windows/make-agent
index 372efe4..41af275 100755
--- a/agents/windows/make-agent
+++ b/agents/windows/make-agent
@@ -15,6 +15,8 @@ if [ -z $SUDO_USER ]; then
exit 1
fi
+script_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
+
. build.sh
parse-args "$@"
@@ -40,7 +42,7 @@ fi
# elements to make
# a) different namespaces possible for (windows agent, agent updater)
# b) parallel builds of different chroot versions possible
-CHROOT_VERSION=$(<$base/agents/windows/$versionfile)
+export CHROOT_VERSION=$(<$base/agents/windows/$versionfile)
CHROOT_BASE_PATH=${CHROOT_BASE_PATH:-$base/$base_rel_dir/chroot}
export CHROOT_PATH=$CHROOT_BASE_PATH/$CHROOT_NAME/$CHROOT_VERSION
@@ -79,14 +81,19 @@ echo "CHROOT_PATH is $CHROOT_PATH"
# Check that user does not exist before since SUDO_USER may be root, as well.
#
# Do this not only during setup, because the setup is only executed once and
- # the build may be started with different SUDO_USER users).
+ # the build may be started with different SUDO_USER users.
if ! grep -q "\<${SUDO_USER}\>" "$CHROOT_PATH/etc/passwd" ;
then
./do-chroot "useradd -lmo -u $(id -u $SUDO_USER) -s /bin/bash
$SUDO_USER"
fi
+
+ # Copy windows test-specific ssh key pair from ~$SUDO_USER/.ssh to chroot.
+ if [[ ! -f "$CHROOT_PATH/home/$SUDO_USER/.ssh/id_rsa" ]] ; then
+ $script_dir/setup-ssh
+ fi
) 200>/var/lock/cmk-make-agent_${CHROOT_PATH//\//-}.lock
echo "[MAKE-CHROOT LOCK] released"
# Build the Windows agent within chroot by calling the 'build-agent' script as
# $SUDO_USER.
./do-chroot \
- "/bin/su - $SUDO_USER -c bash -c 'CHROOT_NAME=$CHROOT_NAME
CHROOT_PATH=$CHROOT_PATH CHROOT_BUILD_DIR=$CHROOT_BUILD_DIR NEW_VERSION=$NEW_VERSION
/$CHROOT_BUILD_DIR/agents/windows/build-agent -j${njobs} $targets'"
+ "/bin/su - $SUDO_USER -c bash -c 'CHROOT_NAME=$CHROOT_NAME
CHROOT_PATH=$CHROOT_PATH CHROOT_BUILD_DIR=$CHROOT_BUILD_DIR NEW_VERSION=$NEW_VERSION
SSH_AUTH_SOCK=$SSH_AUTH_SOCK /$CHROOT_BUILD_DIR/agents/windows/build-agent -j${njobs}
$targets'"
diff --git a/agents/windows/make-chroot b/agents/windows/make-chroot
index 9b6824b..1214319 100755
--- a/agents/windows/make-chroot
+++ b/agents/windows/make-chroot
@@ -56,8 +56,8 @@ package_names=(
autoconf
automake
build-essential
- cabextract
ca-certificates
+ cabextract
curl
gcc
gettext
@@ -85,11 +85,12 @@ package_names=(
libio-socket-ssl-perl
liblwp-mediatypes-perl
liblwp-protocol-https-perl
- libmailtools-perl
+ libmailtools-perl
libnet-http-perl
libnet-smtp-ssl-perl
libnet-ssleay-perl
libperl-dev
+ libpython-stdlib
libtimedate-perl
libtool
liburi-perl
@@ -100,11 +101,16 @@ package_names=(
locales
make
mingw-w64
+ openssh-client
openssl
patch
perl-openssl-defaults
pkg-config
+ python
+ python-minimal
+ python-pytest
python2.7
+ ssh-askpass
uuid-dev
wine-stable
)
diff --git a/agents/windows/setup-ssh b/agents/windows/setup-ssh
new file mode 100755
index 0000000..d1cebfd
--- /dev/null
+++ b/agents/windows/setup-ssh
@@ -0,0 +1,38 @@
+#!/bin/bash
+# This script copies a ssh key pair from ~$SUDO_USER/.ssh/ or
+# /var/lib/jenkins/.ssh/ to chroot jail.
+
+set -e
+
+if [[ -z $CHROOT_PATH ]] ; then
+ echo "CHROOT_PATH is not set"
+ exit 1
+fi
+
+script_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
+ssh_key=id_rsa_windows_test
+remote_ip=$(grep "remote_ip =" $script_dir/it/remote.py | sed
"s/^.*'\(.*\)'/\1/g")
+remoteuser=$(grep "remoteuser =" $script_dir/it/remote.py | sed
"s/^.*'\(.*\)'/\1/g")
+
+if [[ $SUDO_USER == jenkins ]] ; then
+ home_dir=/var/lib/jenkins
+else
+ home_dir=/home/$SUDO_USER
+fi
+
+if [[ ! -f "$home_dir/.ssh/$ssh_key" ]] || [[ ! -f
"$home_dir/.ssh/${ssh_key}.pub" ]] ; then
+ echo "SSH key pair '$ssh_key' not found. Please generate a new key pair
with the command"
+ echo "ssh-keygen -t rsa -N '' -C '$SUDO_USER@$HOSTNAME (Windows
test)' -f $home_dir/.ssh/$ssh_key"
+ echo "and append the public key to \\Users\\$remoteuser\\.ssh\\authorized_keys
at host $remote_ip"
+ exit 1
+fi
+
+if [[ ! -d "$CHROOT_PATH/home/$SUDO_USER/.ssh" ]] ; then
+ su - $SUDO_USER -c bash -c "mkdir -p $CHROOT_PATH/home/$SUDO_USER/.ssh"
+fi
+
+for ending in "" ".pub"; do
+ cp "$home_dir/.ssh/${ssh_key}${ending}"
"$CHROOT_PATH/home/$SUDO_USER/.ssh/id_rsa${ending}"
+ chown $SUDO_USER:$SUDO_USER
"$CHROOT_PATH/home/$SUDO_USER/.ssh/id_rsa${ending}"
+done
+