From a35b2ccd6bcbbbd431d02a89f2bf247df1660159 Mon Sep 17 00:00:00 2001
From: Christophe Sovant <christophe.sovant@forgerock.com>
Date: Tue, 20 May 2008 09:51:57 +0000
Subject: [PATCH] Add 'create_property_table' function

---
 opends/tests/shared/functions/dsconfig.xml |  125 +++++++++++++++++++++++++++++++++++++++++
 opends/tests/shared/python/common.py       |   14 ++++
 2 files changed, 138 insertions(+), 1 deletions(-)

diff --git a/opends/tests/shared/functions/dsconfig.xml b/opends/tests/shared/functions/dsconfig.xml
index 94eb618..48a3dcf 100755
--- a/opends/tests/shared/functions/dsconfig.xml
+++ b/opends/tests/shared/functions/dsconfig.xml
@@ -2140,5 +2140,128 @@
         STAXResult
       </return>
     </sequence>
-  </function>  
+  </function>
+
+  <function name="GetDSConfigProperties">
+    <function-prolog>
+      This function get the value of the given server's attributes
+      It will call dsconfig, then extract the attributes value.
+    </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_DIR,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="dsInstanceHost" 
+                        type="optional" 
+                        default="STAF_REMOTE_HOSTNAME">
+        <function-arg-description>
+          Directory server hostname or IP address
+        </function-arg-description>
+        <function-arg-property name="type" value="hostname" />
+      </function-arg-def>
+      
+      <function-arg-def name="dsInstancePort" type="required">
+        <function-arg-description>
+          Directory server port number
+        </function-arg-description>
+        <function-arg-property name="type" value="Port number" />
+      </function-arg-def>
+      
+      <function-arg-def name="dsInstanceDn" type="required">
+        <function-arg-description>
+          Bind DN
+        </function-arg-description>
+        <function-arg-property name="type" value="DN" />
+      </function-arg-def>
+      
+      <function-arg-def name="dsInstancePswd" type="required">
+        <function-arg-description>
+          Bind password
+        </function-arg-description>
+        <function-arg-property name="type" value="string" />
+      </function-arg-def>
+      
+      <function-arg-def name="subcommand" type="required">
+        <function-arg-description>
+          dsconfig subcommand to execute
+          e.g. get-backend-prop
+        </function-arg-description>
+        <function-arg-property name="type" value="string" />
+      </function-arg-def>
+      
+      <function-arg-def name="optionsString" type="optional">
+        <function-arg-description>
+          String containing the dsconfig options
+          e.g. --backend-name userRoot --property base-dn
+        </function-arg-description>
+        <function-arg-property name="type" value="string" />
+      </function-arg-def>
+      
+      <function-arg-def name="myVariableName" type="required">
+        <function-arg-description>
+          Variable containing the dsconfig properties
+        </function-arg-description>
+        <function-arg-property name="type" value="string" />
+      </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-property name="type" value="string" />
+      </function-arg-def>      
+    </function-map-args>
+    <sequence>
+
+      <script>
+        if optionsString:
+          optionsString = '%s --script-friendly' % optionsString
+        else:
+          optionsString = '--script-friendly'
+      </script>
+      
+      <!-- Call dsconfig -->
+      <call function="'dsconfig'">
+        {
+        'location'       : location ,
+        'dsPath'         : dsPath ,
+        'dsInstanceHost' : dsInstanceHost ,
+        'dsInstancePort' : dsInstancePort ,
+        'dsInstanceDn'   : dsInstanceDn ,
+        'dsInstancePswd' : dsInstancePswd ,
+        'subcommand'     : subcommand ,
+        'optionsString'  : optionsString ,
+        'expectedRC'     : expectedRC
+        }
+      </call>
+  
+      <if expr='RC == 0'>
+        <script>
+          vars()[myVariableName] = create_property_table(STAXResult[0][1], '\t')
+        </script>
+      </if>
+
+      <return>
+        STAXResult
+      </return>
+      
+    </sequence>
+  </function>
+
 </stax>
diff --git a/opends/tests/shared/python/common.py b/opends/tests/shared/python/common.py
index 30f4861..535f5bd 100644
--- a/opends/tests/shared/python/common.py
+++ b/opends/tests/shared/python/common.py
@@ -35,6 +35,7 @@
             "report_generation", 
             "compare_file", 
             "is_windows_platform", 
+            "create_property_table", 
             "exception_thrown" ]
 
 class format_testcase:
@@ -192,3 +193,16 @@
       return Boolean.TRUE
     else:
       return Boolean.FALSE
+
+def create_property_table(output, separator):
+    table = {}
+
+    for line in output.splitlines():
+      key = line.split(separator)[0].strip()
+      try:
+        value = line.split(separator)[1].strip()
+      except IndexError:
+        value = '-'
+      table[key] = value
+
+    return table

--
Gitblit v1.10.0