All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: Chuck Lever <cel@kernel.org>, Daniel Gomez <da.gomez@kruces.com>,
	kdevops@lists.linux.dev
Cc: Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 17/23] reboot-limit: fix kexec and reboot connection handling
Date: Mon, 11 Aug 2025 15:24:44 -0700	[thread overview]
Message-ID: <20250811222452.2213071-18-mcgrof@kernel.org> (raw)
In-Reply-To: <20250811222452.2213071-1-mcgrof@kernel.org>

Replace shell-based kexec implementation with proper Ansible tasks
and fix connection handling for both systemctl reboot and kexec.

For kexec:
- Break down into discrete tasks to find kernel and initrd files
- Use stat module to check multiple possible locations
- Load kernel with kexec -l before executing systemctl kexec
- Use async execution to avoid connection failures

For both reboot types:
- Use async: 1 and poll: 0 to fire-and-forget the reboot command
- Add proper wait_for tasks to handle connection loss and recovery
- Wait for system to go down then come back up

This approach is more idiomatic Ansible and handles the SSH connection
properly during system reboots.

Generated-by: Claude AI
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 .../roles/reboot-limit/tasks/do-reboot.yml    | 126 ++++++++++++++++++
 1 file changed, 126 insertions(+)

diff --git a/playbooks/roles/reboot-limit/tasks/do-reboot.yml b/playbooks/roles/reboot-limit/tasks/do-reboot.yml
index ec5c9fc8..1e5ba925 100644
--- a/playbooks/roles/reboot-limit/tasks/do-reboot.yml
+++ b/playbooks/roles/reboot-limit/tasks/do-reboot.yml
@@ -21,14 +21,140 @@
   become: yes
   become_method: sudo
   command: "systemctl reboot"
+  async: 1
+  poll: 0
   when:
     - reboot_limit_test_type == "systemctl_reboot"
   tags: [ 'run_tests' ]
 
+- name: Wait for system to go down for reboot
+  wait_for:
+    host: "{{ ansible_host }}"
+    port: 22
+    state: stopped
+    delay: 5
+    timeout: 60
+  delegate_to: localhost
+  when:
+    - reboot_limit_test_type == "systemctl_reboot"
+  tags: [ 'run_tests' ]
+
+- name: Wait for system to come back after reboot
+  wait_for:
+    host: "{{ ansible_host }}"
+    port: 22
+    state: started
+    delay: 10
+    timeout: 300
+  delegate_to: localhost
+  when:
+    - reboot_limit_test_type == "systemctl_reboot"
+  tags: [ 'run_tests' ]
+
+# kexec tasks - prepare the kernel for kexec before rebooting
+- name: Get current kernel version for kexec
+  command: uname -r
+  register: current_kernel_version
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+  tags: [ 'run_tests' ]
+
+- name: Check for kernel image locations for kexec
+  stat:
+    path: "{{ item }}"
+  register: kernel_stat
+  with_items:
+    - "/boot/vmlinuz-{{ current_kernel_version.stdout }}"
+    - "/boot/vmlinux-{{ current_kernel_version.stdout }}"
+    - "/boot/kernel-{{ current_kernel_version.stdout }}"
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+    - current_kernel_version is defined
+  tags: [ 'run_tests' ]
+
+- name: Set kernel path for kexec
+  set_fact:
+    kexec_kernel_path: "{{ item.stat.path }}"
+  with_items: "{{ kernel_stat.results }}"
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+    - item.stat.exists
+  tags: [ 'run_tests' ]
+
+- name: Check for initrd/initramfs locations for kexec
+  stat:
+    path: "{{ item }}"
+  register: initrd_stat
+  with_items:
+    - "/boot/initrd.img-{{ current_kernel_version.stdout }}"
+    - "/boot/initramfs-{{ current_kernel_version.stdout }}.img"
+    - "/boot/initrd-{{ current_kernel_version.stdout }}"
+    - "/boot/initrd-{{ current_kernel_version.stdout }}.img"
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+    - current_kernel_version is defined
+  tags: [ 'run_tests' ]
+
+- name: Set initrd path for kexec
+  set_fact:
+    kexec_initrd_path: "{{ item.stat.path }}"
+  with_items: "{{ initrd_stat.results }}"
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+    - item.stat.exists
+  tags: [ 'run_tests' ]
+
+- name: Read current kernel command line for kexec
+  slurp:
+    src: /proc/cmdline
+  register: cmdline_content
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+  tags: [ 'run_tests' ]
+
+- name: Load kernel into kexec
+  become: yes
+  become_method: sudo
+  command: >
+    kexec -l {{ kexec_kernel_path }}
+    --initrd={{ kexec_initrd_path }}
+    --command-line="{{ cmdline_content.content | b64decode | trim }}"
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+    - kexec_kernel_path is defined
+    - kexec_initrd_path is defined
+  tags: [ 'run_tests' ]
+
 - name: Run the reboot test using systemctl kexec
   become: yes
   become_method: sudo
   command: "systemctl kexec"
+  async: 1
+  poll: 0
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+  tags: [ 'run_tests' ]
+
+- name: Wait for system to go down for kexec
+  wait_for:
+    host: "{{ ansible_host }}"
+    port: 22
+    state: stopped
+    delay: 5
+    timeout: 60
+  delegate_to: localhost
+  when:
+    - reboot_limit_test_type == "systemctl_kexec"
+  tags: [ 'run_tests' ]
+
+- name: Wait for system to come back after kexec
+  wait_for:
+    host: "{{ ansible_host }}"
+    port: 22
+    state: started
+    delay: 10
+    timeout: 300
+  delegate_to: localhost
   when:
     - reboot_limit_test_type == "systemctl_kexec"
   tags: [ 'run_tests' ]
-- 
2.47.2


  parent reply	other threads:[~2025-08-11 22:24 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 22:24 [PATCH 00/23] remove old kernel-ci and enhance reboot-limit Luis Chamberlain
2025-08-11 22:24 ` [PATCH 01/23] fstests: remove CONFIG_KERNEL_CI support Luis Chamberlain
2025-08-11 22:24 ` [PATCH 02/23] fstests: remove kernel-ci script symlinks Luis Chamberlain
2025-08-11 22:24 ` [PATCH 03/23] blktests: remove CONFIG_KERNEL_CI support Luis Chamberlain
2025-08-11 22:24 ` [PATCH 04/23] gitr: " Luis Chamberlain
2025-08-11 22:24 ` [PATCH 05/23] ltp: " Luis Chamberlain
2025-08-11 22:24 ` [PATCH 06/23] nfstest: " Luis Chamberlain
2025-08-11 22:24 ` [PATCH 07/23] pynfs: " Luis Chamberlain
2025-08-11 22:24 ` [PATCH 08/23] reboot-limit: convert CONFIG_KERNEL_CI to internal loop feature Luis Chamberlain
2025-08-11 22:24 ` [PATCH 09/23] kconfig: remove CONFIG_KERNEL_CI infrastructure Luis Chamberlain
2025-08-11 22:24 ` [PATCH 10/23] scripts: remove kernel-ci loop infrastructure Luis Chamberlain
2025-08-11 22:24 ` [PATCH 11/23] reboot-limit: simplify what gets selected Luis Chamberlain
2025-08-11 22:24 ` [PATCH 12/23] reboot-limit: add graph visualization support for results Luis Chamberlain
2025-08-11 22:24 ` [PATCH 13/23] reboot-limit: save graphs in organized results/graphs directory Luis Chamberlain
2025-08-11 22:24 ` [PATCH 14/23] docs: add comprehensive reboot-limit workflow documentation Luis Chamberlain
2025-08-11 22:24 ` [PATCH 15/23] reboot-limit: add kexec-tools dependency installation Luis Chamberlain
2025-08-11 22:24 ` [PATCH 16/23] reboot-limit: add A/B testing support targets Luis Chamberlain
2025-08-11 22:24 ` Luis Chamberlain [this message]
2025-08-11 22:24 ` [PATCH 18/23] reboot-limit: add COUNT parameter to override reboot count Luis Chamberlain
2025-08-11 22:24 ` [PATCH 19/23] reboot-limit: fix wait_for tasks using wrong host reference Luis Chamberlain
2025-08-11 22:24 ` [PATCH 20/23] reboot-limit: use ansible reboot module for all reboot types Luis Chamberlain
2025-08-11 22:24 ` [PATCH 21/23] reboot-limit: fix COUNT parameter to properly override reboot count Luis Chamberlain
2025-08-11 22:24 ` [PATCH 22/23] reboot-limit: handle empty dev group gracefully Luis Chamberlain
2025-08-11 22:24 ` [PATCH 23/23] reboot-limit: add kexec comparison feature Luis Chamberlain
2025-08-12 15:06 ` [PATCH 00/23] remove old kernel-ci and enhance reboot-limit Chuck Lever
2025-08-13  1:28   ` Luis Chamberlain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250811222452.2213071-18-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=cel@kernel.org \
    --cc=da.gomez@kruces.com \
    --cc=kdevops@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.