Wednesday, February 01, 2012

Python Robot Framework "FOR loop contains no keywords"

I've just been having a spot of trouble with Robot Framework and :FOR loops. The darn thing wouldn't recognize that the loop contained anything. Turns out, the problem is due to my using a .TXT file (text file with space delimited format). The :FOR loop didn't know how to parse the leading spaces into two empty columns. It had to presume there was one. With only one, the FOR loop contents were empty. This always leads to an error: "FOR loop contains no keywords". The solution for this is to just use pipe delimiters for that keyword. For instance, consider:
| Then I should see that it is below "${critical_value}" |
|   | Log               | In ThenIShouldSeethatItIsBelow keyword now.  | 
|   | ${table_lines}=   | Get Lines Containing String | ${full_output} | Table ${table} is served by  |
|   | Should Not Be Empty | ${table_lines} |
|   | @{lines}= | Split To Lines | ${table_lines}   |
|   | :FOR      | ${line} | IN | @{lines} |
|   |           | Log | havealine ${line} now. |
|   |           | ${value}=  | Fetch From Right | ${line} | ${SPACE} |
|   |           | Convert To Integer | ${value}                         |
|   |           | Should Be True     | ${value} <= ${critical_value}    |
|   | Log       | ending ThenIShouldSeethatItIsBelow now.  |
This allows the pipe delimiter to do its work. A more succinct example is:
| *Setting*  |     *Value*     |
| Library    | OperatingSystem |

| *Variable* |     *Value*     |
| ${MESSAGE} | Hello, world!   |

| *Test Case*  | *Action*        | *Argument*   |
| My Test      | [Documentation] | Example test |
|              | Log             | ${MESSAGE}   |
|              | My Keyword      | /tmp         |
| Another Test | Should Be Equal | ${MESSAGE}   | Hello, world! |
| TestTwo      |
|              | Log             | \nStarting   | WARN |
|              | MyForLoop       |
|              | Log             | \nEnding     | WARN |

| *Keyword*     |
| My Keyword    | [Arguments] | ${path}
|               | Directory Should Exist | ${path}
| MyForLoop     |
|               | Log | In myforloop now. | WARN |
|               | @{gvar}=  | Create List | a | b | c |
|               | Log | gvar is @{gvar} now. | WARN |
|               | :FOR  | ${x} | in | @{gvar} |
|               |       | Log | havealine ${x} now. | WARN |
|               | Log | ending myforloop now.  | WARN |
Enjoy your newfound power and use it responsibly. Or not.

Wednesday, November 30, 2011

I've recently run into the need to create a simple StatefulTelnetProtocol Telnet server. But, most of the examples have lots of extra cruft in the way. So, here's what I came up with by removing some extras from a post I found online: --> Note: I don't know the difference (yet) between doing a self.sendLine() and a self.transport.write() call. Feel free to comment if you know the distinction.
from twisted.internet.protocol import ServerFactory, Protocol
from twisted.conch.telnet import StatefulTelnetProtocol
from twisted.internet import reactor
from time import sleep

class MyProtocol(StatefulTelnetProtocol):
    
    def connectionMade(self):
        print "DEBUG: connectionMade called"
        self.sendLine("***************************************\r\n")
        self.sendLine("Welcome to the Simplified Telnet Server\r\n")
        self.sendLine("***************************************\r\n")
        sleep(2)
        self.transport.write("Can also send a line this way.\r\n")
        self.clearLineBuffer()
     
    def lineReceived(self, line):
        print "DEBUG: lineReceived called with %s" % line.strip()
        if line.strip() != "exit":
            self.sendLine("***************************************\r\n")
            #self.transport.write("TRANSPORT_WRITE: GOT LINE='%s'\n" % (str(line.strip())))
        else:
            print "telnet killed in line: %s" % str(line.strip())
            self.sendLine("TelnetShell killed. Bye Bye ...")
            self.transport.loseConnection()
            self.clearLineBuffer()
     
    def connectionLost(self, reason):
        print "DEBUG: connectionLost called with: %s" % str(reason)
     
def CreateMyFactory():
    factory = ServerFactory()
    factory.protocol = MyProtocol
    return factory
 
if __name__ == "__main__":
    MaFactory = CreateMyFactory()
    reactor.listenTCP(8023, MaFactory)
    reactor.run()

Monday, October 31, 2011

Python sdist package directory not found: Solved

Just was trying to create a new Python module and submit it to PyPi. Trouble was, when I was doing the standard:
me@mybox ~/myusername/blah
$ python setup.py sdist --formats=gztar,zip,bztar,ztar,tar
running sdist
error: package directory 'filenameX' does not exist
turns out the problem was, my setup.py had the following line:
py_modules = ['filenameX.py'],
This should be:
py_modules = ['filenameX'],
FIXED IT! Yay! Now it proceeds nicely.

Friday, October 14, 2011

Using ssh id_rsa without password - another username

Just had to login to another box via ssh, but the other account has a different username than my current one. Further, had to use a different id_dsa / id_dsa.pub set of files. I couldn't figure this out for a while. Turns out, the right way to do this is:
  • generate the keys
  • copy the pub key into authorized_keys2 on the remote box
  • ssh -i ~/.ssh/privateKeyFileName otheruser@remoteboxname
Pretty straightforward, found out. Kinda cool - didn't know about the -i parameter.

Wednesday, October 05, 2011

SSH Slow password prompt

Just had a problem with my vmware player install of Ubuntu Natty. Doing SSH takes a long, long time to come back with a password prompt. This is really aggravating.

Solved it by finding the following info:

1. Edit the /etc/ssh/ssh_config file using the following command

sudo vi /etc/ssh/ssh_config

Commentout the following lines

GSSAPIAuthentication yes
GSSAPIDelegateCredentials no

save the file and exit

2. Test it with ssh to another box, should be very fast now!

Thursday, September 29, 2011

Python BufferedIOBase Error

Just had a problem with a Python script where it was mysteriously generating an error on a simple import gzip statement.

The problem turned out to be someone had created a directory named 'io' in the PYTHONPATH. This caused python to import from that directory instead of importing the builtin library io.

Silly programmers! Don't you know Trix are for kids! Never create a directory named the same as a builtin library! Ug! I'll be changing this dir name as soon as practicable (gotta negotiate with the rest of the code to make sure it isn't a depended-upon bug).

Wednesday, July 20, 2011

Comparison of MS Sql Server vs. Sybase

Comparison Of Sybase and MS Sql Server

Just some thoughts here:

1. There are many large players in the financial industry who have significant investments in Sybase. This means there's a ready supply of DBA's who know both the industry and the technology.

2. Sybase has a data warehousing solution called Sybase IQ, which does lots of optimization specific to data warehouses automatically. It is a 'sparse database' model, storing all unique values and then references to those values, much like is done with varchar2 storage. This saves lots of space, and allows for faster queries if the queries are large. Caution, IQ is built for a few large queries; if you throw lots of small ones at it, it will choke / run very slow, so don't do that.

3. Sybase has available drivers in Perl, Python, etc., and runs on many different OS's (Linux especially). Not true for SQL server, which is a Microsoft-OS-ONLY DBMS.

4. Sybase has a reputation for handling very, very large datasets easily. Terabyte-sized tables are normal. MS SQL Server has a reputation for being optimized for small tables, and choking on large ones.

5. MS SQL Server has a very strange idea of backup / admin tools. These did not handle continuous backup (keeping the DB online thru a backup is a normal thing). Note, this might be fixed now. Sybase has always had this feature.