Skip to content

Commit 81e6cc6

Browse files
committed
Fix/improve flakiness of scs-0101 tests
The console output inside the VM is quite easily disrupted by concurrent processes. This makes finding the relevant output quite complicated. The heuristics for this task was not optimal; let's hope this one is better. Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 7363392 commit 81e6cc6

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

Tests/iaas/scs_0101_entropy/entropy_check.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
TIMEOUT = 5 * 60 # timeout in seconds after which we no longer wait for the VM to complete the run
3434
MARKER = '_scs-test-'
3535
# 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
3638
SERVER_USERDATA_GENERIC = """
3739
#cloud-config
3840
# apt-placeholder
@@ -41,10 +43,14 @@
4143
bootcmd:
4244
- systemctl mask serial-getty@ttyS0.service
4345
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'
4854
- echo '_scs-test-end'
4955
final_message: "_scs-test-end"
5056
""".strip()
@@ -338,23 +344,21 @@ def compute_canonical_image(all_images):
338344

339345

340346
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.
345351
section = None
346352
indent = 0
347353
collected = {}
348354
for line in lines:
349355
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
356+
if idx == -1:
355357
continue
356-
if section:
357-
collected.setdefault(section, []).append(line[indent:])
358+
section, *payload = line[idx + len(marker):].split(':', 1)
359+
if not payload:
360+
continue
361+
collected.setdefault(section, []).append(payload[0].strip())
358362
return collected
359363

360364

0 commit comments

Comments
 (0)