Exemple #1
0
 def doMessage(self, etype):
     host = self.getDefaultHost()
     uuids = host.minimalList("%s-list" % (etype))
     if len(uuids) == 0:
         raise xenrt.XRTError("No entities of type '%s' found" % (etype))
     uuid = uuids[0]
     name = "TC8172_%s_%u" % (etype, xenrt.timenow())
     body = "Test message in TC-8172 for %s [%s]" % (etype, uuid)
     time1 = xenrt.timenow() - 1
     host.messageGeneralCreate(etype, uuid, name, body)
     time2 = xenrt.timenow() + 1
     
     # Check the message
     messages = host.minimalList("message-list", "uuid", "name=%s" % (name))
     if len(messages) == 0:
         raise xenrt.XRTFailure("Could not find message in list")
     if len(messages) > 1:
         raise xenrt.XRTFailure("Found multiple messages in list")
     m = messages[0] 
     h = host.genParamGet("message", m, "class")
     if h.lower() != etype:
         raise xenrt.XRTFailure("Message has incorrect class")
     u = host.genParamGet("message", m, "obj-uuid")
     if u != uuid:
         raise xenrt.XRTFailure("Message has incorrect UUID")
     b = host.genParamGet("message", m, "body")
     if b != body:
         raise xenrt.XRTFailure("Message has incorrect body")
     ts = host.genParamGet("message", m, "timestamp")
     tsint = xenrt.parseXapiTime(ts)
     if tsint < time1 or tsint > time2:
         raise xenrt.XRTFailure("Message timestamp does not match the time "
                                "it was created",
                                "TS %u created in [%u, %u]" %
                                (tsint, time1, time2))
Exemple #2
0
    def doMessage(self, etype):
        host = self.getDefaultHost()
        uuids = host.minimalList("%s-list" % (etype))
        if len(uuids) == 0:
            raise xenrt.XRTError("No entities of type '%s' found" % (etype))
        uuid = uuids[0]
        name = "TC8172_%s_%u" % (etype, xenrt.timenow())
        body = "Test message in TC-8172 for %s [%s]" % (etype, uuid)
        time1 = xenrt.timenow() - 1
        host.messageGeneralCreate(etype, uuid, name, body)
        time2 = xenrt.timenow() + 1

        # Check the message
        messages = host.minimalList("message-list", "uuid", "name=%s" % (name))
        if len(messages) == 0:
            raise xenrt.XRTFailure("Could not find message in list")
        if len(messages) > 1:
            raise xenrt.XRTFailure("Found multiple messages in list")
        m = messages[0]
        h = host.genParamGet("message", m, "class")
        if h.lower() != etype:
            raise xenrt.XRTFailure("Message has incorrect class")
        u = host.genParamGet("message", m, "obj-uuid")
        if u != uuid:
            raise xenrt.XRTFailure("Message has incorrect UUID")
        b = host.genParamGet("message", m, "body")
        if b != body:
            raise xenrt.XRTFailure("Message has incorrect body")
        ts = host.genParamGet("message", m, "timestamp")
        tsint = xenrt.parseXapiTime(ts)
        if tsint < time1 or tsint > time2:
            raise xenrt.XRTFailure(
                "Message timestamp does not match the time "
                "it was created",
                "TS %u created in [%u, %u]" % (tsint, time1, time2))
Exemple #3
0
    def checkEvent(self, name, time1, time2):

        # Check the message
        messages = self.host.minimalList(
            "message-list", "uuid",
            "name=%s class=VM obj-uuid=%s" % (name, self.guest.getUUID()))
        if len(messages) == 0:
            raise xenrt.XRTFailure("Could not find message in list")
        for m in messages:
            ts = self.host.genParamGet("message", m, "timestamp")
            tsint = xenrt.parseXapiTime(ts)
            if tsint >= time1 and tsint <= time2:
                # This is our message
                return
        raise xenrt.XRTFailure("Could not find a message within the time "
                               "window for this operation")
Exemple #4
0
    def checkEvent(self, name, time1, time2):

        # Check the message
        messages = self.host.minimalList("message-list",
                                         "uuid",
                                         "name=%s class=VM obj-uuid=%s" %
                                         (name, self.guest.getUUID()))
        if len(messages) == 0:
            raise xenrt.XRTFailure("Could not find message in list")
        for m in messages:
            ts = self.host.genParamGet("message", m, "timestamp")
            tsint = xenrt.parseXapiTime(ts)
            if tsint >= time1 and tsint <= time2:
                # This is our message
                return
        raise xenrt.XRTFailure("Could not find a message within the time "
                               "window for this operation")
Exemple #5
0
    def check(self, host, mail, msgName):
        # Get the actual message details
        matchingMessages = host.minimalList("message-list", "uuid", 
                                            "name=%s" % (msgName))
        if len(matchingMessages) != 1:
            raise xenrt.XRTError("Found %u messages, expecting 1" % 
                                 (len(matchingMessages)))
        msgDetails = {}
        msgDetails['uuid'] = matchingMessages[0]
        msgDetails['name'] = msgName
        ts = host.genParamGet("message", msgDetails['uuid'], "timestamp")
        msgDetails['ts'] = ts
        msgDetails['time'] = xenrt.parseXapiTime(ts)
        msgDetails['priority'] = host.genParamGet("message", 
                                                  msgDetails['uuid'],
                                                  "priority")
        msgDetails['body'] = host.genParamGet("message", msgDetails['uuid'],
                                              "body")

        # Verify the sender + receiver are correct
        expectedSenders = ["mail-alarm@%s" % (host.getName()), 
                           "noreply@%s" % (host.getName())]
        found = False
        for s in expectedSenders:
            if mail['sender'].startswith(s):
                found = True
                break
        if not found:
            raise xenrt.XRTFailure("SMTP sender incorrect, %s vs %s" %
                                   (mail['sender'], expectedSenders))
        if mail['recipient'] != "*****@*****.**":
            raise xenrt.XRTFailure("SMTP recipient incorrect, %s vs "
                                   "*****@*****.**" % (mail['recipient']))

        # Log the actual message for debugging
        xenrt.TEC().logverbose("Message received:\n%s" % (mail['data']))

        # Parse the email
        inHeaders = True
        headers = {}
        bodyLines = []
        for line in mail['data'].split("\r\n"):
            l = line.strip()
            if inHeaders:
                if l == "":
                    inHeaders = False
                elif ":" in l:
                    h = l.split(":", 1)
                    headers[h[0].strip()] = h[1].strip()
            else:
                bodyLines.append(l)

        # Check the headers we care about
        expectedHeaders = ["Date", "From", "Subject", "To"]
        for e in expectedHeaders:
            if not e in headers:
                raise xenrt.XRTFailure("Didn't find expected header %s in "
                                       "email message" % (e))

        # Date
        # Convert it to a time object, so we can compare it to the message time,
        # it should be >= it up to a max of 5 seconds out.
        t = time.strptime(headers['Date'], "%a, %d %b %Y %H:%M:%S +0000")
        difference = int(calendar.timegm(t) - msgDetails['time'])
        if difference < 0 or difference > 5:
            raise xenrt.XRTFailure("Unexpected date (< 0 or > 5 seconds out "
                                   "as compared to message timestamp) %s (%u "
                                   "difference)" % (headers['Date'],difference))
        # From
        found = False
        for s in expectedSenders:
            if headers['From'].startswith(s):
                found = True
                break                
        if not found:
            raise xenrt.XRTFailure("From header incorrect, %s vs %s" %
                                   (headers['From'], expectedSenders))
        # Subject
        expectedSubjects = ["[%s] XenServer Message: Host %s %s" % \
                            (host.getMyHostName(), host.getMyHostUUID(),
                            msgDetails['name']),
                            "XenServer Message: Host %s %s" % \
                            (host.getMyHostUUID(), msgDetails['name'])]

        if not headers['Subject'] in expectedSubjects:
            raise xenrt.XRTFailure("Subject incorrect, %s vs %s" %
                                   (headers['Subject'], expectedSubjects))
        # To
        if headers['To'] != "*****@*****.**":
            raise xenrt.XRTFailure("To header incorrect, %s vs %s" %
                                   (headers['To'], "*****@*****.**"))

        # Parse the body
        bodyFields = {}
        for l in bodyLines:
            if ":" in l:
                h = l.split(":", 1)
                bodyFields[h[0].strip()] = h[1].strip()

        expectedFields = ["Name", "Priority", "Class", "Object UUID", 
                          "Timestamp", "Message UUID", "Body"]
        for e in expectedFields:
            if not e in bodyFields:
                raise xenrt.XRTFailure("Didn't find expected field %s in "
                                       "email body" % (e))

        if bodyFields['Name'] != msgDetails['name']:
            raise xenrt.XRTFailure("Name in email body incorrect %s vs %s" %
                                   (bodyFields['Name'], msgDetails['name']))
        if bodyFields['Priority'] != msgDetails['priority']:
            raise xenrt.XRTFailure("Priority in email body incorrect %s vs %s" %
                                   (bodyFields['Priority'], 
                                    msgDetails['priority']))
        if bodyFields['Class'] != "Host":
            raise xenrt.XRTFailure("Class in email body incorrect %s vs Host" %
                                   (bodyFields['Class']))
        if bodyFields['Object UUID'] != host.getMyHostUUID():
            raise xenrt.XRTFailure("Obj UUID in email body incorrect %s vs %s" %
                                   (bodyFields['Object UUID'], 
                                    host.getMyHostUUID()))
        if bodyFields['Timestamp'] != msgDetails['ts']:
            raise xenrt.XRTFailure("Timestamp in email body incorrect %s vs %s" %
                                   (bodyFields['Timestamp'], msgDetails['ts']))
        if bodyFields['Message UUID'] != msgDetails['uuid']:
            raise xenrt.XRTFailure("Msg UUID in email body incorrect %s vs %s" %
                                   (bodyFields['Message UUID'],
                                    msgDetails['uuid']))
        if bodyFields['Body'] != msgDetails['body'].strip():
            raise xenrt.XRTFailure("Msg body in email body incorrect %s vs %s" %
                                   (bodyFields['Body'], 
                                    msgDetails['body'].strip()))
Exemple #6
0
    def check(self, host, mail, msgName):
        # Get the actual message details
        matchingMessages = host.minimalList("message-list", "uuid",
                                            "name=%s" % (msgName))
        if len(matchingMessages) != 1:
            raise xenrt.XRTError("Found %u messages, expecting 1" %
                                 (len(matchingMessages)))
        msgDetails = {}
        msgDetails['uuid'] = matchingMessages[0]
        msgDetails['name'] = msgName
        ts = host.genParamGet("message", msgDetails['uuid'], "timestamp")
        msgDetails['ts'] = ts
        msgDetails['time'] = xenrt.parseXapiTime(ts)
        msgDetails['priority'] = host.genParamGet("message",
                                                  msgDetails['uuid'],
                                                  "priority")
        msgDetails['body'] = host.genParamGet("message", msgDetails['uuid'],
                                              "body")

        # Verify the sender + receiver are correct
        expectedSenders = [
            "mail-alarm@%s" % (host.getName()),
            "noreply@%s" % (host.getName())
        ]
        found = False
        for s in expectedSenders:
            if mail['sender'].startswith(s):
                found = True
                break
        if not found:
            raise xenrt.XRTFailure("SMTP sender incorrect, %s vs %s" %
                                   (mail['sender'], expectedSenders))
        if mail['recipient'] != "*****@*****.**":
            raise xenrt.XRTFailure("SMTP recipient incorrect, %s vs "
                                   "*****@*****.**" % (mail['recipient']))

        # Log the actual message for debugging
        xenrt.TEC().logverbose("Message received:\n%s" % (mail['data']))

        # Parse the email
        inHeaders = True
        headers = {}
        bodyLines = []
        for line in mail['data'].split("\r\n"):
            l = line.strip()
            if inHeaders:
                if l == "":
                    inHeaders = False
                elif ":" in l:
                    h = l.split(":", 1)
                    headers[h[0].strip()] = h[1].strip()
            else:
                bodyLines.append(l)

        # Check the headers we care about
        expectedHeaders = ["Date", "From", "Subject", "To"]
        for e in expectedHeaders:
            if not e in headers:
                raise xenrt.XRTFailure("Didn't find expected header %s in "
                                       "email message" % (e))

        # Date
        # Convert it to a time object, so we can compare it to the message time,
        # it should be >= it up to a max of 5 seconds out.
        t = time.strptime(headers['Date'], "%a, %d %b %Y %H:%M:%S +0000")
        difference = int(calendar.timegm(t) - msgDetails['time'])
        if difference < 0 or difference > 5:
            raise xenrt.XRTFailure("Unexpected date (< 0 or > 5 seconds out "
                                   "as compared to message timestamp) %s (%u "
                                   "difference)" %
                                   (headers['Date'], difference))
        # From
        found = False
        for s in expectedSenders:
            if headers['From'].startswith(s):
                found = True
                break
        if not found:
            raise xenrt.XRTFailure("From header incorrect, %s vs %s" %
                                   (headers['From'], expectedSenders))
        # Subject
        expectedSubjects = ["[%s] XenServer Message: Host %s %s" % \
                            (host.getMyHostName(), host.getMyHostUUID(),
                            msgDetails['name']),
                            "XenServer Message: Host %s %s" % \
                            (host.getMyHostUUID(), msgDetails['name'])]

        if not headers['Subject'] in expectedSubjects:
            raise xenrt.XRTFailure("Subject incorrect, %s vs %s" %
                                   (headers['Subject'], expectedSubjects))
        # To
        if headers['To'] != "*****@*****.**":
            raise xenrt.XRTFailure("To header incorrect, %s vs %s" %
                                   (headers['To'], "*****@*****.**"))

        # Parse the body
        bodyFields = {}
        for l in bodyLines:
            if ":" in l:
                h = l.split(":", 1)
                bodyFields[h[0].strip()] = h[1].strip()

        expectedFields = [
            "Name", "Priority", "Class", "Object UUID", "Timestamp",
            "Message UUID", "Body"
        ]
        for e in expectedFields:
            if not e in bodyFields:
                raise xenrt.XRTFailure("Didn't find expected field %s in "
                                       "email body" % (e))

        if bodyFields['Name'] != msgDetails['name']:
            raise xenrt.XRTFailure("Name in email body incorrect %s vs %s" %
                                   (bodyFields['Name'], msgDetails['name']))
        if bodyFields['Priority'] != msgDetails['priority']:
            raise xenrt.XRTFailure(
                "Priority in email body incorrect %s vs %s" %
                (bodyFields['Priority'], msgDetails['priority']))
        if bodyFields['Class'] != "Host":
            raise xenrt.XRTFailure("Class in email body incorrect %s vs Host" %
                                   (bodyFields['Class']))
        if bodyFields['Object UUID'] != host.getMyHostUUID():
            raise xenrt.XRTFailure(
                "Obj UUID in email body incorrect %s vs %s" %
                (bodyFields['Object UUID'], host.getMyHostUUID()))
        if bodyFields['Timestamp'] != msgDetails['ts']:
            raise xenrt.XRTFailure(
                "Timestamp in email body incorrect %s vs %s" %
                (bodyFields['Timestamp'], msgDetails['ts']))
        if bodyFields['Message UUID'] != msgDetails['uuid']:
            raise xenrt.XRTFailure(
                "Msg UUID in email body incorrect %s vs %s" %
                (bodyFields['Message UUID'], msgDetails['uuid']))
        if bodyFields['Body'] != msgDetails['body'].strip():
            raise xenrt.XRTFailure(
                "Msg body in email body incorrect %s vs %s" %
                (bodyFields['Body'], msgDetails['body'].strip()))