From: Benjamin Diaz Date: Mon, 12 Aug 2019 18:14:10 +0000 (-0300) Subject: Adds vrops_password to passwords to decrypt. Adds check of schema_version for backwar... X-Git-Tag: v6.0.2rc1~2 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F79%2F7879%2F1;p=osm%2FMON.git Adds vrops_password to passwords to decrypt. Adds check of schema_version for backwards compatibility Change-Id: I601b2eec9d84b0f2c33486b184c9ef279a583a24 Signed-off-by: Benjamin Diaz (cherry picked from commit 5fbb199c74f8392e5a79f312ef346e346114adc6) --- diff --git a/osm_mon/core/common_db.py b/osm_mon/core/common_db.py index 3b20bbe..88a509c 100644 --- a/osm_mon/core/common_db.py +++ b/osm_mon/core/common_db.py @@ -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], diff --git a/osm_mon/tests/unit/core/test_common_db_client.py b/osm_mon/tests/unit/core/test_common_db_client.py index 81159ee..e584149 100644 --- a/osm_mon/tests/unit/core/test_common_db_client.py +++ b/osm_mon/tests/unit/core/test_common_db_client.py @@ -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)