Exemplo n.º 1
0
Arquivo: sm.py Projeto: mgius/pyz3r
    async def _init(self):
        self.site = http.site(
            site_baseurl=self.baseurl,
            username=self.username,
            password=self.password,
        )

        if self.settings:
            endpoint = f'/api/randomizers/{self.randomizer}/generate'
            self.data = await self.site.generate_game(endpoint, self.settings)
            self.guid = uuid.UUID(hex=self.data['guid'])
            self.slug_id = slugid.encode(self.guid)
        elif self.slug_id:
            self.guid = slugid.decode(self.slug_id)
            self.data = await http.request_generic(
                url=f'{self.baseurl}/api/seed/{self.guid.hex}',
                method='get',
                returntype='json')
        elif self.guid_id:
            self.guid = uuid.UUID(hex=self.guid_id)
            self.slug_id = slugid.encode(self.guid)
            self.data = await http.request_generic(
                url=f'{self.baseurl}/api/seed/{self.guid.hex}',
                method='get',
                returntype='json')
        else:
            self.data = None
            self.slug_id = None
            self.guid = None
Exemplo n.º 2
0
def testSlugDecodeEncode():
    """ Test that 10000 v4 slugs are unchanged after decoding and then encoding them."""

    for i in range(0, 10000):
        slug1 = slugid.v4()
        uuid_ = slugid.decode(slug1)
        slug2 = slugid.encode(uuid_)

        assert slug1 == slug2, "Decode and encode isn't identity"
Exemplo n.º 3
0
def testSlugDecodeEncode():
    """ Test that 10000 v4 slugs are unchanged after decoding and then encoding them."""

    for i in range(0, 10000):
        slug1 = slugid.v4()
        uuid_ = slugid.decode(slug1)
        slug2 = slugid.encode(uuid_)

        assert slug1 == slug2, "Decode and encode isn't identity"
Exemplo n.º 4
0
def testUuidEncodeDecode():
    """ Test that 10000 v4 uuids are unchanged after encoding and then decoding them"""

    for i in range(0, 10000):
        uuid1 = uuid.uuid4()
        slug = slugid.encode(uuid1)
        uuid2 = slugid.decode(slug)

        assert uuid1 == uuid2, "Encode and decode isn't identity: '" + str(uuid1) + "' != '" + str(uuid2) + "'"
Exemplo n.º 5
0
def testUuidEncodeDecode():
    """ Test that 10000 v4 uuids are unchanged after encoding and then decoding them"""

    for i in range(0, 10000):
        uuid1 = uuid.uuid4()
        slug = slugid.encode(uuid1)
        uuid2 = slugid.decode(slug)

        assert uuid1 == uuid2, "Encode and decode isn't identity: '" + str(
            uuid1) + "' != '" + str(uuid2) + "'"
Exemplo n.º 6
0
def slug_to_uuid(slug):
    """ Returns a uuid.UUID object from a slug.

    :param str slug: slug to convert to UUID
    :return: uuid representation of slug
    :rtype: uuid.UUID
    """
    try:
        uuid_out = slugid.decode(slug)
    except Exception as ex:
        raise exceptions.ValidationError('slug could not be decoded')
    return uuid_out
Exemplo n.º 7
0
def get_job_url(task_id, run_id, **params):
    """Build a Treeherder job url for a given Taskcluster task"""
    treeherder_client = TreeherderClient()
    uuid = slugid.decode(task_id)

    # Fetch specific job id from treeherder
    job_details = treeherder_client.get_job_details(
        job_guid=f"{uuid}/{run_id}")
    if len(job_details) > 0:
        params["selectedJob"] = job_details[0]["job_id"]

    return f"https://treeherder.mozilla.org/#/jobs?{urlencode(params)}"
Exemplo n.º 8
0
def testDecode():
    """ Test that we can decode a "non-nice" slug (first bit of uuid is set)
    that begins with `-`"""

    # 11111011111011111011111011111011111011111011111001000011111011111011111111111111111111111111111111111111111111111111111111111101....
    # <f ><b ><e ><f ><b ><e ><f ><b ><e ><f ><b ><e ><4 ><3 ><e ><f ><b ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><d >
    # < -  >< -  >< -  >< -  >< -  >< -  >< -  >< -  >< Q  >< -  >< -  >< -  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< Q  >
    slug = '--------Q--__________Q'
    expectedUuid = uuid.UUID('{fbefbefb-efbe-43ef-bfff-fffffffffffd}')
    actualUuid = slugid.decode(slug)

    assert expectedUuid == actualUuid, "Slug not correctly decoded into uuid: '" + str(expectedUuid) + "' != '" + str(actualUuid) + "'"
Exemplo n.º 9
0
def testDecode():
    """ Test that we can decode a "non-nice" slug (first bit of uuid is set)
    that begins with `-`"""

    # 11111011111011111011111011111011111011111011111001000011111011111011111111111111111111111111111111111111111111111111111111111101....
    # <f ><b ><e ><f ><b ><e ><f ><b ><e ><f ><b ><e ><4 ><3 ><e ><f ><b ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><f ><d >
    # < -  >< -  >< -  >< -  >< -  >< -  >< -  >< -  >< Q  >< -  >< -  >< -  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< _  >< Q  >
    slug = '--------Q--__________Q'
    expectedUuid = uuid.UUID('{fbefbefb-efbe-43ef-bfff-fffffffffffd}')
    actualUuid = slugid.decode(slug)

    assert expectedUuid == actualUuid, "Slug not correctly decoded into uuid: '" + \
        str(expectedUuid) + "' != '" + str(actualUuid) + "'"
Exemplo n.º 10
0
 async def _init(self):
     if self.settings:
         self.endpoint = f'/api/randomizers/{self.randomizer}/generate'
         self.data = await self.generate_game()
         self.guid = uuid.UUID(hex=self.data['guid'])
         self.slug_id = slugid.encode(self.guid)
     elif self.slug_id:
         self.guid = slugid.decode(self.slug_id)
         self.data = await self.retrieve_game()
     elif self.guid_id:
         self.guid = uuid.UUID(hex=self.guid_id)
         self.slug_id = slugid.encode(self.guid)
         self.data = await self.retrieve_game()
     else:
         self.data = None
         self.slug_id = None
         self.guid = None
Exemplo n.º 11
0
def get_job_url(repository, revision, task_id=None, run_id=None, **params):
    """Build a Treeherder job url for a given Taskcluster task"""
    assert isinstance(repository, str) and repository, "Missing repository"
    assert isinstance(revision, str) and revision, "Missing revision"
    assert "repo" not in params, "repo cannot be set in params"
    assert "revision" not in params, "revision cannot be set in params"

    params.update({"repo": repository, "revision": revision})

    if task_id is not None and run_id is not None:
        treeherder_client = TreeherderClient()
        uuid = slugid.decode(task_id)

        # Fetch specific job id from treeherder
        job_details = treeherder_client.get_job_details(
            job_guid=f"{uuid}/{run_id}")
        if len(job_details) > 0:
            params["selectedJob"] = job_details[0]["job_id"]

    return f"{JOBS_URL}?{urlencode(params)}"
Exemplo n.º 12
0
def buildMessage(pushInfo, task, runId, payload):
    taskId = payload["status"]["taskId"]
    jobRun = payload["status"]["runs"][runId]
    treeherderConfig = task["extra"]["treeherder"]

    job = {
      "buildSystem": "taskcluster",
      "owner": task["metadata"]["owner"],
      "taskId": "{taskId}/{runId}".format(taskId=slugid.decode(taskId), runId=runId),
      "retryId": runId,
      "isRetried": False,
      "display": {
        # jobSymbols could be an integer (i.e. Chunk ID) but need to be strings
        # for treeherder
        "jobSymbol": str(treeherderConfig["symbol"]),
        "groupSymbol": treeherderConfig.get("groupSymbol", "?"),
        # Maximum job name length is 100 chars...
        "jobName": task["metadata"]["name"][0:99],
      },
      "state": stateFromRun(jobRun),
      "result": resultFromRun(jobRun),
      "tier": treeherderConfig.get("tier", 1),
      "timeScheduled": task["created"],
      "jobKind": treeherderConfig.get("jobKind", "other"),
      "reason": treeherderConfig.get("reason", "scheduled"),
      "jobInfo": {
        "links": [],
        "summary": task["metadata"]["description"],
      },
      "version": 1,
    }

    job["origin"] = {
      "kind": pushInfo["origin"],
      "project": pushInfo["project"],
      "revision": pushInfo["revision"],
    }

    if pushInfo["origin"] == "hg.mozilla.org":
        job["origin"]["pushLogID"] = pushInfo["id"]
    else:
        job["origin"]["pullRequestID"] = pushInfo["id"]
        job["origin"]["owner"] = pushInfo["owner"]

    # Transform "collection" into an array of labels if task doesn't
    # define "labels".
    labels = treeherderConfig.get("labels", [])
    if not labels:
        if not treeherderConfig.get("collection"):
            labels = ["opt"]
        else:
            labels = list(treeherderConfig["collection"].keys())

    job["labels"] = labels

    machine = treeherderConfig.get("machine", {})
    job["buildMachine"] = {
      "name": jobRun.get("workerId", "unknown"),
      "platform": machine.get("platform", task["workerType"]),
      "os": machine.get("os", "-"),
      "architecture": machine.get("architecture", "-"),
    }

    if treeherderConfig.get("productName"):
        job["productName"] = treeherderConfig["productName"]

    if treeherderConfig.get("groupName"):
        job["display"]["groupName"] = treeherderConfig["groupName"]

    return job