Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to retrieve source volumes #97

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions inttests/snapshot_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func TestCreateModifyDeleteSnapshotPolicy(t *testing.T) {
err = system.AssignVolumeToSnapshotPolicy(assignVolume, snapID)
assert.Nil(t, err)

vol, err2 := system.GetSourceVolume(snapID)
assert.Nil(t, err2)
assert.NotNil(t, vol)

assignVolume = &types.AssignVolumeToSnapshotPolicyParam{
SourceVolumeId: "Invalid",
}
Expand Down
12 changes: 12 additions & 0 deletions snapshot_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ func (system *System) ResumeSnapshotPolicy(id string) error {
}
return nil
}

// GetSourceVolume returns a list of volumes assigned to snapshot policy
func (system *System) GetSourceVolume(id string) ([]*types.Volume, error) {
var volumes []*types.Volume
path := fmt.Sprintf("/api/instances/SnapshotPolicy::%v/relationships/SourceVolume", id)
err := system.client.getJSONWithRetry(
http.MethodGet, path, nil, &volumes)
if err != nil {
return nil, err
}
return volumes, nil
}
45 changes: 45 additions & 0 deletions snapshot_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,48 @@ func TestDeleteSnapshotPolicy(t *testing.T) {
})
}
}

func TestGetSourceVolume(t *testing.T) {
type testCase struct {
id string
expected error
}
cases := []testCase{
{
id: ID2,
expected: nil,
},
{
id: "Invalid",
expected: errors.New("id (Invalid) must be a hexadecimal number (unsigned long)."),
},
}
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))
defer svr.Close()

for _, tc := range cases {
tc := tc
t.Run("", func(ts *testing.T) {
client, err := NewClientWithArgs(svr.URL, "", math.MaxInt64, true, false)
if err != nil {
t.Fatal(err)
}

s := System{
client: client,
}

_, err2 := s.GetSourceVolume(tc.id)
if err2 != nil {
if tc.expected == nil {
t.Errorf("Assigning volume to snapshot policy did not work as expected, \n\tgot: %s \n\twant: %v", err2, tc.expected)
} else {
if err2.Error() != tc.expected.Error() {
t.Errorf("Assigning volume to snapshot policy did not work as expected, \n\tgot: %s \n\twant: %s", err2, tc.expected)
}
}
}
})
}
}
1 change: 0 additions & 1 deletion template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func TestGetTemplateByIDNegative(t *testing.T) {
assert.NotNil(t, err)
}


func TestGetTemplateByFiltersNegative(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ type SnapshotPolicy struct {
Links []*Link `json:"links"`
}

// SnapshotPolicyCreate defines the struct for creating a Snapshot Policy
// SnapshotPolicyCreateParam defines the struct for creating a Snapshot Policy
type SnapshotPolicyCreateParam struct {
AutoSnapshotCreationCadenceInMin string `json:"autoSnapshotCreationCadenceInMin"`
NumOfRetainedSnapshotsPerLevel []string `json:"numOfRetainedSnapshotsPerLevel"`
Expand Down
Loading