1 ##############################################################################
2 # Copyright (c) 2020 Sawyer Bergeron, Parker Berberian, Sean Smith, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from resource_inventory.models import (
22 def rp_has_all_components():
24 Check that every ResourceProfile has an InterfaceProfile,
25 DiskProfile, CpuProfile, and RamProfile.
30 for rp in ResourceProfile.objects.all():
31 ip = InterfaceProfile.objects.filter(host=rp).exists()
32 dp = DiskProfile.objects.filter(host=rp).exists()
33 cp = CpuProfile.objects.filter(host=rp).exists()
34 ram = RamProfile.objects.filter(host=rp).exists()
37 print("No InterfaceProfiles for host", rp.name)
41 print("No DiskProfile for host", rp.name)
45 print("No CpuProfile for host", rp.name)
49 print("No RamProfile for host", rp.name)
55 def ip_for_all_ifaces():
57 Check that every InterfaceProfile for a Resource has
63 for res in ResourceQuery.filter():
64 iface_set = res.get_interfaces()
65 iface_profile_set = InterfaceProfile.objects.filter(host=res.profile)
67 # find out what profiles we have
68 curr_profiles = [iface.profile for iface in iface_set]
69 missing_profiles = set(iface_profile_set) - set(curr_profiles)
72 print('No interface for profiles', missing_profiles, 'for host', res.name)
80 Make sure every ResourceProfile has an Image.
85 rp_set = ResourceProfile.objects.all()
86 image_set = Image.objects.all()
87 image_profiles = set([image.host_type for image in image_set])
90 if rp not in image_profiles:
91 print("ResourceProfile", rp.name, "has no image associated with it.")
97 print('RUNNING TEST', test)
100 print(test, 'WAS A SUCCESS!')
102 print(test, 'FAILED')
103 print('============================================')
107 tests = [rp_has_all_components, ip_for_all_ifaces, rp_has_image]