Fix 500 on missing inventory for provisioning callbacks (#13862)

* Fix 500 on missing inventory for provisioning callbacks

* Added test to cover bug fix

* Reworded msg to clear what is missing to start the callback
This commit is contained in:
Gabriel Muniz
2023-04-19 09:27:41 -04:00
committed by GitHub
parent b75b84e282
commit cd5cc64d6a
2 changed files with 21 additions and 2 deletions

View File

@@ -2692,7 +2692,10 @@ class JobTemplateCallback(GenericAPIView):
# Permission class should have already validated host_config_key.
job_template = self.get_object()
# Attempt to find matching hosts based on remote address.
matching_hosts = self.find_matching_hosts()
if job_template.inventory:
matching_hosts = self.find_matching_hosts()
else:
return Response({"msg": _("Cannot start automatically, an inventory is required.")}, status=status.HTTP_400_BAD_REQUEST)
# If the host is not found, update the inventory before trying to
# match again.
inventory_sources_already_updated = []