Skip to content

Commit

Permalink
domtime: update for s390x
Browse files Browse the repository at this point in the history
hwclock is not available on s390x and guest agent operators that
modify the time either.

1. Don't try to restore time (with --now flag) during teardown.
2. Disable test cases that try to modify time.
3. Skip step that uses hwclock.

Signed-off-by: Sebastian Mitterle <[email protected]>
  • Loading branch information
smitterl committed Oct 9, 2024
1 parent 2eb24f1 commit 646938a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
13 changes: 13 additions & 0 deletions libvirt/tests/cfg/virsh_cmd/domain/virsh_domtime.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
start_vm = no
take_regular_screendumps = "no"
vm_stop_duration = 10
s390-virtio:
positive:
only get_time,with_pretty,suspend_vm,managedsave_vm
negative:
only shutdown_vm,get_time_readonly,no_agent_channel,no_agent
restore_time = no
get_local_hw = no
variants:
- positive:
variants:
- get_time:
- with_pretty:
domtime_pretty = yes
- set_time_now:
no s390-virtio
domtime_now = yes
- set_time_sync:
no s390-virtio
domtime_sync = yes
- set_time:
no s390-virtio
domtime_time = 1334567890
- set_time_max_1:
no s390-virtio
domtime_time = 3155731199
- set_time_max_2:
no s390-virtio
domtime_time = 3155759990
- set_time_max_3:
no s390-virtio
domtime_time = 9223372035
- suspend_vm:
suspend_vm = yes
Expand Down
62 changes: 34 additions & 28 deletions libvirt/tests/src/virsh_cmd/domain/virsh_domtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_cmd(session, cmd):
cmd, duration, output.strip())
return output, duration

def get_guest_times(session):
def get_guest_times(session, get_local_hw):
"""
Retrieve different guest time as a dict for checking.
Keys:
Expand All @@ -84,34 +84,37 @@ def get_guest_times(session):
domtime: Guest system time in UTC got from virsh domtime command
:param session: Session from which to access guest
:param get_local_hw: if to use hwclock to get info
"""
times = {}
get_begin = time.time()
# Guest RTC local timezone time
output, _ = run_cmd(session, 'hwclock')
try:
time_str, _ = re.search(r"(.+) (\S+ seconds)", output).groups()

# Guest RTC local timezone time
if get_local_hw:
output, _ = run_cmd(session, 'hwclock')
try:
# output format 1: Tue 01 Mar 2016 01:53:46 PM CST
# Remove timezone info from output
new_str = re.sub(r'\s+\S+$', '', time_str)
times['local_hw'] = datetime.datetime.strptime(
new_str, r"%a %d %b %Y %I:%M:%S %p")
except ValueError:
# There are known three possible output format for `hwclock`
# output format 2: Sat Feb 14 07:31:33 2009
times['local_hw'] = datetime.datetime.strptime(
time_str, r"%a %b %d %H:%M:%S %Y")
except AttributeError:
try: # output format 3: 2019-03-22 05:16:18.224511-04:00
time_str = output.split(".")[0]
times['local_hw'] = datetime.datetime.strptime(
time_str, r"%Y-%m-%d %H:%M:%S")
except ValueError:
test.fail("Unknown hwclock output format in guest: %s", output)
delta = time.time() - get_begin
times['local_hw'] -= datetime.timedelta(seconds=delta)
time_str, _ = re.search(r"(.+) (\S+ seconds)", output).groups()

try:
# output format 1: Tue 01 Mar 2016 01:53:46 PM CST
# Remove timezone info from output
new_str = re.sub(r'\s+\S+$', '', time_str)
times['local_hw'] = datetime.datetime.strptime(
new_str, r"%a %d %b %Y %I:%M:%S %p")
except ValueError:
# There are known three possible output format for `hwclock`
# output format 2: Sat Feb 14 07:31:33 2009
times['local_hw'] = datetime.datetime.strptime(
time_str, r"%a %b %d %H:%M:%S %Y")
except AttributeError:
try: # output format 3: 2019-03-22 05:16:18.224511-04:00
time_str = output.split(".")[0]
times['local_hw'] = datetime.datetime.strptime(
time_str, r"%Y-%m-%d %H:%M:%S")
except ValueError:
test.fail("Unknown hwclock output format in guest: %s", output)
delta = time.time() - get_begin
times['local_hw'] -= datetime.timedelta(seconds=delta)

# Guest system local timezone time
try:
Expand Down Expand Up @@ -353,6 +356,9 @@ def stop_vm():
vm = env.get_vm(vm_name)
readonly = (params.get("readonly_test", "no") == "yes")

restore_time = "yes" == params.get("restore_time", "yes")
get_local_hw = "yes" == params.get("get_local_hw", "yes")

# Backup domain XML
xml_backup = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
try:
Expand All @@ -365,7 +371,7 @@ def stop_vm():
# have day light savings, to affect the time
session.cmd("timedatectl set-timezone Asia/Kolkata")
try:
init_guest_times, _ = get_guest_times(session)
init_guest_times, _ = get_guest_times(session, get_local_hw)
guest_tz_diff = init_guest_times['local_sys'] - init_guest_times['utc_sys']
logging.debug("Timezone diff on guest is %d hours.",
(guest_tz_diff.total_seconds() // 3600))
Expand Down Expand Up @@ -393,7 +399,7 @@ def stop_vm():
org_host_loc_time = datetime.datetime.strptime(time_st, r"%a %b %d %H:%M:%S %Y")

# Get original guest times
org_times, guest_duration = get_guest_times(session)
org_times, guest_duration = get_guest_times(session, get_local_hw)

# Run some operations to stop guest system
stop_time = stop_vm()
Expand All @@ -410,7 +416,7 @@ def stop_vm():

if not shutdown:
# Get current guest times
cur_times, _ = get_guest_times(session)
cur_times, _ = get_guest_times(session, get_local_hw)

check_time(res, org_times, cur_times)
finally:
Expand All @@ -420,7 +426,7 @@ def stop_vm():
utils_time.sync_timezone_linux(vm)
# Sync guest time with host
if channel and agent and not shutdown:
res = virsh.domtime(vm_name, now=True)
res = virsh.domtime(vm_name, now=restore_time)
if res.exit_status:
session.close()
test.error("Failed to recover guest time:\n%s"
Expand Down

0 comments on commit 646938a

Please sign in to comment.