Skip to content

Commit

Permalink
Add source name to fingerprint metadata. Closes #543 (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
abaiken committed Feb 16, 2018
1 parent 51a78b5 commit 709a069
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion quipucords/fingerprinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def process_fact_collection(sender, instance, **kwargs):
:param sender: Class that was saved
:param instance: FactCollection that was saved
:param facts: dict of raw facts
:param kwargs: Other args
:returns: None
"""
Expand Down Expand Up @@ -448,6 +447,11 @@ def add_fact_to_fingerprint(source,
raw facts instead of direct access.
"""
# pylint: disable=too-many-arguments
source_object = Source.objects.filter(id=source.get('source_id')).first()
if source_object:
source_name = source_object.name
else:
source_name = None
actual_fact_value = None
if fact_value is not None:
actual_fact_value = fact_value
Expand All @@ -458,6 +462,7 @@ def add_fact_to_fingerprint(source,
fingerprint[fingerprint_key] = actual_fact_value
fingerprint[META_DATA_KEY][fingerprint_key] = {
'source_id': source['source_id'],
'source_name': source_name,
'source_type': source['source_type'],
'raw_fact_key': raw_fact_key
}
Expand Down
17 changes: 16 additions & 1 deletion quipucords/fingerprinter/tests_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
_merge_fingerprint,
_create_index_for_fingerprints,
_merge_matching_fingerprints,
_merge_fingerprints_from_source_types)
_merge_fingerprints_from_source_types,
_process_network_fact)
from api.models import Source


Expand Down Expand Up @@ -670,3 +671,17 @@ def test_merge_fingerprint_network_win(self):

self.assertEqual(new_fingerprint.get(
'os_release'), nfingerprint['os_release'])

def test_source_name_in_metadata(self):
"""Test that adding facts includes source_name in metadata."""
source = Source(
name='source1',
source_type='network',
port=22)
source.save()
sourcetopass = {'source_id': 1, 'source_type': 'network'}
fingerprint = {'metadata': {}}
result = _process_network_fact(sourcetopass, fingerprint)
self.assertEqual(
result['metadata']['infrastructure_type']['source_name'],
'source1')

0 comments on commit 709a069

Please sign in to comment.