Auto-tools/Projects/Autolog/Posting with JSON

From MozillaWiki
Jump to navigation Jump to search

To post data directly to Autolog with JSON, instead of using the python package mozautolog, you use the following request format, to http://brasstacks.mozilla.com/:

POST /autologserver/addtestgroup HTTP/1.1
Accept-Encoding: identity
Content-Length: 1344
Host: brasstacks.mozilla.com
Content-Type: application/json
Connection: close
User-Agent: Python-urllib/2.6

{
  "testsuites": [
    {
      "testsuite": "{the name of the test suite}",
      "testfailures": [
        {
          "testsuite": "{the name of the test suite}",
          "errors": [
            {
              "status": "{status, example: TEST-UNEXPECTED-FAIL}",
              "text": "{description of error, example: [phase2] Exception caught: ASSERTION FAILED! places item not found}"
            }
          ],
          "testgroup_id": null,
          "test": "{filename of test, example: test_sync.js}",
          "testsuite_id": null,
          "logurl": null
        },
        {
          "testsuite": "{the name of the test suite}",
          "errors": [
            {
              "status": "{status, example: TEST-UNEXPECTED-FAIL}",
              "text": "{description of error, example: some other error string}"
            }
          ],
          "testgroup_id": null,
          "test": "{filename of test, example: other_test.js}",
          "testsuite_id": null,
          "logurl": null
        }
      ],
      "failed": {total number of failed tests, example: 1},
      "testgroup_id": null,
      "perfdata": [
        {
           "test": "xperf",
           "perfdata": [
             {
                "type": "diskIO",
                other arbitrary fields...
             },
             {
                "type": "pagefaults",
                other arbitrary fields...
             }
           ]
        }
      ],
      "elapsedtime": null,
      "cmdline": null,
      "passed": {total number of passed tests, example: 10},
      "todo": {total number of todo tests, example: 0}
    }
  ],
  "server": "10.2.76.100:9200",
  "testgroup": {
    "harness": "{name of your test harness}",
    "machine": "{name of the machine running the test}",
    "platform": "{example: win32}",
    "version": "{version Firefox, example: 9.0a1}",
    "branch": null,
    "frameworkfailures": null,
    "pending": false,
    "revision": "{revision of Firefox, example: eef657744227}",
    "buildtype": "{buildtype, either opt or debug}",
    "buildid": "{buildid of Firefox, example: 20110914121048}",
    "date": "{example: 2011-09-29}",
    "testrun": null,
    "logurl": null,
    "testgroup": "{name of your test suite or harness}",
    "builder": null,
    "tree": "{tree Firefox was built from, example: mozilla-central}",
    "productname": null,
    "buildurl": null,
    "os": "{specific os version, example: win7}"
  }
}

You will get back a JSON response which will look something like so:

HTTP/1.1 200 OK
Server: nginx/0.8.53
Date: Thu, 29 Sep 2011 19:11:02 GMT
Content-Type: application/json
Connection: close
Allow: GET, POST
Access-Control-Allow-Origin: *
Content-Length: 274 

{
  "testsuites": [
    {
      "testfailures": [
        {
          "testfailure_id": "I1ND25NlT4aTSkjf2aQpEA"
        },
        {
          "testfailure_id": "4gsdkkNlT4aTSkjf2aQpEA"
        },
      ],
      "testsuite_id": "ADdF_xuITXS26XvzYri0rA",
      "perfdata": []
    }
  ],
  "testgroup_id": "pNiMIzkQSZaRckYXKyB2Kg",
  "testrun": "eef657744227.4"
}

The returned JSON contains the id of each of the autolog objects which was created as a result of the POST.

If you'd like to attach log files to any of the testfailures, you can make another POST to do so:

POST /autologserver/savelog?id=I1ND25NlT4aTSkjf2aQpEA&read_index=autolog&write_index=autolog&doc_type=testfailures&server=10.2.76.100:9200 HTTP/1.1
Accept-Encoding: identity
Content-Length: 16910
Host: brasstacks.mozilla.com
Content-Type: text/plain
Connection: close
User-Agent: Python-urllib/2.6 

data:image/png;base64,iVBORw0KGgoAAAANSUh....\n
data:image/png;base64,iVBORw0KGgoAAAAAGSD....\n

The id in the query string should be relevant testfailure_id which was returned from the previous POST.

The 'server' field in the query string, and the 'server' field in the first JSON POST, are set to 10.2.76.100:9200. This is a test instance of ElasticSearch. After you verify that your POST is working correctly, you can remove these from the JSON and the request string.