Revision: 162
Author:   janne.t.harkonen
Date:     Fri Aug 24 05:10:16 2012
Log:      Add keyword Get Connections
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=162

Modified:
 /trunk/atest/connections_and_login.txt
 /trunk/src/SSHLibrary/__init__.py
 /trunk/src/SSHLibrary/config.py

=======================================
--- /trunk/atest/connections_and_login.txt      Fri Aug 24 04:22:16 2012
+++ /trunk/atest/connections_and_login.txt      Fri Aug 24 05:10:16 2012
@@ -1,5 +1,5 @@
 *** Settings ***
-Defaults Tags      pybot   jybot
+Default Tags      pybot   jybot
 Test Teardown   Close All Connections
 Resource        resources/ssh_library_resources.txt

@@ -41,3 +41,12 @@
 Executing Command Before Opening Connection
     Run Keyword And Expect Error  No open connection  Execute Command  ls

+Get Connections
+    Open Connection   ${HOST}   prompt=>>
+    Open Connection   ${HOST}   alias=saila
+    ${conns} =   Get Connections
+    Should Be Equal    ${conns[0].host}    ${HOST}
+    Should Be Equal    ${conns[1].host}    ${HOST}
+    Should Be Equal    ${conns[0].prompt}    >>
+    Should Be Equal    ${conns[1].alias}    saila
+    Should Be Equal    ${conns[0].term_type}    vt100
=======================================
--- /trunk/src/SSHLibrary/__init__.py   Fri Aug 24 05:09:41 2012
+++ /trunk/src/SSHLibrary/__init__.py   Fri Aug 24 05:10:16 2012
@@ -200,6 +200,26 @@
         except AttributeError:
             pass

+    def get_connections(self):
+        """Return information about opened connections.
+
+        The return value is a list of objects that describe the connection.
+        These objects have attributes that correspond to the argument names
+        of `Open Connection`.
+
+        Example:
+        | Open Connection | somehost  | prompt=>> |
+        | Open Connection | otherhost | timeout=5 minutes |
+        | ${info} = | Get Connections |
+        | Should Be Equal | ${info[0].host} | somehost |
+        | Should Be Equal | ${info[1].timeout} | 5 minutes |
+        """
+        # TODO: could the ConnectionCache be enhanced to be iterable?
+        configs = [c.config for c in self._cache._connections]
+        for c in configs:
+            self._log(str(c))
+        return configs
+
     def enable_ssh_logging(self, logfile):
         """Enables logging of SSH protocol output to given `logfile`

=======================================
--- /trunk/src/SSHLibrary/config.py     Fri Aug 24 04:21:43 2012
+++ /trunk/src/SSHLibrary/config.py     Fri Aug 24 05:10:16 2012
@@ -26,6 +26,9 @@
     def __init__(self, **entries):
         self._config = entries

+    def __str__(self):
+ return '\n'.join(['%s=%s' % (k, v) for k, v in self._config.items()])
+
     def update(self, **entries):
         """Update configuration entries.

@@ -72,6 +75,9 @@
     def __init__(self, initial=None):
         self._value = self._create_value(initial)

+    def __str__(self):
+        return str(self._value)
+
     @property
     def value(self):
         return self._value

Reply via email to