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

fault set changes added #87

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
88 changes: 88 additions & 0 deletions fault_set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright © 2019 - 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
AnikaAgiwal2711 marked this conversation as resolved.
Show resolved Hide resolved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package goscaleio

import (
// "errors"
"fmt"
"net/http"
// "time"

types "github.com/dell/goscaleio/types/v1"
)

// CreateFaultSet creates a fault set
func (pd *ProtectionDomain) CreateFaultSet(fs *types.FaultSetParam) (string, error) {
path := fmt.Sprintf("/api/types/FaultSet/instances")
fs.ProtectionDomainID = pd.ProtectionDomain.ID
fsResp := types.FaultSetResp{}
err := pd.client.getJSONWithRetry(
http.MethodPost, path, fs, &fsResp)
if err != nil {
return "", err
}
return fsResp.ID, nil
}

// DeleteFaultSet will delete a fault set
func (pd *ProtectionDomain) DeleteFaultSet(id string) error {
path := fmt.Sprintf("/api/instances/FaultSet::%v/action/removeFaultSet", id)
fsParam := &types.EmptyPayload{}
err := pd.client.getJSONWithRetry(
http.MethodPost, path, fsParam, nil)
if err != nil {
return err
}
return nil
}

// ModifyFaultSetName will modify the name of the fault set
func (pd *ProtectionDomain) ModifyFaultSetName(id, name string) error {
fs := &types.FaultSetRename{}
fs.NewName = name
path := fmt.Sprintf("/api/instances/FaultSet::%v/action/setFaultSetName", id)

err := pd.client.getJSONWithRetry(
http.MethodPost, path, fs, nil)
if err != nil {
return err
}
return nil
}

// ModifyFaultSetPerfProfile will modify the performance profile of the fault set
func (pd *ProtectionDomain) ModifyFaultSetPerfProfile(id, perfProfile string) error {
pp := &types.ChangeSdcPerfProfile{}
pp.PerfProfile = perfProfile
path := fmt.Sprintf("/api/instances/FaultSet::%v/action/setSdsPerformanceParameters", id)

err := pd.client.getJSONWithRetry(
http.MethodPost, path, pp, nil)
if err != nil {
return err
}
return nil
}

// GetFaultSetByID will read the fault set using the ID.
func (system *System) GetFaultSetByID(id string) (*types.FaultSet, error) {
fs := &types.FaultSet{}
path := fmt.Sprintf("/api/instances/FaultSet::%v", id)

err := system.client.getJSONWithRetry(
http.MethodGet, path, nil, fs)
if err != nil {
return nil, err
}
return fs, nil
}
66 changes: 66 additions & 0 deletions inttests/fault_set_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright © 2021 - 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package inttests

import (
"fmt"
"testing"
"time"

types "github.com/dell/goscaleio/types/v1"
"github.com/stretchr/testify/assert"
)

func TestCreateModifyDeleteFaultSet(t *testing.T) {
domain := getProtectionDomain(t)
system := getSystem()
assert.NotNil(t, domain)
assert.NotNil(t, system)
fsName := fmt.Sprintf("%s-%s", testPrefix, "FaultSet")

fs := &types.FaultSetParam{
Name: fsName,
ProtectionDomainID: domain.ProtectionDomain.ID,
}

// create the fault set
fsID, err := domain.CreateFaultSet(fs)
assert.Nil(t, err)
assert.NotNil(t, fsID)

// create a fault set that exists
fsID2, err2 := domain.CreateFaultSet(fs)
assert.NotNil(t, err2)
assert.Equal(t, "", fsID2)

// modify fault set name
err = domain.ModifyFaultSetName(fsID, "faultSetRenamed")
assert.Nil(t, err)

// modify fault set performance profile
err = domain.ModifyFaultSetPerfProfile(fsID, "Compact")
assert.Nil(t, err)
time.Sleep(5 * time.Second)

// read the fault set
fsr, err := system.GetFaultSetByID(fsID)
assert.Equal(t, "faultSetRenamed", fsr.Name)

// delete the fault set
err = domain.DeleteFaultSet(fsID)
assert.Nil(t, err)

// try to delete non-existent fault set
err3 := domain.DeleteFaultSet(invalidIdentifier)
assert.NotNil(t, err3)
}
23 changes: 23 additions & 0 deletions types/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,3 +1753,26 @@ type QuerySystemLimitsResponse struct {

type QuerySystemLimitsParam struct {
}

// FaultSetParam is the parameters required to create a fault set
type FaultSetParam struct {
ProtectionDomainID string `json:"protectionDomainId"`
Name string `json:"name"`
}

// FaultSetResp defines struct for the response when fault set is created successfully
type FaultSetResp struct {
ID string `json:"id"`
}

// FaultSetResp defines struct for the response when fault set is created successfully
type FaultSet struct {
ID string `json:"id"`
Name string `json:"name"`
ProtectionDomainId string `json:"protectionDomainId"`
}

// FaultSetResp defines struct for the response when fault set is created successfully
type FaultSetRename struct {
NewName string `json:"newName"`
}
Loading