From 614cfa191670598c664c69b62b3b372d9b6a7f17 Mon Sep 17 00:00:00 2001 From: zpetrace Date: Thu, 1 Aug 2024 14:07:40 +0200 Subject: [PATCH] feat(test): Adding betelgeuse docstrings to test_client.py --- integration-tests/README.md | 139 +++++++++++++++++++++++++++++++ integration-tests/test_client.py | 109 +++++++++++++++++++----- 2 files changed, 227 insertions(+), 21 deletions(-) create mode 100644 integration-tests/README.md diff --git a/integration-tests/README.md b/integration-tests/README.md new file mode 100644 index 00000000..c3793ade --- /dev/null +++ b/integration-tests/README.md @@ -0,0 +1,139 @@ +# Running Betelgeuse + +## Requirement command +Requirement command generates an XML file that can be imported by the **Requirement XML Importer**. It reads the Python test suite source code and generated XML file with all the information necessary. + +**Requirements must be created in order to link test cases to them** + +```console +$ betelgeuse requirement\ + --assignee assignee\ + --approver approver1\ + sample_project/tests\ + PROJECT\ + betelgeuse-requirements.xml +``` + +## Test-case command +Command generates an XML file suited to be imported by the **Test Case XML Importer**. It reads the Python test suite source code and generated XML file with all the information necessary. + +The `test-case` requires: + +- The path to the Python test suite source code +- The Polarion project ID +- The output XML file path (will be overwritten if exists) + +It is also highly recommended to use `--response-property` as it will then be easier to monitor the importer messages + +Example: + +```console +$ betelgeuse test-case \ + --automation-script-format "https://github.com/SatelliteQE/betelgeuse/tree/master/{path}#L{line_number}" \ + sample_project/tests \ + PROJECT \ + betelgeuse-test-cases.xml +``` + +## Test-results command +Command gives a summary of test cases/results in the given jUnit XML file + +```console +$ betelgeuse test-results --path \ +sample_project/results/sample-junit-result.xml + +Passed: 1 +``` + +## Test-run command +Command generates an XML file suited to be imported by the **Test Run XML Importer**. + +It takes: + +- A valid xUnit XML file +- A Python test suite where test case IDs can be found + +And generates a resulting XML file with all the information necessary. + +It requires: + +- The path to the xUnit XML file +- The path to the Python test suite source code +- The Polarion user ID +- The Polarion project ID +- The output XML file path (will be overwritten if exists) + +It is also highly recommended to use `--response-property` as it will then be easier to monitor the importer messages + +Example: + +```console +$ betelgeuse test-run \ + --response-property property_key=property_value \ + sample_project/results/sample-junit-result.xml \ + sample_project/tests/ \ + testuser \ + PROJECT \ + betelgeuse-test-run.xml +``` + +NOTE: + +`--dry-run` can be used as following: + +```console +$ betelgeuse test-run --dry-run --help +Usage: betelgeuse test-run [OPTIONS] JUNIT_PATH SOURCE_CODE_PATH USER PROJECT + OUTPUT_PATH + + Generate an XML suited to be importer by the test-run importer. + + This will read the jUnit XML at JUNIT_PATH and the source code at + SOURCE_CODE_PATH in order to generate a XML file place at OUTPUT_PATH. The + generated XML file will be ready to be imported by the XML Test Run + Importer. + + The test run will be created on the project ID provided by PROJECT and will + be assigned to the Polarion user ID provided by USER. + + Other test run options can be set by the various options this command + accepts. Check their help for more information. +``` + +Options: + +```console + --collect-ignore-path PATH Ignore path during test collection. This + option can be specified multiple times. + --create-defects Specify to make the importer create defects + for failed tests. + --custom-fields TEXT Indicates to the importer which custom + fields should be set. Expected format is + either id=value or JSON format + {"id":"value"}. This option can be specified + multiple times. + --dry-run Indicate to the importer to not make any + change. + --lookup-method [id|custom] Indicates to the importer which lookup + method to use. "id" for work item id or + "custom" for custom id (default). + --lookup-method-custom-field-id TEXT + Indicates to the importer which field ID to + use when using the custom id lookup method. + --no-include-skipped Specify to make the importer not import + skipped tests. + --project-span-ids TEXT A comma-separated list of project IDs used + to set the project span field on the test + run. + --response-property TEXT When defined, the impoter will mark all + responses with the selector.The format is " + --response-property + property_key=property_value". + --status [finished|inprogress] Define which status the test run should be + set: "Finished" (default)or "In Progress" + --test-run-group-id TEXT Test Run GROUP ID to be created/updated. + --test-run-id TEXT Test Run ID to be created/updated. + --test-run-template-id TEXT Test Run template ID. + --test-run-title TEXT Test Run title. + --test-run-type-id TEXT Test Run type ID. +``` \ No newline at end of file diff --git a/integration-tests/test_client.py b/integration-tests/test_client.py index 4d69ef2e..42795c40 100644 --- a/integration-tests/test_client.py +++ b/integration-tests/test_client.py @@ -5,12 +5,29 @@ import pytest import conftest +""" +:requirement: RHSS-291297 +:subsystemteam: sst_csi_client_tools +:caseautomation: Automated +:upstream: Yes +""" + @pytest.mark.usefixtures("register_subman") def test_client_files_permission(insights_client): - """Verify that permission for lastupload file is 0644: - file /etc/insights-client/.lastupload - Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1924990 + """ + :title: Verify Client Files Permission + :description: Verify that the permission for the last upload file + '/etc/insights-client'/.lastupload is set to 0644 + :tier: Tier 0 + :steps: + 1. Remove /etc/insights-client/.lastupload if it exists + 2. Register insights-client + 3. Verify the file permissions + :expected results: + 1. The file /etc/insights-client/.lastupload does not exist + 2. The insights-client registers successfully + 3. The permission of /etc/insights-client/.lastupload is set to 0644 """ file_last_upload = "/etc/insights-client/.lastupload" with contextlib.suppress(FileNotFoundError): @@ -46,7 +63,15 @@ def rpm_ql_insights_client(): ) def test_client_rpm_mandatory_files(filename, rpm_ql_insights_client): """ - Verify the existence of mandatory files for insights-client rpm + :title: Verify mandatory files for RPM + :description: Verify the existence of mandatory files for the insights-client RPM + :tier: Tier 0 + :steps: + 1. List all files in the insights-client RPM package + 2. Check if each mandatory file existsin the package + :expected results: + 1. A list of files is generated + 2. All of the mandatory files are present in the RPM """ assert ( filename in rpm_ql_insights_client @@ -55,9 +80,17 @@ def test_client_rpm_mandatory_files(filename, rpm_ql_insights_client): @pytest.mark.usefixtures("register_subman") def test_client_logfiles_mask(insights_client): - """Verify that files in /var/log/insights-client have the right mode: 0600 - - Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1955724 + """ + :title: Verify Client logfiles Mask + :description: Verify that the log files in + /var/log/insights-client have the correct mode 0600 + :tier: Tier 0 + :steps: + 1. Register the insights-client to generate log files + 2. Check the file permission of each log file generated + :expected results: + 1. Insights-client is registered and log files are generated + 2. The file permissions for all log files are 0600 """ # It is necessary to perform some command using insights-client # to populate logs @@ -68,8 +101,13 @@ def test_client_logfiles_mask(insights_client): def test_client_logdir_permissions(): - """Verify that permissions on directory /var/log/insights-client - have the right mode: 0700 + """ + :title: Verify log directory permissions + :description: Verify that the permissions on the directory + /var/log/insights-client are set to 0700 + :tier: Tier 0 + :steps: Check the directory permissions of /var/log/insights-client + :expected results: The directory permissions are set to 0700 """ logdir_name = "/var/log/insights-client" assert oct(os.stat(logdir_name).st_mode & 0o777) == "0o700" @@ -78,15 +116,23 @@ def test_client_logdir_permissions(): @pytest.mark.usefixtures("register_subman") def test_verify_logrotate_feature(insights_client): """ - Verify that the standard logrotate works for insights-client - Ref : https://bugzilla.redhat.com/show_bug.cgi?id=1940267 - - Test Steps: - 1 - Perform register and payload operation to ensure both - insights-client.log and insights-client-payload.log files have logs - 2 - Rotate logs by running logrotate command on CLI for insights-client - 3 - Verify insights-client.log and insights-client-payload.log size is 0B - 4 - Verify rotated files are created in log dir by comparing number of log files + :title: Verify Logrotate feature + :description: Verify that the logrotate works properly for insights-client + :tier: Tier 1 + :steps: + 1. Ensure the logrotate configuration file exists + 2. Register insights-client and perform pazload operations + 3. Run the logrotate command + 4. Verify that 2 new log files were created + 5. Verify the size of insights-client.log + 6. Verify the size of insights-client-payload.log + :expected results: + 1. The logrotate config file exists + 2. The insights-client registers successfully and logs are populated + 3. The logrotate command is executed successfully + 4. Two new log files were created + 5. The size is 0B + 6. The size is 0B """ logrotate_conf_file_path = "/etc/logrotate.d/insights-client" @@ -131,8 +177,19 @@ def test_verify_logrotate_feature(insights_client): @pytest.mark.usefixtures("register_subman") def test_insights_details_file_exists(insights_client): """ - This test verifies that /var/lib/insights/insights-details.json exists - when --check-results is called + :title: Verify insights-client details file exists + :description: Verify that the file /var/lib/insights/insights-client.json exists + :tier: Tier 0 + :steps: + 1. Register the insights-client + 2. Delete /var/lib/insights/insights-client.json if it exists + 3. run the --check-results command + 4. Verify the existence of /var/lib/insights/insights-client.json + :expected results: + 1. Insights-client is registrated + 2. The file /var/lib/insights/insights-client.json does not exists + 3. The --check-results command is executed successfully + 4. The file /var/lib/insights/insights-client.json exists """ output_file = "/var/lib/insights/insights-details.json" insights_client.register() @@ -149,7 +206,17 @@ def test_insights_details_file_exists(insights_client): @pytest.mark.usefixtures("register_subman") def test_insights_directory_files(insights_client): """ - Test that /var/lib/insights have content available + :title: Verify insights directory files + :description: Verify that the /var/lib/insights directory has the expected content + :tier: Tier 0 + :steps: + 1. Register the insights-client + 2. Check the content of /var/lib/insights directory + 3. Verify specific files exists + :expected results: + 1. Insights-client is registered + 2. The list of contents of /var/lib/insights directory is created + 3. All specified files are present """ directory = "/var/lib/insights" registered_contents = [