diff --git a/Makefile b/Makefile index 207a3c1081e..d88035e17c6 100644 --- a/Makefile +++ b/Makefile @@ -47,6 +47,9 @@ help: @echo " logs-join to join xdist log files into one" @echo " logs-clean to delete all xdist log files in the root" @echo " pyc-clean to delete all temporary artifacts" + @echo " uuid-check to check for duplicated @id: in testimony docstring tags" + @echo " uuid-replace-empty to replace empty @id: with new generated uuid" + @echo " uuid-replace-duplicate to replace duplicated @id: with new generated uuid" docs: @cd docs; $(MAKE) html @@ -54,7 +57,7 @@ docs: docs-clean: @cd docs; $(MAKE) clean -test-docstrings: +test-docstrings: uuid-check testimony $(TESTIMONY_OPTIONS) validate tests/foreman/api testimony $(TESTIMONY_OPTIONS) validate tests/foreman/cli testimony $(TESTIMONY_OPTIONS) validate tests/foreman/rhci @@ -124,6 +127,15 @@ logs-join: logs-clean: -rm -f robottelo_gw*.log +uuid-check: ## list duplicated uuids + scripts/check_duplicate_uuids.sh + +uuid-replace-duplicate: ## list duplicated uuids + scripts/replace_dup_uuids.sh + +uuid-replace-empty: ## list duplicated uuids + scripts/replace_empty_uuids.sh + # Special Targets ------------------------------------------------------------- .PHONY: help docs docs-clean test-docstrings test-robottelo \ @@ -131,4 +143,5 @@ logs-clean: test-foreman-rhai test-foreman-rhci test-foreman-tier1 \ test-foreman-tier2 test-foreman-tier3 test-foreman-tier4 \ test-foreman-ui test-foreman-ui-xvfb test-foreman-endtoend \ - graph-entities lint logs-join logs-clean pyc-clean + graph-entities lint logs-join logs-clean pyc-clean \ + uuid-check uuid-replace-duplicate uuid-replace-empty diff --git a/scripts/check_duplicate_uuids.sh b/scripts/check_duplicate_uuids.sh new file mode 100755 index 00000000000..e8b81f9e0e2 --- /dev/null +++ b/scripts/check_duplicate_uuids.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# This script checks duplicated or empty uuids and exit with 1 if found + +# finds occurrences of empty @id: testimony tags +grep -E -i -r -n "@id:(.+[[:blank:]]|$)" tests/foreman/ +EMPTY=$? + +if [ $EMPTY = 0 ]; then + echo "Empty @id found in testimony tags" + exit 1 +fi + +# Finds occurrences of @id: in testimony tags then +# sort the output and filters only the duplicated +# then looks for existence of "@id:" in final output +# NOTE: can't print the line number -n here because of uniq -d +grep -r -i "@id:" tests/foreman/ | sort | uniq -d | grep "@id:" +DUPLICATE=$? + +# grep exits with status code 0 if text is found +# but we need to invert the logic here +# if duplicate found return with error 1 +if [ $DUPLICATE = 0 ]; then + echo "Duplicate @id found in testimony tags" + exit 1 +fi diff --git a/scripts/replace_dup_uuids.sh b/scripts/replace_dup_uuids.sh new file mode 100755 index 00000000000..77a1097e7d3 --- /dev/null +++ b/scripts/replace_dup_uuids.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# This script finds duplicated @id and replaces with new uuids + +grep -r -i "@id:" tests/foreman/ | sort | uniq -d | grep "@id:" | while read -r line ; do + OLDIFS=$IFS + IFS=':' read -r dup_file dup_id <<< $line + echo "filename: $dup_file" + echo "Id to replace: $dup_id" + NEW_ID=$(uuidgen) + echo "Replacing with the new id: $NEW_ID" + LAST_LINE=$(grep -i -n "$dup_id" $dup_file | tail -1) + + IFS=':' read -r linenumber linecontent <<< $LAST_LINE + echo $linenumber + trimmed_linecontent=$(echo $linecontent) + sed -i "${linenumber}s/${trimmed_linecontent}/@id: ${NEW_ID}/g" $dup_file + echo "----------------------------------------------------------------" + IFS=$OLDIFS +done diff --git a/scripts/replace_empty_uuids.sh b/scripts/replace_empty_uuids.sh new file mode 100755 index 00000000000..1bb96ec2418 --- /dev/null +++ b/scripts/replace_empty_uuids.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# this script finds empty @id: and replace with new uuids + +# finds occurrences of empty @id: testimony tags +EMPTY_IDS=$(grep -E -i -r -n "@id:(.+[[:blank:]]|$)" tests/foreman/) + +if [ -n "$EMPTY_IDS" ]; then + echo "Generating new UUIDS for empty @id tags..." +else + echo "No empty @id was found" +fi + +# iterate if any empty @id found +for output_line in $EMPTY_IDS +do + if (echo "$output_line" | grep "tests/foreman"); then + OLDIFS=$IFS + # splits the grep output to get filename and occurence line number + IFS=':' read -r filename line <<< $output_line + # generate uuid and place in specific line number + sed -r -i "${line}s/@id:(.+[[:blank:]]|$)/@id: $(uuidgen)/g" $filename + IFS=$OLDIFS + fi +done diff --git a/tests/foreman/api/test_repository.py b/tests/foreman/api/test_repository.py index 10e93268c00..9765acd5ad1 100644 --- a/tests/foreman/api/test_repository.py +++ b/tests/foreman/api/test_repository.py @@ -981,7 +981,7 @@ def test_positive_create_ostree(self): def test_positive_update_name(self): """Update ostree repository name. - @id: 6dff0c90-170f-40b9-9347-8ec97d89f2fd + @id: 4d9f1418-cc08-4c3c-a5dd-1d20fb9052a2 @Assert: The repository name is updated. """ diff --git a/tests/foreman/api/test_variables.py b/tests/foreman/api/test_variables.py index b42421ed43f..8bb3cfe092d 100644 --- a/tests/foreman/api/test_variables.py +++ b/tests/foreman/api/test_variables.py @@ -312,7 +312,7 @@ def test_positive_create_matcher_empty_value(self): def test_negative_create_matcher_empty_value(self): """Create matcher with empty value with type other than string - @id: a90b5bcd-f76c-4663-bf41-2f96e7e15c0f + @id: ad24999f-1bed-4abb-a01f-3cb485d67968 @steps: diff --git a/tests/foreman/cli/test_hostgroup.py b/tests/foreman/cli/test_hostgroup.py index f7d2b263c0f..095eefc74f3 100644 --- a/tests/foreman/cli/test_hostgroup.py +++ b/tests/foreman/cli/test_hostgroup.py @@ -217,7 +217,7 @@ def test_positive_create_with_domain(self): def test_positive_create_with_lifecycle_environment(self): """Check if hostgroup with lifecyle environment can be created - @id: c468fcac-9e42-4ee6-a431-abe29b6848ce + @id: 24bc3010-4e61-47d8-b8ae-0d66e1055aea @Assert: Hostgroup should be created and has lifecycle env assigned @@ -239,7 +239,7 @@ def test_positive_create_with_orgs_and_lce(self): """Check if hostgroup with multiple organizations can be created if one of them is associated with lifecycle environment - @id: 32be4630-0032-4f5f-89d4-44f8d05fe585 + @id: ca110a74-401d-48f9-9700-6c57f1c10f11 @Assert: Hostgroup is created, has both new organizations assigned and has lifecycle env assigned diff --git a/tests/foreman/ui/test_contenthost.py b/tests/foreman/ui/test_contenthost.py index 5d97a68a415..b8e9ec5a841 100644 --- a/tests/foreman/ui/test_contenthost.py +++ b/tests/foreman/ui/test_contenthost.py @@ -216,7 +216,7 @@ def test_positive_remove_package_group(self): def test_positive_install_errata(self): """Install a errata to a host remotely - @id: 13b9422d-4b7a-4068-9a57-a94602cd6410 + @id: b69b9797-3c0c-42cd-94ed-3f751bb9b24c @assert: Errata was successfully installed diff --git a/tests/foreman/ui/test_hostcollection.py b/tests/foreman/ui/test_hostcollection.py index c30cdd41c99..854dc8d7155 100644 --- a/tests/foreman/ui/test_hostcollection.py +++ b/tests/foreman/ui/test_hostcollection.py @@ -632,7 +632,7 @@ def test_positive_remove_package_group(self): def test_positive_install_errata(self): """Install an errata to the hosts inside host collection remotely - @id: 5a6fff0a-686f-419b-a773-4d03713e47e9 + @id: 69c83000-0b46-4735-8c03-e9e0b48af0fb @Assert: Errata was successfully installed in all the hosts in host collection diff --git a/tests/foreman/ui/test_remoteexecution.py b/tests/foreman/ui/test_remoteexecution.py index a0e2a4dcc26..f83188dcb7b 100644 --- a/tests/foreman/ui/test_remoteexecution.py +++ b/tests/foreman/ui/test_remoteexecution.py @@ -410,7 +410,7 @@ def test_positive_run_default_job_template(self): def test_positive_run_custom_job_template(self): """Run a job template against a single host - @id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217 + @id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7 @Setup: Create a working job template. diff --git a/tests/foreman/ui/test_repository.py b/tests/foreman/ui/test_repository.py index f4a6c007a3b..0d5d547d2f4 100644 --- a/tests/foreman/ui/test_repository.py +++ b/tests/foreman/ui/test_repository.py @@ -678,7 +678,7 @@ def test_positive_download_policy_displayed_for_yum_repos(self): def test_positive_create_with_download_policy(self): """Create YUM repositories with available download policies - @id: 8037a68b-66b8-4b42-a80b-fb08495f948d + @id: 8099fb98-963d-4370-bf51-6807f5efd6d3 @Assert: YUM repository with a download policy is created """