From 8a2e109ceb3c6f6053b845d43ce74f284b8766ca Mon Sep 17 00:00:00 2001
From: Christophe Sovant <christophe.sovant@forgerock.com>
Date: Mon, 19 May 2008 17:53:33 +0000
Subject: [PATCH] Fix SNMP tests compilation issue on Windows

---
 opends/tests/shared/functions/snmp.xml        |    6 +++---
 opends/tests/shared/functions/dsconfig.xml    |    4 ++--
 opends/tests/shared/functions/environment.xml |   12 ++----------
 opends/tests/shared/functions/topology.xml    |    2 +-
 opends/tests/shared/functions/utils.xml       |   12 ++++++------
 opends/tests/shared/python/common.py          |   23 ++++++++++++++++++++++-
 6 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/opends/tests/shared/functions/dsconfig.xml b/opends/tests/shared/functions/dsconfig.xml
index 41d3883..94eb618 100755
--- a/opends/tests/shared/functions/dsconfig.xml
+++ b/opends/tests/shared/functions/dsconfig.xml
@@ -1019,7 +1019,7 @@
         
         if aciValue:
             aciValue=aciValue.replace('"','\\"')
-            if isWindows:
+            if is_windows_platform(mylocation):
                 aciValue=aciValue.replace(r'||',r'"||"')
         
         STAFCmdParamsList=[]
@@ -2140,5 +2140,5 @@
         STAXResult
       </return>
     </sequence>
-  </function>
+  </function>  
 </stax>
diff --git a/opends/tests/shared/functions/environment.xml b/opends/tests/shared/functions/environment.xml
index 163905a..ec812f2 100755
--- a/opends/tests/shared/functions/environment.xml
+++ b/opends/tests/shared/functions/environment.xml
@@ -123,20 +123,12 @@
   </function-prolog>
     
     <sequence>
-    
-      <!-- Resolve any OS related variables -->           
-      <call function="'getOSvariables'">
-        { 'hostname' : STAF_REMOTE_HOSTNAME }
-      </call>
 
       <!-- fixMe: this needs some cleanup -->
       <script>
         STAXLogMessage = 1 
-        OPENDS_BINPATH ='%s/%s/bin' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME) 
-        OSName= STAXResult
-        winPattern=re.compile('win', re.IGNORECASE)
-        isWindows=winPattern.search(OSName)
-        if isWindows:
+        OPENDS_BINPATH ='%s/%s/bin' % (DIRECTORY_INSTANCE_DIR,OPENDSNAME)
+        if is_windows_platform(STAF_REMOTE_HOSTNAME):
           fileExt='.bat'
           fileFolder='bat'
           pathSeparator=';'
diff --git a/opends/tests/shared/functions/snmp.xml b/opends/tests/shared/functions/snmp.xml
index e7d30c0..c36aa6d 100755
--- a/opends/tests/shared/functions/snmp.xml
+++ b/opends/tests/shared/functions/snmp.xml
@@ -154,7 +154,7 @@
         snmpPath = '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
         cp = 'CLASSPATH=%s/%s:%s/jdmkrt.jar:.' % (DIRECTORY_INSTANCE_DIR,SNMP_OPENDS_JARFILE, snmpPath)
         
-        if isWindows:
+        if is_windows_platform(location):
           cp = cp.replace(':', ';')
         
         env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp] 
@@ -311,7 +311,7 @@
         snmpPath = '%s/%s/snmp' % (DIRECTORY_INSTANCE_DIR, relativeJavaDir)
         cp = 'CLASSPATH=%s/%s:%s/jdmkrt.jar:.' % (DIRECTORY_INSTANCE_DIR,SNMP_OPENDS_JARFILE, snmpPath)
         
-        if isWindows:
+        if is_windows_platform(location):
           cp = cp.replace(':', ';')
         
         env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp] 
@@ -422,7 +422,7 @@
         cp = 'CLASSPATH=%s/%s:%s/jdmkrt.jar:%s:.' \
         % (DIRECTORY_INSTANCE_DIR,SNMP_OPENDS_JARFILE, snmpPath, jstaf_jarfile)
         
-        if isWindows:
+        if is_windows_platform(location):
           cp = cp.replace(':', ';')
         
         env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp] 
diff --git a/opends/tests/shared/functions/topology.xml b/opends/tests/shared/functions/topology.xml
index d0d92db..a4bfee0 100755
--- a/opends/tests/shared/functions/topology.xml
+++ b/opends/tests/shared/functions/topology.xml
@@ -638,7 +638,7 @@
       </call>
       
       <!-- fixMe: Windows Services are not enabled -->
-      <if expr="isWindows">
+      <if expr="is_windows_platform(dsHost)">
         <script>
           enableWindowsService=''
         </script>
diff --git a/opends/tests/shared/functions/utils.xml b/opends/tests/shared/functions/utils.xml
index 69d6c10..b0846dd 100755
--- a/opends/tests/shared/functions/utils.xml
+++ b/opends/tests/shared/functions/utils.xml
@@ -1486,7 +1486,7 @@
         _id = '%s#%d' % (strftime('%Y-%m-%d %H:%M:%S',localtime()),random.randint(0,999))
         
         if not env:
-          if isWindows:
+          if is_windows_platform(location):
             env=['PATH=C:\Windows;C:\Windows\system32;%s' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME]
           else:
             env=['PATH=/bin:/usr/bin:%s' % dsPath, 'JAVA_HOME=%s' % JAVA_HOME]
@@ -1613,7 +1613,7 @@
       </call>
                                 
       <script>
-        if isWindows:
+        if is_windows_platform(location):
           _cmd = 'tskill'
           _args = STAXResult
         else:
@@ -2029,10 +2029,10 @@
           cp = 'CLASSPATH=%s:.' % classpath
         else:
           cp = 'CLASSPATH=.'
-          
-        if isWindows:
+       
+        if is_windows_platform(location):
           cp = cp.replace(':', ';')
-          
+        
         if location == STAXServiceMachine:
           cmd = '%s/bin/javac' % local_java_home
           env = ['%s' % cp]        
@@ -2040,7 +2040,7 @@
           cmd = '%s/bin/javac' % JAVA_HOME
           env = ['JAVA_HOME=%s' % JAVA_HOME, '%s' % cp]          
       </script>
-      
+
       <call function="'listFolderByExtension'" >
         { 
         'location'   : location ,
diff --git a/opends/tests/shared/python/common.py b/opends/tests/shared/python/common.py
index 7d97eba..30f4861 100644
--- a/opends/tests/shared/python/common.py
+++ b/opends/tests/shared/python/common.py
@@ -29,7 +29,13 @@
 # $Source$
 
 # public symbols
-__all__ = [ "format_testcase", "directory_server_information", "test_time", "report_generation", "compare_file", "exception_thrown" ]
+__all__ = [ "format_testcase",
+            "directory_server_information", 
+            "test_time", 
+            "report_generation", 
+            "compare_file", 
+            "is_windows_platform", 
+            "exception_thrown" ]
 
 class format_testcase:
   'Format the Test name objects'
@@ -171,3 +177,18 @@
       return ret_str
     finally:
       diff_file.close()
+
+def is_windows_platform(host):
+    from java.lang import Boolean
+    from com.ibm.staf import STAFHandle
+    from com.ibm.staf import STAFResult
+    import re
+
+    handle = STAFHandle("varHandle")
+    res = handle.submit2(host, "VAR", "GET SYSTEM VAR STAF/Config/OS/Name")
+
+    winPattern=re.compile('win', re.IGNORECASE)
+    if (winPattern.search(res.result) != None):
+      return Boolean.TRUE
+    else:
+      return Boolean.FALSE

--
Gitblit v1.10.0