From 1a99dc17e0ecd2d8964b018196bf226218a9643b Mon Sep 17 00:00:00 2001
From: Christophe Sovant <christophe.sovant@forgerock.com>
Date: Tue, 04 Jun 2013 15:57:05 +0000
Subject: [PATCH] CR-1789 Added mode to run tests from upgraded instance

---
 opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml    |   74 ++++++++++++++++++
 opendj-sdk/opends/tests/staf-tests/shared/functions/topology.xml |  135 +++++++++++++++++++++++++++++++--
 opendj-sdk/opends/tests/staf-tests/shared/tests/config.py.stubs  |    3 
 3 files changed, 202 insertions(+), 10 deletions(-)

diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
index 52e8961..3e3d877 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/dsadm.xml
@@ -52,6 +52,80 @@
 
   </function>
 
+  <!-- This function upgrades DS using the upgrade script -->
+  <function name="UpgradeDsWithScript" scope="local">
+    <function-prolog>
+      This function upgrades DS using the upgrade script
+    </function-prolog>
+    <function-map-args>
+      <function-arg-def name="location"
+                        type="optional"
+                        default="STAF_REMOTE_HOSTNAME">
+        <function-arg-description>
+          Location of target host
+        </function-arg-description>
+        <function-arg-property name="type" value="hostname"/>
+      </function-arg-def>
+      <function-arg-def name="dsPath"
+                        type="optional"
+                        default="'%s/%s' % (DIRECTORY_INSTANCE_BIN,OPENDSNAME)">
+        <function-arg-description>
+          Pathname to installation root
+        </function-arg-description>
+        <function-arg-property name="type" value="filepath"/>
+      </function-arg-def>
+      <function-arg-def name="dsHelp" type="optional">
+        <function-arg-description>
+          Help option
+        </function-arg-description>
+        <function-arg-property name="help" value="option"/>
+      </function-arg-def>
+      <function-arg-def name="expectedRC" type="optional" default="0">
+        <function-arg-description>
+          Expected return code value. Default value is 0.
+          Wildcard 'noCheck' to not check the RC
+        </function-arg-description>
+      </function-arg-def>
+      <function-arg-def name="knownIssue" type="optional" default="None">
+        <function-arg-description>
+          Known issue. Corresponds to an issue number.
+        </function-arg-description>
+      </function-arg-def>
+    </function-map-args>
+    
+    <sequence>
+    
+      <!-- Build the Command -->
+      <script>
+        STAFCmdParamsList=[]
+        STAFCmdParams=''
+
+        if dsPath:
+          STAFCmd='%s/upgrade%s' % (dsPath,fileExt) 
+          STAFCmdParamsList.append('-n')
+                  
+        if dsHelp:
+          STAFCmdParamsList.append('-H')
+
+        STAFCmdParams=' '.join(STAFCmdParamsList)
+      </script>
+      
+      <message>
+        '%s %s' % (STAFCmd, STAFCmdParams)
+      </message>
+      <call function="'runCommand'">
+        { 'location'  : location,
+          'name'      : 'Upgrade DS Script',
+          'command'   : STAFCmd,
+          'arguments' : STAFCmdParams,
+          'path'      : dsPath,
+          'expectedRC': expectedRC,
+          'knownIssue': knownIssue
+        }
+      </call>
+    </sequence>
+  </function>
+
   <!-- This function sets up DS using the setup script -->
   <function name="SetUpDsWithScript" scope="local">
     <function-prolog>
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/topology.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/topology.xml
index b014a40..fd147c7 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/topology.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/topology.xml
@@ -434,16 +434,105 @@
         </else>
       </if>
 
-      <!--- Install DS Extract zip file -->
-      <message>
-        'Extract DS zip archive to %s on %s' % (dsDir,dsHost)
-      </message>
-      <call function="'unZipFile'">
-        { 'location' : dsHost,
-          'zipfile'  : '%s/%s' % (dsDir,ZIPNAME),
-          'unzipdir' : dsDir
-        }
-      </call>
+      <if expr="UPGRADE_ZIPNAME == ''">
+        <sequence>
+          <!-- *********** -->
+          <!-- NORMAL MODE -->
+          <!-- *********** -->
+          
+	      <!--- Install DS Extract zip file -->
+	      <message>
+	        'Extract DS zip archive to %s on %s' % (dsDir,dsHost)
+	      </message>
+	      <call function="'unZipFile'">
+	        { 'location' : dsHost,
+	          'zipfile'  : '%s/%s' % (dsDir,ZIPNAME),
+	          'unzipdir' : dsDir
+	        }
+	      </call>
+        </sequence>
+        <else>
+		  <sequence>
+		    <!-- ************ -->
+            <!-- UPGRADE MODE -->
+            <!-- ************ -->
+            
+		    <!--- Install old DS Extract zip file -->
+		    <message>
+		      'Extract old DS zip archive to %s on %s' % (local.temp,STAXServiceMachine)
+		    </message>
+		    <call function="'unZipFile'">
+		      { 'location' : STAXServiceMachine,
+		        'zipfile'  : '%s/%s' % (UPGRADE_ZIPPATH,UPGRADE_ZIPNAME),
+		        'unzipdir' : local.temp
+		      }
+		    </call>
+		  
+		    <!-- Rename folder for the old version, for instanceOpenDJ-2.4.5 -> opendj -->
+            <message>
+              'Rename old DS zip folder from %s/%s to %s/%s' % (local.temp,UPGRADE_OPENDJNAME,local.temp,OPENDSNAME)
+            </message>
+		    <script>
+		      import os
+		    
+		      srcDir = os.path.join(local.temp, UPGRADE_OPENDJNAME) 
+		      destDir = os.path.join(local.temp, OPENDSNAME) 
+		      os.rename(srcDir, destDir)
+		    </script>
+		  
+		    <!-- Re-create a new archive for the old DS -->
+            <message>
+              'Re-create old DS archive %s/%s from %s/%s' % (local.temp,UPGRADE_ZIPNAME,local.temp,OPENDSNAME)
+            </message>
+		    <call function="'zipUpFile'">
+		      { 'location'   : STAXServiceMachine,
+		        'zipfile'    : '%s/%s' % (local.temp,UPGRADE_ZIPNAME), 
+		        'folder'     : '%s/%s' % (local.temp,OPENDSNAME),
+		        'relativeto' : local.temp 
+		      }                        
+		    </call>
+		   
+		    <!-- Check if old DS Copy zip exists -->
+		    <call function="'GetEntry'">
+		      {
+		        'location'  : dsHost,
+		        'entry'     : '%s/%s' % (dsDir,UPGRADE_ZIPNAME),
+		        'attribute' : 'TYPE'
+		      }
+		    </call>
+		    <if expr="RC == 48">
+		      <sequence>
+		        <!--- Copy old DS Copy zip file -->
+		        <message>
+		          'Copy old DS zip archive %s/%s to %s' % (local.temp,UPGRADE_ZIPNAME,dsHost)
+		        </message>
+		        <call function="'copyFile'">
+		          { 'srcfile'    : '%s/%s' % (local.temp,UPGRADE_ZIPNAME),
+		            'destfile'   : '%s/%s' % (dsDir,UPGRADE_ZIPNAME),
+		            'remotehost' : dsHost
+		          }
+		        </call>
+		      </sequence>
+		      <else>
+		        <message>
+		          'Old DS zip archive %s/%s already exists, nothing to do' % (dsDir,UPGRADE_ZIPNAME)
+		        </message>
+		      </else>
+		    </if>
+		  
+		    <!--- Install DS Extract zip file -->
+		    <message>
+		      'Extract old DS zip archive to %s on %s' % (dsDir,dsHost)
+		    </message>
+		    <call function="'unZipFile'">
+		      { 'location' : dsHost,
+		        'zipfile'  : '%s/%s' % (dsDir,UPGRADE_ZIPNAME),
+		        'unzipdir' : dsDir
+		      }
+		    </call>
+		  </sequence>
+        </else>
+      </if>
       
       <!-- fixMe: Windows Services are not enabled -->
       <if expr="is_windows_platform(dsHost)">
@@ -501,6 +590,32 @@
           </message>
         </else>
       </if>
+      
+      <!-- ******* -->
+      <!-- UPGRADE -->
+      <!-- ******* -->
+      <if expr="UPGRADE_ZIPNAME != ''">
+        <sequence>
+          <!-- Copy content of new version into old version -->
+	      <!-- Install DS Extract zip file -->
+	      <message>
+	        'Extract DS zip archive to %s on %s' % (dsDir,dsHost)
+	      </message>
+	      <call function="'unZipFile'">
+	        { 'location' : dsHost,
+	          'zipfile'  : '%s/%s' % (dsDir,ZIPNAME),
+	          'unzipdir' : dsDir
+	        }
+	      </call>
+ 
+          <!--  Upgrade instance -->
+          <call function="'UpgradeDsWithScript'">
+            { 'location'   : dsHost,
+              'dsPath'     : '%s/%s' % (dsDir, OPENDSNAME),
+            }
+          </call>
+        </sequence>
+      </if>
     </sequence> 
   </function>
   
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/tests/config.py.stubs b/opendj-sdk/opends/tests/staf-tests/shared/tests/config.py.stubs
index 158b7be..8599d1b 100644
--- a/opendj-sdk/opends/tests/staf-tests/shared/tests/config.py.stubs
+++ b/opendj-sdk/opends/tests/staf-tests/shared/tests/config.py.stubs
@@ -34,6 +34,9 @@
 OPENDSNAME                    = 'opendj'
 ZIPNAME                       = '${opends.name}.zip'
 ZIPPATH                       = '${opends.dir}'
+UPGRADE_OPENDJNAME            = '${upgrade.opendj.name}'
+UPGRADE_ZIPNAME               = '${upgrade.opendj.name}.zip'
+UPGRADE_ZIPPATH               = '${upgrade.opendj.dir}'
 TESTS_TIMESTAMP               = '${tests.timestamp}'
 TESTS_TYPE                    = '${tests.type}'
 TESTS_ROOT                    = '${basedir}'

--
Gitblit v1.10.0