mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Removed unused dashboard inventory graph, doubly useless now that active flag is gone
This commit is contained in:
parent
d9c80dade6
commit
e770a1f225
@ -117,6 +117,7 @@ class ModelAccessPermission(permissions.BasePermission):
|
||||
check_method = getattr(self, 'check_%s_permissions' % request.method.lower(), None)
|
||||
result = check_method and check_method(request, view, obj)
|
||||
if not result:
|
||||
print('Yarr permission denied: %s %s' % (repr(obj), request.method))
|
||||
raise PermissionDenied()
|
||||
|
||||
return result
|
||||
|
@ -274,7 +274,6 @@ v1_urls = patterns('awx.api.views',
|
||||
url(r'^me/$', 'user_me_list'),
|
||||
url(r'^dashboard/$', 'dashboard_view'),
|
||||
url(r'^dashboard/graphs/jobs/$', 'dashboard_jobs_graph_view'),
|
||||
url(r'^dashboard/graphs/inventory/$', 'dashboard_inventory_graph_view'),
|
||||
url(r'^settings/', include(settings_urls)),
|
||||
url(r'^schedules/', include(schedule_urls)),
|
||||
url(r'^organizations/', include(organization_urls)),
|
||||
|
@ -288,8 +288,7 @@ class DashboardView(APIView):
|
||||
def get(self, request, format=None):
|
||||
''' Show Dashboard Details '''
|
||||
data = OrderedDict()
|
||||
data['related'] = {'jobs_graph': reverse('api:dashboard_jobs_graph_view'),
|
||||
'inventory_graph': reverse('api:dashboard_inventory_graph_view')}
|
||||
data['related'] = {'jobs_graph': reverse('api:dashboard_jobs_graph_view')}
|
||||
user_inventory = get_user_queryset(request.user, Inventory)
|
||||
inventory_with_failed_hosts = user_inventory.filter(hosts_with_active_failures__gt=0)
|
||||
user_inventory_external = user_inventory.filter(has_inventory_sources=True)
|
||||
@ -435,49 +434,6 @@ class DashboardJobsGraphView(APIView):
|
||||
element[1]])
|
||||
return Response(dashboard_data)
|
||||
|
||||
class DashboardInventoryGraphView(APIView):
|
||||
|
||||
view_name = "Dashboard Inventory Graphs"
|
||||
new_in_200 = True
|
||||
|
||||
def get(self, request, format=None):
|
||||
period = request.query_params.get('period', 'month')
|
||||
|
||||
end_date = now()
|
||||
if period == 'month':
|
||||
start_date = end_date - dateutil.relativedelta.relativedelta(months=1)
|
||||
start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
delta = dateutil.relativedelta.relativedelta(days=1)
|
||||
elif period == 'week':
|
||||
start_date = end_date - dateutil.relativedelta.relativedelta(weeks=1)
|
||||
start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
delta = dateutil.relativedelta.relativedelta(days=1)
|
||||
elif period == 'day':
|
||||
start_date = end_date - dateutil.relativedelta.relativedelta(days=1)
|
||||
start_date = start_date.replace(minute=0, second=0, microsecond=0)
|
||||
delta = dateutil.relativedelta.relativedelta(hours=1)
|
||||
else:
|
||||
raise ParseError(u'Unknown period "%s"' % force_text(period))
|
||||
|
||||
host_stats = []
|
||||
date = start_date
|
||||
while date < end_date:
|
||||
next_date = date + delta
|
||||
# Find all hosts that existed at end of intevral that are still
|
||||
# active or were deleted after the end of interval. Slow but
|
||||
# accurate; haven't yet found a better way to do it.
|
||||
hosts_qs = Host.objects.filter(created__lt=next_date)
|
||||
hosts_qs = hosts_qs.filter(Q(active=True) | Q(active=False, modified__gte=next_date))
|
||||
hostnames = set()
|
||||
for name, active in hosts_qs.values_list('name', 'active').iterator():
|
||||
if not active:
|
||||
name = re.sub(r'^_deleted_.*?_', '', name)
|
||||
hostnames.add(name)
|
||||
host_stats.append((time.mktime(date.timetuple()), len(hostnames)))
|
||||
date = next_date
|
||||
|
||||
return Response({'hosts': host_stats})
|
||||
|
||||
|
||||
class ScheduleList(ListAPIView):
|
||||
|
||||
|
@ -1115,59 +1115,6 @@ class InventoryTest(BaseTest):
|
||||
self.assertEqual(response['hosts']['total'], 8)
|
||||
self.assertEqual(response['hosts']['failed'], 8)
|
||||
|
||||
def test_dashboard_inventory_graph_view(self):
|
||||
url = reverse('api:dashboard_inventory_graph_view')
|
||||
# Test with zero hosts.
|
||||
with self.current_user(self.super_django_user):
|
||||
response = self.get(url)
|
||||
self.assertFalse(sum([x[1] for x in response['hosts']]))
|
||||
# Create hosts in inventory_a, with created one day apart, and check
|
||||
# the time series results.
|
||||
dtnow = now()
|
||||
hostnames = list('abcdefg')
|
||||
for x in xrange(len(hostnames) - 1, -1, -1):
|
||||
hostname = hostnames[x]
|
||||
created = dtnow - datetime.timedelta(days=x, seconds=60)
|
||||
self.inventory_a.hosts.create(name=hostname, created=created)
|
||||
with self.current_user(self.super_django_user):
|
||||
response = self.get(url)
|
||||
for n, d in enumerate(reversed(response['hosts'])):
|
||||
self.assertEqual(d[1], max(len(hostnames) - n, 0))
|
||||
# Create more hosts a day apart in inventory_b and check the time
|
||||
# series results.
|
||||
hostnames2 = list('hijklmnop')
|
||||
for x in xrange(len(hostnames2) - 1, -1, -1):
|
||||
hostname = hostnames2[x]
|
||||
created = dtnow - datetime.timedelta(days=x, seconds=120)
|
||||
self.inventory_b.hosts.create(name=hostname, created=created)
|
||||
with self.current_user(self.super_django_user):
|
||||
response = self.get(url)
|
||||
for n, d in enumerate(reversed(response['hosts'])):
|
||||
self.assertEqual(d[1], max(len(hostnames2) - n, 0) + max(len(hostnames) - n, 0))
|
||||
# Now create some hosts in inventory_a with the same hostnames already
|
||||
# used in inventory_b; duplicate hostnames should only be counted the
|
||||
# first time they were seen in inventory_b.
|
||||
hostnames3 = list('lmnop')
|
||||
for x in xrange(len(hostnames3) - 1, -1, -1):
|
||||
hostname = hostnames3[x]
|
||||
created = dtnow - datetime.timedelta(days=x, seconds=180)
|
||||
self.inventory_a.hosts.create(name=hostname, created=created)
|
||||
with self.current_user(self.super_django_user):
|
||||
response = self.get(url)
|
||||
for n, d in enumerate(reversed(response['hosts'])):
|
||||
self.assertEqual(d[1], max(len(hostnames2) - n, 0) + max(len(hostnames) - n, 0))
|
||||
# Delete recently added hosts and verify the count drops.
|
||||
hostnames4 = list('defg')
|
||||
for host in Host.objects.filter(name__in=hostnames4):
|
||||
host.delete()
|
||||
with self.current_user(self.super_django_user):
|
||||
response = self.get(url)
|
||||
for n, d in enumerate(reversed(response['hosts'])):
|
||||
count = max(len(hostnames2) - n, 0) + max(len(hostnames) - n, 0)
|
||||
if n == 0:
|
||||
count -= 4
|
||||
self.assertEqual(d[1], count)
|
||||
|
||||
|
||||
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||
|
Loading…
Reference in New Issue
Block a user