def addToCustomer(mc,island,custId,corpus='/tmp/corpus'): print 'addToCustomer()' amptool = ActiveMailboxPartitionTool() emscmdtool = EmsCommandLineTool() print 'executing amp cluster-location' amptool.runCommand('cluster-location',array(['-r'],String)) args = [] args.append("-f" ) args.append( str(island)) args.append("-s" ) args.append( str(island)) args.append( "-i" ) args.append( corpus) args.append( "-o" ) args.append( "/tmp") args.append( "-r" ) args.append( "equal-to-sent") args.append( "-c") args.append(str(custId)) args.append( "-q") argsArr = array(args,String) print 'executing make-test-customer' result = emscmdtool.runCommand('make-test-customer',argsArr) if result is False: raise Exception('make-test-customer failed, customer already exists?') ManagementContainer.getInstance().getMailRoutingConfigGenerator().waitForRegenComplete() # ensure policy_exploded_users updates with user account info rpm = mc.getRetentionPolicyManager() rpm.notifyOfExternalPolicyChanges(int(custId)) # move the contents of staging to sftp.drop src = os.path.join('/tmp',str(custId)) dst = os.path.join('/ems/bigdisk/sftp.drop',str(custId)) if not os.path.exists(dst): os.mkdir(dst) for f in os.listdir(src): if f.endswith('.gzip.enc.done.ftp'): shutil.copy(os.path.join(src,f),dst) os.remove(os.path.join(src,f)) idxF = f.replace('.gzip.enc.done.ftp','.index.done.ftp') shutil.copy(os.path.join(src,idxF),dst) os.remove(os.path.join(src,idxF)) shutil.rmtree(src) return
def setupCustomer(mc,island,domain,isCloud,isOnPremises,userAccounts,loadCorpus=False): deleteCustomer(mc) amptool = ActiveMailboxPartitionTool() emscmdtool = EmsCommandLineTool() print 'creating customer...' cm = mc.getCustomerManager() print 'executing amp cluster-location' amptool.runCommand('cluster-location',array(['-r'],String)) args = [] args.append("-f" ) args.append( str(island)) args.append("-s" ) args.append( str(island)) args.append("-d" ) args.append( domain) args.append( "-n" ) args.append("systest_journaling_customer" ) args.append("-e" ) args.append( "nobody@" + domain) args.append("-q") if loadCorpus: args.append( "-i" ) args.append( "/tmp/corpus") args.append( "-o" ) args.append( "/ems/bigdisk/sftp.drop") if isCloud: args.append("--guid") if isOnPremises: args.append( "--bcc" ) if userAccounts is not None: for address in userAccounts: args.append("--user-account" ) args.append( address + "@" + domain ) print "creating journal-enabled customer " Logger.getLogger( "cloud.py" ).info( "Creating systest_journaling_customer..." ) result = emscmdtool.runCommand('make-test-customer',args) if result is False: raise Exception('make-test-customer failed, customer already exists?') ManagementContainer.getInstance().getMailRoutingConfigGenerator().waitForRegenComplete() cust = cm.findCustomers([SearchConstraint(ICustomerManager.PROP_NAME, SearchConstraintOperator.CONSTRAINT_EQUALS, 'systest_journaling_customer')]) return cust[0]
def expireWinAuthPassword(email): emscmdtool = EmsCommandLineTool() mc = ManagementContainer.getInstance() connection = mc.getDBConnection(ManagementContainer.POOL_NAME) s = connection.createStatement() command = "update dat_user_account set password_expire_time=creation_date where primary_email = \'" + email + "\'" print "EXEC: " + command s.executeUpdate(command) connection.commit() emscmdtool.runCommand('clean-expired-passwords',array([''],String)) command = "select hashed_password,hashed_imap_password from dat_user_account where primary_email = \'" + email + "\'" print "EXEC: " + command resultSet = s.executeQuery(command) resultSet.next() hashedPassword = resultSet.getString(1) hashedImapPassword = resultSet.getString(2) mc.safeReturnDBConnection(connection, ManagementContainer.POOL_NAME) DbUtils.safeClose(s) if not hashedPassword is None or not hashedImapPassword is None: print "Hashed password=\"", hashedPassword, "\" Hashed Imap Password=\"", hashedImapPassword, "\"" sys.exit(1)
def setupCustomer(mc,island,corpus='/tmp/corpus',domain='enron.com',cleanupFirst=True,name='systest_customer',recvDate='equal-to-sent',enableFolderSync=False,runAsync=False,isCloud=False,isOnPremises=False,userAccounts=[],folderid=None, corpusFolders=False, sourceDomain='enron.com',copyMail = False): print 'setupCustomer()' amptool = ActiveMailboxPartitionTool() file = File('/tmp/%s.log') emscmdout = PrintStream(FileOutputStream(file)) emscmdtool = EmsCommandLineTool() emscmdtool.setOutputStream(emscmdout) if cleanupFirst: customerList=[name] domainList=[domain] deleteCustomers( customerList, domainList ) if (sourceDomain is not None) and (domain != sourceDomain): print 'renaming domain in corpus', corpus, 'from', sourceDomain, 'to', domain os.system("find " + corpus +" -type f -print | xargs -n 25 sed -i 's/"+sourceDomain+"/"+domain+"/g'") cm = mc.getCustomerManager() amptool.runCommand('cluster-location',array(['-r'],String)) if runAsync is False: args = [] args.append("-f" ) args.append( str(island)) args.append("-s" ) args.append( str(island)) args.append( "-i" ) args.append( corpus) args.append( "-o" ) args.append( "/ems/bigdisk/sftp.drop") args.append( "-r" ) args.append( recvDate) args.append("-d" ) args.append( domain) args.append( "-n" ) args.append( name) args.append("-e" ) args.append( "nobody@" + domain) args.append("-q") #args.append("-t") #args.append("10") if copyMail: arg.append(" -y") if enableFolderSync: args.append( "-x" ) if isCloud: args.append("--guid") if folderid is not None: args.append("-j") args.append(folderid) elif corpusFolders is True: args.append( "-k" ) if isOnPremises: args.append( "--bcc" ) if userAccounts is not None: for address in userAccounts: args.append("--user-account" ) args.append( address + "@" + domain ) argsArr = array(args,String) print 'executing make-test-customer command' result = emscmdtool.runCommand('make-test-customer',argsArr) if result is False: raise Exception('make-test-customer failed, customer already exists?') ManagementContainer.getInstance().getMailRoutingConfigGenerator().waitForRegenComplete() custIds = cm.findCustomers([SearchConstraint(ICustomerManager.PROP_NAME, SearchConstraintOperator.CONSTRAINT_EQUALS, name)]) custid = custIds[0].getCustID() if runAsync: cmdline = 'ulimit -n 4096 ; /opt/ems/bin/emscmd ' + ' make-test-customer ' + ' -f ' + str(island) + ' -s ' + str(island) cmdline = cmdline + ' -d ' + domain + ' -n ' + ' ' + name + ' ' cmdline = cmdline + ' -e ' + ' nobody@' + domain cmdline = cmdline + " -q" if copyMail: cmdline = cmdline + " -y" if enableFolderSync: cmdline = cmdline + " -x" if isCloud: cmdline = cmdline + ' --guid' if folderid is not None: cmdline = cmdline + " -j '"+folderid+"'" elif corpusFolders is True: cmdline = cmdline + " -k" if isOnPremises: cmdline = cmdline + ' --bcc' if userAccounts is not None: for address in userAccounts: cmdline = cmdline + ' --user-account "' + address + '@' + domain + '"' print 'executing',cmdline rc = os.system('/bin/bash -c ' + cmdline) if rc != 0: raise Exception('make-test-customer failed, customer already exists?') custIds = cm.findCustomers([SearchConstraint(ICustomerManager.PROP_NAME, SearchConstraintOperator.CONSTRAINT_EQUALS, name)]) custid = custIds[0].getCustID() cmdline = 'ulimit -n 4096 ; /opt/ems/bin/emscmd ' + ' make-test-customer ' + ' -f ' + str(island) + ' -s ' + str(island) cmdline = cmdline + ' -i ' + corpus cmdline = cmdline + ' -o ' + ' /ems/bigdisk/sftp.drop ' cmdline = cmdline + ' -c ' + str(custid) cmdline = cmdline + ' -r ' + ' ' + recvDate + ' ' cmdline = cmdline + " -q" if copyMail: cmdline = cmdline + " -y" if enableFolderSync: cmdline = cmdline + " -x" cmdline = cmdline + ' >/tmp/%s.log 2>&1' % name print 'executing',cmdline os.popen(cmdline,'r') return custid