Skip to content

Commit 0633f93

Browse files
committed
[kea-packaging#8] show logs when _STARTED Kea not found
Also make reading of logs more pythonic.
1 parent 4648686 commit 0633f93

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

hammer.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -2248,13 +2248,19 @@ def _build_binaries_and_run_ut(system, revision, features, tarball_path, env, ch
22482248

22492249
def _check_installed_rpm_or_debs(services_list):
22502250
for svc in services_list:
2251-
execute('sudo systemctl stop %s' % svc)
2251+
execute(f'sudo systemctl stop {svc}')
22522252
now = datetime.datetime.now()
22532253
timestamp = now.strftime('%Y-%m-%d%H:%M:%S')
2254-
execute('sudo systemctl start %s' % svc)
2255-
time.sleep(3)
2256-
cmd = "sudo journalctl --since %s -u %s | grep '_STARTED Kea'" % (timestamp, svc)
2257-
execute(cmd, attempts=10, sleep_time_after_attempt=1)
2254+
execute(f'sudo systemctl start {svc}')
2255+
logs = ''
2256+
for _ in range(10):
2257+
_, logs = execute(f'sudo journalctl --since {timestamp} -u {svc}', capture=True)
2258+
if '_STARTED Kea' in logs:
2259+
break
2260+
time.sleep(1)
2261+
if '_STARTED Kea' not in logs:
2262+
print(logs)
2263+
raise UnexpectedError('_STARTED Kea not in logs')
22582264

22592265

22602266
def _build_rpm(system, revision, features, tarball_path, env, check_times, dry_run,
@@ -2429,15 +2435,19 @@ def _build_alpine_apk(revision, features, tarball_path, check_times, dry_run,
24292435

24302436
# check if kea services can be started
24312437
for svc in ['kea-dhcp4', 'kea-dhcp6', 'kea-ctrl-agent', 'kea-dhcp-ddns']:
2432-
execute('sudo rc-service %s start' % svc)
2433-
time.sleep(3)
2438+
execute(f'sudo rc-service {svc} start')
24342439
if svc == 'kea-dhcp-ddns':
24352440
svc = 'kea-ddns'
2436-
log_path = '/var/log/kea/%s.log' % svc
2437-
if revision == '3.10':
2438-
log_path = '/var/log/%s.log' % svc
2439-
cmd = "sudo cat %s | grep '_STARTED Kea'" % log_path
2440-
execute(cmd, attempts=10, sleep_time_after_attempt=1)
2441+
logs = ''
2442+
log_path = f'/var/log/kea/{svc}.log'
2443+
for _ in range(10):
2444+
_, logs = execute(f'sudo cat {log_path}', capture=True)
2445+
if '_STARTED Kea' in logs:
2446+
break
2447+
time.sleep(1)
2448+
if '_STARTED Kea' not in logs:
2449+
print(logs)
2450+
raise UnexpectedError('_STARTED Kea not in logs')
24412451

24422452

24432453
def _build_native_pkg(system, revision, features, tarball_path, env, check_times, dry_run, ccache_dir,

0 commit comments

Comments
 (0)