fixing bug: vim config were not loaded at vim_thread 42/6442/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 29 Aug 2018 08:56:13 +0000 (10:56 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 29 Aug 2018 11:12:02 +0000 (13:12 +0200)
Change-Id: If6cb843ed30d5bb843e31316c86056a681e7ea60
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmanod
osm_ro/nfvo.py
osm_ro/vim_thread.py

index 6cccf0e..6f4c1a8 100755 (executable)
--- a/openmanod
+++ b/openmanod
@@ -48,8 +48,8 @@ import osm_ro
 
 __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes"
 __date__ = "$26-aug-2014 11:09:29$"
-__version__ = "0.5.74-r584"
-version_date = "Jul 2018"
+__version__ = "0.5.75-r585"
+version_date = "Ago 2018"
 database_version = 32      # expected database schema version
 
 
index 98463ea..c748b83 100644 (file)
@@ -4676,7 +4676,7 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
 
     # edit data
     datacenter_id = datacenter['uuid']
-    where={'uuid': datacenter['uuid']}
+    where = {'uuid': datacenter['uuid']}
     remove_port_mapping = False
     new_sdn_port_mapping = None
     if "config" in datacenter_descriptor:
@@ -4686,10 +4686,10 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
                 if "sdn-port-mapping" in new_config_dict:
                     remove_port_mapping = True
                     new_sdn_port_mapping = new_config_dict.pop("sdn-port-mapping")
-                #delete null fields
-                to_delete=[]
+                # delete null fields
+                to_delete = []
                 for k in new_config_dict:
-                    if new_config_dict[k] == None:
+                    if new_config_dict[k] is None:
                         to_delete.append(k)
                         if k == 'sdn-controller':
                             remove_port_mapping = True
@@ -4699,7 +4699,7 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
                     config_text = '{}'
                 config_dict = yaml.load(config_text)
                 config_dict.update(new_config_dict)
-                #delete null fields
+                # delete null fields
                 for k in to_delete:
                     del config_dict[k]
             except Exception as e:
@@ -4712,14 +4712,16 @@ def edit_datacenter(mydb, datacenter_id_name, datacenter_descriptor):
             try:
                 datacenter_sdn_port_mapping_delete(mydb, None, datacenter_id)
             except ovimException as e:
-                logger.error("Error deleting datacenter-port-mapping " + str(e))
+                raise NfvoException("Error deleting datacenter-port-mapping " + str(e), HTTP_Conflict)
 
     mydb.update_rows('datacenters', datacenter_descriptor, where)
     if new_sdn_port_mapping:
         try:
             datacenter_sdn_port_mapping_set(mydb, None, datacenter_id, new_sdn_port_mapping)
         except ovimException as e:
-            logger.error("Error adding datacenter-port-mapping " + str(e))
+            # Rollback
+            mydb.update_rows('datacenters', datacenter, where)
+            raise NfvoException("Error adding datacenter-port-mapping " + str(e), HTTP_Conflict)
     return datacenter_id
 
 
@@ -4730,7 +4732,7 @@ def delete_datacenter(mydb, datacenter):
     try:
         datacenter_sdn_port_mapping_delete(mydb, None, datacenter_dict['uuid'])
     except ovimException as e:
-        logger.error("Error deleting datacenter-port-mapping " + str(e))
+        raise NfvoException("Error deleting datacenter-port-mapping " + str(e))
     return datacenter_dict['uuid'] + " " + datacenter_dict['name']
 
 
index bd1fc3c..089e7b9 100644 (file)
@@ -151,15 +151,20 @@ class vim_thread(threading.Thread):
             with self.db_lock:
                 vims = self.db.get_rows(FROM=from_, SELECT=select_, WHERE=where_)
             vim = vims[0]
-            extra = {'datacenter_tenant_id': vim.get('datacenter_tenant_id'),
-                     'datacenter_id': vim.get('datacenter_id')}
+            vim_config = {}
+            if vim["config"]:
+                vim_config.update(yaml.load(vim["config"]))
+            if vim["dt_config"]:
+                vim_config.update(yaml.load(vim["dt_config"]))
+            vim_config['datacenter_tenant_id'] = vim.get('datacenter_tenant_id')
+            vim_config['datacenter_id'] = vim.get('datacenter_id')
 
             self.vim = vim_module[vim["type"]].vimconnector(
                 uuid=vim['datacenter_id'], name=vim['datacenter_name'],
                 tenant_id=vim['vim_tenant_id'], tenant_name=vim['vim_tenant_name'],
                 url=vim['vim_url'], url_admin=vim['vim_url_admin'],
                 user=vim['user'], passwd=vim['passwd'],
-                config=extra, persistent_info=self.vim_persistent_info
+                config=vim_config, persistent_info=self.vim_persistent_info
             )
             self.error_status = None
         except Exception as e: