Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP-48198: docs-only: test_filter_xapi_clusterd_db.py: Clean-up long comments #103

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 11 additions & 32 deletions tests/unit/test_filter_xapi_clusterd_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,11 @@
def assert_filter_xapi_clusterd_db(bugtool, original, expected):
"""Assert that filter_xapi_clusterd_db() replaces sensitive strings"""

# -------------------------------------------------------------------------
# Common setup:
# -------------
# - Define the file name of the temporary xAPI clusterd db.
#
# Notes:
# ------
# - To allow for checking of logged errors, the bugtool_log fixture will be used.
#
# - After the test function returns, the bugtool_log fixture checks the log:
#
# The bugtool_log fixture will raise an error if the xen-bugtool.log file
# as unexpected content, and the error message will be printed to stderr.
#
# This way, cases where errors logged by the code under test can be checked.
# -> Common setup: Define the file name of the temporary xAPI clusterd db.
#
temporary_test_clusterd_db = "tmp/xapi_clusterd_db.json"
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# Prepare:
# --------
# -> Prepare:
#
# 1. Write the original xapi-clusterd/db contents to the temporary file
# 2. Patch the bugtool module to use the temporary file for reading the db
Expand All @@ -170,30 +153,26 @@ def assert_filter_xapi_clusterd_db(bugtool, original, expected):
f.write(original)

bugtool.XAPI_CLUSTERD = temporary_test_clusterd_db
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# Act:
# ----
#
# -> Call the filter function
# -> Act: Call the filter function
#
filtered = bugtool.filter_xapi_clusterd_db("_")
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# Assert:
# -------
#
# -> Compare the filtered output with the expected output
# -> Assert: Compare the filtered output with the expected output
#
try:
assert json.loads(filtered) == json.loads(expected)
except ValueError: # For invalid json (to test handing of corrupted db)
assert filtered == expected

# -> Cleanup: Remove the temporary xapi clusterd file
#
# Remove the temporary file for the xapi-clusterd/db contents after the test
# is done. The test fixtures used by the test functions check that the test
# did not cause xen-bugtool to leave any temporary files files behind,
# and this temporary file would also trigger that check.
#
os.remove(temporary_test_clusterd_db)
# -------------------------------------------------------------------------


def test_pems_blobs(isolated_bugtool):
Expand Down
Loading