blob: dcea3c0b7420e752e33488f547d834c18d7d65e1 [file] [log] [blame]
tierno59d22d22018-09-25 18:10:19 +02001# -*- coding: utf-8 -*-
2
tierno2e215512018-11-28 09:37:52 +00003##
4# Copyright 2018 Telefonica S.A.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17##
tierno59d22d22018-09-25 18:10:19 +020018
kuused124bfe2019-06-18 12:09:24 +020019import asyncio
tierno59d22d22018-09-25 18:10:19 +020020from collections import OrderedDict
tierno79cd8ad2019-10-18 13:03:10 +000021from time import time
tiernobaa51102018-12-14 13:16:18 +000022# from osm_common.dbbase import DbException
tierno59d22d22018-09-25 18:10:19 +020023
24__author__ = "Alfonso Tierno"
25
26
27class LcmException(Exception):
28 pass
29
30
tiernof578e552018-11-08 19:07:20 +010031class LcmExceptionNoMgmtIP(LcmException):
32 pass
33
34
gcalvinoed7f6d42018-12-14 14:44:56 +010035class LcmExceptionExit(LcmException):
36 pass
37
38
tierno59d22d22018-09-25 18:10:19 +020039def versiontuple(v):
tierno27246d82018-09-27 15:59:09 +020040 """utility for compare dot separate versions. Fills with zeros to proper number comparison
41 package version will be something like 4.0.1.post11+gb3f024d.dirty-1. Where 4.0.1 is the git tag, postXX is the
42 number of commits from this tag, and +XXXXXXX is the git commit short id. Total length is 16 with until 999 commits
43 """
tierno59d22d22018-09-25 18:10:19 +020044 filled = []
45 for point in v.split("."):
tiernoe64f7fb2019-09-11 08:55:52 +000046 point, _, _ = point.partition("+")
47 point, _, _ = point.partition("-")
48 filled.append(point.zfill(20))
tierno59d22d22018-09-25 18:10:19 +020049 return tuple(filled)
50
51
garciaale65003392020-10-21 15:21:37 -030052def deep_get(target_dict, key_list, default_value=None):
tierno626e0152019-11-29 14:16:16 +000053 """
54 Get a value from target_dict entering in the nested keys. If keys does not exist, it returns None
55 Example target_dict={a: {b: 5}}; key_list=[a,b] returns 5; both key_list=[a,b,c] and key_list=[f,h] return None
56 :param target_dict: dictionary to be read
57 :param key_list: list of keys to read from target_dict
garciaale65003392020-10-21 15:21:37 -030058 :param default_value: value to return if key is not present in the nested dictionary
tierno626e0152019-11-29 14:16:16 +000059 :return: The wanted value if exist, None otherwise
60 """
61 for key in key_list:
62 if not isinstance(target_dict, dict) or key not in target_dict:
garciaale65003392020-10-21 15:21:37 -030063 return default_value
tierno626e0152019-11-29 14:16:16 +000064 target_dict = target_dict[key]
65 return target_dict
66
67
garciaale65003392020-10-21 15:21:37 -030068def get_iterable(in_dict, in_key):
69 """
70 Similar to <dict>.get(), but if value is None, False, ..., An empty tuple is returned instead
71 :param in_dict: a dictionary
72 :param in_key: the key to look for at in_dict
73 :return: in_dict[in_var] or () if it is None or not present
74 """
75 if not in_dict.get(in_key):
76 return ()
77 return in_dict[in_key]
78
79
80def populate_dict(target_dict, key_list, value):
81 """
82 Update target_dict creating nested dictionaries with the key_list. Last key_list item is asigned the value.
83 Example target_dict={K: J}; key_list=[a,b,c]; target_dict will be {K: J, a: {b: {c: value}}}
84 :param target_dict: dictionary to be changed
85 :param key_list: list of keys to insert at target_dict
86 :param value:
87 :return: None
88 """
89 for key in key_list[0:-1]:
90 if key not in target_dict:
91 target_dict[key] = {}
92 target_dict = target_dict[key]
93 target_dict[key_list[-1]] = value
94
95
kuused124bfe2019-06-18 12:09:24 +020096class LcmBase:
97
98 def __init__(self, db, msg, fs, logger):
99 """
100
101 :param db: database connection
102 """
103 self.db = db
104 self.msg = msg
105 self.fs = fs
106 self.logger = logger
107
108 def update_db_2(self, item, _id, _desc):
109 """
110 Updates database with _desc information. If success _desc is cleared
111 :param item:
112 :param _id:
113 :param _desc: dictionary with the content to update. Keys are dot separated keys for
114 :return: None. Exception is raised on error
115 """
116 if not _desc:
117 return
tierno79cd8ad2019-10-18 13:03:10 +0000118 now = time()
119 _desc["_admin.modified"] = now
kuused124bfe2019-06-18 12:09:24 +0200120 self.db.set_one(item, {"_id": _id}, _desc)
121 _desc.clear()
122 # except DbException as e:
123 # self.logger.error("Updating {} _id={} with '{}'. Error: {}".format(item, _id, _desc, e))
124
125
126class TaskRegistry(LcmBase):
tierno59d22d22018-09-25 18:10:19 +0200127 """
128 Implements a registry of task needed for later cancelation, look for related tasks that must be completed before
129 etc. It stores a four level dict
130 First level is the topic, ns, vim_account, sdn
131 Second level is the _id
132 Third level is the operation id
133 Fourth level is a descriptive name, the value is the task class
kuused124bfe2019-06-18 12:09:24 +0200134
135 The HA (High-Availability) methods are used when more than one LCM instance is running.
136 To register the current task in the external DB, use LcmBase as base class, to be able
137 to reuse LcmBase.update_db_2()
138 The DB registry uses the following fields to distinguish a task:
139 - op_type: operation type ("nslcmops" or "nsilcmops")
140 - op_id: operation ID
141 - worker: the worker ID for this process
tierno59d22d22018-09-25 18:10:19 +0200142 """
143
kuuse6a470c62019-07-10 13:52:45 +0200144 # NS/NSI: "services" VIM/WIM/SDN: "accounts"
145 topic_service_list = ['ns', 'nsi']
calvinosanch9f9c6f22019-11-04 13:37:39 +0100146 topic_account_list = ['vim', 'wim', 'sdn', 'k8scluster', 'k8srepo']
kuuse6a470c62019-07-10 13:52:45 +0200147
148 # Map topic to InstanceID
149 topic2instid_dict = {
150 'ns': 'nsInstanceId',
151 'nsi': 'netsliceInstanceId'}
152
153 # Map topic to DB table name
154 topic2dbtable_dict = {
155 'ns': 'nslcmops',
156 'nsi': 'nsilcmops',
157 'vim': 'vim_accounts',
158 'wim': 'wim_accounts',
calvinosanch9f9c6f22019-11-04 13:37:39 +0100159 'sdn': 'sdns',
160 'k8scluster': 'k8sclusters',
161 'k8srepo': 'k8srepos'}
kuused124bfe2019-06-18 12:09:24 +0200162
163 def __init__(self, worker_id=None, db=None, logger=None):
tierno59d22d22018-09-25 18:10:19 +0200164 self.task_registry = {
165 "ns": {},
Felipe Vicensc2033f22018-11-15 15:09:58 +0100166 "nsi": {},
tierno59d22d22018-09-25 18:10:19 +0200167 "vim_account": {},
tiernoe37b57d2018-12-11 17:22:51 +0000168 "wim_account": {},
tierno59d22d22018-09-25 18:10:19 +0200169 "sdn": {},
calvinosanch9f9c6f22019-11-04 13:37:39 +0100170 "k8scluster": {},
171 "k8srepo": {},
tierno59d22d22018-09-25 18:10:19 +0200172 }
kuused124bfe2019-06-18 12:09:24 +0200173 self.worker_id = worker_id
174 self.db = db
175 self.logger = logger
tierno59d22d22018-09-25 18:10:19 +0200176
177 def register(self, topic, _id, op_id, task_name, task):
178 """
179 Register a new task
Felipe Vicensc2033f22018-11-15 15:09:58 +0100180 :param topic: Can be "ns", "nsi", "vim_account", "sdn"
tierno59d22d22018-09-25 18:10:19 +0200181 :param _id: _id of the related item
182 :param op_id: id of the operation of the related item
183 :param task_name: Task descriptive name, as create, instantiate, terminate. Must be unique in this op_id
184 :param task: Task class
185 :return: none
186 """
187 if _id not in self.task_registry[topic]:
188 self.task_registry[topic][_id] = OrderedDict()
189 if op_id not in self.task_registry[topic][_id]:
190 self.task_registry[topic][_id][op_id] = {task_name: task}
191 else:
192 self.task_registry[topic][_id][op_id][task_name] = task
193 # print("registering task", topic, _id, op_id, task_name, task)
194
195 def remove(self, topic, _id, op_id, task_name=None):
196 """
tiernobaa51102018-12-14 13:16:18 +0000197 When task is ended, it should be removed. It ignores missing tasks. It also removes tasks done with this _id
Felipe Vicensc2033f22018-11-15 15:09:58 +0100198 :param topic: Can be "ns", "nsi", "vim_account", "sdn"
tierno59d22d22018-09-25 18:10:19 +0200199 :param _id: _id of the related item
200 :param op_id: id of the operation of the related item
tiernobaa51102018-12-14 13:16:18 +0000201 :param task_name: Task descriptive name. If none it deletes all tasks with same _id and op_id
202 :return: None
tierno59d22d22018-09-25 18:10:19 +0200203 """
tiernobaa51102018-12-14 13:16:18 +0000204 if not self.task_registry[topic].get(_id):
tierno59d22d22018-09-25 18:10:19 +0200205 return
206 if not task_name:
tiernobaa51102018-12-14 13:16:18 +0000207 self.task_registry[topic][_id].pop(op_id, None)
208 elif self.task_registry[topic][_id].get(op_id):
209 self.task_registry[topic][_id][op_id].pop(task_name, None)
210
211 # delete done tasks
212 for op_id_ in list(self.task_registry[topic][_id]):
213 for name, task in self.task_registry[topic][_id][op_id_].items():
214 if not task.done():
215 break
216 else:
217 del self.task_registry[topic][_id][op_id_]
tierno59d22d22018-09-25 18:10:19 +0200218 if not self.task_registry[topic][_id]:
219 del self.task_registry[topic][_id]
220
221 def lookfor_related(self, topic, _id, my_op_id=None):
222 task_list = []
223 task_name_list = []
224 if _id not in self.task_registry[topic]:
225 return "", task_name_list
226 for op_id in reversed(self.task_registry[topic][_id]):
227 if my_op_id:
228 if my_op_id == op_id:
229 my_op_id = None # so that the next task is taken
230 continue
231
232 for task_name, task in self.task_registry[topic][_id][op_id].items():
tiernobaa51102018-12-14 13:16:18 +0000233 if not task.done():
234 task_list.append(task)
235 task_name_list.append(task_name)
tierno59d22d22018-09-25 18:10:19 +0200236 break
237 return ", ".join(task_name_list), task_list
238
239 def cancel(self, topic, _id, target_op_id=None, target_task_name=None):
240 """
kuused124bfe2019-06-18 12:09:24 +0200241 Cancel all active tasks of a concrete ns, nsi, vim_account, sdn identified for _id. If op_id is supplied only
Felipe Vicensc2033f22018-11-15 15:09:58 +0100242 this is cancelled, and the same with task_name
tierno59d22d22018-09-25 18:10:19 +0200243 """
244 if not self.task_registry[topic].get(_id):
245 return
246 for op_id in reversed(self.task_registry[topic][_id]):
247 if target_op_id and target_op_id != op_id:
248 continue
249 for task_name, task in self.task_registry[topic][_id][op_id].items():
250 if target_task_name and target_task_name != task_name:
251 continue
252 # result =
253 task.cancel()
254 # if result:
255 # self.logger.debug("{} _id={} order_id={} task={} cancelled".format(topic, _id, op_id, task_name))
256
kuuse6a470c62019-07-10 13:52:45 +0200257 # Is topic NS/NSI?
258 def _is_service_type_HA(self, topic):
259 return topic in self.topic_service_list
260
261 # Is topic VIM/WIM/SDN?
262 def _is_account_type_HA(self, topic):
263 return topic in self.topic_account_list
264
265 # Input: op_id, example: 'abc123def:3' Output: account_id='abc123def', op_index=3
266 def _get_account_and_op_HA(self, op_id):
267 if not op_id:
garciaale65003392020-10-21 15:21:37 -0300268 return None, None
kuuse6a470c62019-07-10 13:52:45 +0200269 account_id, _, op_index = op_id.rpartition(':')
garciaale65003392020-10-21 15:21:37 -0300270 if not account_id or not op_index.isdigit():
271 return None, None
kuuse6a470c62019-07-10 13:52:45 +0200272 return account_id, op_index
273
274 # Get '_id' for any topic and operation
275 def _get_instance_id_HA(self, topic, op_type, op_id):
276 _id = None
277 # Special operation 'ANY', for SDN account associated to a VIM account: op_id as '_id'
278 if op_type == 'ANY':
279 _id = op_id
280 # NS/NSI: Use op_id as '_id'
281 elif self._is_service_type_HA(topic):
282 _id = op_id
calvinosanch9f9c6f22019-11-04 13:37:39 +0100283 # VIM/SDN/WIM/K8SCLUSTER: Split op_id to get Account ID and Operation Index, use Account ID as '_id'
kuuse6a470c62019-07-10 13:52:45 +0200284 elif self._is_account_type_HA(topic):
285 _id, _ = self._get_account_and_op_HA(op_id)
286 return _id
287
288 # Set DB _filter for querying any related process state
289 def _get_waitfor_filter_HA(self, db_lcmop, topic, op_type, op_id):
290 _filter = {}
291 # Special operation 'ANY', for SDN account associated to a VIM account: op_id as '_id'
292 # In this special case, the timestamp is ignored
293 if op_type == 'ANY':
294 _filter = {'operationState': 'PROCESSING'}
295 # Otherwise, get 'startTime' timestamp for this operation
296 else:
297 # NS/NSI
298 if self._is_service_type_HA(topic):
tierno79cd8ad2019-10-18 13:03:10 +0000299 now = time()
kuuse6a470c62019-07-10 13:52:45 +0200300 starttime_this_op = db_lcmop.get("startTime")
301 instance_id_label = self.topic2instid_dict.get(topic)
302 instance_id = db_lcmop.get(instance_id_label)
303 _filter = {instance_id_label: instance_id,
304 'operationState': 'PROCESSING',
tierno79cd8ad2019-10-18 13:03:10 +0000305 'startTime.lt': starttime_this_op,
306 "_admin.modified.gt": now - 2*3600, # ignore if tow hours of inactivity
307 }
calvinosanch9f9c6f22019-11-04 13:37:39 +0100308 # VIM/WIM/SDN/K8scluster
kuuse6a470c62019-07-10 13:52:45 +0200309 elif self._is_account_type_HA(topic):
310 _, op_index = self._get_account_and_op_HA(op_id)
311 _ops = db_lcmop['_admin']['operations']
312 _this_op = _ops[int(op_index)]
313 starttime_this_op = _this_op.get('startTime', None)
314 _filter = {'operationState': 'PROCESSING',
315 'startTime.lt': starttime_this_op}
316 return _filter
317
318 # Get DB params for any topic and operation
319 def _get_dbparams_for_lock_HA(self, topic, op_type, op_id):
320 q_filter = {}
321 update_dict = {}
322 # NS/NSI
323 if self._is_service_type_HA(topic):
324 q_filter = {'_id': op_id, '_admin.worker': None}
325 update_dict = {'_admin.worker': self.worker_id}
326 # VIM/WIM/SDN
327 elif self._is_account_type_HA(topic):
328 account_id, op_index = self._get_account_and_op_HA(op_id)
329 if not account_id:
330 return None, None
331 if op_type == 'create':
332 # Creating a VIM/WIM/SDN account implies setting '_admin.current_operation' = 0
333 op_index = 0
334 q_filter = {'_id': account_id, "_admin.operations.{}.worker".format(op_index): None}
335 update_dict = {'_admin.operations.{}.worker'.format(op_index): self.worker_id,
336 '_admin.current_operation': op_index}
337 return q_filter, update_dict
338
kuused124bfe2019-06-18 12:09:24 +0200339 def lock_HA(self, topic, op_type, op_id):
340 """
kuuse6a470c62019-07-10 13:52:45 +0200341 Lock a task, if possible, to indicate to the HA system that
kuused124bfe2019-06-18 12:09:24 +0200342 the task will be executed in this LCM instance.
kuuse6a470c62019-07-10 13:52:45 +0200343 :param topic: Can be "ns", "nsi", "vim", "wim", or "sdn"
344 :param op_type: Operation type, can be "nslcmops", "nsilcmops", "create", "edit", "delete"
345 :param op_id: NS, NSI: Operation ID VIM,WIM,SDN: Account ID + ':' + Operation Index
kuused124bfe2019-06-18 12:09:24 +0200346 :return:
kuuse6a470c62019-07-10 13:52:45 +0200347 True=lock was successful => execute the task (not registered by any other LCM instance)
kuused124bfe2019-06-18 12:09:24 +0200348 False=lock failed => do NOT execute the task (already registered by another LCM instance)
kuuse6a470c62019-07-10 13:52:45 +0200349
350 HA tasks and backward compatibility:
351 If topic is "account type" (VIM/WIM/SDN) and op_id is None, 'op_id' was not provided by NBI.
352 This means that the running NBI instance does not support HA.
353 In such a case this method should always return True, to always execute
354 the task in this instance of LCM, without querying the DB.
tierno59d22d22018-09-25 18:10:19 +0200355 """
356
calvinosanch9f9c6f22019-11-04 13:37:39 +0100357 # Backward compatibility for VIM/WIM/SDN/k8scluster without op_id
kuuse6a470c62019-07-10 13:52:45 +0200358 if self._is_account_type_HA(topic) and op_id is None:
359 return True
tierno59d22d22018-09-25 18:10:19 +0200360
kuuse6a470c62019-07-10 13:52:45 +0200361 # Try to lock this task
garciaale65003392020-10-21 15:21:37 -0300362 db_table_name = self.topic2dbtable_dict[topic]
kuuse6a470c62019-07-10 13:52:45 +0200363 q_filter, update_dict = self._get_dbparams_for_lock_HA(topic, op_type, op_id)
364 db_lock_task = self.db.set_one(db_table_name,
365 q_filter=q_filter,
366 update_dict=update_dict,
367 fail_on_empty=False)
kuused124bfe2019-06-18 12:09:24 +0200368 if db_lock_task is None:
369 self.logger.debug("Task {} operation={} already locked by another worker".format(topic, op_id))
370 return False
371 else:
kuuse6a470c62019-07-10 13:52:45 +0200372 # Set 'detailed-status' to 'In progress' for VIM/WIM/SDN operations
373 if self._is_account_type_HA(topic):
374 detailed_status = 'In progress'
375 account_id, op_index = self._get_account_and_op_HA(op_id)
376 q_filter = {'_id': account_id}
377 update_dict = {'_admin.operations.{}.detailed-status'.format(op_index): detailed_status}
378 self.db.set_one(db_table_name,
379 q_filter=q_filter,
380 update_dict=update_dict,
381 fail_on_empty=False)
kuused124bfe2019-06-18 12:09:24 +0200382 return True
383
garciaale65003392020-10-21 15:21:37 -0300384 def unlock_HA(self, topic, op_type, op_id, operationState, detailed_status):
kuuse6a470c62019-07-10 13:52:45 +0200385 """
386 Register a task, done when finished a VIM/WIM/SDN 'create' operation.
387 :param topic: Can be "vim", "wim", or "sdn"
388 :param op_type: Operation type, can be "create", "edit", "delete"
389 :param op_id: Account ID + ':' + Operation Index
390 :return: nothing
391 """
392
393 # Backward compatibility
garciaale65003392020-10-21 15:21:37 -0300394 if not self._is_account_type_HA(topic) or not op_id:
kuuse6a470c62019-07-10 13:52:45 +0200395 return
396
397 # Get Account ID and Operation Index
398 account_id, op_index = self._get_account_and_op_HA(op_id)
garciaale65003392020-10-21 15:21:37 -0300399 db_table_name = self.topic2dbtable_dict[topic]
kuuse6a470c62019-07-10 13:52:45 +0200400
401 # If this is a 'delete' operation, the account may have been deleted (SUCCESS) or may still exist (FAILED)
402 # If the account exist, register the HA task.
403 # Update DB for HA tasks
404 q_filter = {'_id': account_id}
405 update_dict = {'_admin.operations.{}.operationState'.format(op_index): operationState,
garciaale65003392020-10-21 15:21:37 -0300406 '_admin.operations.{}.detailed-status'.format(op_index): detailed_status,
407 '_admin.operations.{}.worker'.format(op_index): None,
408 '_admin.current_operation': None}
kuuse6a470c62019-07-10 13:52:45 +0200409 self.db.set_one(db_table_name,
410 q_filter=q_filter,
411 update_dict=update_dict,
412 fail_on_empty=False)
413 return
414
kuused124bfe2019-06-18 12:09:24 +0200415 async def waitfor_related_HA(self, topic, op_type, op_id=None):
tierno59d22d22018-09-25 18:10:19 +0200416 """
kuused124bfe2019-06-18 12:09:24 +0200417 Wait for any pending related HA tasks
tierno59d22d22018-09-25 18:10:19 +0200418 """
kuused124bfe2019-06-18 12:09:24 +0200419
kuuse6a470c62019-07-10 13:52:45 +0200420 # Backward compatibility
421 if not (self._is_service_type_HA(topic) or self._is_account_type_HA(topic)) and (op_id is None):
422 return
kuused124bfe2019-06-18 12:09:24 +0200423
kuuse6a470c62019-07-10 13:52:45 +0200424 # Get DB table name
425 db_table_name = self.topic2dbtable_dict.get(topic)
426
427 # Get instance ID
428 _id = self._get_instance_id_HA(topic, op_type, op_id)
429 _filter = {"_id": _id}
430 db_lcmop = self.db.get_one(db_table_name,
431 _filter,
kuused124bfe2019-06-18 12:09:24 +0200432 fail_on_empty=False)
433 if not db_lcmop:
tierno59d22d22018-09-25 18:10:19 +0200434 return
kuuse6a470c62019-07-10 13:52:45 +0200435
436 # Set DB _filter for querying any related process state
437 _filter = self._get_waitfor_filter_HA(db_lcmop, topic, op_type, op_id)
kuused124bfe2019-06-18 12:09:24 +0200438
439 # For HA, get list of tasks from DB instead of from dictionary (in-memory) variable.
440 timeout_wait_for_task = 3600 # Max time (seconds) to wait for a related task to finish
441 # interval_wait_for_task = 30 # A too long polling interval slows things down considerably
442 interval_wait_for_task = 10 # Interval in seconds for polling related tasks
443 time_left = timeout_wait_for_task
444 old_num_related_tasks = 0
445 while True:
kuuse6a470c62019-07-10 13:52:45 +0200446 # Get related tasks (operations within the same instance as this) which are
kuused124bfe2019-06-18 12:09:24 +0200447 # still running (operationState='PROCESSING') and which were started before this task.
kuuse6a470c62019-07-10 13:52:45 +0200448 # In the case of op_type='ANY', get any related tasks with operationState='PROCESSING', ignore timestamps.
449 db_waitfor_related_task = self.db.get_list(db_table_name,
kuused124bfe2019-06-18 12:09:24 +0200450 q_filter=_filter)
451 new_num_related_tasks = len(db_waitfor_related_task)
kuuse6a470c62019-07-10 13:52:45 +0200452 # If there are no related tasks, there is nothing to wait for, so return.
kuused124bfe2019-06-18 12:09:24 +0200453 if not new_num_related_tasks:
kuused124bfe2019-06-18 12:09:24 +0200454 return
455 # If number of pending related tasks have changed,
456 # update the 'detailed-status' field and log the change.
kuuse6a470c62019-07-10 13:52:45 +0200457 # Do NOT update the 'detailed-status' for SDNC-associated-to-VIM operations ('ANY').
458 if (op_type != 'ANY') and (new_num_related_tasks != old_num_related_tasks):
459 step = "Waiting for {} related tasks to be completed.".format(new_num_related_tasks)
460 update_dict = {}
461 q_filter = {'_id': _id}
462 # NS/NSI
463 if self._is_service_type_HA(topic):
garciaale65003392020-10-21 15:21:37 -0300464 update_dict = {'detailed-status': step, 'queuePosition': new_num_related_tasks}
kuuse6a470c62019-07-10 13:52:45 +0200465 # VIM/WIM/SDN
466 elif self._is_account_type_HA(topic):
467 _, op_index = self._get_account_and_op_HA(op_id)
468 update_dict = {'_admin.operations.{}.detailed-status'.format(op_index): step}
469 self.logger.debug("Task {} operation={} {}".format(topic, _id, step))
470 self.db.set_one(db_table_name,
471 q_filter=q_filter,
472 update_dict=update_dict,
473 fail_on_empty=False)
kuused124bfe2019-06-18 12:09:24 +0200474 old_num_related_tasks = new_num_related_tasks
475 time_left -= interval_wait_for_task
476 if time_left < 0:
477 raise LcmException(
478 "Timeout ({}) when waiting for related tasks to be completed".format(
479 timeout_wait_for_task))
480 await asyncio.sleep(interval_wait_for_task)
481
482 return