示例#1
0
    def __init__(self, mmsGroupName, tag=None, *args, **kwargs):
        self.mmsGroupName = mmsGroupName
        self.tag = tag
        self.mongo = kwargs['mongo']

        # Individual ping documents
        self.pings = {}
        # If tag not specified get the most recent tag of the group
        if self.tag is None:
            try:
                match = {'name': mmsGroupName}
                proj = {'_id': 0, 'tag': 1}
                curr_pings = self.mongo.euphonia.pings.find(match, proj).\
                    sort("tag", -1).limit(1)
            except pymongo.errors.PyMongoError as e:
                raise e

            if curr_pings.count() > 0:
                self.tag = curr_pings[0]['tag']

        if self.tag is not None:
            try:
                # Get all pings with this tag
                match = {'tag': self.tag, 'hostInfo.deactivated': False}
                curr_pings = self.mongo.euphonia.pings.find(match)
            except pymongo.errors.PyMongoError as e:
                raise e

            for p in curr_pings:
                self.pings[p['_id']] = ping.Ping(p)

        # Get Salesforce project id
        res = mmsGroupNameToSFProjectId(mmsGroupName, self.mongo)
        if not res['ok']:
            raise Exception("Failed to determine Salesforce project id for MMS"
                            "group %s" % mmsGroupName)
        gid = res['payload']

        from groupping_tests import GroupPingTests
        grouptestdocument.GroupTestDocument.__init__(
            self,
            groupId=gid,
            mongo=self.mongo,
            src='pings',
            testsLibrary=GroupPingTests)
示例#2
0
    def __init__(self, mmsGroupName, tag=None, *args, **kwargs):
        self.mmsGroupName = mmsGroupName
        self.tag = tag
        self.mongo = kwargs['mongo']

        # Individual ping documents
        self.pings = {}
        # If tag not specified get the most recent tag of the group
        if self.tag is None:
            try:
                match = {'name': mmsGroupName}
                proj = {'_id': 0, 'tag': 1}
                curr_pings = self.mongo.euphonia.pings.find(match, proj).\
                    sort("tag", -1).limit(1)
            except pymongo.errors.PyMongoError as e:
                raise e

            if curr_pings.count() > 0:
                self.tag = curr_pings[0]['tag']

        if self.tag is not None:
            try:
                # Get all pings with this tag
                match = {'tag': self.tag, 'hostInfo.deactivated': False}
                curr_pings = self.mongo.euphonia.pings.find(match)
            except pymongo.errors.PyMongoError as e:
                raise e

            for p in curr_pings:
                self.pings[p['_id']] = ping.Ping(p)

        # Get Salesforce project id
        res = mmsGroupNameToSFProjectId(mmsGroupName, self.mongo)
        if not res['ok']:
            raise Exception("Failed to determine Salesforce project id for MMS"
                            "group %s" % mmsGroupName)
        gid = res['payload']

        from groupping_tests import GroupPingTests
        grouptestdocument.GroupTestDocument.__init__(
            self, groupId=gid,
            mongo=self.mongo,
            src='pings',
            testsLibrary=GroupPingTests)
mongo = pymongo.MongoClient()

# Convert groups documents to the new schema. They will be placed in a new
# collection which will need to be renamed manually. groups for which we were
# not able to identify a Salesforce project id will be moved to lostgroups
coll_groups = mongo.euphonia.groups
coll_newgroups = mongo.euphonia.newgroups
coll_lostgroups = mongo.euphonia.lostgroups
try:
    curr = coll_groups.find()
except pymongo.errors.PyMongoError as e:
    raise e
for doc in curr:
    mmsGroupName = doc.get("name")
    res = mmsGroupNameToSFProjectId(mmsGroupName, mongo)
    if not res["ok"]:
        logger.warning(res["payload"])
        coll_lostgroups.insert(doc)
    else:
        logger.info("%s -> %s", mmsGroupName, res["payload"])
        newdoc = {"_id": res["payload"]}

        res = sfProjectIdToSFProjectName(res["payload"], mongo)
        if not res["ok"]:
            logger.warning(res["payload"])
            continue
        newdoc["name"] = res["payload"]

        if "failedTests" in doc:
            newdoc["failedtests"] = copy.deepcopy(doc["failedTests"])