Ejemplo n.º 1
0
def test(numMessages, islandId, domain, cloudDomainFormat, cloudDomainSize, stage1Mta, storageImporter):
    users = ["testuser1", "testuser2", "testuser3", "testuser4"]
    sftpUserMsgs = [4, 3, 3, 3]
    
    userMsgs = [0] * len(users)
    result = False
    mc = ManagementContainer.getInstance()
    cm = mc.getCustomerManager()   
    cust = cloud.setupCustomer(mc, str(islandId), domain, False, True, users)    
    
    try:
        cloud.propagateMtaConfig()
        
        onPremisesGuid = cust.getGuids(CloudService.ONPREMISES)[0].getGuid()
        format = MessageFormat(cloudDomainFormat)
        
        # stage SMTP messages
        for i in range(numMessages):
            replZone = i % (cloudDomainSize + 1)
            if replZone == 0:
                cloudDomain = String(cloudDomainFormat).replaceFirst("(\\{.*\\})", "") # non replicated
            else:
                cloudDomain = format.format(array(Object, [replZone])) # replicated
            
            if (i % 5) == 0:
                cloud.sendJournalMessage(onPremisesGuid, users[0], ["invaliduser"], None, None, domain, cloudDomain, stage1Mta)
                userMsgs[0] += 1
            elif (i % 4) == 0:
                cloud.sendJournalMessage(onPremisesGuid, "invaliduser", [users[1]], None, None, domain, cloudDomain, stage1Mta)
                userMsgs[1] += 1
            elif (i % 3) == 0:
                cloud.sendJournalMessage(onPremisesGuid, "invaliduser", None, [users[2]], None, domain, cloudDomain, stage1Mta)
                userMsgs[2] += 1
            elif (i % 2) == 0:
                cloud.sendJournalMessage(onPremisesGuid, "invaliduser", None, None, [users[3]], domain, cloudDomain, stage1Mta)
                userMsgs[3] += 1
            else :
                cloud.sendJournalMessage(onPremisesGuid, users[0], [users[1]], [users[2]], [users[3]], domain, cloudDomain, stage1Mta)
                for j in range(len(users)):
                    userMsgs[j] += 1
                    
            sleep(1)
        
        # stage SFTP messages
        if os.system("cd /tmp;rm -rf sftp_journal;tar -xf endtoend-sftp-journaled-mail.tar;cd -") != 0:
            print 'failed to overwrite SFTP journal bundle to /tmp/sftp_journal/'                        
        numSftpMsgs = len(os.listdir('/tmp/sftp_journal/')) / 2 
        numMessages += 4
        print "uploading " + str(numSftpMsgs) + " SFTP messages to " + storageImporter
        
        print 'uploading 1 - 4 new messages...'
        if os.system("sed -i 's/${guid}/" + onPremisesGuid + "/g' /tmp/sftp_journal/*.journal.m1.index.done.ftp") != 0:
            print 'failed to replace the GUID variable' 
        if os.system("lftp -u root,!mailst0rm -e 'mput -O /ems/bigdisk/sftp.drop/" + str(cust.getCustID()) + " /tmp/sftp_journal/2000[1-4].journal.m1.gzip.enc.done.ftp; quit' sftp://" + storageImporter) != 0:
            print 'failed to upload the journal content files'  
        if os.system("lftp -u root,!mailst0rm -e 'mput -O /ems/bigdisk/sftp.drop/" + str(cust.getCustID()) + " /tmp/sftp_journal/2000[1-4].journal.m1.index.done.ftp; quit' sftp://" + storageImporter) != 0:
            print 'failed to upload the journal index files, is the storage importer running?'
        
        # Do not shorten this because the test will intermittently fail. These messages are expected to match
        # previously imported messages (see above) so the sleep must be long enough to allow the original copy of
        # of the message to be imported first.
        sleep(60)
        
        print 'uploading 5 - ' + str(numSftpMsgs) + ' message updates...'
        if os.system("lftp -u root,!mailst0rm -e 'mput -O /ems/bigdisk/sftp.drop/" + str(cust.getCustID()) + " /tmp/sftp_journal/2000[5-6].journal.m1.gzip.enc.done.ftp; quit' sftp://" + storageImporter) != 0:
            print 'failed to upload the journal content files'  
        if os.system("lftp -u root,!mailst0rm -e 'mput -O /ems/bigdisk/sftp.drop/" + str(cust.getCustID()) + " /tmp/sftp_journal/2000[5-6].journal.m1.index.done.ftp; quit' sftp://" + storageImporter) != 0:
            print 'failed to upload the journal index files, is the storage importer running?'
            
        # add static SFTP message counts
        for j in range(len(userMsgs)):
            userMsgs[j] += sftpUserMsgs[j]
        
        # wait for cloud messages to import
        msgs = cloud.findMessages(mc, cust.getCustID(), numMessages)
        if msgs.size() < numMessages:
            print 'Did not find all on-premises messages in mailstore, only found', msgs.size()
        else:
            result = True         
    
        # verify individual users were categorized correctly as sender/recipients
        if result is True:
            print 'verifying categorized recipients...'
            for i in range(len(users)):
                userAddress = users[i] + '@' + domain
                userCount = 0;
                for msg in msgs:
                    json = msg.getCategorizedRecipients()
                    if json is None:
                        print 'categorized recipients not set for: ' + msg.toString()
                        result = False
                    
                    # count recipient fields
                    for key in json.keys():
                        recipients = json.optJSONArray(key);
                        for j in range(recipients.length()):
                            if userAddress == recipients.getString(j):
                                userCount += 1
                    
                    # count sender field
                    if userAddress == msg.getSender():
                        userCount += 1    
                
                if userMsgs[i] != userCount or result is False:
                    print 'categorized recipients count for ' + userAddress + ' was ' + str(userCount) + ', but expected ' + str(userMsgs[i]) 
                    result = False
                    break
            
        # verify archive search
        if result is True and not cloud.checkCustomerSearchStatus(mc, msgs, cust.getCustID()):
            print 'Did not find all on-premises messages in index'
            result = False 
    
        # verify individual users were resolved correctly
        if result is True:
            for i in range(len(users)):
                userAccount = mc.getUserManager().findUserForEmail(users[i] + '@' + domain)
                print 'searching for ' + str(userMsgs[i]) + ' indexed messages resolved to: ' + users[i] + '@' + domain + ', ' + str(userAccount.getUserID())
                if not cloud.checkUserSearchStatus(mc, userMsgs[i], cust.getCustID(), userAccount.getUserID()):
                    print 'Did not find messages in index for user: '******'@' + domain + ', ' + str(userAccount.getUserID())
                    result = False         
        
        if result is True:
            print 'on-premises message import successful'
        else:
            print 'on-premises message import failed'
    finally:
        print "Deleting customer " + str(cust.getCustID()) + "..."
        cm.deleteCustomers([cust.getCustID()])
    
    if result is True:
        sys.exit(0)
    else:
        sys.exit(1)    
Ejemplo n.º 2
0
def test(numMessages, islandId, domain, cloudDomain, stage1Mta):
    users = ["testuser1", "testuser2", "testuser3", "testuser4"]
    userMsgs = [0] * len(users)
    result = False
    mc = ManagementContainer.getInstance()
    cm = mc.getCustomerManager()    
    cust = cloud.setupCustomer(mc, str(islandId), domain, True, False, users)
    
    try:
        cloud.propagateMtaConfig()
        
        office365Guid = cust.getGuids(CloudService.OFFICE365)[0].getGuid()
        
        # stage cloud messages
        for i in range(numMessages):
            if (i % 5) == 0:
                cloud.sendJournalMessage(office365Guid, users[0], ["invaliduser"], None, None, domain, cloudDomain, stage1Mta)
                userMsgs[0] += 1
            elif (i % 4) == 0:
                cloud.sendJournalMessage(office365Guid, "invaliduser", [users[1]], None, None, domain, cloudDomain, stage1Mta)
                userMsgs[1] += 1
            elif (i % 3) == 0:
                cloud.sendJournalMessage(office365Guid, "invaliduser", None, [users[2]], None, domain, cloudDomain, stage1Mta)
                userMsgs[2] += 1
            elif (i % 2) == 0:
                cloud.sendJournalMessage(office365Guid, "invaliduser", None, None, [users[3]], domain, cloudDomain, stage1Mta)
                userMsgs[3] += 1
            else :
                cloud.sendJournalMessage(office365Guid, users[0], [users[1]], [users[2]], [users[3]], domain, cloudDomain, stage1Mta)
                for j in range(len(users)):
                    userMsgs[j] += 1
                
            sleep(1)
                
        # wait for cloud messages to import
        msgs = cloud.findMessages(mc, cust.getCustID(), numMessages)
        if msgs.size() < numMessages:
            print 'Did not find all cloud messages in mailstore, only found', msgs.size()
        else:
            result = True         
    
        # verify problematic character sets, e.g. windows-1252
        if result is True:
            pm = mc.getPartitionManager()

            for msg in msgs:
                proxy = pm.getContentProxy(msg.getPartitionId())
                reader = proxy.parseMessage(msg.getCustomerId(), -1, msg.getMessageId(), -1)
                json = JSONObject(JSONTokener(reader))
                body = json.getString("data")
                encoding = None
                headers = json.getJSONArray("headers")
                for i in range(headers.length()):
                    encoding = headers.getJSONObject(i).optString('Content-Type', encoding)

                if encoding == None:
                    print 'missing Content-Type header for message ' + str(msg.getMessageId())
                    result = False
                    break
                elif encoding.endswith('windows-1252'):
                    print 'verifying windows-1252 encoding for message ' + str(msg.getMessageId())
                    if body != String('bullet \x95, euro sign \x80, latin F \x83, tilde \x98', 'windows-1252').toString():
                        print 'windows-1252 body content is incorrect for message ' + str(msg.getMessageId()) + ': ' + body
                        result = False
                        break
                elif encoding.endswith('utf-8'):
                    print 'verifying utf-8 encoding for message ' + str(msg.getMessageId())
                    if body != 'bullet \xe2\x80\xa2, euro sign \xe2\x82\xac, latin F \xc6\x92, tilde \x7e':
                        print 'utf-8 body content is incorrect for message ' + str(msg.getMessageId()) + ': ' + body
                        result = False
                        break
                else:
                    print 'verifying ascii encoding for message ' + str(msg.getMessageId())
                    if body != 'plain ascii text...':
                        print 'ascii body content is incorrect for message ' + str(msg.getMessageId()) + ': ' + body
                        result = False
                        break
    
        # verify individual users were categorized correctly as sender/recipients
        if result is True:
            print 'verifying categorized recipients...'
            for i in range(len(users)):
                userAddress = users[i] + '@' + domain
                userCount = 0;
                for msg in msgs:
                    json = msg.getCategorizedRecipients()
                    if json is None:
                        print 'categorized recipients not set for: ' + msg.toString()
                        result = False
                    
                    # count recipient fields
                    for key in json.keys():
                        recipients = json.optJSONArray(key);
                        for j in range(recipients.length()):
                            if userAddress == recipients.getString(j):
                                userCount += 1
                    
                    # count sender field
                    if userAddress == msg.getSender():
                        userCount += 1    
                
                if userMsgs[i] != userCount or result is False:
                    print 'categorized recipients count for ' + userAddress + ' was ' + str(userCount) + ', but expected ' + str(userMsgs[i]) 
                    result = False
                    break
    
        # verify archive search
        if result is True and not cloud.checkCustomerSearchStatus(mc, msgs, cust.getCustID()):
            print 'Did not find all cloud messages in index'
            result = False 
    
        # verify individual users were resolved correctly
        if result is True:
            for i in range(len(users)):
                userAccount = mc.getUserManager().findUserForEmail(users[i] + '@' + domain)
                print 'searching for ' + str(userMsgs[i]) + ' indexed messages resolved to: ' + users[i] + '@' + domain + ', ' + str(userAccount.getUserID())
                if not cloud.checkUserSearchStatus(mc, userMsgs[i], cust.getCustID(), userAccount.getUserID()):
                    print 'Did not find messages in index for user: '******'@' + domain + ', ' + str(userAccount.getUserID())
                    result = False     
    
        if result is True:
            print 'cloud message import successful'
        else:
            print 'cloud message import failed'
    finally:
        print "Deleting customer " + str(cust.getCustID()) + "..."
        cm.deleteCustomers([cust.getCustID()])
    
    if result is True:
        sys.exit(0)
    else:
        sys.exit(1)