Issue with updating host reservations when they don't contain IP addresses
The issue can be reproduced with two servers using the same configuration (e.g. HA partners). When they define host reservations without IP addresses, approving the second server registration will cause Stork server to match its host reservations with the existing reservations. As a result, a dbmodel.UpdateHost()
function is called to update the hosts. It results in the following error:
021-12-16 10:51:35.544 UTC [103] ERROR: syntax error at or near ")" at character 101
postgres_1 | 2021-12-16 10:51:35.544 UTC [103] STATEMENT: DELETE FROM "ip_reservation" WHERE (ip_reservation.host_id = 4) AND (ip_reservation.address NOT IN ())
server_1 | ERRO[2021-12-16 10:51:35] statepuller.go:287 cannot store application state: ERROR #42601 syntax error at or near ")"
server_1 | problem with deleting IP reservations for host 4
server_1 | isc.org/stork/server/database/model.UpdateHost
server_1 | /repo/build-root/backend/server/database/model/host.go:191
The query fails because of this particular part of the statement: NOT IN ()
. The empty set is not allowed. We should check if the list is empty and, in this case, do not issue the database statement.