Skip to content

Commit

Permalink
Added env var TESTLOG to enable logging for end2end tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Nov 16, 2023
1 parent 8ad4796 commit a291af4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ help:
@echo " random - one random choice from the complete list of resources (default)"
@echo " all - the complete list of resources"
@echo " <pattern> - the resources with names matching the regexp pattern"
@echo " TESTLOG=1 - Enable logging for end2end tests"
@echo " PACKAGE_LEVEL - Package level to be used for installing dependent Python"
@echo " packages in 'install' and 'develop' targets:"
@echo " latest - Latest package versions available on Pypi"
Expand Down
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Released: not yet
* Increased minimum zhmcclient version to 1.12.0 to pick up fixes and
functionality. (issue #510)

* Tests: Added an environment variable TESTLOG to enable logging for end2end
tests. (issue #414)

**Cleanup:**

**Known issues:**
Expand Down
8 changes: 5 additions & 3 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ There are two kinds of tests:
* end2end tests: End2end testcases run against an HMC or set of HMCs defined
in an HMC inventory file, with credentials from an HMC vault file.


Running function tests
^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -137,6 +136,8 @@ The positional arguments of the ``tox`` command are passed to ``py.test`` using
its ``-k`` option. Invoke ``py.test --help`` for details on the expression
syntax of its ``-k`` option.

In addition to ``TESTCASES``, the environment variable ``TESTOPTS`` can be
specified for function tests. Invoke ``make help`` for details.

Running end2end tests
^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -199,8 +200,9 @@ Examples:
$ TESTINVENTORY=./hmc_inventory.yaml TESTVAULT=./hmc_vault.yaml make end2end
In addition, the variables ``TESTCASES`` and ``TESTOPTS`` can be specified,
as for function tests. Invoke ``make help`` for details.
In addition to ``TESTHMC``, ``TESTINVENTORY`` and ``TESTVAULT``, the environment
variables ``TESTCASES``, ``TESTOPTS``, ``TESTRESOURCES`` and ``TESTLOG`` can be
specified for end2end tests. Invoke ``make help`` for details.

.. _HMC inventory file: https://python-zhmcclient.readthedocs.io/en/latest/development.html#hmc-inventory-file
.. _HMC vault file: https://python-zhmcclient.readthedocs.io/en/latest/development.html#hmc-vault-file
Expand Down
11 changes: 7 additions & 4 deletions tests/end2end/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
# pylint: enable=line-too-long,unused-import

from .utils import run_zhmc, create_hmc_session, delete_hmc_session, \
is_valid_hmc_session
is_valid_hmc_session, env2bool

urllib3.disable_warnings()

# Enable logging via environment
TESTLOG = env2bool('TESTLOG')


def assert_session_create(
rc, stdout, stderr, hmc_definition, # noqa: F811
Expand Down Expand Up @@ -528,7 +531,7 @@ def test_session_create(
logon_args = prepare_logon_args(logon_opts, hmc_definition)

pdb_ = run == 'pdb'
log = run == 'log'
log = (run == 'log' or TESTLOG)

zhmc_args = logon_args + ['session', 'create']

Expand Down Expand Up @@ -777,7 +780,7 @@ def test_session_delete(
logon_args = prepare_logon_args(logon_opts, hmc_definition)

pdb_ = run == 'pdb'
log = run == 'log'
log = (run == 'log' or TESTLOG)

zhmc_args = logon_args + ['session', 'delete']

Expand Down Expand Up @@ -1032,7 +1035,7 @@ def test_session_command(
logon_args = prepare_logon_args(logon_opts, hmc_definition)

pdb_ = run == 'pdb'
log = run == 'log'
log = (run == 'log' or TESTLOG)

zhmc_args = logon_args + ['cpc', 'list', '--names-only']

Expand Down
11 changes: 11 additions & 0 deletions tests/end2end/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
TEST_PREFIX = 'zhmcclient_tests_end2end'


def env2bool(name):
"""
Evaluate the (string) value of the specified environment variable as a
boolean value and return the result as a bool.
The following variable values are considered True: 'true', 'yes', '1'.
Any other value or if the variable is not set, is considered False.
"""
return os.getenv(name, 'false').lower() in ('true', 'yes', '1')


class End2endTestWarning(UserWarning):
"""
Python warning indicating an issue with an end2end test.
Expand Down

0 comments on commit a291af4

Please sign in to comment.