Skip to content

Commit

Permalink
bbtest resilient to journactl logs ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Nov 5, 2021
1 parent e4d2c3e commit 4f53716
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ executors:
docker:
- image: docker.io/jancajthaml/debian-packager:latest

machine:
testbed:
machine:
image: circleci/classic:201808-01
image: ubuntu-1604:202007-01
docker_layer_caching: false

# ---------------------------------------------------------------------------- #
Expand Down Expand Up @@ -525,7 +525,7 @@ jobs:
# -------------------------------------------------------------------------- #

blackbox-test-amd64:
executor: machine
executor: testbed
working_directory: /home/circleci/project
steps:
- checkout
Expand Down
1 change: 1 addition & 0 deletions bbtest/helpers/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

def logger():
log = logging.getLogger('bbtest')
log.propagate = False
log.addHandler(journal.JournalHandler())
log.setLevel(logging.DEBUG)
return log
2 changes: 1 addition & 1 deletion bbtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]

if str(os.environ.get('CI', 'false')) == 'false':
args.append('-f plain')
args.append('-f pretty')
args.append('--tags=~@wip')
else:
args.append('-f progress3')
Expand Down
33 changes: 23 additions & 10 deletions bbtest/steps/logs_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import re
import os
from behave import *
from helpers.shell import execute
from helpers.eventually import eventually
Expand All @@ -12,23 +13,35 @@ def step_impl(context, unit):
expected_lines = [item.strip() for item in context.text.split('\n') if len(item.strip())]
ansi_escape = re.compile(r'(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]')

def get_unit_description():
(code, result, error) = execute(["systemctl", "status", unit])
result = ansi_escape.sub('', result)
assert len(result), str(result) + ' ' + str(error)
result = result.split(os.linesep)[0]
pivot = "{} - ".format(unit)
idx = result.rfind(pivot)
if idx >= 0:
return result[idx+len(pivot):]
else:
return None

description = get_unit_description()

@eventually(5)
def impl():
(code, result, error) = execute(['journalctl', '-o', 'cat', '-u', unit, '--no-pager'])
result = ansi_escape.sub('', result)
assert code == 'OK', str(result) + ' ' + str(error)

actual_lines_merged = [item.strip() for item in result.split('\n') if len(item.strip())]
actual_lines = []
idx = len(actual_lines_merged) - 1
if description:
idx = result.rfind("Stopped {}.".format(description))
else:
idx = -1

while True:
if idx < 0 or actual_lines_merged[idx].startswith("Starting openbank Bondster Marketplace connection"):
break
actual_lines.append(actual_lines_merged[idx])
idx -= 1
if idx > 0:
result = result[idx:]

actual_lines = reversed(actual_lines)
actual_lines = [item.strip() for item in result.split('\n') if len(item.strip())]

for expected in expected_lines:
found = False
Expand All @@ -37,6 +50,6 @@ def impl():
found = True
break

assert found == True, 'message "{}" was not found in logs'.format(context.text.strip())
assert found, 'message "{}" was not found in logs\n {}'.format(context.text.strip(), '\n '.join(actual_lines))

impl()
5 changes: 3 additions & 2 deletions packaging/debian/bondster-bco-watcher.path
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[Unit]
Description=openbank Bondster Marketplace connection configuration watcher
After=bondster-bco.service

[Path]
PathChanged=/etc/bondster-bco/conf.d/init.conf
PathChanged=/etc/bondster-bco/conf.d
Unit=bondster-bco-watcher.service

[Install]
WantedBy=multi-user.target
WantedBy=paths.target
7 changes: 3 additions & 4 deletions packaging/debian/bondster-bco-watcher.service
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ Description=openbank Bondster Marketplace connection configuration watcher
StartLimitBurst=5

[Service]
Type=oneshot
ExecStart=/bin/sh -c 'echo reloading bondster-bco.service'
Type=simple
ExecStartPre=echo 'restarting bondster-bco (configuration has changed)'
ExecStart=/bin/sh -c 'systemctl restart bondster-bco.service'
ExecStart=/bin/sh -c 'echo reloaded bondster-bco.service'

[Install]
WantedBy=multi-user.target
WantedBy=bondster-bco.service

0 comments on commit 4f53716

Please sign in to comment.