Merge ~alexmurray/ubuntu-security-tools:cmd-autopkgtest into ubuntu-security-tools:master

Proposed by Alex Murray
Status: Merged
Merged at revision: da14542b3dcfc028ecce807a08789613ae3f9a49
Proposed branch: ~alexmurray/ubuntu-security-tools:cmd-autopkgtest
Merge into: ubuntu-security-tools:master
Diff against target: 148 lines (+111/-1)
2 files modified
build-tools/umt (+110/-0)
build-tools/umt-completion.bash (+1/-1)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+376893@code.launchpad.net

Description of the change

Like the recent qrt subcommand, add a new autopkgtest subcommand which will try and launch autopkgtest's using the built binary packages and if available, also run a baseline test against the build-orig binaries if these have been retained.

To post a comment you must log in.
Revision history for this message
Alex Murray (alexmurray) wrote :

No review after over a week, merging anyway (this is self-contained so is unlikely to break anything anyway).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/build-tools/umt b/build-tools/umt
2index b42696c..0ae824e 100755
3--- a/build-tools/umt
4+++ b/build-tools/umt
5@@ -37,6 +37,7 @@ reports_dest = '../reports'
6 previous_dest = '../previous'
7 coverity_dest = '../coverity'
8 qrt_dest = '../qrt'
9+autopkgtest_dest = '../autopkgtest'
10
11 # Per-package overrides for the sbuild resolver
12 # <sbuild resolver> = sbuild_dep_resolver_overrides[<srcpkg>][<ubuntu release>]
13@@ -1748,6 +1749,114 @@ def run_qrt_tests(opt, details):
14 print("Stopping uvt VM " + vm + "...")
15 runcmdopt([uvt, "stop", vm], opt)
16
17+
18+def cmd_autopkgtest():
19+ '''Run AUTOPKGTEST tests for the package in the current directory of unpacked source'''
20+ parser = umt_optparse("usage: %prog autopkgtest [options]")
21+ parser.add_option("-a", "--arch", dest="arch", default="amd64",
22+ help="Architecture to test (default: amd64)")
23+ parser.add_option("-p", "--images-path", dest="images_path", default="~/images/",
24+ help="Location QEMU autopkgtest images to use for tests (default: ~/images/)")
25+ parser.add_option("-i", "--image", dest="image", default=None,
26+ help="QEMU autopkgtest image name to use for tests (default: {images-path}/autopkgtest-{release}-{arch}.img)")
27+ parser.add_option("-s", "--skip-baseline", dest="skip_baseline", default=False, action='store_true',
28+ help="Don't try and run the tests against the previous build as a baseline")
29+ parser.add_option("-n", "--dry-run", dest="dry_run", default=False, action='store_true',
30+ help="Don't actually execute tests, instead print what would be run")
31+ parser.add_option("--debug", default=False, action='store_true',
32+ help="Report additional debug details")
33+ parser.add_option("-f", "--force", dest="force", default=False, action='store_true',
34+ help="force deletion of ../tests/autopkgtest before running")
35+ (opt, args) = parser.parse_args()
36+
37+ validate_toplevel()
38+ details = parse_package_details(skip_sanity=True)
39+ run_autopkgtest_tests(opt, details)
40+
41+
42+def run_autopkgtest_tests(opt, details):
43+ autopkgtest_test = os.path.join("debian", "tests", "control")
44+ if not os.path.exists(autopkgtest_test):
45+ print("No autopkgtest found for " + details["package"] + ": expected to find in " + autopkgtest_test)
46+ return
47+ if not opt.dry_run:
48+ prepare_dir(autopkgtest_dest, opt.force)
49+ if opt.image is not None:
50+ image = opt.image
51+ else:
52+ image = os.path.join(os.path.expanduser(opt.images_path), "autopkgtest-" + details["release"] + "-" + opt.arch + ".img")
53+ try:
54+ if not os.path.exists(image):
55+ print("autopkgtest qemu image '%s' does not exist - do you wish to create it (y|N)? " % image, end=' ', flush=True)
56+ answer = sys.stdin.readline().strip().lower()
57+ print("")
58+ if answer.startswith("y"):
59+ print("Creating autopkgtest qemu image '%s'" % image)
60+ runcmdopt(["/usr/bin/autopkgtest-buildvm-ubuntu-cloud",
61+ "-r", details["release"],
62+ "-o", os.path.dirname(image)],
63+ opt)
64+ print("Created autopkgtest qemu image '%s'" % image)
65+ # for the baseline test, use the orig (aka previous) .changes
66+ if not opt.skip_baseline:
67+ prev_changes = glob.glob("../previous/binary/*" + opt.arch + ".changes")
68+ prev_version = None
69+ if len(prev_changes) > 0:
70+ prev_changes = prev_changes[0]
71+ prev_version = os.path.splitext(os.path.basename(prev_changes))[0].replace(details["package"] + "_", "").replace("_source", "")
72+ print("Executing autopkgtest baseline test using %s on %s..." % (prev_changes, image))
73+ report = runcmdopt(["/usr/bin/autopkgtest", "-U",
74+ "-o", os.path.join(autopkgtest_dest, prev_version),
75+ prev_changes,
76+ "--",
77+ "qemu", image], opt)
78+ if not opt.dry_run:
79+ # save the report so we can compare it later
80+ path = os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + prev_version + ".txt")
81+ with open(path,"w+") as handle:
82+ handle.write(report)
83+ handle.flush()
84+ else:
85+ warn("No previous build found - unable to run baseline autopkgtest (try running `umt build-orig --leave`) ...")
86+ changes = glob.glob("../binary/*" + opt.arch + ".changes")
87+ version = None
88+ if len(changes) > 0:
89+ changes = changes[0]
90+ version = os.path.splitext(os.path.basename(changes))[0].replace(details["package"] + "_", "").replace("_source", "")
91+ print("Executing autopkgtest test using %s on %s..." % (changes, image))
92+ report = runcmdopt(["/usr/bin/autopkgtest", "-U",
93+ "-o", os.path.join(autopkgtest_dest, version),
94+ changes,
95+ "--",
96+ "qemu", image], opt)
97+ if not opt.dry_run:
98+ # save the report so we can compare it later
99+ path = os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + version + ".txt")
100+ with open(path,"w+") as handle:
101+ handle.write(report)
102+ handle.flush()
103+ else:
104+ warn("No current binary build found - not running autopkgtest...")
105+ if (prev_version is not None and version is not None and
106+ os.path.exists(os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + prev_version + ".txt")) and
107+ os.path.exists(os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + version + ".txt"))):
108+ print("Generating diff of autopkgtest tests output...")
109+ report = runcmdopt(["/usr/bin/diff", "-u",
110+ os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + prev_version + ".txt"),
111+ os.path.join(autopkgtest_dest, "autopkgtest-test-" + details["package"] + "-" + version + ".txt")],
112+ # diff returns 1 if different and 0 if same - so
113+ # both are valid ok return codes
114+ opt, [0, 1])
115+ if not opt.dry_run:
116+ # save the diff
117+ path = os.path.join(autopkgtest_dest, "qrt-test-" + details["package"] + '.diff')
118+ with open(path,"w+") as handle:
119+ handle.write(report)
120+ handle.flush()
121+ print("autopkgtest test run diff in " + path)
122+ except Exception as e:
123+ err(str(e))
124+
125 #
126 # Misc functions
127 #
128@@ -3466,6 +3575,7 @@ commands = {
129 'repo' : cmd_repo,
130 'upload' : cmd_upload,
131 'qrt' : cmd_qrt,
132+ 'autopkgtest' : cmd_autopkgtest,
133 'open' : cmd_open,
134 'read' : cmd_read,
135 'help' : cmd_help
136diff --git a/build-tools/umt-completion.bash b/build-tools/umt-completion.bash
137index bd73861..b62b8b1 100644
138--- a/build-tools/umt-completion.bash
139+++ b/build-tools/umt-completion.bash
140@@ -12,7 +12,7 @@ _umt_complete()
141 COMPREPLY=( $( compgen -W "$( grep Package: /var/lib/apt/lists/*Sources | awk '{print $2}' | sort | uniq )" "$cur") )
142 }
143
144- umt_commands="search download changelog source binary build build-orig compare-log compare-bin sign check upload qrt"
145+ umt_commands="search download changelog source binary build build-orig compare-log compare-bin sign check upload qrt autopkgtest"
146
147 if [ $COMP_CWORD -eq 1 ]; then
148 COMPREPLY=( $(compgen -W "$umt_commands" -- ${COMP_WORDS[COMP_CWORD]}) )

Subscribers

People subscribed via source and target branches