From 9bf9e1d49706e1f64429cbc2dc3142452939040c Mon Sep 17 00:00:00 2001
From: esaka <esaka@localhost.localdomain>
Date: Dec 07 2017 11:41:36 +0000
Subject: [PATCH 1/2] Adding changes for dnf_dcoker tests for PR in dnf_behave_tests_pr


---

diff --git a/Dockerfile.patch b/Dockerfile.patch
new file mode 100644
index 0000000..8a800db
--- /dev/null
+++ b/Dockerfile.patch
@@ -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
diff --git a/dnf-testing.sh.patch b/dnf-testing.sh.patch
new file mode 100644
index 0000000..7cb401c
--- /dev/null
+++ b/dnf-testing.sh.patch
@@ -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
diff --git a/download_rpmy.py b/download_rpmy.py
new file mode 100644
index 0000000..d2d608f
--- /dev/null
+++ b/download_rpmy.py
@@ -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)
+        
diff --git a/runtest.sh b/runtest.sh
new file mode 100755
index 0000000..9dddc7d
--- /dev/null
+++ b/runtest.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+check_cpu()
+{
+    echo $(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}')
+}
+
+cpu=$( check_cpu )
+while [ $cpu \> 80 ]
+do
+    sleep 1
+    cpu=$( check_cpu )
+done
+
+
+#run test
+echo $(./dnf-testing.sh run "$1" > test."$1".log 2>&1)
+
+
+
+
diff --git a/standard-inventory-behave b/standard-inventory-behave
new file mode 100755
index 0000000..dc48e4d
--- /dev/null
+++ b/standard-inventory-behave
@@ -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))
diff --git a/tests.yml b/tests.yml
new file mode 100644
index 0000000..b82c5cb
--- /dev/null
+++ b/tests.yml
@@ -0,0 +1,121 @@
+- hosts: localhost
+  roles:
+     - role: standard-test-behave
+       tags:
+          - classic
+       run_in_background: true
+       features:
+          - 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

From a5ef8124709ac47289dfea03aad77d1d7f8c6cf2 Mon Sep 17 00:00:00 2001
From: esaka <esaka@localhost.localdomain>
Date: Dec 08 2017 15:23:51 +0000
Subject: [PATCH 2/2] Modifying runtest.sh according with changes instandard-test-behave model


---

diff --git a/runtest.sh b/runtest.sh
index 9dddc7d..ffba15d 100755
--- a/runtest.sh
+++ b/runtest.sh
@@ -1,18 +1,5 @@
 #!/bin/bash
 
-check_cpu()
-{
-    echo $(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}')
-}
-
-cpu=$( check_cpu )
-while [ $cpu \> 80 ]
-do
-    sleep 1
-    cpu=$( check_cpu )
-done
-
-
 #run test
 echo $(./dnf-testing.sh run "$1" > test."$1".log 2>&1)
 

