Skip to content

Commit

Permalink
Merge pull request #507 from libhe/master
Browse files Browse the repository at this point in the history
Ensure the VM is fully down before starting the reboot.
  • Loading branch information
libhe authored Jan 16, 2025
2 parents 5a34ae2 + 032aabe commit c2350aa
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions os_tests/tests/test_collect_boot_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,33 +97,48 @@ def test_collect_boot_time(self):
utils_lib.init_connection(self, timeout=self.ssh_timeout)
first_launch_time = utils_lib.getboottime(self)

# Measure reboot time
# Measure reboot time
self.vm.reboot(wait=True)
reboot_start = int(time.time())
new_ip = self.vm.floating_ip
# Ensure the VM is fully down before starting the reboot time measurement
while True:
ret, _ = utils_lib.run_cmd_local(ping_cmd, is_log_ret=True)
if int(ret) != 0:
break
time.sleep(1)

# Measure the time until the VM becomes reachable again
while True:
ret, _ = utils_lib.run_cmd_local(ping_cmd, is_log_ret=True)
reboot_end = int(time.time())
reboot_time = reboot_end - reboot_start
time_to_ping = reboot_end - reboot_start
if int(ret) == 0:
break
self.log.info(f"Time for VM reboot: {reboot_time}s")

time.sleep(60)
if time_to_ping > self.ssh_timeout:
try:
self.vm.get_console_log()
except NotImplementedError:
self.log.info(f"{self.vm.provider} does not implement get_console_log")
self.log.info("Ensure your network settings allow ping before reporting bugs")
self.fail(f"System is not pingable after {self.ssh_timeout}s")
time.sleep(1)
self.log.info(f"Time to become pingable: {time_to_ping}s")

# Measure VM stop time
# Initialize SSH and collect boot time
utils_lib.init_connection(self, timeout=self.ssh_timeout)
reboot_time = utils_lib.getboottime(self)
self.log.info(f"Time for VM reboot: {reboot_time}s")

#Stop-Start VM
self.log.info("Stopping the VM...")
stop_start_time = int(time.time())
self.vm.stop(wait=True)
for _ in utils_lib.iterate_timeout(120, "Timed out waiting for VM to stop."):
if self.vm.is_stopped():
break
time.sleep(30)
stop_end_time = int(time.time())
stop_time = stop_end_time - stop_start_time
self.log.info(f"Time to stop VM: {stop_time}s")

# Measure VM start time
self.log.info("Starting the VM...")
start_start_time = int(time.time())
self.vm.start(wait=True)
Expand All @@ -132,13 +147,22 @@ def test_collect_boot_time(self):
while True:
ret, _ = utils_lib.run_cmd_local(ping_cmd, is_log_ret=True)
start_end_time = int(time.time())
start_time = start_end_time - start_start_time
time_to_ping = start_end_time - start_start_time
if int(ret) == 0:
break
self.log.info(f"Time for VM start: {start_time}s")
if time_to_ping > self.ssh_timeout:
try:
self.vm.get_console_log()
except NotImplementedError:
self.log.info(f"{self.vm.provider} does not implement get_console_log")
self.log.info("Ensure your network settings allow ping before reporting bugs")
self.fail(f"System is not pingable after {self.ssh_timeout}s")
time.sleep(1)
self.log.info(f"Time to become pingable: {time_to_ping}s")

# Initialize SSH and collect VM information
utils_lib.init_connection(self, timeout=self.ssh_timeout)
stop_start_time = utils_lib.getboottime(self)

release = str(utils_lib.run_cmd(self, "cat /etc/system-release"))
kernelVersion = str(utils_lib.run_cmd(self, "uname -r"))
Expand All @@ -158,9 +182,7 @@ def test_collect_boot_time(self):
"InstanceType": self.vm.instance_type,
"FirstLaunchTime(s)": first_launch_time,
"RebootTime(s)": reboot_time,
"StopTime(s)": stop_time,
"StartTime(s)": start_time,
"Stop-StartTime(s)": stop_time + start_time
"Stop-StartTime(s)": stop_start_time
}

# Save information to a CSV file
Expand Down

0 comments on commit c2350aa

Please sign in to comment.