Merge lp:~sbaldassin/qa-jenkins-jobs/run_tests into lp:qa-jenkins-jobs

Proposed by Santiago Baldassin
Status: Merged
Approved by: Allan LeSage
Approved revision: 169
Merged at revision: 161
Proposed branch: lp:~sbaldassin/qa-jenkins-jobs/run_tests
Merge into: lp:qa-jenkins-jobs
Diff against target: 50 lines (+46/-0)
1 file modified
scripts/ubuntu-system-tests/get_tests_to_run.py (+46/-0)
To merge this branch: bzr merge lp:~sbaldassin/qa-jenkins-jobs/run_tests
Reviewer Review Type Date Requested Status
Allan LeSage (community) Approve
platform-qa-bot continuous-integration Approve
Max Brustkern (community) Needs Information
Review via email: mp+301077@code.launchpad.net

Commit message

Adding a script to select the tests to be run from the commit message

Description of the change

This mp adds a python script to get the list of tests to be run from the commit message in the merge proposal

To post a comment you must log in.
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

I'd like the file to be executable. When I run it like this:
python3 get_tests_to_run.py -mpu "https://code.launchpad.net/~canonical-platform-qa/ubuntu-system-tests/dynamic-dependencies"
I get this:
Traceback (most recent call last):
  File "get_tests_to_run.py", line 30, in <module>
    main(args.merge_proposal_url)
  File "get_tests_to_run.py", line 20, in main
    mp = json.loads(requests.get(branch.landing_targets_collection_link).text)
AttributeError: 'NoneType' object has no attribute 'landing_targets_collection_link'

review: Needs Fixing
Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

Thanks for the feedback Max. There's a problem with the line above, you should use the lp url instead of the http url. python3 get_tests_to_run.py -mpu "lp:~canonical-platform-qa/ubuntu-system-tests/dynamic-dependencies"

I'll make a couple of changes to enforce the use of the lp url. Moreover the above line will through an error message because there are no tests included in the commit message so I'll improve that as well

166. By Santiago Baldassin

Addressing comments from the reviews

Revision history for this message
Santiago Baldassin (sbaldassin) wrote :

I've updated the script and tested it with the following command line: TESTS_TO_RUN=$(python3 get_tests_to_run.py -mpu "lp:~canonical-platform-qa/ubuntu-system-tests/restart_unity8" 2>&1).
That's the command that we should include in the jenkins step, that way, TESTS_TO_RUN should be available within the jenkins job context

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Max Brustkern (nuclearbob) wrote :

I'm getting commas in the list. Will ubuntu-system-tests accept that? I always send a list of tests separated by spaces with no commas.

Also, I'd like to see the script be executable and inside the ubuntu-system-tests directory.

review: Needs Information
Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) wrote :

Ignore above failure :) .

Revision history for this message
Allan LeSage (allanlesage) wrote :

Sorry for the delay in testing this, you can see it working here: https://code.launchpad.net/~canonical-platform-qa/ubuntu-system-tests/mp-test-do-not-merge/+merge/301542 .

One note, that I think we should be getting the MP not via the branch but via the MP itself, although I can't find any way to do this cleanly via the API (https://launchpad.net/+apidoc/1.0.html) :/ . It's pretty rare that we're proposing to merge against more than one though so ok for now.

I agree with Max about relocating the script to /scripts/ubuntu-system-tests .

Also let's do a flake8 check on this just to be extra-picky.

review: Needs Fixing
167. By Santiago Baldassin

Addressing comments from the reviews

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
168. By Santiago Baldassin

Adding an option to get the tests to run from the http url

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) wrote :

Hey do we need that get_test_to_run.sh script, sbalda? (Asking b/c I'm skeptical :) .)

Otherwise this runs well and thanks for the MP option.

review: Needs Fixing
169. By Santiago Baldassin

addressing comments from the reviews

Revision history for this message
platform-qa-bot (platform-qa-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'scripts/ubuntu-system-tests/get_tests_to_run.py'
2--- scripts/ubuntu-system-tests/get_tests_to_run.py 1970-01-01 00:00:00 +0000
3+++ scripts/ubuntu-system-tests/get_tests_to_run.py 2016-08-02 16:23:52 +0000
4@@ -0,0 +1,46 @@
5+#!/usr/bin/python
6+import argparse
7+import requests
8+import sys
9+from launchpadlib.launchpad import Launchpad
10+
11+MP_URL_PREFIX = 'https://code.launchpad.net/'
12+LAUNCHPAD_API_PREFIX = 'https://api.launchpad.net/1.0/'
13+
14+
15+def main(mp_url):
16+ if mp_url.startswith('lp'):
17+ # Login to launchpad anonymously
18+ launchpad = Launchpad.login_anonymously('ci job', 'production')
19+
20+ # Get the branch
21+ branch = launchpad.branches.getByUrl(url=mp_url)
22+
23+ if branch is not None:
24+ # Get the merge proposal data
25+ mp = requests.get(
26+ branch.landing_targets_collection_link).json()['entries'][0]
27+ else:
28+ raise ValueError("The url provided did not returned any "
29+ "data from launchpad")
30+ elif mp_url.startswith('http'):
31+ url = mp_url.replace(MP_URL_PREFIX, LAUNCHPAD_API_PREFIX)
32+ mp = requests.get(url).json()
33+ else:
34+ raise ValueError("Please provide a valid url")
35+
36+ commit_message = mp['commit_message']
37+ try:
38+ tests = commit_message.split('@run_tests:')[1:][0].strip()
39+ except IndexError:
40+ tests = []
41+ sys.stdout.write(str(tests))
42+
43+if __name__ == "__main__":
44+ parser = argparse.ArgumentParser(
45+ description='This script will get the list of tests '
46+ 'to be run from the mp commit message')
47+ parser.add_argument('-mpu', '--merge_proposal_url',
48+ help='Merge proposal url', required=True)
49+ args = parser.parse_args()
50+ main(args.merge_proposal_url)

Subscribers

People subscribed via source and target branches