From 594f5e5a70491c2f1c28727422d054b5f5724cbf Mon Sep 17 00:00:00 2001 From: shenda1 Date: Fri, 13 Dec 2024 10:50:29 +0530 Subject: [PATCH 1/5] adding replication rule modify function Signed-off-by: shenda1 --- client.go | 1 + replication.go | 15 +++++++++++++++ replication_test.go | 16 ++++++++++++++++ replication_types.go | 18 +++++++++++++++++- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 66253f4..2784cdf 100644 --- a/client.go +++ b/client.go @@ -116,6 +116,7 @@ type Client interface { ModifyFS(ctx context.Context, modifyParams *FSModify, volID string) (EmptyResponse, error) CloneFS(ctx context.Context, createParams *FsClone, fsID string) (CreateResponse, error) CreateReplicationRule(ctx context.Context, createParams *ReplicationRuleCreate) (CreateResponse, error) + ModifyReplicationRule(ctx context.Context, modifyParams *ReplicationRuleModify, id string) (EmptyResponse, error) GetReplicationRule(ctx context.Context, id string) (resp ReplicationRule, err error) GetReplicationRuleByName(ctx context.Context, name string) (ReplicationRule, error) CreateProtectionPolicy(ctx context.Context, createParams *ProtectionPolicyCreate) (CreateResponse, error) diff --git a/replication.go b/replication.go index 4f3e837..c6ce79c 100644 --- a/replication.go +++ b/replication.go @@ -279,3 +279,18 @@ func (c *ClientIMPL) ExecuteActionOnReplicationSession(ctx context.Context, id s &res) return resp, WrapErr(err) } + +// ModifyReplicationRule modifies replication rule +func (c *ClientIMPL) ModifyReplicationRule(ctx context.Context, + modifyParams *ReplicationRuleModify, id string) (resp EmptyResponse, err error) { + _, err = c.APIClient().Query( + ctx, + RequestConfig{ + Method: "PATCH", + Endpoint: replicationRuleURL, + ID: id, + Body: modifyParams, + }, + &resp) + return resp, WrapErr(err) +} diff --git a/replication_test.go b/replication_test.go index 5db8579..eccf4ff 100644 --- a/replication_test.go +++ b/replication_test.go @@ -91,6 +91,22 @@ func TestClientIMPL_CreateReplicationRuleSync(t *testing.T) { assert.Equal(t, volID, resp.ID) } +func TestClientIMPL_ModifyReplicationRule(t *testing.T) { + httpmock.Activate() + defer httpmock.DeactivateAndReset() + httpmock.RegisterResponder("PATCH", fmt.Sprintf("%s/%s", replicationRuleMockURL, replicationRuleID), + httpmock.NewStringResponder(201, "")) + + modifyParams := ReplicationRuleModify{ + Name: "rr-test-modified", + Rpo: "One_Day", + } + + resp, err := C.ModifyReplicationRule(context.Background(), &modifyParams, replicationRuleID) + assert.Nil(t, err) + assert.Equal(t, EmptyResponse(""), resp) +} + func TestClientIMPL_DeleteProtectionPolicy(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/replication_types.go b/replication_types.go index 43a98e7..5056cd2 100644 --- a/replication_types.go +++ b/replication_types.go @@ -67,6 +67,8 @@ type ReplicationRuleCreate struct { Rpo RPOEnum `json:"rpo"` // Unique identifier of the remote system to which this rule will replicate the associated resources RemoteSystemID string `json:"remote_system_id"` + AlertThreshold int `json:"alert_threshold,omitempty"` + IsReadOnly bool `json:"is_read_only,omitempty"` } type ReplicationRule struct { @@ -80,10 +82,12 @@ type ReplicationRule struct { // RemoteSystemID - unique identifier of the remote system to which this rule will replicate the associated resources. RemoteSystemID string `json:"remote_system_id"` ProtectionPolicies []ProtectionPolicy `json:"policies"` + AlertThreshold int `json:"alert_threshold"` + IsReadOnly bool `json:"is_read_only,omitempty"` } func (rule *ReplicationRule) Fields() []string { - return []string{"id", "name", "rpo", "remote_system_id"} + return []string{"id", "name", "rpo", "remote_system_id", "alert_threshold", "is_read_only"} } // VirtualMachines - Details of virtual machine @@ -187,3 +191,15 @@ const ( ReplicationRoleMetroPreferred ReplicationRoleEnum = "Metro_Preferred" ReplicationRoleMetroNonPreferred ReplicationRoleEnum = "Metro_Non_Preferred" ) + +// ReplicationRuleModify modifies replication rule +type ReplicationRuleModify struct { + // Name of the replication rule. + Name string `json:"name,omitempty"` + // Recovery point objective (RPO), which is the acceptable amount of data, measured in units of time, that may be lost in case of a failure. + // If RPO is Zero, it indicates the replication_type is 'sync'. + Rpo RPOEnum `json:"rpo,omitempty"` + // Unique identifier of the remote system to which this rule will replicate the associated resources + RemoteSystemID string `json:"remote_system_id,omitempty"` + AlertThreshold int `json:"alert_threshold,omitempty"` +} From ec3422de30077bd971025a66dd69e0ec3cce4c90 Mon Sep 17 00:00:00 2001 From: shenda1 Date: Fri, 13 Dec 2024 11:10:53 +0530 Subject: [PATCH 2/5] addressed linting issues Signed-off-by: shenda1 --- replication.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/replication.go b/replication.go index c6ce79c..8243c18 100644 --- a/replication.go +++ b/replication.go @@ -281,8 +281,7 @@ func (c *ClientIMPL) ExecuteActionOnReplicationSession(ctx context.Context, id s } // ModifyReplicationRule modifies replication rule -func (c *ClientIMPL) ModifyReplicationRule(ctx context.Context, - modifyParams *ReplicationRuleModify, id string) (resp EmptyResponse, err error) { +func (c *ClientIMPL) ModifyReplicationRule(ctx context.Context, modifyParams *ReplicationRuleModify, id string) (resp EmptyResponse, err error) { _, err = c.APIClient().Query( ctx, RequestConfig{ From 9a8809ed7240ea4b0ddaba33edf10ea11b33c5a0 Mon Sep 17 00:00:00 2001 From: shenda1 Date: Fri, 13 Dec 2024 17:15:43 +0530 Subject: [PATCH 3/5] addressing comments Signed-off-by: shenda1 --- replication_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replication_test.go b/replication_test.go index eccf4ff..2104980 100644 --- a/replication_test.go +++ b/replication_test.go @@ -95,7 +95,7 @@ func TestClientIMPL_ModifyReplicationRule(t *testing.T) { httpmock.Activate() defer httpmock.DeactivateAndReset() httpmock.RegisterResponder("PATCH", fmt.Sprintf("%s/%s", replicationRuleMockURL, replicationRuleID), - httpmock.NewStringResponder(201, "")) + httpmock.NewStringResponder(204, "")) modifyParams := ReplicationRuleModify{ Name: "rr-test-modified", From 2a32cb1e6cca43b87ee73d2fa743ed4956203164 Mon Sep 17 00:00:00 2001 From: shenda1 Date: Fri, 13 Dec 2024 18:08:40 +0530 Subject: [PATCH 4/5] adding mock for ModifyReplicationRule Signed-off-by: shenda1 --- mocks/Client.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mocks/Client.go b/mocks/Client.go index d138f0d..5fcf1c0 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -4364,6 +4364,34 @@ func (_m *Client) WearMetricsByDrive(ctx context.Context, entityID string, inter return r0, r1 } +// ModifyReplicationRule provides a mock function with given fields: ctx, modifyParams, id +func (_m *Client) ModifyReplicationRule(ctx context.Context, modifyParams *gopowerstore.ReplicationRuleModify, id string) (gopowerstore.EmptyResponse, error) { + ret := _m.Called(ctx, modifyParams, id) + + if len(ret) == 0 { + panic("no return value specified for ModifyReplicationRule") + } + + var r0 gopowerstore.EmptyResponse + var r1 error + if rf, ok := ret.Get(0).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) (gopowerstore.EmptyResponse, error)); ok { + return rf(ctx, modifyParams, id) + } + if rf, ok := ret.Get(0).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) gopowerstore.EmptyResponse); ok { + r0 = rf(ctx, modifyParams, id) + } else { + r0 = ret.Get(0).(gopowerstore.EmptyResponse) + } + + if rf, ok := ret.Get(1).(func(context.Context, *gopowerstore.ReplicationRuleModify, string) error); ok { + r1 = rf(ctx, modifyParams, id) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. // The first argument is typically a *testing.T value. func NewClient(t interface { @@ -4377,4 +4405,4 @@ func NewClient(t interface { t.Cleanup(func() { mock.AssertExpectations(t) }) return mock -} +} \ No newline at end of file From 93567526ff8e23cc57b5dd45f2c2374c62bf83ae Mon Sep 17 00:00:00 2001 From: shenda1 Date: Fri, 13 Dec 2024 19:41:52 +0530 Subject: [PATCH 5/5] addressing fmt issues Signed-off-by: shenda1 --- mocks/Client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mocks/Client.go b/mocks/Client.go index 5fcf1c0..affb0a9 100644 --- a/mocks/Client.go +++ b/mocks/Client.go @@ -4405,4 +4405,4 @@ func NewClient(t interface { t.Cleanup(func() { mock.AssertExpectations(t) }) return mock -} \ No newline at end of file +}