mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
retain support for insights system_id discovery
This commit is contained in:
@@ -769,11 +769,18 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin):
|
|||||||
modified = parser.parse(modified, tzinfos=[tzutc()])
|
modified = parser.parse(modified, tzinfos=[tzutc()])
|
||||||
if not host.ansible_facts_modified or modified > host.ansible_facts_modified:
|
if not host.ansible_facts_modified or modified > host.ansible_facts_modified:
|
||||||
ansible_facts = cache.get(host_key)
|
ansible_facts = cache.get(host_key)
|
||||||
|
try:
|
||||||
|
ansible_facts = json.loads(ansible_facts)
|
||||||
|
except Exception:
|
||||||
|
ansible_facts = None
|
||||||
|
|
||||||
if ansible_facts is None:
|
if ansible_facts is None:
|
||||||
cache.delete(host_key)
|
cache.delete(host_key)
|
||||||
continue
|
continue
|
||||||
host.ansible_facts = ansible_facts
|
host.ansible_facts = ansible_facts
|
||||||
host.ansible_facts_modified = modified
|
host.ansible_facts_modified = modified
|
||||||
|
if 'insights' in ansible_facts and 'system_id' in ansible_facts['insights']:
|
||||||
|
host.insights_system_id = ansible_facts['insights']['system_id']
|
||||||
host.save()
|
host.save()
|
||||||
system_tracking_logger.info('New fact for inventory {} host {}'.format(host.inventory.name, host.name),
|
system_tracking_logger.info('New fact for inventory {} host {}'.format(host.inventory.name, host.name),
|
||||||
extra=dict(inventory_id=host.inventory.id, host_name=host.name,
|
extra=dict(inventory_id=host.inventory.id, host_name=host.name,
|
||||||
|
|||||||
@@ -119,13 +119,15 @@ def test_finish_job_fact_cache(job, hosts, inventory, mocker, new_time):
|
|||||||
host_key = job.memcached_fact_host_key(hosts[1].name)
|
host_key = job.memcached_fact_host_key(hosts[1].name)
|
||||||
modified_key = job.memcached_fact_modified_key(hosts[1].name)
|
modified_key = job.memcached_fact_modified_key(hosts[1].name)
|
||||||
|
|
||||||
job._get_memcache_connection().set(host_key, 'blah')
|
ansible_facts_new = {"foo": "bar", "insights": {"system_id": "updated_by_scan"}}
|
||||||
|
job._get_memcache_connection().set(host_key, json.dumps(ansible_facts_new))
|
||||||
job._get_memcache_connection().set(modified_key, new_time.isoformat())
|
job._get_memcache_connection().set(modified_key, new_time.isoformat())
|
||||||
|
|
||||||
job.finish_job_fact_cache()
|
job.finish_job_fact_cache()
|
||||||
|
|
||||||
hosts[0].save.assert_not_called()
|
hosts[0].save.assert_not_called()
|
||||||
hosts[2].save.assert_not_called()
|
hosts[2].save.assert_not_called()
|
||||||
assert hosts[1].ansible_facts == 'blah'
|
assert hosts[1].ansible_facts == ansible_facts_new
|
||||||
|
assert hosts[1].insights_system_id == "updated_by_scan"
|
||||||
hosts[1].save.assert_called_once_with()
|
hosts[1].save.assert_called_once_with()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user