forked from SatelliteQE/robottelo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scripts to validate and fix duplicated and empty @ids
closes SatelliteQE#3834 closes SatelliteQE#3735
- Loading branch information
1 parent
7e72f58
commit 5c0304a
Showing
11 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters