Skip to content

Commit

Permalink
Merge pull request #5414 from iccaszhulili/timer_remove_interface
Browse files Browse the repository at this point in the history
Remove existing interfaces when testing timer
  • Loading branch information
chloerh authored Jan 26, 2024
2 parents 5cfb96d + b284d75 commit 66086ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions libvirt/tests/src/timer_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def set_clock_xml(test, vm, params):
newtimers.append(newtimer)
vmclockxml.timers = newtimers
vmxml.clock = vmclockxml
vmxml.remove_all_device_by_type('interface')
logging.debug("New vm XML:\n%s", vmxml)
vmxml.sync()
# Return timer elements for test verify
Expand All @@ -92,7 +93,7 @@ def vm_clock_source(vm, target, value=''):
clock_file = 'current_clocksource'
else:
exceptions.TestError("Clock source target must be 'available' or 'current'")
session = vm.wait_for_login()
session = vm.wait_for_serial_login()
session.cmd("cd %s" % CLOCK_SOURCE_PATH)
set_clock = False
if value:
Expand Down Expand Up @@ -121,10 +122,11 @@ def get_time(vm=None, time_type=None, windows=False):
:return: Epoch time or timezone
"""
if vm:
session = vm.wait_for_login()
session = vm.wait_for_serial_login()
if time_type == "utc":
cmd = "date -u +%Y/%m/%d/%H/%M/%S"
ts, timestr = session.cmd_status_output(cmd)
logging.debug("VM UTC time is %s", timestr)
elif windows is True:
# Date in this format: Sun 09/14/2014 or 2014/09/14 Sun
# So deal with it after getting date
Expand Down Expand Up @@ -197,7 +199,7 @@ def set_vm_timezone(test, vm, timezone="America/New_York", windows=False):
cmd_o = ''
if not windows:
timezone_file = "/usr/share/zoneinfo/%s" % timezone
session = vm.wait_for_login()
session = vm.wait_for_serial_login()
if session.cmd_status("ls %s" % timezone_file):
session.close()
test.error("Not correct timezone:%s" % timezone_file)
Expand All @@ -214,7 +216,7 @@ def set_vm_timezone(test, vm, timezone="America/New_York", windows=False):
if timezone not in list(timezone_codes.keys()):
test.error("Not supported timezone, please add it.")
cmd = "tzutil /s \"%s\"" % timezone_codes[timezone]
session = vm.wait_for_login()
session = vm.wait_for_serial_login()
cmd_s, cmd_o = session.cmd_status_output(cmd)
session.close()
if cmd_s:
Expand Down Expand Up @@ -303,6 +305,8 @@ def manipulate_vm(vm, operation, params=None):
os.remove(save_path)
except OSError:
pass
vm.cleanup_serial_console()
vm.create_serial_console()
else:
err_msg = "Unsupported operation in this function: %s" % operation
return err_msg
Expand Down Expand Up @@ -347,6 +351,7 @@ def test_timers_in_vm(test, vm, params):

# Set host timezone
set_host_timezone(test, host_tz)
syncup_host_time(test)

# Confirm vm is down for editing
if vm.is_alive():
Expand All @@ -357,7 +362,7 @@ def test_timers_in_vm(test, vm, params):

# Logging vm to set time
vm.start()
vm.wait_for_login()
vm.wait_for_serial_login()
set_vm_timezone(test, vm, vm_tz, windows_test)

# manipulate vm if necessary, linux guest only
Expand Down Expand Up @@ -452,7 +457,7 @@ def test_specific_timer(test, vm, params):
start_error = "yes" == params.get("timer_start_error", "no")
if vm.is_dead():
vm.start()
vm.wait_for_login()
vm.wait_for_serial_login()
# Not config VM clock if the timer is unsupported in VM
config_clock_in_vm = True
for timer in timers:
Expand All @@ -472,7 +477,7 @@ def test_specific_timer(test, vm, params):
# Logging vm to verify whether setting is work
try:
vm.start()
vm.wait_for_login()
vm.wait_for_serial_login()
if start_error:
test.fail("Start vm succeed, but expect fail.")
except virt_vm.VMStartError as detail:
Expand Down Expand Up @@ -522,6 +527,17 @@ def test_specific_timer(test, vm, params):
" while present is yes" % t_name)


def syncup_host_time(test):
"""
Sync up host time to ntp server before testing.
"""
try:
process.run("chronyd -q 'server clock.redhat.com iburst'", shell=True)
process.run("hwclock --systohc", shell=True)
except Exception as e:
logging.error("sync up host time to ntp server error: %s", e)


def run(test, params, env):
"""
Test vm time according timer management of XML configuration.
Expand Down
1 change: 1 addition & 0 deletions spell.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -1230,3 +1230,4 @@ hwrng
buitin
Meina
meili
ntp

0 comments on commit 66086ab

Please sign in to comment.