Skip to content

Commit

Permalink
Merge pull request #49 from prasannakumari-sundaraeasan/dashboard_change
Browse files Browse the repository at this point in the history
Pushing results to dashboard for volume workflow
  • Loading branch information
vidhutsingh authored May 24, 2021
2 parents 742e2b8 + 70f5340 commit 6029274
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 29 deletions.
13 changes: 11 additions & 2 deletions test/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ package test

import (
"flag"
"strconv"
"strings"

"github.com/hpe-storage/nimble-golang-sdk/pkg/client/v1/nimbleos"
"github.com/hpe-storage/nimble-golang-sdk/pkg/param"
"github.com/hpe-storage/nimble-golang-sdk/pkg/sdkprovider"
"github.com/hpe-storage/nimble-golang-sdk/pkg/service"
"strconv"
"strings"
)

const defaultVolumeName = "DefaultVolumeTest"
Expand All @@ -31,6 +32,14 @@ var sourceArrayUsername = flag.String("sourceArrayUsername", "xxx", "Source arra

var sourceArrayPassword = flag.String("sourceArrayPassword", "xxx", "Source array password")

// Dashboard
var postResultToDashboard = flag.String("postResultToDashboard", "xxx", "Dashboard flag")
var dashboardUsername = flag.String("dashboardUsername", "xxx", "Dashboard username")
var dashboardPassword = flag.String("dashboardPassword", "xxx", "Dashboard password")
var dashboardURL = flag.String("dashboardURL", "xxx", "Dashboard Url")
var testStarted []bool
var testCompleted []bool

func config() (*service.NsGroupService, error) {
groupService, err := service.NewNsGroupService(*arrayIP, *arrayUsername, *arrayPassword, "v1", true)
if err != nil {
Expand Down
122 changes: 122 additions & 0 deletions test/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// Copyright 2021 Hewlett Packard Enterprise Development LP

package test

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
)

var jar *cookiejar.Jar
var runId string
var postDataClient *http.Client

func loginDashboard() *http.Client {
jar, _ := cookiejar.New(nil)
client := &http.Client{
Jar: jar,
}
username := *dashboardUsername
password := *dashboardPassword
var jsonStr = []byte("{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}")
url := *dashboardURL + "/apilogin"
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
panic(err)
} else {
resp.Body.Close()
}
return client
}

func generateRunid() *http.Client {

postDataClient := loginDashboard()
if runId != "" {
return postDataClient
}
newBuild := "true"
json_string := "{\"TestCaseResults\": {\"Status\": \"PASS\", \"Branch\": \"default\"," +
"\"NewBuild\": \"" + newBuild + "\"," +
"\"BuildId\": \"1\"," +
"\"AppName\": \"Golang\"," +
"\"ArrayBuild\": \"5.087\"," +
"\"ProductName\": \"GolangSDK\"," +
"\"TestCaseName\": \"san-1235\"," +
"\"Description\": \"VolumeVolCollAssociate\"," +
"\"PlatformName\": \"Linux\"," +
"\"Duration\": \"2\"," +
"\"StartTimeStamp\": \"120102\"," +
"\"RingId\": \"2\"," +
"\"EndTimeStamp\": \"120103\"," +
"\"TargetScope\": \"volume\"," +
"\"Protocol\": \"iscsi\"," +
"\"SuiteName\": \"Golang SDK\"," +
"\"JenkinsJob\": \"\"" +
"}}"
var testData = []byte(json_string)
url := *dashboardURL + "/testcasevalues"
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(testData))
req.Header.Add("Content-Type", "application/json")
resp, err := postDataClient.Do(req)
if err != nil {
fmt.Println(err)

} else {
body, _ := ioutil.ReadAll(resp.Body)
var data map[string]interface{}
error := json.Unmarshal([]byte(string(body)), &data)
if error != nil {
panic(error)
}
status, ok := data["status"].(map[string]interface{})
if !ok {
panic("Response status not found!")
}
runId = fmt.Sprintf("%v", status["RunId"])
resp.Body.Close()
}
return postDataClient
}

func pushResultToDashboard(result string, testId string, testName string) {

postDataClient := generateRunid()
newBuild := "false"
json_string := "{\"TestCaseResults\": {\"Status\": \"" + result + "\", \"Branch\": \"default\"," +
"\"NewBuild\": \"" + newBuild + "\"," +
"\"BuildId\": \"1\"," +
"\"AppName\": \"Golang\"," +
"\"ArrayBuild\": \"5.087\"," +
"\"ProductName\": \"GolangSDK\"," +
"\"TestCaseName\": \"" + testId + "\"," +
"\"Description\": \"" + testName + "\"," +
"\"PlatformName\": \"Linux\"," +
"\"Duration\": \"2\"," +
"\"StartTimeStamp\": \"120102\"," +
"\"RingId\": \"2\"," +
"\"EndTimeStamp\": \"120103\"," +
"\"TargetScope\": \"volume\"," +
"\"Protocol\": \"iscsi\"," +
"\"SuiteName\": \"Golang SDK\"," +
"\"JenkinsJob\": \"\"," +
"\"RunId\": \"" + runId + "\"" +
"}}"
var testData = []byte(json_string)
url := *dashboardURL + "/testcasevalues"
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(testData))
req.Header.Add("Content-Type", "application/json")
resp, err := postDataClient.Do(req)
if err != nil {
fmt.Println(err)
} else {
resp.Body.Close()
}

}
87 changes: 60 additions & 27 deletions test/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
package test

import (
"testing"

"github.com/hpe-storage/nimble-golang-sdk/pkg/client/v1/nimbleos"
"github.com/hpe-storage/nimble-golang-sdk/pkg/param"
"github.com/hpe-storage/nimble-golang-sdk/pkg/sdkprovider"
"github.com/hpe-storage/nimble-golang-sdk/pkg/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"testing"
)

const volumeName = "VolumeTest"
Expand All @@ -25,35 +26,50 @@ type VolumeWorkflowSuite struct {

func (suite *VolumeWorkflowSuite) SetupSuite() {
groupService, err := config()
assert.Nilf(suite.T(), err, "Unable to connect to group, err: %v", err)
require.Nilf(suite.T(), err, "Unable to connect to group, err: %v", err)
suite.groupService = groupService
suite.volumeService = groupService.GetVolumeService()
suite.snapshotService = groupService.GetSnapshotService()
suite.volcollService = groupService.GetVolumeCollectionService()
suite.initiatorGrpService = groupService.GetInitiatorGroupService()
_, err = createDefaultInitiatorGrp(suite.initiatorGrpService)
assert.Nilf(suite.T(), err, "Unable to create default initiator group, err: %v", err)
require.Nilf(suite.T(), err, "Unable to create default initiator group, err: %v", err)
_, err = createDefaultVolColl(suite.volcollService)
assert.Nilf(suite.T(), err, "Unable to create default volume collection, err: %v", err)
require.Nilf(suite.T(), err, "Unable to create default volume collection, err: %v", err)
suite.createVolume()

}

func (suite *VolumeWorkflowSuite) TearDownSuite() {

var volumeTestResult string
if len(testStarted) == len(testCompleted) {
volumeTestResult = "PASS"
} else {
volumeTestResult = "FAIL"
}
var postResult = *postResultToDashboard
if postResult == "true" {
pushResultToDashboard(volumeTestResult, "C545072", "Volume workflow")
}
//cleanup test result
testStarted = testStarted[:0]
testCompleted = testCompleted[:0]
suite.deleteVolume(volumeName)
err := deleteDefaultInitiatorGroup(suite.initiatorGrpService)
assert.Nilf(suite.T(), err, "Unable to delete default initiator group, err: %v", err)
require.Nilf(suite.T(), err, "Unable to delete default initiator group, err: %v", err)
err = deleteDefaultVolColl(suite.volcollService)
assert.Nilf(suite.T(), err, "Unable to delete default volume collection, err: %v", err)
require.Nilf(suite.T(), err, "Unable to delete default volume collection, err: %v", err)
suite.groupService.LogoutService()
}

func (suite *VolumeWorkflowSuite) deleteVolume(volumeName string) {
volObj, _ := suite.volumeService.GetVolumeByName(volumeName)
_, err := suite.volumeService.OfflineVolume(*volObj.ID, true)
assert.Nilf(suite.T(), err, "Unable to offline volume, err: %v", err)
require.Nilf(suite.T(), err, "Unable to offline volume, err: %v", err)
if volObj != nil {
err := suite.volumeService.DeleteVolume(*volObj.ID)
assert.Nilf(suite.T(), err, "Unable to delete volume, err: %v", volumeName)
require.Nilf(suite.T(), err, "Unable to delete volume, err: %v", volumeName)
}
}

Expand All @@ -64,30 +80,35 @@ func (suite *VolumeWorkflowSuite) createVolume() {
Size: &sizeField,
}
_, err := suite.volumeService.CreateVolume(newVolume)
assert.Nilf(suite.T(), err, "Volume creation failed with error: %v", err)
require.Nilf(suite.T(), err, "Volume creation failed with error: %v", err)
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
assert.Equal(suite.T(), sizeField, *vol.Size, "Size was not set correctly")
require.Equal(suite.T(), sizeField, *vol.Size, "Size was not set correctly")
}

func (suite *VolumeWorkflowSuite) TestVolumeCreateWithMissParams() {
testStarted = append(testStarted, true)
newVolume := &nimbleos.Volume{
Name: param.NewString(volumeName),
}
_, err := suite.volumeService.CreateVolume(newVolume)
assert.NotNil(suite.T(), err, "Volume creation should have failed")
require.NotNil(suite.T(), err, "Volume creation should have failed")
testCompleted = append(testCompleted, true)
}

func (suite *VolumeWorkflowSuite) TestVolumeCreateDuplicate() {
testStarted = append(testStarted, true)
var sizeField int64 = 5120
newVolume := &nimbleos.Volume{
Name: param.NewString(volumeName),
Size: &sizeField,
}
_, err := suite.volumeService.CreateVolume(newVolume)
assert.NotNil(suite.T(), err, "Creating duplicate volume should have failed")
require.NotNil(suite.T(), err, "Creating duplicate volume should have failed")
testCompleted = append(testCompleted, true)
}

func (suite *VolumeWorkflowSuite) TestCreateVolumeByCloning() {
testStarted = append(testStarted, true)
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
if vol != nil {
newSnapshot := &nimbleos.Snapshot{
Expand All @@ -101,17 +122,19 @@ func (suite *VolumeWorkflowSuite) TestCreateVolumeByCloning() {
BaseSnapId: snap.ID,
}
_, err := suite.volumeService.CreateVolume(newVolume)
assert.Nilf(suite.T(), err, "Unable to clone volume, err: %v", err)
require.Nilf(suite.T(), err, "Unable to clone volume, err: %v", err)
cloneVol, _ := suite.volumeService.GetVolumeByName("TestClone")
assert.NotNil(suite.T(), cloneVol, "TestClone should have been present")
require.NotNil(suite.T(), cloneVol, "TestClone should have been present")
_, err = suite.volumeService.OfflineVolume(*cloneVol.ID, true)
assert.Nilf(suite.T(), err, "Unable to offline volume, err: %v", err)
require.Nilf(suite.T(), err, "Unable to offline volume, err: %v", err)
err = suite.volumeService.DeleteVolume(*cloneVol.ID)
assert.Nilf(suite.T(), err, "Unable to delete volume, err: %v", err)
require.Nilf(suite.T(), err, "Unable to delete volume, err: %v", err)
testCompleted = append(testCompleted, true)
}
}

func (suite *VolumeWorkflowSuite) TestVolumeUpdateSize() {
testStarted = append(testStarted, true)
var sizeIncField int64 = 10240
var limitIopsField int64 = 256
var limitMbpsField int64 = 1
Expand All @@ -123,52 +146,62 @@ func (suite *VolumeWorkflowSuite) TestVolumeUpdateSize() {
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
if vol != nil {
_, err := suite.volumeService.UpdateVolume(*vol.ID, newVolume)
assert.Nilf(suite.T(), err, "Unable to update volume size, err: %v", err)
require.Nilf(suite.T(), err, "Unable to update volume size, err: %v", err)
}
updateVol, _ := suite.volumeService.GetVolumeByName(volumeName)
assert.Equal(suite.T(), *updateVol.LimitMbps, limitMbpsField, "Volume modify failed to update LimitMbps")
assert.Equal(suite.T(), *updateVol.Size, sizeIncField, "Volume size increase failed.")
require.Equal(suite.T(), *updateVol.LimitMbps, limitMbpsField, "Volume modify failed to update LimitMbps")
require.Equal(suite.T(), *updateVol.Size, sizeIncField, "Volume size increase failed.")
var sizeDecField int64 = 4000
newVolume = &nimbleos.Volume{
Size: &sizeDecField,
}
if vol != nil {
_, err := suite.volumeService.UpdateVolume(*vol.ID, newVolume)
assert.NotNil(suite.T(), err, "Decreasing volume size without force should have failed")
require.NotNil(suite.T(), err, "Decreasing volume size without force should have failed")
testCompleted = append(testCompleted, true)
}
}

func (suite *VolumeWorkflowSuite) TestVolumeUpdateOfflineVolume() {
testStarted = append(testStarted, true)
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
if vol != nil {
_, err := suite.volumeService.OfflineVolume(*vol.ID, false)
assert.Nilf(suite.T(), err, "Unable to set volume offline, err: %v", err)
require.Nilf(suite.T(), err, "Unable to set volume offline, err: %v", err)
vol, _ = suite.volumeService.GetVolumeByName(volumeName)
assert.Equal(suite.T(), *vol.VolState, *nimbleos.NsVolStatusOffline, "Volume did not go offline")
require.Equal(suite.T(), *vol.VolState, *nimbleos.NsVolStatusOffline, "Volume did not go offline")
testCompleted = append(testCompleted, true)
} else {
suite.T().Errorf("Could not find the volume")
}

}

func (suite *VolumeWorkflowSuite) TestVolumeUpdateOnlineVolume() {
testStarted = append(testStarted, true)
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
if vol != nil {
_, err := suite.volumeService.OnlineVolume(*vol.ID, false)
assert.Nilf(suite.T(), err, "Unable to set volume online, error: %v", err)
require.Nilf(suite.T(), err, "Unable to set volume online, error: %v", err)
vol, _ = suite.volumeService.GetVolumeByName(volumeName)
assert.Equal(suite.T(), *vol.VolState, *nimbleos.NsVolStatusOnline, "Volume did not come online")
require.Equal(suite.T(), *vol.VolState, *nimbleos.NsVolStatusOnline, "Volume did not come online")
testCompleted = append(testCompleted, true)

} else {
suite.T().Error("Could not find volume")

}
}

func (suite *VolumeWorkflowSuite) TestVolumeVolCollAssociate() {
testStarted = append(testStarted, true)
vol, _ := suite.volumeService.GetVolumeByName(volumeName)
volcoll, _ := suite.volcollService.GetVolumeCollectionByName(defaultVolCollName)
err := suite.volumeService.AssociateVolume(*vol.ID, *volcoll.ID)
assert.Nilf(suite.T(), err, "Associating volume to a volume collection failed: %v", err)
require.Nilf(suite.T(), err, "Associating volume to a volume collection failed: %v", err)
err = suite.volumeService.DisassociateVolume(*vol.ID)
assert.Nilf(suite.T(), err, "Disassociating volume to a volume collection failed: %v", err)
require.Nilf(suite.T(), err, "Disassociating volume to a volume collection failed: %v", err)
testCompleted = append(testCompleted, true)
}

func TestVolumeWorkflowSuite(t *testing.T) {
Expand Down

0 comments on commit 6029274

Please sign in to comment.