Merge lp:~roadmr/checkbox/image-info-parsers into lp:checkbox
- image-info-parsers
- Merge into trunk
| Status: | Merged |
|---|---|
| Approved by: | Zygmunt Krynicki on 2015-06-02 |
| Approved revision: | 3817 |
| Merged at revision: | 3821 |
| Proposed branch: | lp:~roadmr/checkbox/image-info-parsers |
| Merge into: | lp:checkbox |
| Diff against target: |
710 lines (+621/-0) 6 files modified
checkbox-support/checkbox_support/parsers/image_info.py (+194/-0) checkbox-support/checkbox_support/parsers/submission.py (+65/-0) checkbox-support/checkbox_support/parsers/tests/fixtures/submission_info_image_info.xml (+51/-0) checkbox-support/checkbox_support/parsers/tests/test_image_info.py (+247/-0) checkbox-support/checkbox_support/parsers/tests/test_submission.py (+61/-0) checkbox-support/setup.py (+3/-0) |
| To merge this branch: | bzr merge lp:~roadmr/checkbox/image-info-parsers |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Zygmunt Krynicki (community) | 2015-05-25 | Approve on 2015-06-02 | |
|
Review via email:
|
|||
Commit Message
checkbox-
Description of the Change
Adds 3 new parsers dealing with the image and recovery info attachments.
- Bto.xml parser
- recovery_info attachment parser
- buildstamp parser
Each of these comprises 2 commits: one adding the subparser with plainbox dev parse support and unit tests, and another integrating it with the submission parser, including integration tests with that and modifications to the TestRun class so "plainbox dev parse submission" does the right thing.
I rolled these into one merge request since they're somewhat related but I can also split into separate MRs.
| Zygmunt Krynicki (zyga) wrote : | # |
| Zygmunt Krynicki (zyga) wrote : | # |
This looks good but I have two general comments below. Please have a look. Perhaps we could do a one-off camelCase -> under_score patch next?
Preview Diff
| 1 | === added file 'checkbox-support/checkbox_support/parsers/image_info.py' |
| 2 | --- checkbox-support/checkbox_support/parsers/image_info.py 1970-01-01 00:00:00 +0000 |
| 3 | +++ checkbox-support/checkbox_support/parsers/image_info.py 2015-05-25 19:30:44 +0000 |
| 4 | @@ -0,0 +1,194 @@ |
| 5 | +# This file is part of Checkbox. |
| 6 | +# |
| 7 | +# Copyright 2011-2015 Canonical Ltd. |
| 8 | +# |
| 9 | +# Checkbox is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License version 3, |
| 11 | +# as published by the Free Software Foundation. |
| 12 | +# |
| 13 | +# Checkbox is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU General Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU General Public License |
| 19 | +# along with Checkbox. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + |
| 21 | +""" |
| 22 | +Parsers for OEM image information. |
| 23 | + |
| 24 | +There are 3 possible attachments containing data relevant to OEM images:: |
| 25 | + |
| 26 | + * /etc/buildstamp |
| 27 | + * recovery_info_attachment |
| 28 | + * dell_bto_xml_attachment |
| 29 | + |
| 30 | +A class is provided to parse each of these. |
| 31 | +""" |
| 32 | + |
| 33 | +from __future__ import absolute_import |
| 34 | +from __future__ import division |
| 35 | +from __future__ import print_function |
| 36 | +from __future__ import unicode_literals |
| 37 | + |
| 38 | +import io |
| 39 | +from xml.dom import minidom |
| 40 | +from xml.parsers.expat import ExpatError |
| 41 | + |
| 42 | + |
| 43 | +class ImageInfoResult(): |
| 44 | + |
| 45 | + """ |
| 46 | + A simple class to hold image information results. |
| 47 | + |
| 48 | + It has methods for all the parser classes in this module so it can be |
| 49 | + easily reused. |
| 50 | + |
| 51 | + """ |
| 52 | + |
| 53 | + def __init__(self): |
| 54 | + self.image_info = {} |
| 55 | + |
| 56 | + def addBuildstampInfo(self, data): |
| 57 | + """Add the given buildstamp.""" |
| 58 | + self.image_info['buildstamp'] = data |
| 59 | + |
| 60 | + def addImageVersionInfo(self, key, data): |
| 61 | + """Add image version data under the given key.""" |
| 62 | + self.image_info[key] = data |
| 63 | + |
| 64 | + |
| 65 | +class BtoInfoResult(): |
| 66 | + |
| 67 | + """A simple class to hold BTO information results.""" |
| 68 | + |
| 69 | + def __init__(self): |
| 70 | + self.bto_info = {} |
| 71 | + |
| 72 | + def addBtoInfo(self, key, data): |
| 73 | + """Add bto data under the given key.""" |
| 74 | + self.bto_info[key] = data |
| 75 | + |
| 76 | + |
| 77 | +class BuildstampParser(): |
| 78 | + |
| 79 | + """ |
| 80 | + Parser for the info/buildstamp attachment. |
| 81 | + |
| 82 | + Buildstamp is quite unstructured, so the parser is very simple, it will |
| 83 | + just verify that the attachment contains exactly 2 lines and call the |
| 84 | + addBuildstamp method of the resutl class with the entire content of the |
| 85 | + second line. |
| 86 | + """ |
| 87 | + |
| 88 | + def __init__(self, stream): |
| 89 | + self.stream = stream |
| 90 | + |
| 91 | + def run(self, result): |
| 92 | + """Parse stream and set the buildstamp in the result.""" |
| 93 | + buildstamp = "" |
| 94 | + for index, line in enumerate(self.stream): |
| 95 | + if index == 1: |
| 96 | + buildstamp = line |
| 97 | + if index >= 2 and line.strip() != '': |
| 98 | + # It contains more than 2 non-blank |
| 99 | + # lines, so exit right now, |
| 100 | + # this attachment looks bogus. |
| 101 | + return |
| 102 | + if buildstamp.strip(): |
| 103 | + result.addBuildstampInfo(buildstamp.strip()) |
| 104 | + |
| 105 | + |
| 106 | +class RecoveryInfoParser(): |
| 107 | + |
| 108 | + """ |
| 109 | + Parser for recovery_info. |
| 110 | + |
| 111 | + Recovery_info can contain two keys: image_version and bto_version. |
| 112 | + |
| 113 | + """ |
| 114 | + |
| 115 | + def __init__(self, stream): |
| 116 | + self.stream = stream |
| 117 | + |
| 118 | + def run(self, result): |
| 119 | + """Parse stream and set the version attributes in the result.""" |
| 120 | + for line in self.stream: |
| 121 | + try: |
| 122 | + key, value = line.split(":", 1) |
| 123 | + except (ValueError, AttributeError): |
| 124 | + # Just skip this line |
| 125 | + pass |
| 126 | + else: |
| 127 | + key = key.strip() |
| 128 | + value = value.strip() |
| 129 | + if key in ("image_version", "bto_version") and value: |
| 130 | + result.addImageVersionInfo(key, value) |
| 131 | + |
| 132 | + |
| 133 | +class BtoParser(): |
| 134 | + |
| 135 | + """Parser for Dell bto.xml data file.""" |
| 136 | + |
| 137 | + def __init__(self, stream): |
| 138 | + self.stream = stream |
| 139 | + |
| 140 | + def run(self, result): |
| 141 | + """ |
| 142 | + Parse stream and set bto attributes in the result. |
| 143 | + |
| 144 | + Possible BTO attributes are (the result.addBtoInfo method will be |
| 145 | + called with each key/value):: |
| 146 | + |
| 147 | + * iso - a single string with the name of the installed ISO |
| 148 | + * generator - a single string |
| 149 | + * bootstrap - a single string |
| 150 | + * ubiquity - a single string |
| 151 | + * base - a single string, presumably name of ISO on which this |
| 152 | + project is based |
| 153 | + * fish. A list of strings with fish packages (they're .debs) |
| 154 | + """ |
| 155 | + try: |
| 156 | + bto_dom = minidom.parse(self.stream) |
| 157 | + except ExpatError: |
| 158 | + # Bogus data, give up silently |
| 159 | + return |
| 160 | + for key in ['iso', 'generator', 'bootstrap', |
| 161 | + 'ubiquity', 'base', 'driver']: |
| 162 | + elems = bto_dom.getElementsByTagName(key) |
| 163 | + items = [item.firstChild.data for item in elems |
| 164 | + if hasattr(item.firstChild, 'data')] |
| 165 | + if len(items) == 1: |
| 166 | + result.addBtoInfo(key, items[0]) |
| 167 | + elif len(items) > 1: |
| 168 | + result.addBtoInfo(key, items) |
| 169 | + |
| 170 | + |
| 171 | +def parse_buildstamp_attachment_output(output): |
| 172 | + """Parse info/buildstamp attachment output.""" |
| 173 | + stream = io.StringIO(output) |
| 174 | + parser = BuildstampParser(stream) |
| 175 | + result = ImageInfoResult() |
| 176 | + parser.run(result) |
| 177 | + return result.image_info['buildstamp'] |
| 178 | + |
| 179 | + |
| 180 | +def parse_bto_attachment_output(output): |
| 181 | + """Parse bto.xml attachment output.""" |
| 182 | + stream = io.StringIO(output) |
| 183 | + parser = BtoParser(stream) |
| 184 | + result = BtoInfoResult() |
| 185 | + parser.run(result) |
| 186 | + return result.bto_info |
| 187 | + |
| 188 | + |
| 189 | +def parse_recovery_info_attachment_output(output): |
| 190 | + """Parse recovery_info attachment output.""" |
| 191 | + stream = io.StringIO(output) |
| 192 | + parser = RecoveryInfoParser(stream) |
| 193 | + result = ImageInfoResult() |
| 194 | + parser.run(result) |
| 195 | + |
| 196 | + return {k: result.image_info[k] |
| 197 | + for k in result.image_info.keys() |
| 198 | + if k in ("bto_version", "image_version")} |
| 199 | |
| 200 | === modified file 'checkbox-support/checkbox_support/parsers/submission.py' |
| 201 | --- checkbox-support/checkbox_support/parsers/submission.py 2015-05-25 13:19:47 +0000 |
| 202 | +++ checkbox-support/checkbox_support/parsers/submission.py 2015-05-25 19:30:44 +0000 |
| 203 | @@ -48,6 +48,9 @@ |
| 204 | from checkbox_support.parsers.pci_config import PciSubsystemIdParser |
| 205 | from checkbox_support.parsers.dkms_info import DkmsInfoParser |
| 206 | from checkbox_support.parsers.modinfo import MultipleModinfoParser |
| 207 | +from checkbox_support.parsers.image_info import (BtoParser, |
| 208 | + BuildstampParser, |
| 209 | + RecoveryInfoParser) |
| 210 | |
| 211 | logger = logging.getLogger("checkbox_support.parsers.submission") |
| 212 | |
| 213 | @@ -179,6 +182,36 @@ |
| 214 | "module": module, |
| 215 | "attributes": data}) |
| 216 | |
| 217 | + def addBuildstampInfo(self, buildstamp): |
| 218 | + self.messages.append({ |
| 219 | + "type": "set-buildstamp", |
| 220 | + "buildstamp": buildstamp}) |
| 221 | + logger.debug("Setting buildstamp: %s", buildstamp) |
| 222 | + |
| 223 | + def addImageVersionInfo(self, kind, version): |
| 224 | + my_type = "set-image-version" |
| 225 | + if not self.messages or self.messages[-1]["type"] != my_type: |
| 226 | + self.messages.append({ |
| 227 | + "type": my_type, |
| 228 | + "image-version": {}}) |
| 229 | + |
| 230 | + message = self.messages[-1] |
| 231 | + logger.debug("ADDING image version:") |
| 232 | + logger.debug("%s %s", kind, version) |
| 233 | + message["image-version"][kind] = version |
| 234 | + |
| 235 | + def addBtoInfo(self, key, data): |
| 236 | + my_type = "add-bto-info" |
| 237 | + if not self.messages or self.messages[-1]["type"] != my_type: |
| 238 | + self.messages.append({ |
| 239 | + "type": my_type, |
| 240 | + "bto-info": {}}) |
| 241 | + |
| 242 | + message = self.messages[-1] |
| 243 | + logger.debug("ADDING BTO info:") |
| 244 | + logger.debug("%s %s", key, data) |
| 245 | + message["bto-info"][key] = data |
| 246 | + |
| 247 | def setKernelCmdline(self, kernel_cmdline): |
| 248 | self.messages.append({ |
| 249 | "type": "set-kernel-cmdline", |
| 250 | @@ -589,6 +622,9 @@ |
| 251 | register(("test_run", "modprobe",), self.addModprobeInfo) |
| 252 | register(("test_run", "dkms_info",), self.addDkmsInfo) |
| 253 | register(("test_run", "modinfo",), self.addModuleInfo) |
| 254 | + register(("test_run", "bto_info",), self.addBtoInfo) |
| 255 | + register(("test_run", "buildstamp_info",), self.setBuildstampInfo) |
| 256 | + register(("test_run", "image_version_info",), self.addImageVersionInfo) |
| 257 | |
| 258 | # Register handlers to set information once |
| 259 | register(("architecture",), self.setArchitecture, count=1) |
| 260 | @@ -649,6 +685,9 @@ |
| 261 | "lspci_standard_config": self.parsePciSubsystemId, |
| 262 | "dkms_info": self.parseDkmsInfo, |
| 263 | r"modinfo_attachment": self.parseModinfo, |
| 264 | + "dell_bto_xml_attachment": self.parseBtoInfo, |
| 265 | + "recovery_info_attachment": self.parseImageVersionInfo, |
| 266 | + "info/buildstamp": self.parseBuildstampInfo, |
| 267 | } |
| 268 | for context, parser in context_parsers.items(): |
| 269 | if re.search(context, command): |
| 270 | @@ -723,6 +762,20 @@ |
| 271 | self.dispatcher.publishEvent("modinfo", modinfo) |
| 272 | return DeferredParser(self.dispatcher, "modinfo_result") |
| 273 | |
| 274 | + def parseBtoInfo(self, bto_info): |
| 275 | + self.dispatcher.publishEvent("bto_info", bto_info) |
| 276 | + return DeferredParser(self.dispatcher, "bto_info_result") |
| 277 | + |
| 278 | + def parseBuildstampInfo(self, buildstamp_info): |
| 279 | + self.dispatcher.publishEvent("buildstamp_info", buildstamp_info) |
| 280 | + return DeferredParser(self.dispatcher, "buildstamp_info_result") |
| 281 | + |
| 282 | + def parseImageVersionInfo(self, image_version_info): |
| 283 | + self.dispatcher.publishEvent("image_version_info", |
| 284 | + image_version_info) |
| 285 | + return DeferredParser(self.dispatcher, |
| 286 | + "image_version_info_result") |
| 287 | + |
| 288 | def parsePciSubsystemId(self, lspci_data): |
| 289 | self.dispatcher.publishEvent("lspci_data", lspci_data) |
| 290 | return DeferredParser(self.dispatcher, "pci_subsystem_id_result") |
| 291 | @@ -735,6 +788,18 @@ |
| 292 | parser = MultipleModinfoParser(modinfo) |
| 293 | parser.run(test_run) |
| 294 | |
| 295 | + def setBuildstampInfo(self, test_run, buildstamp_info): |
| 296 | + parser = BuildstampParser(buildstamp_info) |
| 297 | + parser.run(test_run) |
| 298 | + |
| 299 | + def addBtoInfo(self, test_run, bto_info): |
| 300 | + parser = BtoParser(bto_info) |
| 301 | + parser.run(test_run) |
| 302 | + |
| 303 | + def addImageVersionInfo(self, test_run, image_version_info): |
| 304 | + parser = RecoveryInfoParser(image_version_info) |
| 305 | + parser.run(test_run) |
| 306 | + |
| 307 | def addIdentifier(self, identifier): |
| 308 | try: |
| 309 | self.identifiers.append(identifier) |
| 310 | |
| 311 | === added file 'checkbox-support/checkbox_support/parsers/tests/fixtures/submission_info_image_info.xml' |
| 312 | --- checkbox-support/checkbox_support/parsers/tests/fixtures/submission_info_image_info.xml 1970-01-01 00:00:00 +0000 |
| 313 | +++ checkbox-support/checkbox_support/parsers/tests/fixtures/submission_info_image_info.xml 2015-05-25 19:30:44 +0000 |
| 314 | @@ -0,0 +1,51 @@ |
| 315 | +<?xml version="1.0" ?> |
| 316 | +<system version="1.0"> |
| 317 | + <context> |
| 318 | + <info command="info/buildstamp">kakaduplum Tue, 12 May 2015 06:46:55 +0000 |
| 319 | + somerville-trusty-amd64-osp1-20150512-0 |
| 320 | + </info> |
| 321 | + <info command="recovery_info_attachment">image_version: somerville-trusty-amd64-osp1-20150512-0 |
| 322 | + bto_version: A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso |
| 323 | + </info> |
| 324 | + <info command="dell_bto_xml_attachment"><?xml version="1.0" encoding="utf-8"?><bto> |
| 325 | + <date>2015-05-21</date> |
| 326 | + <versions> |
| 327 | + <os/> |
| 328 | + <iso>A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso</iso> |
| 329 | + <generator>1.24.3~somerville11</generator> |
| 330 | + <bootstrap>1.36~somerville3</bootstrap> |
| 331 | + <ubiquity>2.18.8.8kittyhawk1somerville3</ubiquity> |
| 332 | + </versions> |
| 333 | + <base>somerville-trusty-amd64-osp1-iso-20150512-0.iso</base> |
| 334 | + <fid> |
| 335 | + <git_tag/> |
| 336 | + <deb_archive/> |
| 337 | + </fid> |
| 338 | + <fish> |
| 339 | + <driver md5="ed884782d541974e2a887d6523778656">libcuda1-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 340 | + <driver md5="f536d125300b29ccd4d17f585fc9a20d">nvidia-libopencl1-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 341 | + <driver md5="d339d194d242043f18ba9df6bc2b2589">bbswitch-dkms_0.7-2ubuntu1_amd64.deb</driver> |
| 342 | + <driver md5="9b00de6e7dbc41e7bc62305655c0b7a1">config-prime-select-intel-all_0.6_all.deb</driver> |
| 343 | + <driver md5="b4354596045ca3ec27e96627d5895e18">nvidia-prime_0.6.2_amd64.deb</driver> |
| 344 | + <driver md5="17fcea6133304d332f27acfb0312594e">screen-resolution-extra_0.17.1_all.deb</driver> |
| 345 | + <driver md5="f047ea4d70eb539f8153080103873345">nvidia-346-uvm_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 346 | + <driver md5="91bb933c7e246a61d5f52115cf42c58b">nvidia-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 347 | + <driver md5="1d56f62ad2dd5db429db4bfb65416041">nvidia-settings_346.47-0somerville1_amd64.deb</driver> |
| 348 | + <driver md5="be80560b798fba58998f32bfecbd208e">nvidia-opencl-icd-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 349 | + <driver md5="3d1fa1561aa23361c3a270a0fa99a0ba">libvdpau1_1.1-0somerville1_amd64.deb</driver> |
| 350 | + </fish> |
| 351 | + <logs> |
| 352 | + <syslog>May 21 16:29:23 ubuntu rsyslogd: [origin software=&quot;rsyslogd&quot; swVersion=&quot;7.4.4&quot; x-pid=&quot;3119&quot; x-info=&quot;http://www.rsyslog.com&quot;] start |
| 353 | + May 21 16:30:41 ubuntu ubiquity[4393]: log-output -t ubiquity efibootmgr -c -d /dev/sda -p 1 -l \EFI\ubuntu\shimx64.efi -L ubuntu |
| 354 | + May 21 16:30:41 ubuntu ubiquity[4393]: log-output -t ubiquity umount /mnt/efi |
| 355 | + </syslog> |
| 356 | + <debug>Ubiquity 2.18.8.8kittyhawk1somerville3 |
| 357 | + May 21 16:30:05 ubiquity: ['log-output', '-t', 'ubiquity', '--pass-stdout', '/usr/share/ubiquity/dell-bootstrap'] exited with code 0 |
| 358 | + </debug> |
| 359 | + </logs> |
| 360 | + </bto></info> |
| 361 | + </context> |
| 362 | + <summary> |
| 363 | + <architecture value="amd64"/> |
| 364 | + </summary> |
| 365 | +</system> |
| 366 | |
| 367 | === added file 'checkbox-support/checkbox_support/parsers/tests/test_image_info.py' |
| 368 | --- checkbox-support/checkbox_support/parsers/tests/test_image_info.py 1970-01-01 00:00:00 +0000 |
| 369 | +++ checkbox-support/checkbox_support/parsers/tests/test_image_info.py 2015-05-25 19:30:44 +0000 |
| 370 | @@ -0,0 +1,247 @@ |
| 371 | +# This file is part of Checkbox. |
| 372 | +# |
| 373 | +# Copyright 2015 Canonical Ltd. |
| 374 | +# |
| 375 | +# Checkbox is free software: you can redistribute it and/or modify |
| 376 | +# it under the terms of the GNU General Public License version 3, |
| 377 | +# as published by the Free Software Foundation. |
| 378 | +# |
| 379 | +# Checkbox is distributed in the hope that it will be useful, |
| 380 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 381 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 382 | +# GNU General Public License for more details. |
| 383 | +# |
| 384 | +# You should have received a copy of the GNU General Public License |
| 385 | +# along with Checkbox. If not, see <http://www.gnu.org/licenses/>. |
| 386 | + |
| 387 | +"""Tests for the image_info parsers.""" |
| 388 | + |
| 389 | +from __future__ import absolute_import |
| 390 | +from __future__ import division |
| 391 | +from __future__ import print_function |
| 392 | +from __future__ import unicode_literals |
| 393 | + |
| 394 | +from io import StringIO |
| 395 | +from unittest import TestCase |
| 396 | + |
| 397 | +from checkbox_support.parsers.image_info import ( |
| 398 | + BuildstampParser, |
| 399 | + RecoveryInfoParser, |
| 400 | + BtoParser, |
| 401 | + BtoInfoResult, |
| 402 | + ImageInfoResult) |
| 403 | + |
| 404 | + |
| 405 | +class TestBuildstampParser(TestCase): |
| 406 | + |
| 407 | + """Tests for Buildstamp parser class.""" |
| 408 | + |
| 409 | + def _bogus_test(self, string): |
| 410 | + """ |
| 411 | + Helper to test for bogus data. |
| 412 | + |
| 413 | + It checks that the given string does NOT produce a valid buildstamp. |
| 414 | + """ |
| 415 | + stream = StringIO(string) |
| 416 | + self.parser = BuildstampParser(stream) |
| 417 | + result = ImageInfoResult() |
| 418 | + self.parser.run(result) |
| 419 | + self.assertNotIn("buildstamp", result.image_info) |
| 420 | + |
| 421 | + def test_one_line(self): |
| 422 | + """A one-line attachment is bogus, no result.""" |
| 423 | + self._bogus_test("bogus\n") |
| 424 | + |
| 425 | + def test_two_lines_bogus(self): |
| 426 | + """A two-line attachment (empty second line) is bogus, no result.""" |
| 427 | + self._bogus_test("bogus\n\n") |
| 428 | + |
| 429 | + def test_three_lines(self): |
| 430 | + """A three-line attachment is bogus, no result.""" |
| 431 | + self._bogus_test("bogus\nwith-tree\nlines") |
| 432 | + |
| 433 | + def test_many_lines_empty_line(self): |
| 434 | + """Attachment with some empty lines is mostly good, get a result.""" |
| 435 | + stream = StringIO("bogus\nwith-tree\n\n\n") |
| 436 | + self.parser = BuildstampParser(stream) |
| 437 | + result = ImageInfoResult() |
| 438 | + self.parser.run(result) |
| 439 | + self.assertIn("buildstamp", result.image_info) |
| 440 | + |
| 441 | + def test_two_lines_good(self): |
| 442 | + """A three-line attachment is good, check expected value.""" |
| 443 | + stream = StringIO("kakaduplum Tue, 12 May 2015 06:46:55 +0000\n" |
| 444 | + "somerville-trusty-amd64-osp1-20150512-0") |
| 445 | + self.parser = BuildstampParser(stream) |
| 446 | + result = ImageInfoResult() |
| 447 | + self.parser.run(result) |
| 448 | + self.assertIn("buildstamp", result.image_info) |
| 449 | + self.assertEqual("somerville-trusty-amd64-osp1-20150512-0", |
| 450 | + result.image_info["buildstamp"]) |
| 451 | + |
| 452 | + |
| 453 | +class TestRecoveryInfoParser(TestCase): |
| 454 | + |
| 455 | + """Tests for Recovery Info parser class.""" |
| 456 | + |
| 457 | + def _result_for(self, string): |
| 458 | + """Helper to run string through the parser and return result.""" |
| 459 | + stream = StringIO(string) |
| 460 | + self.parser = RecoveryInfoParser(stream) |
| 461 | + result = ImageInfoResult() |
| 462 | + self.parser.run(result) |
| 463 | + return result |
| 464 | + |
| 465 | + def test_bad_data(self): |
| 466 | + """A bad attachment is bogus, no result.""" |
| 467 | + result = self._result_for("bogus\nlorem\nreally bad\n") |
| 468 | + self.assertNotIn("image_version", result.image_info) |
| 469 | + self.assertNotIn("bto_version", result.image_info) |
| 470 | + |
| 471 | + def test_tricky_data(self): |
| 472 | + """A validly-formatted attachment with wrong keys. No result.""" |
| 473 | + result = self._result_for("key: value\nkey2: value2") |
| 474 | + self.assertNotIn("image_version", result.image_info) |
| 475 | + self.assertNotIn("bto_version", result.image_info) |
| 476 | + |
| 477 | + def test_empty_data(self): |
| 478 | + """Attachment with good keys but no data. No result.""" |
| 479 | + result = self._result_for("image_version: \nbto_version: \n") |
| 480 | + self.assertNotIn("image_version", result.image_info) |
| 481 | + self.assertNotIn("bto_version", result.image_info) |
| 482 | + |
| 483 | + def test_good_data(self): |
| 484 | + """A good and complete attachment, check expected value.""" |
| 485 | + result = self._result_for( |
| 486 | + "image_version: somerville-trusty-amd64-osp1-20150512-0\n" |
| 487 | + "bto_version: " |
| 488 | + "A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso") |
| 489 | + self.assertIn("image_version", result.image_info) |
| 490 | + self.assertEqual("somerville-trusty-amd64-osp1-20150512-0", |
| 491 | + result.image_info["image_version"]) |
| 492 | + self.assertIn("bto_version", result.image_info) |
| 493 | + self.assertEqual( |
| 494 | + "A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso", |
| 495 | + result.image_info["bto_version"]) |
| 496 | + |
| 497 | + def test_good_partial_data_image(self): |
| 498 | + """A good attachment with only image_version, check expected value.""" |
| 499 | + result = self._result_for( |
| 500 | + "image_version: somerville-trusty-amd64-osp1-20150512-0\n" |
| 501 | + "bogus: chogus.iso") |
| 502 | + self.assertIn("image_version", result.image_info) |
| 503 | + self.assertEqual("somerville-trusty-amd64-osp1-20150512-0", |
| 504 | + result.image_info["image_version"]) |
| 505 | + self.assertNotIn("bto_version", result.image_info) |
| 506 | + |
| 507 | + def test_good_partial_data_bto(self): |
| 508 | + """A good attachment with only bto_version, check expected value.""" |
| 509 | + result = self._result_for( |
| 510 | + "bogus: bogon\n" |
| 511 | + "bto_version: " |
| 512 | + "A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso") |
| 513 | + self.assertNotIn("image_version", result.image_info) |
| 514 | + self.assertIn("bto_version", result.image_info) |
| 515 | + self.assertEqual( |
| 516 | + "A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso", |
| 517 | + result.image_info["bto_version"]) |
| 518 | + |
| 519 | + |
| 520 | +BTO1 = """\ |
| 521 | +<?xml version="1.0" encoding="utf-8"?><bto> |
| 522 | + <date>2015-05-21</date> |
| 523 | + <versions> |
| 524 | + <os/> |
| 525 | + <iso>A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso</iso> |
| 526 | + <generator>1.24.3~somerville11</generator> |
| 527 | + <bootstrap>1.36~somerville3</bootstrap> |
| 528 | + <ubiquity>2.18.8.8kittyhawk1somerville3</ubiquity> |
| 529 | + </versions> |
| 530 | + <base>somerville-trusty-amd64-osp1-iso-20150512-0.iso</base> |
| 531 | + <fid> |
| 532 | + <git_tag/> |
| 533 | + <deb_archive/> |
| 534 | + </fid> |
| 535 | + <fish> |
| 536 | + <driver md5="ed884782d541974e2a887d6523778656">libcuda1-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 537 | + <driver md5="f536d125300b29ccd4d17f585fc9a20d">nvidia-libopencl1-346_346.59-0ubuntu1somerville1_amd64.deb</driver> |
| 538 | + </fish> |
| 539 | + <logs> |
| 540 | + <syslog>blah</syslog> |
| 541 | + </logs> |
| 542 | +</bto> |
| 543 | +""" |
| 544 | + |
| 545 | +BTO2 = """\ |
| 546 | +<?xml version="1.0" encoding="utf-8"?><bto> |
| 547 | + <date>2015-05-21</date> |
| 548 | + <versions> |
| 549 | + <os/> |
| 550 | + </versions> |
| 551 | + <foo> |
| 552 | + <bar>baz</bar> |
| 553 | + </foo> |
| 554 | +</bto> |
| 555 | +""" |
| 556 | + |
| 557 | +BTO3 = """\ |
| 558 | +<?xml version="1.0" encoding="utf-8"?><bto> |
| 559 | + <date>2015-05-21</date> |
| 560 | + <versions> |
| 561 | + <os/> |
| 562 | + <iso></iso> |
| 563 | + <generator>1.24.3~somerville11</generator> |
| 564 | + </versions> |
| 565 | + <base/> |
| 566 | + <fish> |
| 567 | + <driver/> |
| 568 | + <driver md5="f536d125300b29ccd4d17f585fc9a20d">boo.deb</driver> |
| 569 | + <driver md5="f536d125300b29ccd4d17f585fc9a20a">choo.deb</driver> |
| 570 | + </fish> |
| 571 | +</bto> |
| 572 | +""" |
| 573 | + |
| 574 | + |
| 575 | +class TestBtoParser(TestCase): |
| 576 | + |
| 577 | + """Tests for BTO data parser class.""" |
| 578 | + |
| 579 | + def _result_for(self, string): |
| 580 | + """Helper to run string through the parser and return result.""" |
| 581 | + stream = StringIO(string) |
| 582 | + self.parser = BtoParser(stream) |
| 583 | + result = BtoInfoResult() |
| 584 | + self.parser.run(result) |
| 585 | + return result |
| 586 | + |
| 587 | + def test_bad_data(self): |
| 588 | + """A bad attachment is bogus, no result.""" |
| 589 | + result = self._result_for("bogus\nlorem\nreally bad\n") |
| 590 | + self.assertEqual({}, result.bto_info) |
| 591 | + |
| 592 | + def test_bogus_xml(self): |
| 593 | + """A xml with values we don't want is bogus, no result.""" |
| 594 | + result = self._result_for(BTO2) |
| 595 | + self.assertEqual({}, result.bto_info) |
| 596 | + |
| 597 | + def test_tricky_xml(self): |
| 598 | + """A xml with mix of keys we want and empty values, partial result.""" |
| 599 | + result = self._result_for(BTO3) |
| 600 | + self.assertDictEqual( |
| 601 | + {'generator': '1.24.3~somerville11', |
| 602 | + 'driver': ['boo.deb', 'choo.deb']}, |
| 603 | + result.bto_info) |
| 604 | + |
| 605 | + def test_good_data(self): |
| 606 | + """A good and complete xml, check expected value.""" |
| 607 | + result = self._result_for(BTO1) |
| 608 | + expected_dict = { |
| 609 | + 'base': 'somerville-trusty-amd64-osp1-iso-20150512-0.iso', |
| 610 | + 'bootstrap': '1.36~somerville3', |
| 611 | + 'driver': [ |
| 612 | + 'libcuda1-346_346.59-0ubuntu1somerville1_amd64.deb', |
| 613 | + 'nvidia-libopencl1-346_346.59-0ubuntu1somerville1_amd64.deb'], |
| 614 | + 'generator': '1.24.3~somerville11', |
| 615 | + 'iso': 'A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso', |
| 616 | + 'ubiquity': '2.18.8.8kittyhawk1somerville3'} |
| 617 | + self.assertDictEqual(expected_dict, result.bto_info) |
| 618 | |
| 619 | === modified file 'checkbox-support/checkbox_support/parsers/tests/test_submission.py' |
| 620 | --- checkbox-support/checkbox_support/parsers/tests/test_submission.py 2015-05-22 19:24:34 +0000 |
| 621 | +++ checkbox-support/checkbox_support/parsers/tests/test_submission.py 2015-05-25 19:30:44 +0000 |
| 622 | @@ -68,6 +68,16 @@ |
| 623 | self.result.setdefault('dkms_info', {}) |
| 624 | self.result['dkms_info'][pkg] = details |
| 625 | |
| 626 | + def addBuildstampInfo(self, data): |
| 627 | + self.result['buildstamp'] = data |
| 628 | + |
| 629 | + def addImageVersionInfo(self, key, data): |
| 630 | + self.result[key] = data |
| 631 | + |
| 632 | + def addBtoInfo(self, key, data): |
| 633 | + self.result.setdefault('bto_info', {}) |
| 634 | + self.result['bto_info'][key] = data |
| 635 | + |
| 636 | def addAttachment(self, **attachment): |
| 637 | self.result.setdefault("attachments", []) |
| 638 | self.result["attachments"].append(attachment) |
| 639 | @@ -348,6 +358,57 @@ |
| 640 | self.assertEqual(['crypto-ctr', 'ctr', 'crypto-rfc3686', 'rfc3686'], |
| 641 | result['modinfo']['ctr']['alias']) |
| 642 | |
| 643 | + def test_buildstamp(self): |
| 644 | + """ |
| 645 | + test buildstamp attachment. |
| 646 | + |
| 647 | + Buildstamp is in the image_info element if there was a buildstamp |
| 648 | + attachment. |
| 649 | + """ |
| 650 | + result = self.getResult("submission_info_image_info.xml") |
| 651 | + self.assertTrue("buildstamp" in result) |
| 652 | + self.assertEqual('somerville-trusty-amd64-osp1-20150512-0', |
| 653 | + result['buildstamp']) |
| 654 | + |
| 655 | + def test_image_info(self): |
| 656 | + """ |
| 657 | + test image_info attachment. |
| 658 | + |
| 659 | + We should have image versions in the image_info element if there was a |
| 660 | + recovery_info attachment. |
| 661 | + """ |
| 662 | + result = self.getResult("submission_info_image_info.xml") |
| 663 | + self.assertTrue("image_version" in result) |
| 664 | + self.assertEqual('somerville-trusty-amd64-osp1-20150512-0', |
| 665 | + result['image_version']) |
| 666 | + self.assertTrue("bto_version" in result) |
| 667 | + self.assertEqual( |
| 668 | + 'A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso', |
| 669 | + result['bto_version']) |
| 670 | + |
| 671 | + def test_bto_info(self): |
| 672 | + """bto data if there was a bto.xml attachment.""" |
| 673 | + result = self.getResult("submission_info_image_info.xml") |
| 674 | + self.assertTrue("bto_info" in result) |
| 675 | + self.assertDictEqual( |
| 676 | + {'base': 'somerville-trusty-amd64-osp1-iso-20150512-0.iso', |
| 677 | + 'bootstrap': '1.36~somerville3', |
| 678 | + 'driver': ['libcuda1-346_346.59-0ubuntu1somerville1_amd64.deb', |
| 679 | + 'nvidia-libopencl1-346_346.59-0ubuntu1somerville1_amd64.deb', |
| 680 | + 'bbswitch-dkms_0.7-2ubuntu1_amd64.deb', |
| 681 | + 'config-prime-select-intel-all_0.6_all.deb', |
| 682 | + 'nvidia-prime_0.6.2_amd64.deb', |
| 683 | + 'screen-resolution-extra_0.17.1_all.deb', |
| 684 | + 'nvidia-346-uvm_346.59-0ubuntu1somerville1_amd64.deb', |
| 685 | + 'nvidia-346_346.59-0ubuntu1somerville1_amd64.deb', |
| 686 | + 'nvidia-settings_346.47-0somerville1_amd64.deb', |
| 687 | + 'nvidia-opencl-icd-346_346.59-0ubuntu1somerville1_amd64.deb', |
| 688 | + 'libvdpau1_1.1-0somerville1_amd64.deb'], |
| 689 | + 'generator': '1.24.3~somerville11', |
| 690 | + 'iso': 'A00_dell-bto-trusty-miramar-15-17-X01-iso-20150521-0.iso', |
| 691 | + 'ubiquity': '2.18.8.8kittyhawk1somerville3'}, |
| 692 | + result['bto_info']) |
| 693 | + |
| 694 | def test_test_results(self): |
| 695 | """Test results are in the questions element.""" |
| 696 | result = self.getResult("submission_questions.xml") |
| 697 | |
| 698 | === modified file 'checkbox-support/setup.py' |
| 699 | --- checkbox-support/setup.py 2015-05-19 13:50:42 +0000 |
| 700 | +++ checkbox-support/setup.py 2015-05-25 19:30:44 +0000 |
| 701 | @@ -62,6 +62,9 @@ |
| 702 | "pci-subsys-id=checkbox_support.parsers.pci_config:parse_pci_subsys_id", |
| 703 | "dkms-info=checkbox_support.parsers.dkms_info:parse_dkms_info", |
| 704 | "modinfo=checkbox_support.parsers.modinfo:parse_modinfo_attachment_output", |
| 705 | + "buildstamp=checkbox_support.parsers.image_info:parse_buildstamp_attachment_output", |
| 706 | + "recovery-info=checkbox_support.parsers.image_info:parse_recovery_info_attachment_output", |
| 707 | + "bto=checkbox_support.parsers.image_info:parse_bto_attachment_output", |
| 708 | ], |
| 709 | }, |
| 710 | ) |


Sorry for starving this. I will review this today.