Skip to content

Commit

Permalink
Merge branch 'install-6.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
ydirson committed Oct 8, 2024
2 parents ddfcaee + f0f56e1 commit f034488
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
# Get a decoded version of the output in any case, replacing potential errors
output_for_errors = res.stdout.decode(errors='replace').strip()

# Even if check is False, we still raise in case of return code 255, which means a SSH error.
if res.returncode == 255:
return False, SSHCommandFailed(255, "SSH Error: %s" % output_for_errors, command)
# # Even if check is False, we still raise in case of return code 255, which means a SSH error.
# if res.returncode == 255:
# return False, SSHCommandFailed(255, "SSH Error: %s" % output_for_errors, command)

output = res.stdout
if config.ignore_ssh_banner:
Expand All @@ -125,7 +125,7 @@ def _ssh(hostname_or_ip, cmd, check, simple_output, suppress_fingerprint_warning
if decode:
output = output.decode()

if res.returncode and check:
if res.returncode not in (0, 255) and check:
return False, SSHCommandFailed(res.returncode, output_for_errors, command)

if simple_output:
Expand Down
28 changes: 23 additions & 5 deletions lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from lib.commands import ssh, SSHCommandFailed
from lib.common import wait_for

# FIXME should only be used for <7.0
SSHOPTS = ("-o KexAlgorithms=+diffie-hellman-group1-sha1",
"-o HostKeyAlgorithms=+ssh-rsa",
"-o PubkeyAcceptedKeyTypes=+ssh-rsa",
"-c +aes256-cbc")

class AnswerFile:
def __init__(self, kind, /):
from data import BASE_ANSWERFILES
Expand Down Expand Up @@ -62,36 +68,41 @@ def _defn_to_xml_et(defn, /, *, parent=None):

def poweroff(ip):
try:
ssh(ip, ["poweroff"])
ssh(ip, ["/sbin/poweroff"], options=SSHOPTS)
except SSHCommandFailed as e:
# ignore connection closed by reboot
if e.returncode == 255 and "closed by remote host" in e.stdout:
logging.info("sshd closed the connection")
pass
elif e.returncode == 255:
logging.info("sshd misbehaving?")
else:
raise

def monitor_install(*, ip):
# wait for "yum install" phase to finish
wait_for(lambda: ssh(ip, ["grep",
wait_for(lambda: "DISPATCH: NEW PHASE: Completing installation" in ssh(ip, ["grep",
"'DISPATCH: NEW PHASE: Completing installation'",
"/tmp/install-log"],
check=False, simple_output=False,
).returncode == 0,
options=SSHOPTS,
).stdout,
"Wait for rpm installation to succeed",
timeout_secs=40 * 60) # FIXME too big

# wait for install to finish
wait_for(lambda: ssh(ip, ["grep",
wait_for(lambda: "The installation completed successfully" in ssh(ip, ["grep",
"'The installation completed successfully'",
"/tmp/install-log"],
check=False, simple_output=False,
).returncode == 0,
options=SSHOPTS,
).stdout,
"Wait for system installation to succeed",
timeout_secs=40 * 60) # FIXME too big

wait_for(lambda: ssh(ip, ["ps a|grep '[0-9]. python /opt/xensource/installer/init'"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 1,
"Wait for installer to terminate")

Expand All @@ -101,6 +112,7 @@ def monitor_upgrade(*, ip):
"'DISPATCH: NEW PHASE: Reading package information'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for upgrade preparations to finish",
timeout_secs=40 * 60) # FIXME too big
Expand All @@ -110,6 +122,7 @@ def monitor_upgrade(*, ip):
"'DISPATCH: NEW PHASE: Completing installation'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for rpm installation to succeed",
timeout_secs=40 * 60) # FIXME too big
Expand All @@ -119,12 +132,14 @@ def monitor_upgrade(*, ip):
"'The installation completed successfully'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for system installation to succeed",
timeout_secs=40 * 60) # FIXME too big

wait_for(lambda: ssh(ip, ["ps a|grep '[0-9]. python /opt/xensource/installer/init'"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 1,
"Wait for installer to terminate")

Expand All @@ -134,6 +149,7 @@ def monitor_restore(*, ip):
"'Restoring backup'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for data restoration to start",
timeout_secs=40 * 60) # FIXME too big
Expand All @@ -143,6 +159,7 @@ def monitor_restore(*, ip):
"'Data restoration complete. About to re-install bootloader.'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for data restoration to complete",
timeout_secs=40 * 60) # FIXME too big
Expand All @@ -154,6 +171,7 @@ def monitor_restore(*, ip):
"'ran .*swaplabel.*rc 0'",
"/tmp/install-log"],
check=False, simple_output=False,
options=SSHOPTS,
).returncode == 0,
"Wait for installer to hopefully finish",
timeout_secs=40 * 60) # FIXME too big
Expand Down
3 changes: 3 additions & 0 deletions tests/install/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def remastered_iso(installer_iso, answerfile):
set -ex
INSTALLIMG="$1"
# bad permissions in XS 6.5 preventing ssh to use authorized_keys
chmod g-w "$INSTALLIMG/root"
mkdir -p "$INSTALLIMG/root/.ssh"
echo "{TEST_SSH_PUBKEY}" > "$INSTALLIMG/root/.ssh/authorized_keys"
Expand Down
9 changes: 5 additions & 4 deletions tests/install/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestNested:
"821.1",
"81", "80", "76", "75",
"xs8", "ch821.1",
"xs70",
"xs70", "xs65",
))
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
@pytest.mark.vm_definitions(
Expand Down Expand Up @@ -109,7 +109,7 @@ def helper_vm_with_plugged_disk(running_vm, create_vms):
"81", "80",
"76", "75",
"ch821.1", "xs8",
"xs70",
"xs70", "xs65",
))
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
@pytest.mark.continuation_of(
Expand Down Expand Up @@ -167,6 +167,7 @@ def _test_firstboot(self, create_vms, mode, *, machine='DEFAULT'):
else:
expected_rel_id = split_mode[-1]
expected_rel = {
"xs65": "6.5.0-90233c",
"xs70": "7.0.0-125380c",
"ch821.1": "8.2.1",
"xs8": "8.4.0",
Expand Down Expand Up @@ -215,7 +216,7 @@ def _test_firstboot(self, create_vms, mode, *, machine='DEFAULT'):
]
STAMPS_DIR = "/var/lib/misc"
STAMPS = [f"ran-{service}" for service in SERVICES]
elif lsb_rel in ["7.0.0-125380c", "7.5.0", "7.6.0", "8.0.0", "8.1.0"]:
elif lsb_rel in ["6.5.0", "7.0.0-125380c", "7.5.0", "7.6.0", "8.0.0", "8.1.0"]:
SERVICES = ["xs-firstboot"]
STAMPS_DIR = "/etc/firstboot.d/state"
STAMPS = [
Expand Down Expand Up @@ -301,7 +302,7 @@ def _test_firstboot(self, create_vms, mode, *, machine='DEFAULT'):
"81", "80",
"76", "75",
"ch821.1", "xs8",
"xs70",
"xs70", "xs65",
))
@pytest.mark.parametrize("firmware", ("uefi", "bios"))
@pytest.mark.continuation_of(
Expand Down

0 comments on commit f034488

Please sign in to comment.