Skip to content

Commit 42f3342

Browse files
Merge pull request #424 from MahnoorAsghar/delay-prov-master-4.15
Set node "alive" when inspection finished
2 parents dccbfd2 + 0feaa17 commit 42f3342

5 files changed

Lines changed: 46 additions & 5 deletions

File tree

ironic/conductor/cleaning.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ def do_node_clean(task, clean_steps=None, disable_ramdisk=False):
9898
'out-of-band only cleaning has been requested for node '
9999
'%s', node.uuid)
100100
prepare_result = None
101+
except exception.AgentConnectionFailed:
102+
LOG.info('Agent is not yet running on node %(node)s, waiting for'
103+
' agent to come up for fast track', {'node': node.uuid})
104+
target_state = states.MANAGEABLE if manual_clean else None
105+
task.process_event('wait', target_state=target_state)
106+
return
101107
except Exception as e:
102108
msg = (_('Failed to prepare node %(node)s for cleaning: %(e)s')
103109
% {'node': node.uuid, 'e': e})

ironic/conductor/deployments.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ def do_node_deploy(task, conductor_id=None, configdrive=None,
180180

181181
try:
182182
task.driver.deploy.prepare(task)
183+
except exception.AgentConnectionFailed:
184+
LOG.info('Agent is not yet running on node %(node)s, waiting for agent'
185+
' to come up for fast track', {'node': node.uuid})
186+
task.process_event('wait')
187+
return
183188
except exception.IronicException as e:
184189
with excutils.save_and_reraise_exception():
185190
utils.deploying_error_handler(

ironic/conductor/utils.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,13 +1119,18 @@ def fast_track_able(task):
11191119
def value_within_timeout(value, timeout):
11201120
"""Checks if the time is within the previous timeout seconds from now.
11211121
1122-
:param value: a string representing date and time or None.
1122+
:param value: a datetime or string representing date and time or None.
11231123
:param timeout: timeout in seconds.
11241124
"""
11251125
# use native datetime objects for conversion and compare
11261126
# slightly odd because py2 compatability :(
1127-
last = datetime.datetime.strptime(value or '1970-01-01T00:00:00.000000',
1128-
"%Y-%m-%dT%H:%M:%S.%f")
1127+
if isinstance(value, datetime.datetime):
1128+
# Converts to a offset-naive datetime(as created by timeutils.utcnow())
1129+
last = value.replace(tzinfo=None)
1130+
else:
1131+
defaultdt = '1970-01-01T00:00:00.000000'
1132+
last = datetime.datetime.strptime(value or defaultdt,
1133+
'%Y-%m-%dT%H:%M:%S.%f')
11291134
# If we found nothing, we assume that the time is essentially epoch.
11301135
time_delta = datetime.timedelta(seconds=timeout)
11311136
last_valid = timeutils.utcnow() - time_delta
@@ -1142,14 +1147,20 @@ def agent_is_alive(node, timeout=None):
11421147
:param node: A node object.
11431148
:param timeout: Heartbeat timeout, defaults to `fast_track_timeout`.
11441149
"""
1150+
1151+
timeout = timeout or CONF.deploy.fast_track_timeout
1152+
if node.power_state == states.POWER_ON and \
1153+
node.inspection_finished_at and \
1154+
value_within_timeout(node.inspection_finished_at, timeout):
1155+
return True
1156+
11451157
# If no agent_url is present then we have powered down since the
11461158
# last agent heartbeat
11471159
if not node.driver_internal_info.get('agent_url'):
11481160
return False
11491161

11501162
return value_within_timeout(
1151-
node.driver_internal_info.get('agent_last_heartbeat'),
1152-
timeout or CONF.deploy.fast_track_timeout)
1163+
node.driver_internal_info.get('agent_last_heartbeat'), timeout)
11531164

11541165

11551166
def is_fast_track(task):

ironic/tests/unit/conductor/test_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,6 +2184,18 @@ def test_is_fast_track_no_heartbeat(self, mock_get_power):
21842184
self.context, self.node.uuid, shared=False) as task:
21852185
self.assertFalse(conductor_utils.is_fast_track(task))
21862186

2187+
def test_is_fast_track_inspected_no_heartbeat(self, mock_get_power):
2188+
mock_get_power.return_value = states.POWER_ON
2189+
self.node = obj_utils.create_test_node(
2190+
self.context, driver='fake-hardware',
2191+
uuid=uuidutils.generate_uuid(),
2192+
inspection_finished_at=timeutils.utcnow(),
2193+
power_state=states.POWER_ON
2194+
)
2195+
with task_manager.acquire(
2196+
self.context, self.node.uuid, shared=False) as task:
2197+
self.assertTrue(conductor_utils.is_fast_track(task))
2198+
21872199
def test_is_fast_track_powered_after_heartbeat(self, mock_get_power):
21882200
mock_get_power.return_value = states.POWER_ON
21892201
with task_manager.acquire(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
Set node "alive" and make it fast trackable
5+
as soon as inspection is finished, in addition
6+
add a wait for the agent to callback should
7+
it not be available when fast track is attempted.

0 commit comments

Comments
 (0)