From 26492f0e3537d2433ebab93f728a82a69c2bc977 Mon Sep 17 00:00:00 2001
From: Esben Haabendal <esben@geanix.com>
Date: Thu, 13 Apr 2023 16:15:21 +0200
Subject: [PATCH] openharmony-standard-image-tests: Fix ptest ssh timeout in
 QEMU

SSH host keys are generated by sshdgenkeys.service, which is started by socket
activation on first SSH connection. On QEMU this can take a very long time, even
more than the 300 seconds that is the default timeout when running SSH commands
testimage recipes.

Pre-generated SSH host keys prevents this.

Note, this is only done in the -test image, as it is insecure and should never
be done in images used for other purposes!

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 conf/distro/oniro-openharmony-linux.conf               |  3 +++
 .../images/openharmony-standard-image-tests.bb         | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/conf/distro/oniro-openharmony-linux.conf b/conf/distro/oniro-openharmony-linux.conf
index 2c37be43..cc8a420e 100644
--- a/conf/distro/oniro-openharmony-linux.conf
+++ b/conf/distro/oniro-openharmony-linux.conf
@@ -40,6 +40,9 @@ INHERIT += "uninative"
 # instead.
 HOSTTOOLS += "ip ping ps scp ssh stty"
 
+# Yocto does not have ssh-keygen-native, so we need to use ssh-keygen from host
+HOSTTOOLS += "ssh-keygen"
+
 # Default to enabling serial debug console on RaspberryPi
 # Placed here to amend the machine config living in meta-raspberrypi
 ENABLE_UART:raspberrypi4-64 ?= "1"
diff --git a/recipes-openharmony/images/openharmony-standard-image-tests.bb b/recipes-openharmony/images/openharmony-standard-image-tests.bb
index 98629f11..103b7f83 100644
--- a/recipes-openharmony/images/openharmony-standard-image-tests.bb
+++ b/recipes-openharmony/images/openharmony-standard-image-tests.bb
@@ -25,3 +25,13 @@ IMAGE_INSTALL += "ptest-runner"
 
 # install OpenHarmony components and ptests
 IMAGE_INSTALL += "openharmony-standard-ptest"
+
+# Pre-generate SSH host keys for quick first time SSH connection
+ROOTFS_POSTPROCESS_COMMAND += "ssh_host_key_gen;"
+SSH_HOST_KEY_TYPES="rsa ecdsa ed25519"
+ssh_host_key_gen() {
+    mkdir -p "${IMAGE_ROOTFS}${sysconfdir}/ssh/"
+    for type in ${SSH_HOST_KEY_TYPES} ; do
+        ssh-keygen -f "${IMAGE_ROOTFS}${sysconfdir}/ssh/ssh_host_"$type"_key" -N '' -t $type
+    done
+}
-- 
GitLab