Fixing update sites incomplete status

- Updating align_result to default to Success if there are no subtasks.

Change-Id: Ib17ef4b84e9376f69569256e01481ff6510ad21d
This commit is contained in:
Aaron Sheffield 2018-02-06 14:05:58 -06:00
parent 455c3215db
commit cd4333c4d8
3 changed files with 37 additions and 42 deletions

View File

@ -296,7 +296,11 @@ class Task(object):
:param reset_status: Whether to reset the result status of this task before aligning
"""
if reset_status:
self.result.status = hd_fields.ActionResult.Incomplete
# Defaults the ActionResult to Success if there are no tasks
if not self.statemgr.get_all_subtasks(self.task_id):
self.result.status = hd_fields.ActionResult.Success
else:
self.result.status = hd_fields.ActionResult.Incomplete
for st in self.statemgr.get_complete_subtasks(self.task_id):
if action_filter is None or (action_filter is not None
and st.action == action_filter):

View File

@ -529,7 +529,6 @@ class PrepareNodes(BaseAction):
:param node_driver: driver instance to use for execution
:param node_list: a list of objects.BaremetalNode instances
:return: list of uuid.UUID task ids of the tasks executing this step
"""
if len(node_list) > 0:
self.logger.info(
@ -560,12 +559,10 @@ class PrepareNodes(BaseAction):
except errors.MaxRetriesReached:
self.task.failure()
break
return [node_commission_task.get_id()]
else:
self.logger.warning(
"No nodes successfully identified, skipping commissioning subtask"
)
return list()
def step_node_identify(self, node_driver, node_list):
"""Execute the IdentifyNode step of this action on a list of nodes.

View File

@ -106,26 +106,12 @@ class DrydockState(object):
:param task_id: uuid.UUID ID of the parent task for subtasks
"""
try:
conn = self.db_engine.connect()
query_text = sql.text(
"SELECT * FROM tasks WHERE " # nosec no strings are user-sourced
"parent_task_id = :parent_task_id AND "
"status IN ('" + hd_fields.TaskStatus.Terminated + "','" +
hd_fields.TaskStatus.Complete + "')")
rs = conn.execute(query_text, parent_task_id=task_id.bytes)
task_list = [objects.Task.from_db(dict(r)) for r in rs]
conn.close()
self._assemble_tasks(task_list=task_list)
for t in task_list:
t.statemgr = self
return task_list
except Exception as ex:
self.logger.error("Error querying complete subtask: %s" % str(ex))
return []
query_text = sql.text(
"SELECT * FROM tasks WHERE " # nosec no strings are user-sourced
"parent_task_id = :parent_task_id AND "
"status IN ('" + hd_fields.TaskStatus.Terminated + "','" +
hd_fields.TaskStatus.Complete + "')")
return self._query_subtasks(task_id, query_text, "Error querying complete subtask: %s")
def get_active_subtasks(self, task_id):
"""Query database for subtasks of the provided task that are active.
@ -135,27 +121,35 @@ class DrydockState(object):
:param task_id: uuid.UUID ID of the parent task for subtasks
"""
query_text = sql.text(
"SELECT * FROM tasks WHERE " # nosec no strings are user-sourced
"parent_task_id = :parent_task_id AND "
"status NOT IN ['" + hd_fields.TaskStatus.Terminated + "','" +
hd_fields.TaskStatus.Complete + "']")
return self._query_subtasks(task_id, query_text, "Error querying active subtask: %s")
def get_all_subtasks(self, task_id):
"""Query database for all subtasks of the provided task.
:param task_id: uuid.UUID ID of the parent task for subtasks
"""
query_text = sql.text(
"SELECT * FROM tasks WHERE " # nosec no strings are user-sourced
"parent_task_id = :parent_task_id")
return self._query_subtasks(task_id, query_text, "Error querying all subtask: %s")
def _query_subtasks(self, task_id, query_text, error):
try:
conn = self.db_engine.connect()
query_text = sql.text(
"SELECT * FROM tasks WHERE " # nosec no strings are user-sourced
"parent_task_id = :parent_task_id AND "
"status NOT IN ['" + hd_fields.TaskStatus.Terminated + "','" +
hd_fields.TaskStatus.Complete + "']")
with self.db_engine.connect() as conn:
rs = conn.execute(query_text, parent_task_id=task_id.bytes)
task_list = [objects.Task.from_db(dict(r)) for r in rs]
rs = conn.execute(query_text, parent_task_id=task_id.bytes)
task_list = [objects.Task.from_db(dict(r)) for r in rs]
conn.close()
self._assemble_tasks(task_list=task_list)
for t in task_list:
t.statemgr = self
return task_list
self._assemble_tasks(task_list=task_list)
for t in task_list:
t.statemgr = self
return task_list
except Exception as ex:
self.logger.error("Error querying active subtask: %s" % str(ex))
self.logger.error(error % str(ex))
return []
def get_next_queued_task(self, allowed_actions=None):