mirror of
https://github.com/ansible/awx.git
synced 2026-09-05 03:18:29 -02:30
Merge pull request #9654 from amolgautam25/issue_4687
Adding host_metrics for customers who don't have automation analytics SUMMARY I am trying to accomplish the following: Create a new model that stores details about hostname create corresponding migrations for it Update the table (main_hostmetrics) after playbook execution retrieve the data with custom awx-manage command : awx-manage host_metrics --since <date> --until <date> ISSUE TYPE Feature Pull Request COMPONENT NAME API AWX VERSION awx: 18.0.0 ADDITIONAL INFORMATION Reviewed-by: Ryan Petrello <ryan@ryanpetrello.com> Reviewed-by: Amol Gautam <amol_gautam25@yahoo.co.in> Reviewed-by: Chris Meyers <None> Reviewed-by: Jeff Bradberry <None> Reviewed-by: Bill Nottingham <None> Reviewed-by: Ladislav Smola <lsmola@redhat.com> Reviewed-by: Alan Rominger <arominge@redhat.com>
This commit is contained in:
22
awx/main/tests/functional/models/test_host_metric.py
Normal file
22
awx/main/tests/functional/models/test_host_metric.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from django.utils.timezone import now
|
||||
from awx.main.models import HostMetric
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_host_metrics_generation():
|
||||
hostnames = [f'Host {i}' for i in range(100)]
|
||||
current_time = now()
|
||||
HostMetric.objects.bulk_create([HostMetric(hostname=h, last_automation=current_time) for h in hostnames])
|
||||
|
||||
# 3 assertions have to be made
|
||||
# 1) if all the objects were created or not
|
||||
assert HostMetric.objects.count() == len(hostnames)
|
||||
|
||||
# 2) Match the hostnames stored in DB with the one passed in bulk_create
|
||||
assert sorted([s.hostname for s in HostMetric.objects.all()]) == sorted(hostnames)
|
||||
|
||||
# 3) Make sure that first_automation attribute is today's date
|
||||
date_today = now().strftime('%Y-%m-%d')
|
||||
result = HostMetric.objects.filter(first_automation__startswith=date_today).count()
|
||||
assert result == len(hostnames)
|
||||
Reference in New Issue
Block a user