[node-patches] Change in ovirt-node[master]: test: Add igor plugin

fabiand at fedoraproject.org fabiand at fedoraproject.org
Thu May 2 10:43:40 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: test: Add igor plugin
......................................................................

test: Add igor plugin

The plugin contains a service which communicates with the igor daemon.
This is needed to run testcases within an instance.

Change-Id: I5bd03d8f19b1fa3d47e5e5efb2fbd5ab6f5535f4
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M ovirt-node.spec.in
M scripts/Makefile.am
A scripts/ovirt-node-igor-slave
M services/Makefile.am
A services/init.d/ovirt-node-igor-slave
A services/ovirt-node-igor-slave.service
6 files changed, 275 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/82/14382/1

diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index fb89efe..3df5e5f 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -78,6 +78,7 @@
 %description
 Provides a series of daemons and support utilities for hypervisor distribution.
 
+
 %package recipe
 Summary:        Recipes for building and running %{product_family} image
 Group:          Applications/System
@@ -93,6 +94,7 @@
 This package is not to be installed on the %{product_family},
 however on a development machine to help to build the image.
 
+
 %package tools
 Summary:        Recipes for building and running %{product_family} image
 Group:          Applications/System
@@ -106,6 +108,7 @@
 %{product_family} image.
 This package is not to be installed on the %{product_family},
 however on a development machine to work with the image.
+
 
 %package plugin-snmp
 Summary:        SNMP plugin for %{product_family} image
@@ -151,6 +154,7 @@
 #CIM related changes
 # set read-only
 echo "readonly = true;" > /etc/libvirt-cim.conf
+
 
 #
 # SELinux subpackage
@@ -206,6 +210,42 @@
 # FIXME what about semanage?
 
 
+#
+# Igor service subpackage
+#
+%package plugin-igor-slave
+Summary:        Igor slave plugin for %{product_family}
+Group:          Applications/System
+
+%if %{is_systemd}
+BuildRequires:  systemd-units
+Requires:       systemd
+%else
+BuildRequires:  initscripts
+Requires(post): chkconfig
+%endif
+
+# We need python-uinput for TUI tests
+Requires:       python-uinput
+
+
+%description plugin-igor-slave
+This package provides an igor service for %{product_family}. This service
+is responsible for running testcase offered by an igor server.
+
+
+%post plugin-igor-slave
+%if %{is_systemd}
+if [ $1 -eq 1 ] ; then
+    # Initial installation
+    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+    /bin/systemctl enable ovirt-node-igor-slave.service >/dev/null 2>&1 || :
+fi
+%else
+/sbin/chkconfig --add ovirt-node-igor-slave >/dev/null 2>&1 || :
+%endif
+
+
 %prep
 %setup -q
 
@@ -226,6 +266,7 @@
     mv -v %{modulename}.pp %{modulename}.pp.${selinuxvariant}
 done
 cd -
+
 
 %install
 %{__rm} -rf %{buildroot}
@@ -335,6 +376,7 @@
 fi
 %endif
 
+
 %preun plugin-cim
 %if ! %{is_systemd}
 if [ $1 = 0 ] ; then
@@ -349,6 +391,10 @@
 fi
 %endif
 
+
+#
+# FILES
+#
 %files recipe
 %defattr(0644,root,root,0755)
 %doc README COPYING
@@ -362,10 +408,12 @@
 %{_sbindir}/edit-node
 %{_mandir}/man8/edit-node.8.gz
 
+
 %files plugin-snmp
 %{python_sitelib}/ovirt_config_setup/snmp.py
 %{_sysconfdir}/ovirt-plugins.d/snmp.minimize
 %{_sysconfdir}/ovirt-config-boot.d/snmp_autoinstall.py
+
 
 %files plugin-cim
 %{python_sitelib}/ovirt_config_setup/cim.py
@@ -377,6 +425,15 @@
 %endif
 
 
+%files plugin-igor-slave
+%{_libexecdir}/ovirt-node-igor-slave
+%if %{is_systemd}
+%{_unitdir}/ovirt-node-igor-slave.service
+%else
+%{_initrddir}/ovirt-node-igor-slave
+%endif
+
+
 %files selinux
 %defattr(-,root,root,0755)
 %doc semodule/*.fc semodule/*.te
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index f73f3a8..3dbb006 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -38,6 +38,7 @@
   ovirt-init-functions.sh \
   ovirt-auto-install.py \
   ovirt-admin-shell \
+  ovirt-node-igor-slave \
   legacy/ovirt-config-installer.py \
   legacy/ovirt-config-setup.py \
   legacy/ovirt-config-storage
diff --git a/scripts/ovirt-node-igor-slave b/scripts/ovirt-node-igor-slave
new file mode 100755
index 0000000..4665ecd
--- /dev/null
+++ b/scripts/ovirt-node-igor-slave
@@ -0,0 +1,173 @@
+#!/bin/bash
+
+. /usr/libexec/ovirt-functions
+
+prog=ovirt-node-igor
+
+TRIALS=10
+TRIAL_SLEEP=10
+
+_log()
+{
+    echo $@ >&2
+}
+
+_get_bootif()
+{
+    bootif=
+    i=$(echo "$@" | egrep -o "BOOTIF=[^[:space:]]*")
+    i=${i#BOOTIF=}
+    case "$i" in
+        [ep]*)
+        bootif=$i
+        _log "BOOTIF was set to $bootif"
+        ;;
+        link)
+        for eth in $(cd /sys/class/net; echo [ep]*); do
+            ip link set dev $eth up 2>&1 > /dev/null
+            if ethtool $eth 2>/dev/null | grep -q "Link detected: yes"
+            then
+                bootif=$eth
+                break
+            fi
+        done
+        _log "BOOTIF asked for linked device: $bootif"
+        ;;
+        ??-??-??-??-??-??-??)
+        i=${i#??-}
+        bootif=$(grep -il $(echo $i|sed 's/-/:/g') /sys/class/net/[ep]*/address|rev|cut -d/ -f2|rev)
+        _log "BOOTIF device by mac: $bootif"
+        ;;
+    esac
+
+    [[ -z $bootif ]] && {
+        bootif=$(cd /sys/class/net/ ; ls -d1 [ep]* | head -n1)
+        _log "Not BOOTIF= given, choosing first NIC: $bootif"
+    }
+
+    [[ -z $bootif ]] && {
+        _log "bootif could not be determined"
+    }
+
+    echo $bootif
+}
+
+
+_is_network_available()
+{
+    bootif=$1
+    ip link show $bootif | grep -q ",UP,"
+}
+_start_network()
+{
+    bootif=$1
+    [[ ! -z $bootif ]] && {
+        dhclient $bootif
+        _is_network_available $bootif
+        retval=$?
+        _log "Got ip address for interface $bootif"
+        return $retval
+    }
+    _log "Got no address"
+    return 1
+}
+
+_is_auto_installation()
+{
+    grep BOOTIF /proc/cmdline && grep storage_init /proc/cmdline
+    return $?
+}
+
+run()
+{
+    _log "Starting $prog (`rpm -qf $0`)"
+
+    if _is_auto_installation
+    then
+        _log "oVirt Node is not yet installed, aborting."
+        exit 0
+    else
+        _log "oVirt Node seems to be installed, continuing."
+    fi
+
+    [[ -z $OVIRT_BOOTPARAMS ]] && {
+        _log "Missing OVIRT_BOOTPARAMS, fallback to cmdline"
+        OVIRT_BOOTPARAMS=$(cat /proc/cmdline)
+    }
+
+    TESTJOB=$(echo "$OVIRT_BOOTPARAMS" | egrep -o '[^[:space:]=]+/testjob/[^[:space:]]+')
+
+    if [[ "x$TESTJOB" = "x" ]];
+    then
+        _log "No testsuite found."
+    else
+        _log "Testjob found in kernelargs: $TESTJOB"
+
+        if [[ -f "/usr/bin/nm-online" ]]
+        then
+            _log "NetworkManager is used, waiting for the network to come up ..."
+            nm-online -x
+        fi
+
+        bootif=$(_get_bootif "$OVIRT_BOOTPARAMS")
+        if _is_network_available $bootif
+        then
+            _log "Network connection is available"
+        else
+            _log "No network connection available"
+            _log "Requesting temporary ip address"
+            _start_network $bootif
+        fi
+
+        _log "Settling for $TRIAL_SLEEP seconds to give the dhcp client time"
+        # Needed because sometimes retrieving an IP via DHCP leads to TZ updates
+        # This can then lead to an invalid lease, which the results in the dhcp client
+        # requesting a new IP
+        sleep $TRIAL_SLEEP
+
+        _log "Network link configuration:"
+        ip link show
+        _log "Network addr configuration:"
+        ip addr show
+
+        _log "Network setup is done, fetching testsuite ..."
+
+        TESTJOBURL="http://${TESTJOB#http://}"
+        APIURL=${TESTJOBURL/testjob*/}
+
+        TESTJOBSCRIPT="/tmp/ovirt-autotesting-bootstrap.sh"
+
+        rm -f $TESTJOBSCRIPT
+
+        while [[ ! -e "$TESTJOBSCRIPT" && $TRIALS -gt 0 ]]
+        do
+            _log "Trying to fetch ($TRIALS) testjob from $TESTJOBURL to $TESTJOBSCRIPT"
+            curl --output "$TESTJOBSCRIPT" "$TESTJOBURL"
+            TRIALS=$(($TRIALS - 1))
+            sleep $TRIAL_SLEEP
+        done
+
+        if [[ -e "$TESTJOBSCRIPT" ]]
+        then
+            _log "Running testjob $TESTJOBSCRIPT"
+            export TESTJOB APIURL
+            chmod a+x "$TESTJOBSCRIPT"
+            $TESTJOBSCRIPT $@
+        else
+            _log "Fetching testjob script failed."
+        fi
+    fi
+
+    _log "Completed $prog"
+
+    exit 0
+}
+
+case $1 in
+run) run;;
+*)
+    echo "Usage: $0 run" >&2:
+    ::
+esac
+
+exit 0
diff --git a/services/Makefile.am b/services/Makefile.am
index fece4c2..abb5fe1 100644
--- a/services/Makefile.am
+++ b/services/Makefile.am
@@ -25,7 +25,8 @@
   ovirt.service \
   ovirt-post.service \
   ovirt-firstboot.service \
-  ovirt-cim.service
+  ovirt-cim.service \
+  ovirt-node-igor-slave.service
 else
 dist_initd_SCRIPTS = \
   init.d/ovirt-awake \
@@ -33,7 +34,8 @@
   init.d/ovirt \
   init.d/ovirt-post \
   init.d/ovirt-firstboot \
-  init.d/ovirt-cim
+  init.d/ovirt-cim \
+  init.d/ovirt-node-igor-slave
 endif
 
 # vim: ts=2
diff --git a/services/init.d/ovirt-node-igor-slave b/services/init.d/ovirt-node-igor-slave
new file mode 100755
index 0000000..772fcd7
--- /dev/null
+++ b/services/init.d/ovirt-node-igor-slave
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Start commuication to Igor (for test automation)
+#
+### BEGIN INIT INFO
+# Provides: ovirt-node-igor
+# Required-Start: network ovirt-early
+# Default-Start: 2 3 4 5
+# Description: Perform test automation with Igor
+### END INIT INFO
+
+# Source functions library
+. /etc/init.d/functions
+
+prog=ovirt-node-igor-slave
+
+case "$1" in
+    start)
+        echo -n "Starting $prog (async): "
+        /usr/bin/$prog run > /tmp/$prog.log 2>&1 &
+#        test $? == 0 && success || failure
+#        echo
+        ;;
+    *)
+        echo "Usage: $prog {start}"
+        exit 2
+esac
diff --git a/services/ovirt-node-igor-slave.service b/services/ovirt-node-igor-slave.service
new file mode 100644
index 0000000..71cd070
--- /dev/null
+++ b/services/ovirt-node-igor-slave.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Communication with Igor (for test automation)
+Wants=basic.target network.target ovirt-early.service
+After=basic.target network.target
+Before=ovirt-early.service
+DefaultDependencies=no
+
+[Service]
+RemainAfterExit=no
+ExecStart=/usr/bin/ovirt-node-igor-slave run
+
+[Install]
+WantedBy=default.target


--
To view, visit http://gerrit.ovirt.org/14382
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5bd03d8f19b1fa3d47e5e5efb2fbd5ab6f5535f4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list