Skip to content

Commit

Permalink
fix: add-schedule on non existing host
Browse files Browse the repository at this point in the history
This was failing with a non descriptive exception as we were trying
to access the host.broken parameter on a None type object when the
host is not found on DB.
Resolved to display a proper validation error.

Change-Id: I5f820180e6795fd5b16a3c3d765d2ca1c53471cf
  • Loading branch information
grafuls committed Feb 15, 2022
1 parent 310f9db commit cf33b4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion quads/api_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,12 @@ def POST(self, **data):

_host = data["host"]
_host_obj = Host.objects(name=_host).first()
if not _host_obj:
result.append(f"Host {_host} is not defined")

broken_hosts = Host.objects(broken=True)
if _host_obj in broken_hosts:
result.append(f"Host {_host_obj.name} is in broken state")
result.append(f"Host {_host_obj.name} does not exist")

# Check if there were data validation errors
if result:
Expand Down
2 changes: 2 additions & 0 deletions quads/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def insert_schedule(self, cloud, host, start, end):
@queryset_manager
def is_host_available(self, queryset, host, start, end, exclude=None):
_host = Host.objects(name=host).first()
if not _host:
return False
if _host.broken or _host.retired:
return False
_query = Q(host=_host)
Expand Down

0 comments on commit cf33b4c

Please sign in to comment.