Skip to content

Commit

Permalink
Support for logon/logoff and named sessions
Browse files Browse the repository at this point in the history
TODO:

* Testcases for _session_file.py module
* Testcases for _cmd_session.py module

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Dec 27, 2024
1 parent 87a990d commit 821d57b
Show file tree
Hide file tree
Showing 8 changed files with 1,160 additions and 81 deletions.
18 changes: 11 additions & 7 deletions tests/function/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_info_error_no_host(self):
assert_rc(1, rc, stdout, stderr)
assert stdout == ""
assert stderr.startswith(
"Error: No HMC host provided\n"), \
"Error: No HMC host or session in HMC session file provided\n"), \
f"stderr={stderr!r}"

def test_info_error_no_conn(self):
Expand All @@ -80,7 +80,7 @@ def test_info_error_no_conn(self):
# Invoke the command to be tested
rc, stdout, stderr = call_zhmc_child(
['info'],
{'ZHMC_HOST': 'invalid_host'}
{'ZHMC_HOST': 'invalid_host', 'ZHMC_USERID': 'user'}
)

assert_rc(1, rc, stdout, stderr)
Expand Down Expand Up @@ -205,7 +205,8 @@ def test_option_outputformat_table(
"""

faked_session = FakedSession(
'fake-host', hmc_name, hmc_version, api_version)
'fake-host', hmc_name, hmc_version, api_version,
userid='fake-user')
api_version_parts = [int(vp) for vp in api_version.split('.')]
exp_values = {
'hnam': hmc_name,
Expand Down Expand Up @@ -266,7 +267,8 @@ def test_option_outputformat_json(
"""

faked_session = FakedSession(
'fake-host', hmc_name, hmc_version, api_version)
'fake-host', hmc_name, hmc_version, api_version,
userid='fake-user')

args = [out_opt, 'json']
if transpose_opt is not None:
Expand Down Expand Up @@ -325,7 +327,7 @@ def test_option_errorformat(self, err_opt, err_format, exp_stderr_patterns):
# Invoke the command to be tested
rc, stdout, stderr = call_zhmc_child(
err_args + ['info'],
{'ZHMC_HOST': 'invalid_host'}
{'ZHMC_HOST': 'invalid_host', 'ZHMC_USERID': 'user'}
)

assert_rc(1, rc, stdout, stderr)
Expand Down Expand Up @@ -371,7 +373,8 @@ def test_option_log(
"""Test 'zhmc info' with global option --log"""

faked_session = FakedSession(
'fake-host', hmc_name, hmc_version, api_version)
'fake-host', hmc_name, hmc_version, api_version,
userid='fake-user')

# Invoke the command to be tested
rc, stdout, stderr = call_zhmc_inline(
Expand Down Expand Up @@ -404,7 +407,8 @@ def test_option_logdest(
"""Test 'zhmc info' with global option --log-dest (and --log)"""

faked_session = FakedSession(
'fake-host', hmc_name, hmc_version, api_version)
'fake-host', hmc_name, hmc_version, api_version,
userid='fake-user')

args = ['--log', 'api=debug']
logger_name = 'zhmcclient.api' # corresponds to --log option
Expand Down
10 changes: 6 additions & 4 deletions tests/function/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ def call_zhmc_inline(args, env=None, faked_session=None):
env = copy(env)

# Unset the zhmc-specific env vars if not provided
if 'ZHMC_HOST' not in env:
env['ZHMC_HOST'] = None
if 'ZHMC_USERID' not in env:
env['ZHMC_USERID'] = None
if faked_session:
# Communicate the faked session object to the zhmc CLI code.
# It is accessed in CmdContext.execute_cmd().
Expand All @@ -179,7 +175,13 @@ def call_zhmc_inline(args, env=None, faked_session=None):
session_id = 'faked_session:{s}'.format(
s='zhmcclient_mock.zhmccli_faked_session')
env['ZHMC_SESSION_ID'] = session_id
env['ZHMC_HOST'] = faked_session.host
env['ZHMC_USERID'] = faked_session.userid
else:
if 'ZHMC_HOST' not in env:
env['ZHMC_HOST'] = None
if 'ZHMC_USERID' not in env:
env['ZHMC_USERID'] = None
if 'ZHMC_SESSION_ID' not in env:
env['ZHMC_SESSION_ID'] = None

Expand Down
Loading

0 comments on commit 821d57b

Please sign in to comment.