fix error updating sdnc 88/8788/2
authortierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 15 Apr 2020 17:00:31 +0000 (17:00 +0000)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Wed, 15 Apr 2020 17:16:02 +0000 (17:16 +0000)
Change-Id: I2721ad846748c1260a71463d421a637e9e979833
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
RO/osm_ro/sdn.py

index a199928..10126ea 100755 (executable)
@@ -207,8 +207,8 @@ class Sdn:
         # get database wim_accounts
         wim_account = self._get_of_controller(of_id)
 
-        db_wim_update = {x: ofc_data[x] for x in ("name", "description", "type", "wim_url")}
-        db_wim_account_update = {x: ofc_data[x] for x in ("name", "user", "password")}
+        db_wim_update = {x: ofc_data[x] for x in ("name", "description", "type", "wim_url") if x in ofc_data}
+        db_wim_account_update = {x: ofc_data[x] for x in ("name", "user", "password") if x in ofc_data}
         db_wim_account_config = ofc_data.get("config", {})
 
         if ofc_data.get("ip") or ofc_data.get("port"):
@@ -222,13 +222,15 @@ class Sdn:
             db_wim_account_config["version"] = ofc_data["version"]
 
         if db_wim_account_config:
-            db_wim_account_update["config"] = yaml.load(wim_account["config"]) or {}
+            db_wim_account_update["config"] = yaml.load(wim_account["config"], Loader=yaml.Loader) or {}
             db_wim_account_update["config"].update(db_wim_account_config)
+            db_wim_account_update["config"] = yaml.safe_dump(db_wim_account_update["config"], default_flow_style=True,
+                                                             width=256)
 
         if db_wim_account_update:
             self.db.update_rows('wim_accounts', db_wim_account_update, WHERE={'uuid': of_id})
         if db_wim_update:
-            self.db.update_rows('wims', db_wim_account_update, WHERE={'uuid': wim_account["wim_id"]})
+            self.db.update_rows('wims', db_wim_update, WHERE={'uuid': wim_account["wim_id"]})
 
     def _get_of_controller(self, of_id):
         wim_accounts = self.db.get_rows(FROM='wim_accounts', WHERE={"uuid": of_id, "sdn": "true"})