>From db2b66be00d0c46ba62fd84b5b8758b80b62f01c Mon Sep 17 00:00:00 2001
From: Abhishek Koneru <akoneru@redhat.com>
Date: Wed, 20 Nov 2013 02:24:38 -0500
Subject: [PATCH] Maintain seperate scripts for task and jobxml creation.

The compose script for creating the test rpm and submitting the job
is broken into two scripts, one for creating the test rpm
and one for creating the job xml.

CI Test Framework
---
 scripts/compose_pki_test_package           | 25 ++++++-------
 scripts/create-beaker-job-xml              | 42 +++++++++++++++++++++
 scripts/run_tests                          | 28 --------------
 tests/dogtag/README                        | 60 +++++++++++++++---------------
 tests/dogtag/beakerjob.dogtag.xml.template |  4 +-
 tests/dogtag/make-package.sh               |  7 +---
 6 files changed, 88 insertions(+), 78 deletions(-)
 create mode 100755 scripts/create-beaker-job-xml
 delete mode 100755 scripts/run_tests

diff --git a/scripts/compose_pki_test_package b/scripts/compose_pki_test_package
index 879c48a92d9c1068dd4cf95e08ea50df2de1b242..061970e3f131646f1f6f1d5740429d5800291e02 100755
--- a/scripts/compose_pki_test_package
+++ b/scripts/compose_pki_test_package
@@ -23,17 +23,17 @@ check_for_dependencies()
 
 check_for_dependencies
 
-if [ $# -lt 2 ];
+if [ $# -lt 1 ];
 then
-  echo "Usage: $0 User-ID_for_personalization Job_xml_config_file [--runtests]"
+  echo "Usage: $0 User-ID_for_personalization [--submit-tests]"
   exit -1
 fi
 
 RUN_TESTS='N'
 
-if [ $# -gt 2 ];
+if [ $# -gt 1 ];
 then
-    if [ $3 = "--runtests" ]
+    if [ $2 = "--submit-tests" ]
     then
         RUN_TESTS='Y'
     fi
@@ -53,12 +53,14 @@ WORK_DIR=`cd $COMPOSE_DIR/../..;pwd`
 
 BUILD_DIR="$WORK_DIR/package.tests"
 
-rm -rf $BUILD_DIR
-
-mkdir $BUILD_DIR
+if [ ! -d $BUILD_DIR ] ; then
+    mkdir $BUILD_DIR
+fi
 
 cd $BUILD_DIR
 
+rm -rf *.rpm
+
 cp -r "$PKI_SOURCE_DIR/tests" .
 
 ### Compile the java test source ###
@@ -79,16 +81,13 @@ cd ..
 
 ### Passing the keyword for personalizing and an option
 ### to maintain a seperate folder for each beaker job (Optional)
-./make-package.sh $1 $2
+./make-package.sh $1
 
 mv *.rpm ../../
 
-mv *.xml ../../
-
+cd ../..
 ### Running the tasks
 
-cd $COMPOSE_DIR
-
 if [ $RUN_TESTS = "Y" ] ; then
-     ./run_tests
+     bkr task-add *.rpm
 fi
diff --git a/scripts/create-beaker-job-xml b/scripts/create-beaker-job-xml
new file mode 100755
index 0000000000000000000000000000000000000000..5184d48832a70bca55bb983aa681cc75bb204220
--- /dev/null
+++ b/scripts/create-beaker-job-xml
@@ -0,0 +1,42 @@
+#! /bin/bash
+
+### Exit if there not enough parameters specified.
+if [ $# -lt 2 ];
+then
+  echo "Usage: ./create-beaker-job-xml unique_identifier Job_xml_config_file [--submit-job]"
+  exit -1
+fi
+
+user_id=$1
+### Directory with all the compose scripts
+COMPOSE_DIR=`dirname $0 | cd ; pwd`
+
+PKI_SOURCE_DIR=`cd $COMPOSE_DIR/..; pwd`
+
+WORK_DIR=`cd $COMPOSE_DIR/../..;pwd`
+
+BUILD_DIR="$WORK_DIR/package.tests"
+
+if [ ! -d $BUILD_DIR ] ; then
+    mkdir $BUILD_DIR
+fi
+
+cd $BUILDDIR
+
+cp -r $PKI_SOURCE_DIR/tests .
+
+cd tests/dogtag
+
+sed -e "s|PKI_TEST_USER_ID|${user_id}|g"  beakerjob.dogtag.xml.template >> beakerjob.dogtag.xml
+
+python update_beaker_job.py beakerjob.dogtag.xml $2
+
+if [ $# -gt 2 ];
+then
+    if [ $3 = "--submit-job" ]
+    then
+        bkr job-submit beakerjob.dogtag.xml
+    fi
+fi
+
+mv beakerjob.dogtag.xml ../../
diff --git a/scripts/run_tests b/scripts/run_tests
deleted file mode 100755
index 8e4d65e9f8f9b7c40b4eba38e518d74ae5f8ce88..0000000000000000000000000000000000000000
--- a/scripts/run_tests
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-
-WAIT_FOR_RESULT='N'
-if [ $# -ge 1 ] ; then
-    if [ "$1" = "--wait-on-beaker-job" ] ; then
-        WAIT_FOR_RESULT="Y"
-    else
-        echo "Unrecognized option. Usage: ./runtests --wait-on-beaker-job(Optional)"
-    fi
-fi
-COMPOSE_PWD=`dirname $0 | cd; pwd`
-
-TEST_PACKAGE=`cd $COMPOSE_PWD/../../package.tests; pwd`
-
-if [ ! -d $TEST_PACKAGE ] ; then
-    echo "Cannot run tests on beaker. Please compose the test rpms."
-    exit -1
-fi
-
-cd $TEST_PACKAGE
-
-bkr task-add *.rpm
-
-if [ "$WAIT_FOR_RESULT" = "Y" ] ; then
-    bkr job-submit --wait *.xml
-else
-    bkr job-submit *.xml
-fi
diff --git a/tests/dogtag/README b/tests/dogtag/README
index c9679bea05a0743bf5ff9c0f393b6754aba87879..33da9828a90769fcfc514ac1ec7ddee5e57ee188 100644
--- a/tests/dogtag/README
+++ b/tests/dogtag/README
@@ -95,8 +95,6 @@
 
         This sets up the machine as a beaker client, on which new task rpms can
         be built and new jobs submitted to the beaker server.
-        A beaker job is an XML file. The template used to create a job is in
-        tests/dogtag/beakerjob.dogtag.xml.template.
 
   1.2.2 Building the beaker task rpm and submitting a beaker job.
 
@@ -120,47 +118,49 @@
      1.2.2.2 Building the task rpm and submitting the job to a beaker server is done
         by executing the compose script in pki/scripts:
 
-        ./compose_pki_test_package unique_identifier beaker_job_config [--runtests]
+        ./compose_pki_test_package unique_identifier [--submit-tests]
 
         The builds are done in <pki_source_root>/../package.tests/ folder.
 
-        -- The unique_identifier is for personalizing the rpm.
+         -- The unique_identifier is for personalizing the rpm.
 
-           This path at which the test source is extracted from the rpm on the
-           beaker server is specified by the TEST variable in the
-           Makefile (pki/tests/dogtag/Makefile).
+            This path at which the test source is extracted from the rpm on the
+            beaker server is specified by the TEST variable in the
+            Makefile (pki/tests/dogtag/Makefile).
 
-           So another rpm with the same to-be-extracted path overwrites
-           the existing test code.
-           In order to prevent it, a unique id is asked to personalize the rpm
-           to provide a unique to-be-extracted path for every test rpm of
-           dogtag tests (especially at a user level).
+            So another rpm with the same to-be-extracted path overwrites
+            the existing test code.
+            In order to prevent it, a unique id is asked to personalize the rpm
+            to provide a unique to-be-extracted path for every test rpm of
+            dogtag tests (especially at a user level).
 
-        -- beaker_job_config (the absolute path of the file from /)
-           - to configure the recipe of a job.
+         -- The optional --submit-tests option.
+            This option submits the test rpm to the beaker server.
 
-           A sample configuration file is at tests/conf/beaker-job.cfg.
+        ./create-beaker-job-xml unique_identifier beaker_job_config [--submit-job]
 
-           The repos parameter should point to the URL's to access the dogtag
-           rpms. The hostname means the hostname of a specific beaker test
-           machine. The distro_* are the details of the distribution on the
-           beaker server, that has to be installed on the test machine.
+        The unique_identifier has the same functionality as the one used in the
+        compose_pki_test_rpm command.
 
-        -- The optional --runtests option.
-           Without the --runtests options the task rpm and the job xml are
-           not submitted to the beaker server.
+        The "beaker_job_config" (the absolute path of the file from /)
+        is for configuring the recipe of a job.
 
-     ** An already built rpm/job (built without the --runtests option above)
-        can be submitted to a beaker server by:
-
-        ./run_tests [--wait-on-beaker-job]
-
-        -- The run_tests just submits the task rpm and job xml to beaker.
-           But specifying --wait-on-beaker-job option, the process is
-           blocked until the job is completed.
+        A sample configuration file is at tests/conf/beaker-job.cfg.
 
+        The repos parameter should point to the URL's to access the dogtag
+        rpms. The hostname means the hostname of a specific beaker test
+        machine. The distro_* are the details of the distribution on the
+        beaker server, that has to be installed on the test machine.
 
+        The optional --submit-job command submits the job to the beaker server.
 
+**Note- A beaker job is an XML file. The template used to create a job is in
+        tests/dogtag/beakerjob.dogtag.xml.template.
+        The task /distribution/reservesys is commented. On uncommenting this
+        task in the template, the beaker test machine is reserved for a certain
+        period of time after the tests are run. This option can be used to 
+        debug any tests that are failing. 
+        
 **Note- In the case of creating a repository on a remote machine, the remote
         machine must be a known_host to the local machine.
 
diff --git a/tests/dogtag/beakerjob.dogtag.xml.template b/tests/dogtag/beakerjob.dogtag.xml.template
index 5358da4d41a1834abf560bb9a65eb614dca8862c..2b86bd3f8fccc5dc745a93375aa66a5dc2177bc3 100644
--- a/tests/dogtag/beakerjob.dogtag.xml.template
+++ b/tests/dogtag/beakerjob.dogtag.xml.template
@@ -35,9 +35,9 @@
                                         <param name="DEV_JAVA_TESTS" value="FALSE"/>
 				</params>
 			</task>
-			<task name="/distribution/reservesys" role="STANDALONE">
+			<!-- <task name="/distribution/reservesys" role="STANDALONE">
 				<params/>
-			</task>
+			</task> -->
 		</recipe>
 	</recipeSet>
 </job>
diff --git a/tests/dogtag/make-package.sh b/tests/dogtag/make-package.sh
index fd32657302abd9d82c01c929dda7e0d311ca83ef..f52f67959c1458a774f1794c5a43d8a1d8432fdb 100755
--- a/tests/dogtag/make-package.sh
+++ b/tests/dogtag/make-package.sh
@@ -1,9 +1,9 @@
 #!/bin/sh
 
 ### Exit if there not enough parameters specified.
-if [ $# -lt 2 ];
+if [ $# -lt 1 ];
 then
-  echo "Usage: ./make-package.sh User-ID Job_xml_config_file [Different_subfolder_for_each_beaker_job_?(Y/N)]"
+  echo "Usage: ./make-package.sh User-ID [Different_subfolder_for_each_beaker_job_?(Y/N)]"
   exit -1
 fi
 
@@ -36,6 +36,3 @@ rm -rf Makefile
 
 mv .Makefile.save Makefile
 
-sed -e "s|PKI_TEST_USER_ID|${user_id}|g"  beakerjob.dogtag.xml.template >> beakerjob.dogtag.xml
-
-python update_beaker_job.py beakerjob.dogtag.xml $2
-- 
1.8.3.1

