Adds vrops_password to passwords to decrypt. Adds check of schema_version for backwar... 43/7843/1
authorBenjamin Diaz <bdiaz@whitestack.com>
Mon, 12 Aug 2019 18:14:10 +0000 (15:14 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Mon, 12 Aug 2019 18:14:10 +0000 (15:14 -0300)
Change-Id: I601b2eec9d84b0f2c33486b184c9ef279a583a24
Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
osm_mon/core/common_db.py
osm_mon/tests/unit/core/test_common_db_client.py

index 3b20bbe..88a509c 100644 (file)
@@ -95,7 +95,13 @@ class CommonDbClient:
         vim_account['vim_password'] = self.decrypt_vim_password(vim_account['vim_password'],
                                                                 vim_account['schema_version'],
                                                                 vim_account_id)
-        vim_config_encrypted = ("admin_password", "nsx_password", "vcenter_password")
+        vim_config_encrypted_dict = {
+            "1.1": ("admin_password", "nsx_password", "vcenter_password"),
+            "default": ("admin_password", "nsx_password", "vcenter_password", "vrops_password")
+        }
+        vim_config_encrypted = vim_config_encrypted_dict['default']
+        if vim_account['schema_version'] in vim_config_encrypted_dict.keys():
+            vim_config_encrypted = vim_config_encrypted_dict[vim_account['schema_version']]
         for key in vim_account['config']:
             if key in vim_config_encrypted:
                 vim_account['config'][key] = self.decrypt_vim_password(vim_account['config'][key],
index 81159ee..e584149 100644 (file)
@@ -97,3 +97,52 @@ class CommonDbClientTest(unittest.TestCase):
         }
 
         self.assertDictEqual(vdur, expected_vdur)
+
+    @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock())
+    @mock.patch.object(dbmongo.DbMongo, "get_one")
+    @mock.patch.object(CommonDbClient, "decrypt_vim_password")
+    def test_get_vim_account_default_schema(self, decrypt_vim_password, get_one):
+        schema_version = '10.0'
+        vim_id = '1'
+        get_one.return_value = {
+            '_id': vim_id,
+            'vim_password': 'vim_password',
+            'schema_version': schema_version,
+            'config': {
+                'admin_password': 'admin_password',
+                'vrops_password': 'vrops_password',
+                'nsx_password': 'nsx_password',
+                'vcenter_password': 'vcenter_password'
+            }
+        }
+
+        common_db_client = CommonDbClient(self.config)
+        common_db_client.get_vim_account('1')
+
+        decrypt_vim_password.assert_any_call('vim_password', schema_version, vim_id)
+        decrypt_vim_password.assert_any_call('vrops_password', schema_version, vim_id)
+        decrypt_vim_password.assert_any_call('admin_password', schema_version, vim_id)
+        decrypt_vim_password.assert_any_call('nsx_password', schema_version, vim_id)
+        decrypt_vim_password.assert_any_call('vcenter_password', schema_version, vim_id)
+
+    @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock())
+    @mock.patch.object(dbmongo.DbMongo, "get_one")
+    @mock.patch.object(CommonDbClient, "decrypt_vim_password")
+    def test_get_vim_account_1_1_schema(self, decrypt_vim_password, get_one):
+        schema_version = '1.1'
+        vim_id = '1'
+        get_one.return_value = {
+            '_id': vim_id,
+            'vim_password': 'vim_password',
+            'schema_version': schema_version,
+            'config': {
+                'vrops_password': 'vrops_password'
+            }
+        }
+
+        common_db_client = CommonDbClient(self.config)
+        common_db_client.get_vim_account('1')
+
+        decrypt_vim_password.assert_any_call('vim_password', schema_version, vim_id)
+        self.assertRaises(AssertionError, decrypt_vim_password.assert_any_call, 'vrops_password', schema_version,
+                          vim_id)