thomas: utils/testing create-annotated-destroy.py,NONE,1.1

cvs at intevation.de cvs at intevation.de
Wed Feb 22 12:02:22 CET 2006


Author: thomas

Update of /kolabrepository/utils/testing
In directory doto:/tmp/cvs-serv13576

Added Files:
	create-annotated-destroy.py 
Log Message:
Added create-annotated-destroy.py (stress test for IMAP annotations.de)


--- NEW FILE: create-annotated-destroy.py ---
# -------------------------------------------------------------------
# Copyright (C) 2006 by Intevation GmbH
# Author(s):
# Sascha Wilde <wilde at intevation.de>

# This program is free software under the GNU GPL (>=v2)
# Read the file COPYING coming with the software for details.
# -------------------------------------------------------------------
# Try to make some imap traffic which forces annotations.db to break.

# Usage: create-annotated-destroy.py USER MAILLEN
#
#   Traffic is generated as USER (with passwd USER)
#   Mails are generated with a maximum length of MAILLEN KiB

# imaplib version needs to be at least 2.58, get it from:
# http://svn.python.org/projects/python/trunk/Lib/imaplib.py
import imaplib
import sys
from random import *

import time

seed()

# XXX set imap host and mail domain:
domain = "example.com"
host = "kolab.%s" % domain

def mailgen(len):
    n = randint(1,1000000)
    mail = "From: Badboy at test.invalid\nTo: %s@%s\nSubject: BAD!\n\n" % (user,
                                                                        domain)
    for i in range(len):
        n = n ^ (n << 1) ^ i
        if i % 79 == 0:
            mail = mail + "\n"
        else:
            mail = mail + chr(long(n) % 74 + 48)
    return mail


# imaplib.Debug=1

m=imaplib.IMAP4(host)

if len(sys.argv) >= 2:
    user = sys.argv[1]
else:
    user = "test1"

if len(sys.argv) >= 3:
    maillen = int(sys.argv[2]) * 1024
else:
    maillen = 102400

m.login("%s@%s" % (user, domain), user)

# Ok, now lets boogie...

print "Writing one big mail..."
m.append("INBOX", None, None, mailgen(200000))

while True:
    n = randint(1,260)

    print "Creating and annotating %i Mailboxes..." % n

    for i in range(n):
        box = "INBOX/badbox%i" % i
        print i,
        m.create(box)
        print ".",
        m.setannotation(box,"/vendor/kolab/death",
                        '("value.shared" "die server die")')
        print ".",
        m.setannotation(box,"/vendor/kolab/murder",
                        '("value.shared" "Die die die!!!")')
        print ".",
        m.setannotation(box,"/vendor/kolab/kill",
                        '("value.shared" "Annotations must die!")')

    if randint(0,2) == 0:
        print "...writing Mail (%i bytes)..." % maillen,

        mail = mailgen(maillen)

        for i in range(n):
            print ".",
            m.append("INBOX/badbox%i" % (n-1), None, None, mail)

        print "done!"
        time.sleep(1)
        print "Reading mail..."
        m.select("INBOX")
        m.check()
        m.fetch("1", "(UID BODY[TEXT])")
        m.select("INBOX/badbox%i" % (n-1))
        m.check()
        m.fetch("1:*", "(UID BODY[TEXT])")
        print "starting a search..."
        m.uid("SEARCH",None,'(FROM "Toltec Synchronization")')

    print
    print "Reading annotations..."
    for i in range(n):
        box = "INBOX/badbox%i" % i
        print i,
        m.getannotation(box,"/vendor/kolab/*",'"value.shared"')

    print
    print "Deleting mailboxes again ..."
    for i in range(n):
        box = "INBOX/badbox%i" % i
        print i,
        m.delete(box)
        
    print
    print "------------------------------------------------------------"

    if randint(0,5) == 4:
        m.shutdown()
        print "Time for a fresh connection!"
        time.sleep(2)
        m=imaplib.IMAP4(host)
        m.login("%s@%s" % (user, domain), user)








More information about the commits mailing list