summaryrefslogtreecommitdiff
path: root/ironic/db/sqlalchemy/api.py
diff options
context:
space:
mode:
authorJulia Kreger <juliaashleykreger@gmail.com>2020-03-06 12:25:33 -0800
committerJulia Kreger <juliaashleykreger@gmail.com>2020-03-06 12:29:19 -0800
commitae3a14e65c81f48472040a086075b63ca1ce76ac (patch)
tree2abb0f2261b9ea182ea3cad7c93221a81ed874e8 /ironic/db/sqlalchemy/api.py
parent7a15df60c3da28bbae44e8e3cbb0b5c4042730ed (diff)
downloadironic-ae3a14e65c81f48472040a086075b63ca1ce76ac.tar.gz
Make reservation checks caseless
If a conductor hostname is changed while reservations are issued to a conductor with one hostname, such as 'hostName' and then the process is restarted with 'hostname', then the queries would not match the node and effectively the nodes would become inaccessible until the reservation is cleared. This patch changes the queries to use a case insenitive like search, better known as ilike. Special thanks to the nova team for finding a bug in the hash ring calculation in the ironic virt driver where a customer changed their nova-compute hostname, which inspired this patch. Change-Id: Ib7da925ba5ca6a82ba542e0f4ae4cf7f0d070835
Diffstat (limited to 'ironic/db/sqlalchemy/api.py')
-rw-r--r--ironic/db/sqlalchemy/api.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/ironic/db/sqlalchemy/api.py b/ironic/db/sqlalchemy/api.py
index f072856bb..95baf75fd 100644
--- a/ironic/db/sqlalchemy/api.py
+++ b/ironic/db/sqlalchemy/api.py
@@ -999,9 +999,9 @@ class Connection(api.Connection):
nodes = []
with _session_for_write():
query = (model_query(models.Node)
- .filter_by(reservation=hostname))
+ .filter(models.Node.reservation.ilike(hostname)))
nodes = [node['uuid'] for node in query]
- query.update({'reservation': None})
+ query.update({'reservation': None}, synchronize_session=False)
if nodes:
nodes = ', '.join(nodes)
@@ -1014,13 +1014,14 @@ class Connection(api.Connection):
nodes = []
with _session_for_write():
query = (model_query(models.Node)
- .filter_by(reservation=hostname))
+ .filter(models.Node.reservation.ilike(hostname)))
query = query.filter(models.Node.target_power_state != sql.null())
nodes = [node['uuid'] for node in query]
query.update({'target_power_state': None,
'last_error': _("Pending power operation was "
"aborted due to conductor "
- "restart")})
+ "restart")},
+ synchronize_session=False)
if nodes:
nodes = ', '.join(nodes)