[VOL-3107] Add DeleteGroup API to OpenOLT Agent
- DeleteGroup proto API method implemented.
- Unit tests added.
Change-Id: If196a92f7a717fc4cc6c2f0e0bb6ca74fc3683d2
diff --git a/agent/test/Makefile b/agent/test/Makefile
index 1693af0..4f86165 100644
--- a/agent/test/Makefile
+++ b/agent/test/Makefile
@@ -21,7 +21,7 @@
TOP_DIR=`pwd`
OPENOLTDEVICE ?= asfvolt16
-OPENOLT_PROTO_VER ?= v3.3.6
+OPENOLT_PROTO_VER ?= v3.3.9
GTEST_VER ?= release-1.8.0
gtest-target = /usr/local/lib/libgtest.a
diff --git a/agent/test/src/test_core.cc b/agent/test/src/test_core.cc
index 698b894..db957e3 100644
--- a/agent/test/src/test_core.cc
+++ b/agent/test/src/test_core.cc
@@ -2809,3 +2809,88 @@
Status status = OnuItuPonAlarmSet_(onu_itu_pon_alarm_tc);
ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
}
+
+////////////////////////////////////////////////////////////////////////////
+// For testing DeleteGroup functionality
+////////////////////////////////////////////////////////////////////////////
+
+class TestDeleteGroup : public Test {
+ protected:
+ uint32_t group_id = 1;
+ NiceMock<BalMocker> balMock;
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+// Test 1 - DeleteGroup success case
+TEST_F(TestDeleteGroup, DeleteGroupSuccess) {
+ bcmos_errno group_cfg_get_res = BCM_ERR_OK;
+ bcmos_errno group_cfg_clear_res = BCM_ERR_OK;
+ bcmolt_group_cfg grp_cfg_out;
+ bcmolt_group_key grp_key = {};
+
+ grp_key.id = group_id;
+ BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
+
+ EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+ bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
+ grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
+ memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
+ return group_cfg_get_res;
+ }
+ ));
+
+ EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
+
+ Status status = DeleteGroup_(group_id);
+ ASSERT_TRUE( status.error_message() == Status::OK.error_message() );
+}
+
+// Test 2 - DeleteGroup failure case: Group does not exist
+TEST_F(TestDeleteGroup, DeleteGroupFailure_NotFound) {
+ bcmos_errno group_cfg_get_res = BCM_ERR_OK;
+ bcmolt_group_cfg grp_cfg_out;
+ bcmolt_group_key grp_key = {};
+
+ grp_key.id = group_id;
+ BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
+
+ EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+ bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
+ grp_cfg->data.state = BCMOLT_GROUP_STATE_NOT_CONFIGURED;
+ memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
+ return group_cfg_get_res;
+ }
+ ));
+
+ Status status = DeleteGroup_(group_id);
+ ASSERT_TRUE( status.error_code() == grpc::StatusCode::NOT_FOUND );
+}
+
+// Test 3 - DeleteGroup failure case: Group exists but cannot be deleted (due to flow association etc.)
+TEST_F(TestDeleteGroup, DeleteGroupFailure_CannotDelete) {
+ bcmos_errno group_cfg_get_res = BCM_ERR_OK;
+ bcmos_errno group_cfg_clear_res = BCM_ERR_INTERNAL;
+ bcmolt_group_cfg grp_cfg_out;
+ bcmolt_group_key grp_key = {};
+
+ grp_key.id = group_id;
+ BCMOLT_CFG_INIT(&grp_cfg_out, group, grp_key);
+
+ EXPECT_CALL(balMock, bcmolt_cfg_get(_, _)).WillOnce(Invoke([group_cfg_get_res, &grp_cfg_out] (bcmolt_oltid olt, bcmolt_cfg *cfg) {
+ bcmolt_group_cfg* grp_cfg = (bcmolt_group_cfg*)cfg;
+ grp_cfg->data.state = BCMOLT_GROUP_STATE_CONFIGURED;
+ memcpy(&grp_cfg_out, grp_cfg, sizeof(bcmolt_group_cfg));
+ return group_cfg_get_res;
+ }
+ ));
+
+ EXPECT_CALL(balMock, bcmolt_cfg_clear(_, _)).WillOnce(Return(group_cfg_clear_res));
+
+ Status status = DeleteGroup_(group_id);
+ ASSERT_TRUE( status.error_message() != Status::OK.error_message() );
+}