|
33 | 33 | TIMEOUT = 5 * 60 # timeout in seconds after which we no longer wait for the VM to complete the run |
34 | 34 | MARKER = '_scs-test-' |
35 | 35 | # NOTE we mask serial-getty@ttyS0.service because the login prompt messes up the console output that we want to parse |
| 36 | +# NOTE we use awk to prefix each relevant line so we can find it easily later |
| 37 | +# NOTE we use >- to indicate that the following line is a string (that may contain colons), and newlines should be stripped |
36 | 38 | SERVER_USERDATA_GENERIC = """ |
37 | 39 | #cloud-config |
38 | 40 | # apt-placeholder |
|
41 | 43 | bootcmd: |
42 | 44 | - systemctl mask serial-getty@ttyS0.service |
43 | 45 | runcmd: |
44 | | - - echo '_scs-test-entropy-avail'; cat /proc/sys/kernel/random/entropy_avail |
45 | | - - echo '_scs-test-fips-test'; cat /dev/random | rngtest -c 1000 |
46 | | - - echo '_scs-test-rngd'; sudo systemctl status rngd |
47 | | - - echo '_scs-test-virtio-rng'; cat /sys/devices/virtual/misc/hw_random/rng_available; sudo /bin/sh -c 'od -vAn -N2 -tu2 < /dev/hwrng' |
| 46 | + - >- |
| 47 | + cat /proc/sys/kernel/random/entropy_avail | awk '$0="_scs-test-entropy-avail: "$0' |
| 48 | + - >- |
| 49 | + cat /dev/random | rngtest -c 1000 2>&1 | awk '$0="_scs-test-fips-test: "$0' |
| 50 | + - >- |
| 51 | + sudo systemctl status rngd 2>&1 | awk '$0="_scs-test-rngd: "$0' |
| 52 | + - >- |
| 53 | + cat /sys/devices/virtual/misc/hw_random/rng_available 2>&1 | awk '$0="_scs-test-virtio-rng: "$0'; sudo /bin/sh -c 'od -vAn -N2 -tu2 < /dev/hwrng' 2>&1 | awk '$0="_scs-test-virtio-rng: "$0' |
48 | 54 | - echo '_scs-test-end' |
49 | 55 | final_message: "_scs-test-end" |
50 | 56 | """.strip() |
@@ -338,23 +344,20 @@ def compute_canonical_image(all_images): |
338 | 344 |
|
339 | 345 |
|
340 | 346 | def _convert_to_collected(lines, marker=MARKER): |
341 | | - # parse lines from console output |
342 | | - # removing any "indent", stuff that looks like '[ 70.439502] cloud-init[513]: ' |
343 | | - # NOTE this logic can fail when something (such as a login prompt) messes up the console output |
344 | | - # therefore we disable the corresponding service (see cloud-init) |
| 347 | + """parse `lines` from console output""" |
| 348 | + # Each line usually starts with something like '[ 70.439502] cloud-init[513]: '; |
| 349 | + # HOWEVER, concurrent processes can easily disturb this pattern, so we use a |
| 350 | + # unique prefix on each line ourselves. |
345 | 351 | section = None |
346 | | - indent = 0 |
347 | 352 | collected = {} |
348 | 353 | for line in lines: |
349 | 354 | idx = line.find(marker) |
350 | | - if idx != -1: |
351 | | - section = line[idx + len(marker):].strip() |
352 | | - if section == 'end': |
353 | | - section = None |
354 | | - indent = idx |
| 355 | + if idx == -1: |
355 | 356 | continue |
356 | | - if section: |
357 | | - collected.setdefault(section, []).append(line[indent:]) |
| 357 | + section, *payload = line[idx + len(marker):].split(':', 1) |
| 358 | + if not payload: |
| 359 | + continue |
| 360 | + collected.setdefault(section, []).append(payload[0].strip()) |
358 | 361 | return collected |
359 | 362 |
|
360 | 363 |
|
|
0 commit comments