Robottelo: `{fix|check}-uuids` are not comparing across multiple files

Created on 2 Aug 2017  路  2Comments  路  Source: SatelliteQE/robottelo

I found a bug in our fix-uuids and check-uuids scripts

That script should output all entries for \:id:.* in all test_ files, sort it and grep for duplicate uuids, if found it takes the filename and linenumber and apply the fix by creating a new uuid to the latest duplicate found.

In this part: https://github.com/SatelliteQE/robottelo/blob/master/scripts/fix_uuids.sh#L52-L81

The command uniq -d is considering the whole output line and not only the \:id:.* so if it find duplicates in the same file it reports, but if duplicates are in different files it will not consider a duplicate because the filename is different.

We need to find a way to make uniq -d to compare only the string after :id: or change it to use awk

Bug High Priority

Most helpful comment

@rochacbruno
Output example:

tests/foreman/cli/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
  1. We need to sort by id and not by filename:
% sort --help
-n, --numeric-sort          compare according to string numerical value
-k, --key=KEYDEF          sort via a key; KEYDEF gives location and type

i.e. it would be sort -n -k3 that means sort by third field separated by whitespaces for output above.

  1. We need to compare by id and not by filename:
% uniq --help
  -f, --skip-fields=N   avoid comparing the first N fields

i.e. it would be uniq -d -f2 that meansskip first two fields separated by whitespaces that contains name and ':id:' string for output above.

Results:

% grep -r -i $ID_TOKEN tests/foreman/ --include='*.py' | grep 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/cli/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
% grep -r -i $ID_TOKEN tests/foreman/ --include='*.py' | sort -n -k3 | uniq -d -f2                
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca

All 2 comments

@elyezer @kbidarkar @Ichimonji10 as it is a bash issue I think one of you can help to find a solution. I am experimenting with awk but no success yet.

@rochacbruno
Output example:

tests/foreman/cli/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
  1. We need to sort by id and not by filename:
% sort --help
-n, --numeric-sort          compare according to string numerical value
-k, --key=KEYDEF          sort via a key; KEYDEF gives location and type

i.e. it would be sort -n -k3 that means sort by third field separated by whitespaces for output above.

  1. We need to compare by id and not by filename:
% uniq --help
  -f, --skip-fields=N   avoid comparing the first N fields

i.e. it would be uniq -d -f2 that meansskip first two fields separated by whitespaces that contains name and ':id:' string for output above.

Results:

% grep -r -i $ID_TOKEN tests/foreman/ --include='*.py' | grep 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
tests/foreman/cli/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
% grep -r -i $ID_TOKEN tests/foreman/ --include='*.py' | sort -n -k3 | uniq -d -f2                
tests/foreman/api/test_repository.py:        :id: 71388973-50ea-4a20-9406-0aca142014ca
Was this page helpful?
0 / 5 - 0 ratings