def loadServices(self): if self.DCHOSTS is None: return for host in self.DCHOSTS: url = 'http://%s:9022/sv/*/status' % host fd = None try: try: fd = urllib.urlopen(url) data = '' for d in fd.readlines(): data = data + str(d.strip()) self.SVCBYHOST[host] = [] jo = JSONObject(data) for key in jo.keys(): so = jo.get(key) service = so.get('service') self.SVCBYHOST[host].append(service) if not self.HOSTBYSVC.has_key(service): self.HOSTBYSVC[service] = [] self.HOSTBYSVC[service].append(host) except: # ignore hosts that do not respond pass finally: if fd is not None: fd.close()
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)