mirror of
https://github.com/ansible/awx.git
synced 2026-04-07 02:59:21 -02:30
created a new model 'HostMetrics' which will contain the first timestamp and the most recent timestamp of any automation on a given object and Added a new 'awx-manage' command. command : awx-manage host_metrics --since <datetime> --until <datetime>
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