Skip to content

Commit 26eb14d

Browse files
committed
Added scripts to validate and fix duplicated and empty @ids
closes SatelliteQE#3834 closes SatelliteQE#3735
1 parent 7e72f58 commit 26eb14d

11 files changed

+95
-10
lines changed

Makefile

+15-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ help:
4747
@echo " logs-join to join xdist log files into one"
4848
@echo " logs-clean to delete all xdist log files in the root"
4949
@echo " pyc-clean to delete all temporary artifacts"
50+
@echo " uuid-check to check for duplicated @id: in testimony docstring tags"
51+
@echo " uuid-replace-empty to replace empty @id: with new generated uuid"
52+
@echo " uuid-replace-duplicate to replace duplicated @id: with new generated uuid"
5053

5154
docs:
5255
@cd docs; $(MAKE) html
5356

5457
docs-clean:
5558
@cd docs; $(MAKE) clean
5659

57-
test-docstrings:
60+
test-docstrings: uuid-check
5861
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/api
5962
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/cli
6063
testimony $(TESTIMONY_OPTIONS) validate tests/foreman/rhci
@@ -124,11 +127,21 @@ logs-join:
124127
logs-clean:
125128
-rm -f robottelo_gw*.log
126129

130+
uuid-check: ## list duplicated uuids
131+
scripts/check_duplicate_uuids.sh
132+
133+
uuid-replace-duplicate: ## list duplicated uuids
134+
scripts/replace_dup_uuids.sh
135+
136+
uuid-replace-empty: ## list duplicated uuids
137+
scripts/replace_empty_uuids.sh
138+
127139
# Special Targets -------------------------------------------------------------
128140

129141
.PHONY: help docs docs-clean test-docstrings test-robottelo \
130142
test-robottelo-coverage test-foreman-api test-foreman-cli \
131143
test-foreman-rhai test-foreman-rhci test-foreman-tier1 \
132144
test-foreman-tier2 test-foreman-tier3 test-foreman-tier4 \
133145
test-foreman-ui test-foreman-ui-xvfb test-foreman-endtoend \
134-
graph-entities lint logs-join logs-clean pyc-clean
146+
graph-entities lint logs-join logs-clean pyc-clean \
147+
uuid-check uuid-replace-duplicate uuid-replace-empty

scripts/check_duplicate_uuids.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
# This script checks duplicated or empty uuids and exit with 1 if found
4+
5+
# finds occurrences of empty @id: testimony tags
6+
grep -E -i -r -n "@id:(.+[[:blank:]]|$)" tests/foreman/
7+
EMPTY=$?
8+
9+
if [ $EMPTY = 0 ]; then
10+
echo "Empty @id found in testimony tags"
11+
exit 1
12+
fi
13+
14+
# Finds occurrences of @id: in testimony tags then
15+
# sort the output and filters only the duplicated
16+
# then looks for existence of "@id:" in final output
17+
# NOTE: can't print the line number -n here because of uniq -d
18+
grep -r -i "@id:" tests/foreman/ | sort | uniq -d | grep "@id:"
19+
DUPLICATE=$?
20+
21+
# grep exits with status code 0 if text is found
22+
# but we need to invert the logic here
23+
# if duplicate found return with error 1
24+
if [ $DUPLICATE = 0 ]; then
25+
echo "Duplicate @id found in testimony tags"
26+
exit 1
27+
fi

scripts/replace_dup_uuids.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# This script finds duplicated @id and replaces with new uuids
4+
5+
grep -r -i "@id:" tests/foreman/ | sort | uniq -d | grep "@id:" | while read -r line ; do
6+
OLDIFS=$IFS
7+
IFS=':' read -r dup_file dup_id <<< $line
8+
echo "filename: $dup_file"
9+
echo "Id to replace: $dup_id"
10+
NEW_ID=$(uuidgen)
11+
echo "Replacing with the new id: $NEW_ID"
12+
LAST_LINE=$(grep -i -n "$dup_id" $dup_file | tail -1)
13+
14+
IFS=':' read -r linenumber linecontent <<< $LAST_LINE
15+
echo $linenumber
16+
trimmed_linecontent=$(echo $linecontent)
17+
sed -i~ "${linenumber}s/${trimmed_linecontent}/@id: ${NEW_ID}/g" $dup_file
18+
echo "----------------------------------------------------------------"
19+
IFS=$OLDIFS
20+
done

scripts/replace_empty_uuids.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# this script finds empty @id: and replace with new uuids
4+
5+
# finds occurrences of empty @id: testimony tags
6+
EMPTY_IDS=$(grep -E -i -r -n "@id:(.+[[:blank:]]|$)" tests/foreman/)
7+
8+
if [ -n "$EMPTY_IDS" ]; then
9+
echo "Generating new UUIDS for empty @id tags..."
10+
else
11+
echo "No empty @id was found"
12+
fi
13+
14+
# iterate if any empty @id found
15+
for output_line in $EMPTY_IDS
16+
do
17+
if (echo "$output_line" | grep "tests/foreman"); then
18+
OLDIFS=$IFS
19+
# splits the grep output to get filename and occurrence line number
20+
IFS=':' read -r filename line <<< $output_line
21+
# generate uuid and place in specific line number
22+
sed -r -i~ "${line}s/@id:(.+[[:blank:]]|$)/@id: $(uuidgen)/g" $filename
23+
IFS=$OLDIFS
24+
fi
25+
done

tests/foreman/api/test_repository.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ def test_positive_create_ostree(self):
981981
def test_positive_update_name(self):
982982
"""Update ostree repository name.
983983
984-
@id: 6dff0c90-170f-40b9-9347-8ec97d89f2fd
984+
@id: 4d9f1418-cc08-4c3c-a5dd-1d20fb9052a2
985985
986986
@Assert: The repository name is updated.
987987
"""

tests/foreman/api/test_variables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def test_positive_create_matcher_empty_value(self):
312312
def test_negative_create_matcher_empty_value(self):
313313
"""Create matcher with empty value with type other than string
314314
315-
@id: a90b5bcd-f76c-4663-bf41-2f96e7e15c0f
315+
@id: ad24999f-1bed-4abb-a01f-3cb485d67968
316316
317317
@steps:
318318

tests/foreman/cli/test_hostgroup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def test_positive_create_with_domain(self):
217217
def test_positive_create_with_lifecycle_environment(self):
218218
"""Check if hostgroup with lifecyle environment can be created
219219
220-
@id: c468fcac-9e42-4ee6-a431-abe29b6848ce
220+
@id: 24bc3010-4e61-47d8-b8ae-0d66e1055aea
221221
222222
@Assert: Hostgroup should be created and has lifecycle env assigned
223223
@@ -239,7 +239,7 @@ def test_positive_create_with_orgs_and_lce(self):
239239
"""Check if hostgroup with multiple organizations can be created
240240
if one of them is associated with lifecycle environment
241241
242-
@id: 32be4630-0032-4f5f-89d4-44f8d05fe585
242+
@id: ca110a74-401d-48f9-9700-6c57f1c10f11
243243
244244
@Assert: Hostgroup is created, has both new organizations assigned
245245
and has lifecycle env assigned

tests/foreman/ui/test_contenthost.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_positive_remove_package_group(self):
216216
def test_positive_install_errata(self):
217217
"""Install a errata to a host remotely
218218
219-
@id: 13b9422d-4b7a-4068-9a57-a94602cd6410
219+
@id: b69b9797-3c0c-42cd-94ed-3f751bb9b24c
220220
221221
@assert: Errata was successfully installed
222222

tests/foreman/ui/test_hostcollection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def test_positive_remove_package_group(self):
632632
def test_positive_install_errata(self):
633633
"""Install an errata to the hosts inside host collection remotely
634634
635-
@id: 5a6fff0a-686f-419b-a773-4d03713e47e9
635+
@id: 69c83000-0b46-4735-8c03-e9e0b48af0fb
636636
637637
@Assert: Errata was successfully installed in all the hosts in host
638638
collection

tests/foreman/ui/test_remoteexecution.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ def test_positive_run_default_job_template(self):
410410
def test_positive_run_custom_job_template(self):
411411
"""Run a job template against a single host
412412
413-
@id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217
413+
@id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7
414414
415415
@Setup: Create a working job template.
416416

tests/foreman/ui/test_repository.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def test_positive_download_policy_displayed_for_yum_repos(self):
678678
def test_positive_create_with_download_policy(self):
679679
"""Create YUM repositories with available download policies
680680
681-
@id: 8037a68b-66b8-4b42-a80b-fb08495f948d
681+
@id: 8099fb98-963d-4370-bf51-6807f5efd6d3
682682
683683
@Assert: YUM repository with a download policy is created
684684
"""

0 commit comments

Comments
 (0)