Merge "Clear target_power_state on conductor startup"
This commit is contained in:
commit
953f06aefd
@ -125,6 +125,8 @@ class BaseConductorManager(object):
|
||||
self._periodic_task_callables,
|
||||
executor_factory=periodics.ExistingExecutor(self._executor))
|
||||
|
||||
# clear all target_power_state with locks by this conductor
|
||||
self.dbapi.clear_node_target_power_state(self.host)
|
||||
# clear all locks held by this conductor before registering
|
||||
self.dbapi.clear_node_reservations_for_conductor(self.host)
|
||||
try:
|
||||
|
@ -755,6 +755,24 @@ class Connection(api.Connection):
|
||||
_LW('Cleared reservations held by %(hostname)s: '
|
||||
'%(nodes)s'), {'hostname': hostname, 'nodes': nodes})
|
||||
|
||||
def clear_node_target_power_state(self, hostname):
|
||||
nodes = []
|
||||
with _session_for_write():
|
||||
query = (model_query(models.Node)
|
||||
.filter_by(reservation=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"})
|
||||
|
||||
if nodes:
|
||||
nodes = ', '.join(nodes)
|
||||
LOG.warning(
|
||||
_LW('Cleared target_power_state of the locked nodes in '
|
||||
'powering process, their power state can be incorrect: '
|
||||
'%(nodes)s'), {'nodes': nodes})
|
||||
|
||||
def get_active_driver_dict(self, interval=None):
|
||||
if interval is None:
|
||||
interval = CONF.conductor.heartbeat_timeout
|
||||
|
@ -110,6 +110,24 @@ class DbConductorTestCase(base.DbTestCase):
|
||||
self.assertEqual('hostname2', node2.reservation)
|
||||
self.assertIsNone(node3.reservation)
|
||||
|
||||
def test_clear_node_target_power_state(self):
|
||||
node1 = self.dbapi.create_node({'reservation': 'hostname1',
|
||||
'target_power_state': 'power on'})
|
||||
node2 = self.dbapi.create_node({'reservation': 'hostname2',
|
||||
'target_power_state': 'power on'})
|
||||
node3 = self.dbapi.create_node({'reservation': None,
|
||||
'target_power_state': 'power on'})
|
||||
self.dbapi.clear_node_target_power_state('hostname1')
|
||||
node1 = self.dbapi.get_node_by_id(node1.id)
|
||||
node2 = self.dbapi.get_node_by_id(node2.id)
|
||||
node3 = self.dbapi.get_node_by_id(node3.id)
|
||||
self.assertIsNone(node1.target_power_state)
|
||||
self.assertIn('power operation was aborted', node1.last_error)
|
||||
self.assertEqual('power on', node2.target_power_state)
|
||||
self.assertIsNone(node2.last_error)
|
||||
self.assertEqual('power on', node3.target_power_state)
|
||||
self.assertIsNone(node3.last_error)
|
||||
|
||||
@mock.patch.object(timeutils, 'utcnow', autospec=True)
|
||||
def test_get_active_driver_dict_one_host_no_driver(self, mock_utcnow):
|
||||
h = 'fake-host'
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Clear target_power_state of the nodes locked by the conductor on its
|
||||
startup.
|
Loading…
Reference in New Issue
Block a user