+
+ @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,
+ )
+
+ @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock())
+ @mock.patch.object(dbmongo.DbMongo, "get_list")
+ def test_get_alarms(self, get_list):
+ get_list.return_value = [
+ {
+ "uuid": "1",
+ "name": "name",
+ "severity": "severity",
+ "threshold": 50,
+ "operation": "operation",
+ "statistic": "statistic",
+ "tags": {},
+ }
+ ]
+
+ common_db_client = CommonDbClient(self.config)
+ alarms = common_db_client.get_alarms()
+ self.assertEqual("1", alarms[0].uuid)
+
+ @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock())
+ @mock.patch.object(dbmongo.DbMongo, "create")
+ def test_create_alarm(self, create):
+ alarm = Alarm(
+ "name",
+ "severity",
+ 50.0,
+ "operation",
+ "statistic",
+ "metric",
+ "scale_out",
+ {},
+ "ok",
+ )
+ alarm.uuid = "1"
+ common_db_client = CommonDbClient(self.config)
+ common_db_client.create_alarm(alarm)
+ create.assert_called_with(
+ "alarms",
+ {
+ "tags": {},
+ "threshold": 50.0,
+ "metric": "metric",
+ "severity": "severity",
+ "statistic": "statistic",
+ "name": "name",
+ "operation": "operation",
+ "uuid": "1",
+ "alarm_status": "ok",
+ },
+ )
+
+ @mock.patch.object(dbmongo.DbMongo, "db_connect", mock.Mock())
+ @mock.patch.object(dbmongo.DbMongo, "del_one")
+ def test_delete_alarm(self, delete):
+ common_db_client = CommonDbClient(self.config)
+ common_db_client.delete_alarm("1")
+ delete.assert_called_with("alarms", {"uuid": "1"})