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 new methods for NAS server support #51

Merged
merged 2 commits into from
Apr 18, 2023
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jarcoal/httpmock v1.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.2.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jarcoal/httpmock v1.3.0/go.mod h1:3yb8rc4BI7TCBhFY8ng0gjuLKJNquuDNiPaZjnENuYg=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
128 changes: 128 additions & 0 deletions inttests/nfs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright © 2021 - 2023 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"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

// getNasName returns GOSCALEIO_NASSERVER, if set.
func getNasName(t *testing.T) string {
if os.Getenv("GOSCALEIO_NASSERVER") != "" {
return os.Getenv("GOSCALEIO_NASSERVER")
}
system := getSystem()
assert.NotNil(t, system)
nasServer, _ := system.GetNASByName("")
assert.NotNil(t, nasServer)
if nasServer == nil {
return ""
}
fmt.Printf("nas server[0].Name: %v", nasServer.Name)
return nasServer.Name
}

// TestGetNasByName gets a single specific nas server by Name
func TestGetNasByName(t *testing.T) {
system := getSystem()
assert.NotNil(t, system)

nasName := getNasName(t)
assert.NotZero(t, len(nasName))

if len(nasName) > 0 {
nas, err := system.GetNASByName(nasName)
assert.Nil(t, err)
assert.Equal(t, nasName, nas.Name)
}
}

// TestGetNasByNameInvalid attempts to get a nas server that does not exist
func TestGetNasByNameInvalid(t *testing.T) {
system := getSystem()
assert.NotNil(t, system)

nas, err := system.GetNAS(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, nas)
}

// TestGetNasByID will return nas server by id
func TestGetNasByID(t *testing.T) {
system := getSystem()
assert.NotNil(t, system)

nasName := getNasName(t)
assert.NotZero(t, len(nasName))

nasserver, err := system.GetNASByName(nasName)
assert.Nil(t, err)
assert.Equal(t, nasName, nasserver.Name)

if nasserver != nil {
nas, err := system.GetNAS(nasserver.ID)
assert.Nil(t, err)
assert.Equal(t, nasserver.ID, nas.ID)
}
}

// TestGetNasByIDInvalid attempts to get a file system that does not exist
func TestGetNasByIDInvalid(t *testing.T) {
system := getSystem()
assert.NotNil(t, system)

nas, err := system.GetNAS(invalidIdentifier)
assert.NotNil(t, err)
assert.Nil(t, nas)
}

func TestCreateDeleteNAS(t *testing.T) {
system := getSystem()
assert.NotNil(t, system)

nasName := fmt.Sprintf("%s-%s", testPrefix, "twee2")

// get protection domain
pd := getProtectionDomain(t)
assert.NotNil(t, pd)

var pdID string

if pd != nil {
pDomain, _ := system.FindProtectionDomain(pd.ProtectionDomain.ID, "", "")
assert.NotNil(t, pDomain)
pdID = pDomain.ID
}

// create the NAS Server
nasID, err := system.CreateNAS(nasName, pdID)
assert.Nil(t, err)
assert.NotNil(t, nasID.ID)

// try to create a NAS Server that exists
_, err = system.CreateNAS(nasName, pdID)
assert.NotNil(t, err)

// delete the NAS Server
err = system.DeleteNAS(nasID.ID)
assert.Nil(t, err)

// try to delete non-existent NAS Server
err = system.DeleteNAS(nasID.ID)
assert.NotNil(t, err)

}
88 changes: 88 additions & 0 deletions nfs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright © 2019 - 2023 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 goscaleio

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

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

// GetNASByName gets a NAS server by name
func (s *System) GetNASByName(name string) (*types.NAS, error) {
var nasList []types.NAS

path := fmt.Sprintf("/rest/v1/nas-servers?select=*")
err := s.client.getJSONWithRetry(
http.MethodGet, path, nil, &nasList)
if err != nil {
return nil, err
}

for _, nas := range nasList {
if nas.Name == name {
return &nas, nil
}
}
return nil, errors.New("couldn't find given NAS server name")
}

// GetNAS gets a NAS server by ID
func (s *System) GetNAS(id string) (*types.NAS, error) {
path := fmt.Sprintf("/rest/v1/nas-servers/%s?select=*", id)

var resp *types.NAS
err := s.client.getJSONWithRetry(
http.MethodGet, path, nil, &resp)
if err != nil {
return nil, err
}
return resp, nil
}

// CreateNAS creates a NAS server
func (s *System) CreateNAS(name string, protectionDomainID string) (*types.CreateNASResponse, error) {
var resp types.CreateNASResponse

path := fmt.Sprintf("/rest/v1/nas-servers")

var body types.CreateNASParam = types.CreateNASParam{
Name: name,
ProtectionDomainID: protectionDomainID,
}

err := s.client.getJSONWithRetry(http.MethodPost, path, body, &resp)

if err != nil {
return nil, err
}

return &resp, nil
}

// DeleteNAS deletes a NAS server
func (s *System) DeleteNAS(id string) error {

path := fmt.Sprintf("/rest/v1/nas-servers/%s", id)

err := s.client.getJSONWithRetry(http.MethodDelete, path, nil, nil)

if err != nil {
fmt.Println("err", err)
return err
}

return nil
}
Loading