#
##
-""""
+"""
This is thread that interacts with a VIM. It processes TASKs sequentially against a single VIM.
The tasks are stored at database in table ro_tasks
A single ro_task refers to a VIM element (flavor, image, network, ...).
:param target_dict: dictionary to be read
:param args: list of keys to read from target_dict
:param kwargs: only can contain default=value to return if key is not present in the nested dictionary
- :return: The wanted value if exist, None or default otherwise
+ :return: The wanted value if exists, None or default otherwise
"""
for key in args:
if not isinstance(target_dict, dict) or key not in target_dict:
task = ro_task["tasks"][task_index]
task_id = task["task_id"]
created = False
- created_items = {}
target_vim = self.my_vims[ro_task["target_id"]]
try:
created = True
try:
# FIND
+ vim_image_id = ""
if task.get("find_params"):
vim_images = target_vim.get_image_list(**task["find_params"])
ro_vim_item_update = {
"vim_id": vim_image_id,
- "vim_status": "DONE",
+ "vim_status": "ACTIVE",
"created": created,
"created_items": created_items,
"vim_details": None,
ro_vim_item_update = {
"vim_id": vim_flavor_id,
- "vim_status": "DONE",
+ "vim_status": "ACTIVE",
"created": created,
"created_items": created_items,
"vim_details": None,
try:
affinity_group_vim_id = None
affinity_group_data = None
+ param_affinity_group_id = ""
if task.get("params"):
affinity_group_data = task["params"].get("affinity_group_data")
ro_vim_item_update = {
"vim_id": affinity_group_vim_id,
- "vim_status": "DONE",
+ "vim_status": "ACTIVE",
"created": created,
"created_items": created_items,
"vim_details": None,
target_vim = self.my_vims[ro_task["target_id"]]
try:
+ vim_vm_id = ""
if task.get("params"):
vim_vm_id = task["params"].get("vim_vm_id")
action = task["params"].get("action")
# created = True
ro_vim_item_update = {
"vim_id": vim_vm_id,
- "vim_status": "DONE",
+ "vim_status": "ACTIVE",
"created": created,
"created_items": created_items,
"vim_details": None,
@staticmethod
def _match_pci(port_pci, mapping):
"""
- Check if port_pci matches with mapping
- mapping can have brackets to indicate that several chars are accepted. e.g
+ Check if port_pci matches with mapping.
+ The mapping can have brackets to indicate that several chars are accepted. e.g
pci '0000:af:10.1' matches with '0000:af:1[01].[1357]'
:param port_pci: text
:param mapping: text, can contain brackets to indicate several chars are available
try:
# CREATE
+ db_vim = {}
params = task["params"]
vlds_to_connect = params.get("vlds", [])
associated_vim = params.get("target_vim")
refreshed_vim_info = {}
try:
+ vim_vm_id = ""
if task.get("params"):
vim_vm_id = task["params"].get("vim_vm_id")
migrate_host = task["params"].get("migrate_host")
target_vim = self.my_vims[ro_task["target_id"]]
try:
+ vim_vm_id = ""
if task.get("params"):
vim_vm_id = task["params"].get("vim_vm_id")
flavor_dict = task["params"].get("flavor_dict")
ro_vim_item_update = {
"vim_id": vim_vm_id,
- "vim_status": "DONE",
+ "vim_status": "ACTIVE",
"created": created,
"created_items": created_items,
"vim_details": None,
if target == "wim"
else "sdns"
)
+ error_text = ""
try:
step = "Getting {} from db".format(target_id)
"""
Load or reload a vim_account, sdn_controller or wim_account.
Read content from database, load the plugin if not loaded.
- In case of error loading the plugin, it load a failing VIM_connector
+ In case of error loading the plugin, it loads a failing VIM_connector
It fills self db_vims dictionary, my_vims dictionary and vim_targets list
:param target_id: Contains type:_id; where type can be 'vim', ...
:return: None if ok, descriptive text if error
"""
my_task = ro_task["tasks"][task_index]
task_id = my_task["task_id"]
- task_status = None
if my_task["status"] == "FAILED":
return None, None # TODO need to be retry??
task_path = "tasks.{}.status".format(task_index)
try:
db_vim_info_update = None
+ dependency_ro_task = {}
if task["status"] == "SCHEDULED":
# check if tasks that this depends on have been completed
lock_object["locked_at"],
lock_object["locked_at"] + self.task_locked_time,
]
- # locked_at contains two times to avoid race condition. In case the lock has been renew, it will
+ # locked_at contains two times to avoid race condition. In case the lock has been renewed, it will
# contain exactly locked_at + self.task_locked_time
LockRenew.remove_lock_object(lock_object)
# modify own task. Try filtering by to_next_check. For race condition if to_check_at has been modified,
# outside this task (by ro_nbi) do not update it
db_ro_task_update["locked_by"] = None
- # locked_at converted to int only for debugging. When has not decimals it means it has been unlocked
+ # locked_at converted to int only for debugging. When it is not decimals it means it has been unlocked
db_ro_task_update["locked_at"] = int(now - self.task_locked_time)
db_ro_task_update["modified_at"] = now
db_ro_task_update["to_check_at"] = next_check_at
self.assertEqual(result[0], "DONE")
self.assertEqual(result[1].get("vim_id"), "sample_affinity_group_id_1")
self.assertEqual(result[1].get("created"), True)
- self.assertEqual(result[1].get("vim_status"), "DONE")
+ self.assertEqual(result[1].get("vim_status"), "ACTIVE")
def test__new_affinity_group_failed(self):
"""
self.assertEqual(result[0], "DONE")
self.assertEqual(result[1].get("vim_id"), None)
self.assertEqual(result[1].get("created"), False)
- self.assertEqual(result[1].get("vim_status"), "DONE")
+ self.assertEqual(result[1].get("vim_status"), "ACTIVE")
def test__delete_affinity_group_ok(self):
"""
task_index = "task_index_1"
result = instance.exec(ro_task, task_index, self.task_depends)
self.assertEqual(result[0], "DONE")
- self.assertEqual(result[1].get("vim_status"), "DONE")
+ self.assertEqual(result[1].get("vim_status"), "ACTIVE")
class TestVimInteractionMigration(unittest.TestCase):