Skip to content

Commit

Permalink
Merge pull request #828 from lionriver/lgr_socket_timeput
Browse files Browse the repository at this point in the history
Support SMAPI timeout configuration
  • Loading branch information
jichenjc authored Jul 9, 2024
2 parents 3fe4038 + 9f7d668 commit bd0601c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
25 changes: 25 additions & 0 deletions doc/source/zvmsdk.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,31 @@
#remotehost_sshd_port=22


#
# The timeout value for a long-duration SMAPI socket is specified in seconds.
#
# The default value is 900 seconds.
#
# SMAPIs are socket-based systems management application programming interfaces.
# If the SMAPI socket connection of a long-duration operation exceeds this timeout,
# the SMAPI long-duration operation will fail.
#
# This param is optional
#smapi_socket_long_call_timeout_seconds=900


#
# The timeout value for a general SMAPI socket is specified in seconds.
#
# The default value is 240 seconds.
#
# SMAPIs are socket-based systems management application programming interfaces.
# If the SMAPI socket connection exceeds this timeout, the SMAPI operation will fail.
#
# This param is optional
#smapi_socket_timeout_seconds=240


#
# If configure the dasd group, the user can configure `swap_default_with_mdisk`
# to create swap device with MDISK or VDISK, the default value `True` means create
Expand Down
3 changes: 2 additions & 1 deletion smtLayer/tests/unit/test_vmUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ def test_getVM_directory_py3(self):
self.assertEqual(res['response'], expected_resp)
exec_cmd.assert_called_once_with(
['sudo', '/opt/zthin/bin/smcli', 'Image_Query_DM',
'--addRCheader', '-T', 'fakeuid'], close_fds=True)
'--addRCheader', '-T', 'fakeuid',
'--timeout', '240'], close_fds=True)
33 changes: 33 additions & 0 deletions smtLayer/vmUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@
from smtLayer import msgs
from smtLayer import vmStatus

from zvmsdk import config

modId = 'VMU'
version = '1.0.0' # Version of this script

DEFAULT_SMAPI_SOCKET_LONG_CALL_TIMEOUT_SECONDS = 900
DEFAULT_SMAPI_SOCKET_TIMEOUT_SECONDS = 240


def disableEnableDisk(rh, userid, vaddr, option):
"""
Expand Down Expand Up @@ -692,6 +697,11 @@ def invokeSMCLI(rh, api, parms, hideInLog=[]):
values or contain too few words then one or more error
messages are generated. THIS SHOULD NEVER OCCUR !!!!
"""
# APIs requiring a long-duration socket connection
# currently, only VMRELOCATE operation is defined as ong-duration
# VMRELOCATE operation is called when resizing or migrating
SOCKET_LONG_CALL_APIS = ('VMRELOCATE')

if len(hideInLog) == 0:
rh.printSysLog("Enter vmUtils.invokeSMCLI, userid: " +
rh.userid + ", function: " + api +
Expand Down Expand Up @@ -720,6 +730,29 @@ def invokeSMCLI(rh, api, parms, hideInLog=[]):
cmd.append(api)
cmd.append('--addRCheader')

if api in SOCKET_LONG_CALL_APIS:
# add the --timeout argument for long-duration SMAPI
# the timeout value is read from zvmsdk.conf
rh.printSysLog("Setting timeout for long-duration APIs...")
if config.CONF.zvm.smapi_socket_long_call_timeout_seconds:
lgr_socket_timeput = config.CONF.zvm.smapi_socket_long_call_timeout_seconds
elif config.CONF.zvm.smapi_socket_timeout_seconds:
lgr_socket_timeput = config.CONF.zvm.smapi_socket_timeout_seconds
else:
lgr_socket_timeput = DEFAULT_SMAPI_SOCKET_LONG_CALL_TIMEOUT_SECONDS
rh.printSysLog("long-duration timeout = " + str(lgr_socket_timeput))
parms.extend(["--timeout", str(lgr_socket_timeput)])
else:
# add the --timeout argument for general SMAPI
# whose value is read from zvmsdk.conf
rh.printSysLog("Setting timeout for general APIs...")
if config.CONF.zvm.smapi_socket_timeout_seconds:
lgr_socket_timeput = config.CONF.zvm.smapi_socket_timeout_seconds
else:
lgr_socket_timeput = DEFAULT_SMAPI_SOCKET_TIMEOUT_SECONDS
rh.printSysLog("general timeout = " + str(lgr_socket_timeput))
parms.extend(["--timeout", str(lgr_socket_timeput)])

status = vmStatus.GetSMAPIStatus()

try:
Expand Down
29 changes: 29 additions & 0 deletions zvmsdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,35 @@ def __init__(self, opt_name, section='default',
Sample root disk in user directory:
MDISK 0100 <disktype> <start> <end> <volumelabel> <readwrite>
'''),
Opt('smapi_socket_timeout_seconds',
section='zvm',
required=False,
default=240,
opt_type='int',
help='''
The timeout value for a general SMAPI socket is specified in seconds.
The default value is 240 seconds.
SMAPIs are socket-based systems management application programming interfaces.
If the SMAPI socket connection exceeds this timeout, the SMAPI operation will fail.
'''
),
Opt('smapi_socket_long_call_timeout_seconds',
section='zvm',
required=False,
default=900,
opt_type='int',
help='''
The timeout value for a long-duration SMAPI socket is specified in seconds.
The default value is 900 seconds.
SMAPIs are socket-based systems management application programming interfaces.
If the SMAPI socket connection of a long-duration operation exceeds this timeout,
the SMAPI long-duration operation will fail.
'''
),
# tests options
Opt('images',
section='tests',
Expand Down
12 changes: 9 additions & 3 deletions zvmsdk/smtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ def _is_smt_internal_error(results):

rc = results.get('rc', 0)
if rc in [-110, -102, -103, -108]:
msg += ("This is likely to be caused by temporary z/VM "
"SMAPI down issue, Contact with your z/VM "
"administrators for further help")
if rc == -108:
msg += ("This is likely to be caused by too short timeout "
"specified for z/VM SMAPI. Update SMAPI timeout "
"configuration in zvmsdk.conf. Contact with your z/VM "
"administrators for further help")
else:
msg += ("This is likely to be caused by temporary z/VM "
"SMAPI down issue, Contact with your z/VM "
"administrators for further help")

raise exception.SDKInternalError(msg=msg,
modID='smt',
Expand Down

0 comments on commit bd0601c

Please sign in to comment.