|
29 | 29 |
|
30 | 30 | import unittest |
31 | 31 | import os |
| 32 | +import time |
32 | 33 |
|
33 | 34 | from common.OpTestSSHConnection import OpTestSSHConnection, OpTestCommandResult |
34 | 35 | from common.OpTestCommandExecutor import OpTestCommandExecutor |
@@ -105,21 +106,42 @@ def runTest(self): |
105 | 106 | continue |
106 | 107 |
|
107 | 108 | if "reboot" in line: |
108 | | - log.info("Reboot command detected - system will restart") |
109 | | - if self.console_thread: |
110 | | - self.console_thread.console_terminate() |
111 | | - self.cv_SYSTEM.goto_state(OpSystemState.OFF) |
112 | | - self.cv_SYSTEM.goto_state(OpSystemState.OS) |
| 109 | + log.info("Reboot command detected - executing reboot and waiting for system to come back") |
113 | 110 |
|
114 | | - # Reconnect after reboot |
| 111 | + # Execute reboot command |
115 | 112 | if use_new_ssh: |
116 | | - executor = self.cv_SYSTEM.cv_HOST.get_command_executor() |
| 113 | + try: |
| 114 | + executor.run_command(line, timeout=10) |
| 115 | + except: |
| 116 | + pass # SSH will disconnect during reboot |
117 | 117 | else: |
118 | | - con = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 118 | + try: |
| 119 | + con.run_command(line, timeout=10) |
| 120 | + except: |
| 121 | + pass # SSH will disconnect during reboot |
| 122 | + |
| 123 | + # Wait for system to reboot and SSH to come back |
| 124 | + log.info("Waiting for system to reboot...") |
| 125 | + time.sleep(60) # Give system time to start rebooting |
| 126 | + |
| 127 | + # Wait for SSH to become available again |
| 128 | + log.info("Waiting for SSH to become available after reboot...") |
| 129 | + max_wait = 300 # 5 minutes |
| 130 | + for i in range(max_wait): |
| 131 | + try: |
| 132 | + if use_new_ssh: |
| 133 | + executor = self.cv_SYSTEM.cv_HOST.get_command_executor() |
| 134 | + executor.run_command("echo 'SSH is back'", timeout=10) |
| 135 | + else: |
| 136 | + con = self.cv_SYSTEM.cv_HOST.get_ssh_connection() |
| 137 | + con.run_command("echo 'SSH is back'", timeout=10) |
| 138 | + log.info(f"SSH reconnected after {i + 60}s") |
| 139 | + break |
| 140 | + except: |
| 141 | + if i % 10 == 0: |
| 142 | + log.info(f"Still waiting for SSH... ({i + 60}s elapsed)") |
| 143 | + time.sleep(1) |
119 | 144 |
|
120 | | - if not use_new_ssh: |
121 | | - self.console_thread = OpSOLMonitorThread(1, "console") |
122 | | - self.console_thread.start() |
123 | 145 | continue |
124 | 146 |
|
125 | 147 | if use_new_ssh: |
|
0 commit comments