Browse Source

misc: test unattended-upgrade reboot

keep-around/f0213a1ad618625d0b79700e7c7e17bc9325874c
Loïc Dachary 7 months ago
committed by Loic Dachary
parent
commit
f0213a1ad6
Signed by: dachary GPG Key ID: 992D23B392F9E4F2
  1. 38
      playbooks/misc/tests/test_upgrade.py

38
playbooks/misc/tests/test_upgrade.py

@ -1,3 +1,5 @@
import sh
from enough.common import retry
@ -5,11 +7,10 @@ testinfra_hosts = ['ansible://debian-host']
def test_upgrade(host):
return
# that does not work, probably because the socket to the host needs reset after reboot
with host.sudo():
cmd = host.run("""
set -x ; sed -i -e '/.*Unattended-Upgrade::Automatic-Reboot /s|^|//|' \
reboot = "Unattended-Upgrade::Automatic-Reboot-Time"
cmd = host.run(f"""
set -x ; sed -i -e 's/.*{reboot} .*/{reboot} "now";/' \
/etc/apt/apt.conf.d/50unattended-upgrades
""")
assert 0 == cmd.rc
@ -17,16 +18,29 @@ def test_upgrade(host):
cmd = host.run("set -x ; touch /var/run/reboot-required")
assert 0 == cmd.rc
cmd = host.run("unattended-upgrade")
print(cmd.stdout)
print(cmd.stderr)
assert 0 == cmd.rc
before = host.run("uptime --since").stdout.strip()
print(f'debian-host is up since {before}')
@retry.retry((AssertionError, KeyError), tries=7)
def run():
cmd = host.run("! test -f /var/run/reboot-required")
#
# It will most likely fail because reboot will interrupt the connection
#
try:
cmd = host.run("unattended-upgrade")
print(cmd.stdout)
print(cmd.stderr)
assert 0 == cmd.rc
except RuntimeError:
pass
variables = host.ansible.get_variables()
address = variables['ansible_host']
private_key_file = variables['ansible_ssh_private_key_file']
@retry.retry((sh.ErrorReturnCode_255, AssertionError), tries=7)
def run():
r = sh.ssh('-oStrictHostKeyChecking=no',
'-i', private_key_file, 'debian@' + address,
'uptime', '--since')
after = r.stdout.decode('utf-8').strip()
assert before < after, f'debian-host did not reboot since {before}'
run()
Loading…
Cancel
Save