#74 Run a "behave" test with the CI pipeline (Proof of Concept)
Opened 6 years ago by esakaiev. Modified 6 years ago
git://fedorapeople.org/~esakaiev/dnf_tests dnf_docker_tests_pr  into  master

Modifying runtest.sh according with changes instandard-test-behave model
esaka • 6 years ago  
Adding changes for dnf_dcoker tests for PR in dnf_behave_tests_pr
esaka • 6 years ago  
Dockerfile.patch
file added
+13
@@ -0,0 +1,13 @@

+ diff --git a/Dockerfile b/Dockerfile

+ index 479f757..86aced6 100644

+ --- a/Dockerfile

+ +++ b/Dockerfile

+ @@ -37,7 +37,7 @@ RUN set -x && \

+      dnf -y --best upgrade dnf && \

+      if [ $type = "local" ]; then \

+          # install all rpms if present

+ -        if ls /rpms/*.rpm 1>/dev/null 2>&1; then dnf -y install /rpms/*.rpm; fi && \

+ +        if ls /rpms/*.rpm 1>/dev/null 2>&1; then dnf -y --skip-broken install /rpms/*.rpm; fi && \

+          # workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1398272

+          rpm -q dnf && \

+          # some unknown thing

dnf-testing.sh.patch
file added
+74
@@ -0,0 +1,74 @@

+ diff --git a/dnf-testing.sh b/dnf-testing.sh

+ index 608a5f9..c7bc616 100755

+ --- a/dnf-testing.sh

+ +++ b/dnf-testing.sh

+ @@ -57,6 +57,11 @@ EOF

+      exit 0

+  }

+  

+ +check_cpu_usage()

+ +{

+ +    echo $(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}')

+ +}

+ +

+  TEMP=$(getopt -n $0 -o hdrRc: -l help,devel,reserve,reserveonfail,container: -- "$@") || show_usage

+  eval set -- "$TEMP"

+  

+ @@ -153,26 +158,37 @@ build()

+  }

+  [ "$action" = "build" ] && build

+  

+ +get_container_id()

+ +{

+ +    docker_ps=$(docker ps | grep "${IMAGE}")

+ +    echo  $docker_ps | grep -oP "[0-9a-zA-Z]* (?=${IMAGE})"

+ +}

+ +

+  run()

+  {

+ +    IMAGE=${IMAGE%:latest} # cut-off :latest suffix if present

+      [ ${#TESTS[@]} -eq 0 ] && TESTS=("${FEATURES[@]}")

+      local failed=0

+      local failed_test_name='Failed test(s):'

+      if [ -z "$devel" ];then

+          for feature in "${TESTS[@]}"; do

+              feature=${feature%.feature}  # cut-off .feature suffix if present

+ +            echo $( get_container_id )

+ +            docker commit $( get_container_id ) $feature  #clone image

+              for command in dnf-2 dnf-3; do

+ -                printf "\nsudo docker run $PARAM_TTY --rm "$IMAGE" launch-test $PARAM_RESERVE "$feature" $command\n"

+ -                sudo docker run $PARAM_TTY --rm "$IMAGE" launch-test $PARAM_RESERVE "$feature" $command >&2 || \

+ +                printf "\nsudo docker run $PARAM_TTY --rm "$feature" launch-test $PARAM_RESERVE "$feature" $command\n"

+ +                sudo docker run $PARAM_TTY --rm "$feature" launch-test $PARAM_RESERVE "$feature" $command >&2 || \

+                  if [ $? -ne 0 ]; then let ++failed && failed_test_name+=" $feature-$command"; fi

+              done

+ +            docker rmi $feature

+          done

+      else

+          for feature in "${TESTS[@]}"; do

+              feature=${feature%.feature}  # cut-off .feature suffix if present

+ +            docker commit $( get_container_id ) $feature #clone image

+              for command in dnf-2 dnf-3; do

+ -                printf "\nsudo docker run $PARAM_TTY --rm -v "$devel" "$IMAGE" launch-test $PARAM_RESERVE "$feature" $command\n"

+ -                sudo docker run $PARAM_TTY --rm -v "$devel" -v "$devel_steps" "$IMAGE" launch-test $PARAM_RESERVE "$feature" $command >&2 || \

+ +                printf "\nsudo docker run $PARAM_TTY --rm -v "$devel" "$feature" launch-test $PARAM_RESERVE "$feature" $command\n"

+ +                sudo docker run $PARAM_TTY --rm -v "$devel" -v "$devel_steps" "$feature" launch-test $PARAM_RESERVE "$feature" $command >&2 || \

+                  if [ $? -ne 0 ]; then let ++failed && failed_test_name+=" $feature-$command"; fi

+              done

+          done

+ @@ -187,11 +203,11 @@ run()

+  shell()

+  {

+      if [ -z "$devel" ];then

+ -        printf "\nsudo docker run -it --rm "$IMAGE" bash\n"

+ -        sudo docker run -it --rm "$IMAGE" bash

+ +        printf "\nsudo docker run -it --rm "$1" bash\n"

+ +        sudo docker run -it --rm "$image" bash

+      else

+ -        printf "\nsudo docker run -it --rm -v "$devel" "$IMAGE" bash\n"

+ -        sudo docker run -it --rm -v "$devel" "$IMAGE" bash

+ +        printf "\nsudo docker run -it --rm -v "$devel" "$1" bash\n"

+ +        sudo docker run -it --rm -v "$devel" "$image" bash

+      fi

+  }

+  [ "$action" == "shell" ] && shell

download_rpmy.py
file added
+64
@@ -0,0 +1,64 @@

+ import subprocess

+ import sys

+ 

+ rpms = [

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//libsolv-devel-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//libsolv-debuginfo-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//python3-solv-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//perl-solv-0.6.30-37gb5d0451.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//libsolv-0.6.30-37gb5d0451.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//ruby-solv-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//python2-solv-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//libsolv-demo-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684588-libsolv//libsolv-tools-0.6.30-37gb5d0451.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684592-librepo//python2-librepo-1.8.1-3gfd11033.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684592-librepo//librepo-devel-1.8.1-3gfd11033.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684592-librepo//librepo-debuginfo-1.8.1-3gfd11033.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684592-librepo//python3-librepo-1.8.1-3gfd11033.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684592-librepo//librepo-1.8.1-3gfd11033.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//createrepo_c-devel-0.10.0-48g0cac54d.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//python2-createrepo_c-0.10.0-48g0cac54d.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//createrepo_c-0.10.0-48g0cac54d.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//python3-createrepo_c-0.10.0-48g0cac54d.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//createrepo_c-debuginfo-0.10.0-48g0cac54d.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684595-createrepo_c//createrepo_c-libs-0.10.0-48g0cac54d.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//libcomps-debuginfo-0.1.8-3g01a4759.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//libcomps-devel-0.1.8-3g01a4759.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//python-libcomps-doc-0.1.8-3g01a4759.fc26.noarch.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//libcomps-0.1.8-3g01a4759.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//python3-libcomps-0.1.8-3g01a4759.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//python2-libcomps-0.1.8-3g01a4759.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684597-libcomps//libcomps-doc-0.1.8-3g01a4759.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684600-libdnf//python3-hawkey-0.12.2-0.234g429669a.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684600-libdnf//libdnf-devel-0.12.2-0.234g429669a.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684600-libdnf//python2-hawkey-0.12.2-0.234g429669a.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684600-libdnf//libdnf-debuginfo-0.12.2-0.234g429669a.fc26.x86_64.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684600-libdnf//libdnf-0.12.2-0.234g429669a.fc26.x86_64.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//dnf-yum-2.8.4-0.81g59e4a05f.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//python2-dnf-2.8.4-0.81g59e4a05f.fc26.noarch.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//dnf-conf-2.8.4-0.81g59e4a05f.fc26.noarch.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//python3-dnf-2.8.4-0.81g59e4a05f.fc26.noarch.rpm', 

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//dnf-automatic-2.8.4-0.81g59e4a05f.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684601-dnf//dnf-2.8.4-0.81g59e4a05f.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python3-dnf-plugins-core-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//dnf-plugins-core-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugin-migrate-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugins-core-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python3-dnf-plugin-local-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python3-dnf-plugin-leaves-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugin-versionlock-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python3-dnf-plugin-versionlock-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugin-show-leaves-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//dnf-utils-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugin-leaves-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python3-dnf-plugin-show-leaves-2.1.5-9g49dfb76.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684602-dnf-plugins-core//python2-dnf-plugin-local-2.1.5-9g49dfb76.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-kickstart-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugins-extras-common-2.0.4-1gde2e604.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python2-dnf-plugin-tracer-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-tracer-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python2-dnf-plugin-kickstart-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python2-dnf-plugin-snapper-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python2-dnf-plugin-system-upgrade-2.0.4-1gde2e604.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-rpmconf-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-torproxy-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-snapper-2.0.4-1gde2e604.fc26.noarch.rpm https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python2-dnf-plugins-extras-common-2.0.4-1gde2e604.fc26.noarch.rpm',

+ 'https://copr-be.cloud.fedoraproject.org/results/rpmsoftwaremanagement/rpm-gitoverlay-1512476567.874611/fedora-26-x86_64/00684604-dnf-plugins-extras//python3-dnf-plugin-system-upgrade-2.0.4-1gde2e604.fc26.noarch.rpm',

+ ]

+ 

+ 

+ # downloading specific pacakges:

+ 

+ for rpm in rpms:

+     cmd = ['curl', '-O', rpm]

+     try:

+         subprocess.check_call(cmd, stdout=sys.stderr.fileno())

+     except subprocess.CalledProcessError as ex:

+     	print "Could not download rpms: {}". format(ex)

+         

runtest.sh
file added
+8
@@ -0,0 +1,8 @@

+ #!/bin/bash

+ 

+ #run test

+ echo $(./dnf-testing.sh run "$1" > test."$1".log 2>&1)

+ 

+ 

+ 

+ 

standard-inventory-behave
file added
+196
@@ -0,0 +1,196 @@

+ #!/usr/bin/env python

+ 

+ import argparse

+ import errno

+ import json

+ import os

+ import shutil

+ import shlex

+ import signal

+ import socket

+ import subprocess

+ import sys

+ import tempfile

+ import time

+ import traceback

+ import distutils.util

+ 

+ def main(argv):

+     parser = argparse.ArgumentParser(description="Inventory for a container image in a registry")

+     parser.add_argument("--list", action="store_true", help="Verbose output")

+     parser.add_argument('--host', help="Get host variables")

+     parser.add_argument('--docker-extra-args', help="Extra docker arguments for launching container",

+                         default=os.environ.get("TEST_DOCKER_EXTRA_ARGS", ""))

+     parser.add_argument("subjects", nargs="*", default=shlex.split(os.environ.get("TEST_SUBJECTS", "")))

+     opts = parser.parse_args()

+ 

+     try:

+         if opts.host:

+             name, data = host(opts.host, opts.docker_extra_args)

+         else:

+             data = list(opts.subjects, opts.docker_extra_args)

+         sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))

+     except RuntimeError as ex:

+         sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))

+         return 1

+ 

+     return 0

+ 

+ def list(subjects, docker_extra_args):

+     hosts = [ ]

+     variables = { }

+     for subject in subjects:

+         if subject.startswith("behave:"): #behave:dnf-bot/dnf-testing:latest

+             image = subject[7:]

+             name, vars = host(image, docker_extra_args)

+             if vars:

+                 hosts.append(name)

+                 variables[name] = vars

+     return { "localhost": { "hosts": hosts, "vars": { } }, "subjects": { "hosts": hosts, "vars": { } }, "_meta": { "hostvars": variables } }

+ 

+ def host(image, docker_extra_args):

+     null = open(os.devnull, 'w')

+ 

+     try:

+         tty = os.open("/dev/tty", os.O_WRONLY)

+         os.dup2(tty, 2)

+     except OSError:

+         tty = None

+         pass

+ 

+     directory = tempfile.mkdtemp(prefix="inventory-behave")

+     cidfile = os.path.join(directory, "cid")

+ 

+     # Determine if container should be kept available for diagnosis after completion

+     try:

+         diagnose = distutils.util.strtobool(os.getenv("TEST_DEBUG", "0"))

+     except ValueError:

+         diagnose = 0

+ 

+     # Check for any additional arguments to include when starting docker container

+     try:

+         extra_arg_list = shlex.split(docker_extra_args)

+     except ValueError:

+         raise RuntimeError("Could not parse DOCKER_EXTRA_ARGS")

+ 

+     sys.stderr.write("Launching Docker container for {0}\n".format(image))

+ 

+     # Make sure the docker service is running

+     cmd = [

+         "/usr/sbin/service", "docker", "start"

+     ]

+ 

+     try:

+         subprocess.check_call(cmd, stdout=sys.stderr.fileno())

+     except subprocess.CalledProcessError as ex:

+         raise RuntimeError("Could not start docker service")

+ 

+     cmd = [ #--build-arg local

+         "/usr/bin/docker", "build", "--build-arg", "local", "--no-cache", "--force-rm", "-t", image, "."

+         ]

+ 

+     try:

+         subprocess.check_call(cmd, stdout=sys.stderr.fileno())

+     except subprocess.CalledProcessError as ex:

+         raise RuntimeError("Could not build container image: {0}".format(image))

+ 

+     # And launch the actual container

+     cmd = [

+         "/usr/bin/docker", "run", "--detach", "--cidfile={0}".format(cidfile),

+     ] + extra_arg_list + [

+         "--entrypoint=/bin/sh", image, "-c", "sleep 1000000"

+     ]

+ 

+     try:

+         subprocess.check_call(cmd, stdout=sys.stderr.fileno())

+     except subprocess.CalledProcessError as ex:

+         raise RuntimeError("Could not run container image: {0}".format(image))

+ 

+     # Read out the container environment variable

+     for x in xrange(1, 90):

+         if os.path.exists(cidfile):

+             break

+         time.sleep(1)

+     else:

+         raise RuntimeError("Could not find container file for launched container")

+ 

+     with open(cidfile, "r") as f:

+         name = f.read().strip()

+ 

+     # Now install the necessary stuff in the container :S

+     install = [

+         "/usr/bin/docker", "exec", name, "/usr/bin/yum", "-y", "install",

+         "python2", "python2-dnf", "libselinux-python"

+     ]

+     try:

+         subprocess.check_call(install, stdout=sys.stderr.fileno())

+     except subprocess.CalledProcessError as ex:

+         raise RuntimeError("Could not install Ansible dependencies in launched container")

+ 

+     # Directory to place artifacts

+     artifacts = os.environ.get("TEST_ARTIFACTS", os.path.join(os.getcwd(), "artifacts"))

+ 

+     # The variables

+     variables = {

+         "ansible_connection": "localhost",

+     }

+ 

+     # Process of our parent

+     ppid = os.getppid()

+ 

+     child = os.fork()

+     if child:

+         return name, variables

+ 

+     # Daemonize and watch the processes

+     os.chdir("/")

+     os.setsid()

+     os.umask(0)

+ 

+     if tty is None:

+         tty = null.fileno()

+ 

+     # Duplicate standard input to standard output and standard error.

+     os.dup2(null.fileno(), 0)

+     os.dup2(tty, 1)

+     os.dup2(tty, 2)

+ 

+     # Now wait for the parent process to go away, then kill the VM

+     while True:

+         time.sleep(3)

+ 

+         try:

+             os.kill(ppid, 0)

+         except OSError:

+             break # Either of the processes no longer exist

+ 

+     if diagnose:

+         sys.stderr.write("\n")

+         sys.stderr.write("DIAGNOSE: docker exec -it {0} /bin/bash\n".format(name))

+         sys.stderr.write("DIAGNOSE: kill {0} # when finished\n".format(os.getpid()))

+ 

+         def _signal_handler(*args):

+             sys.stderr.write("\nDIAGNOSE ending...\n")

+ 

+         signal.signal(signal.SIGTERM, _signal_handler)

+         signal.pause()

+ 

+     # Dump the container logs

+     try:

+         os.makedirs(artifacts)

+     except OSError as exc:

+         if exc.errno != errno.EEXIST or not os.path.isdir(artifacts):

+             raise

+     log = os.path.join(artifacts, "{0}.log".format(os.path.basename(image)))

+ 

+     # Kill the container

+     with open(log, "w") as f:

+         subprocess.call(["/usr/bin/docker", "logs", name ], stdout=f.fileno())

+     subprocess.call(["/usr/bin/docker", "kill", name ], stdout=null.fileno())

+     subprocess.call(["/usr/bin/docker", "rm", "-f", name ], stdout=null)

+ 

+     shutil.rmtree(directory)

+     sys.exit(0)

+ 

+ if __name__ == '__main__':

+     sys.exit(main(sys.argv))

tests.yml
file added
+121
@@ -0,0 +1,121 @@

+ - hosts: localhost

+   roles:

+      - role: standard-test-behave

+        tags:

+           - classic

+        run_in_background: true

+        features:

I think we need to make this feature to work dynamically. just run behave to find all tests. and then run them

+           - autoremove

+           - builddep

+           - check-1

+           - check-2

+           - check-3 

+           - clean-1 

+           - clean-2 

+           - clean-requirements-on-remove 

+           - config-1

+           - config 

+           - deplist-1

+           - downgrade-1 

+           - download-1 

+           - gpg-1 

+           - gpg-2

+           - gpg-3

+           - gpg-4

+           - gpg-checksum

+           - group-1 

+           - group-2

+           - group-conditional-pkgs

+           - help-1 

+           - history-1 

+           - history-2

+           - history_undo

+           - install-1

+           - install-2 

+           - install-downgrade-1

+           - install-obsoletes

+           - install_remove-1 

+           - installroot-1

+           - installroot-2 

+           - installroot-3 

+           - installroot-4 

+           - installroot-5 

+           - list-1 

+           - list-repo-installed 

+           - mark-3 

+           - mark-install 

+           - mark-remove 

+           - obsoletes-1 

+           - obsoletes-2 

+           - obsoletes-3 

+           - obsoletes-4 

+           - obsoletes-keep-reason 

+           - obsoletes-one-to-one 

+           - obsoletes-reason 

+           - persistdir-1 

+           - persistdir-2 

+           - plugin-path-1 

+           - plugin-path-2 

+           - plugin-path-3 

+           - plugin-path-4 

+           - plugin-path-5 

+           - plugin-path-6 

+           - protected_packages

+           - provides-1 

+           - reinstall-notavailable

+           - reinstall-reason 

+           - remove-1 

+           - remove-or-distro-sync

+           - repolist-1 

+           - repolist-2 

+           - repolist-disabled

+           - repolist-enabled-disabled

+           - repolist-no-repos

+           - repoquery-1 

+           - repoquery-2

+           - repoquery-3 

+           - repoquery-4

+           - repository-1

+           - repository-2

+           - repository-packages-info

+           - repository-packages-reinstall

+           - repository-packages-remove 

+           - repository-packages-update

+           - rich-1 

+           - rich-2 

+           - rich-3 

+           - rich-4

+           - rich-5

+           - rich-6 

+           - rich-7

+           - rich-8

+           - rich-9 

+           - scriptlets-1 

+           - security_1 

+           - security_2 

+           - security_3 

+           - security_4 

+           - security_5 

+           - setopt-1

+           - shell-1 

+           - shell-2 

+           - shell-3

+           - shell-4 

+           - shell-5 

+           - shell-6

+           - shell-7

+           - shell-8 

+           - ssl-1 

+           - ssl-2

+           - swap-2 

+           - swap-2-shell 

+           - swap-3 

+           - swap-3-shell 

+           - swap 

+           - updateinfo-1

+           - updateinfo-2 

+           - upgrade-1 

+           - upgrade-2

+           - upgrade-3 

+           - upgrade-to-1 

+           - vars-releaseve

no initial comment

Justification

Purpose: This pull request only for reviewing changes for dnf_dcoker tests, adopting it for standard-test-roles for running it with ci-pipeline.

GitHub source:

       https://github.com/rpm-software-management/ci-dnf-stack

Link to clone dnf_docker tests:

     https://github.com/rpm-software-management/ci-dnf-stack.git

Dependencies

Current patch is aimed at adopting dnf_docker tests to standard_test_roles
- Link to the pull request for standard-test-behave-role (tests need it for execution)

    https://pagure.io/fedora-ci/AtomicCi/pull-request/73

Patches:

  1. patch for Dockerfile (Dockerfile.patch):
- https://github.com/rpm-software-management/ci-dnf-stack/blob/master/Dockerfile
includes "--skip-broken " flag to skip broken rpm during installation
  1. patch for dnf-testing.sh (dnf-testing.sh.patch)
     - https://github.com/rpm-software-management/ci-dnf-stack/blob/master/dnf-testing.sh
     This script is used for executing behave features under docker image. 
     The main idea is to run each feature under separate docker image. 
  1. standard-inventory-behave
   -  new file, need to locate under root folder
   Standard-inventory-behave inventory uses for building main docker image with all dependencies and rpm packages for behave tests
   Each behave test will clone this docker image and start execution under separate docker container. 
  1. download_rpmy.py
   -  new file, need to locate under rpmy folder
   - Download all rpm (taken from Jenkins job) 
   - need to execute python download_rpmy.py
  1. runtest.sh
   -  new file, need to locate under root folder
   -  main script, that will be trigered from "standard-test-behave" role during "Running behave tests" step
   -  it includes iteration for checking cpu usage, if cpu > 80%, script will wait while previous feature will finish execution and release cpu. 
      This step has been included for running tests in parallel.
  1. tests.yml
   - ansible playbook file
   - tests_folder variable - explicit way to determine folder with runtest.sh executable file
   - run_in_background - specify the way for execution (true means run tests in background, in parallel)
   - features -list with behave features

Run tests for Classic

    # export ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory)
        # python rpmy/download_rpmy.py
    # export TEST_SUBJECTS=behave:dnf-bot/dnf-testing:latest
        # ansible-playbook -i standard-inventory-behave --tags=classic tests.yml

Tests results:

TASK [standard-test-behave : Check the results] *******************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost                  : ok=14   changed=9    unreachable=0    failed=0   

PASS autoremove
PASS builddep
PASS check-1
PASS check-2
PASS check-3
PASS clean-1
PASS clean-2
PASS clean-requirements-on-remove
PASS config-1
PASS config
PASS deplist-1
PASS downgrade-1
PASS download-1
PASS gpg-1
PASS gpg-2
PASS gpg-3
PASS gpg-4
PASS gpg-checksum
PASS group-1
PASS group-2
PASS group-conditional-pkgs
PASS help-1
PASS history-1
PASS history-2
PASS history_undo
PASS install-1
PASS install-2
PASS install-downgrade-1
PASS install-obsoletes
PASS install_remove-1
PASS installroot-1
PASS installroot-2
PASS installroot-3
PASS installroot-4
PASS installroot-5
PASS list-1
PASS list-repo-installed
PASS mark-3
PASS mark-install
PASS mark-remove
PASS obsoletes-1
PASS obsoletes-2
PASS obsoletes-3
PASS obsoletes-4
PASS obsoletes-keep-reason
PASS obsoletes-one-to-one
PASS obsoletes-reason
PASS persistdir-1
PASS persistdir-2
PASS plugin-path-1
PASS plugin-path-2
PASS plugin-path-3
PASS plugin-path-4
PASS plugin-path-5
PASS plugin-path-6
PASS protected_packages
PASS provides-1
PASS reinstall-notavailable
PASS reinstall-reason
PASS remove-1
PASS remove-or-distro-sync
PASS repolist-1
PASS repolist-2
PASS repolist-disabled
PASS repolist-enabled-disabled
PASS repolist-no-repos
PASS repoquery-1
PASS repoquery-2
PASS repoquery-3
PASS repoquery-4
PASS repository-1
PASS repository-2
PASS repository-packages-info
PASS repository-packages-reinstall
PASS repository-packages-remove
PASS repository-packages-update
PASS rich-1
PASS rich-2
PASS rich-3
PASS rich-4
PASS rich-5
PASS rich-6
PASS rich-7
PASS rich-8
PASS rich-9
PASS scriptlets-1
PASS security_1
PASS security_2
PASS security_3
PASS security_4
PASS security_5
PASS setopt-1
PASS shell-1
PASS shell-2
PASS shell-3
PASS shell-4
PASS shell-5
PASS shell-6
PASS shell-7
PASS shell-8
PASS ssl-1
PASS ssl-2
PASS swap-2
PASS swap-2-shell
PASS swap-3
PASS swap-3-shell
PASS swap
PASS updateinfo-1
PASS updateinfo-2
PASS upgrade-1
PASS upgrade-2
PASS upgrade-3
PASS upgrade-to-1
PASS vars-releaseve   

1 new commit added

  • Modifying runtest.sh according with changes instandard-test-behave model
6 years ago

Sounds nice, although still didn't look into code

I think we need to make this feature to work dynamically. just run behave to find all tests. and then run them