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

Code coverage enhanced for service.go in PowerScale #102

Merged
merged 1 commit into from
Jul 7, 2022
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
88 changes: 58 additions & 30 deletions service/features/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Feature: Isilon CSI interface
| "blah" | "unknown" | "none" | "none" | "probe of all isilon clusters failed" |
| "blah" | "controller" | "noIsiService" | "none" | "none" |
| "blah" | "node" | "noIsiService" | "none" | "none" |
| "blah" | "" | "none" | "none" | "none" |

Scenario Outline: Calling logStatistics different times
Given a Isilon service
Expand All @@ -287,8 +288,15 @@ Feature: Isilon CSI interface
| times | errormsg |
| 100 | "none" |

Scenario: Calling functions with noProbeOnStart set to true
Given a Isilon service
When I set noProbeOnStart to "true"
When I call BeforeServe
Then the error contains "none"

Scenario: Calling BeforeServe
Given a Isilon service
When I set noProbeOnStart to "false"
When I call BeforeServe
Then the error contains "probe of all isilon clusters failed"

Expand Down Expand Up @@ -345,33 +353,53 @@ Feature: Isilon CSI interface
And I call NodeGetInfo
Then a valid NodeGetInfoResponse is returned

Scenario: ControllerGetVolume good scenario
Given a Isilon service
When I call Probe
And I call ControllerGetVolume with name "volume2=_=_=43=_=_=System=_=_=cluster1"
Then a valid ControllerGetVolumeResponse is returned

Scenario: ControllerGetVolume volume does not exist scenario
Given a Isilon service
When I call Probe
And I induce error "VolumeNotExistError"
And I call ControllerGetVolume with name ""
Then the error contains "no VolumeID found in request"

Scenario: NodeGetVolumeStats volume does not exist scenario
Given a Isilon service
When I call Probe
And I induce error "VolumeNotExistError"
And I call NodeGetVolumeStats with name "" and path ""
Then the error contains "no VolumeID found in request"

Scenario: NodeGetVolumeStats volume does not exist scenario
Given a Isilon service
When I call Probe
And I call NodeGetVolumeStats with name "volume2=_=_=43=_=_=System=_=_=cluster1" and path ""
Then the error contains "no Volume Path found in request"

Scenario: Identity GetReplicationCapabilities call
Given a Isilon service
When I call GetReplicationCapabilities
Then a valid GetReplicationCapabilitiesResponse is returned
Scenario: ControllerGetVolume good scenario
Given a Isilon service
When I call Probe
And I call ControllerGetVolume with name "volume2=_=_=43=_=_=System=_=_=cluster1"
Then a valid ControllerGetVolumeResponse is returned

Scenario: ControllerGetVolume volume does not exist scenario
Given a Isilon service
When I call Probe
And I induce error "VolumeNotExistError"
And I call ControllerGetVolume with name ""
Then the error contains "no VolumeID found in request"

Scenario: NodeGetVolumeStats volume does not exist scenario
Given a Isilon service
When I call Probe
And I induce error "VolumeNotExistError"
And I call NodeGetVolumeStats with name "" and path ""
Then the error contains "no VolumeID found in request"

Scenario: NodeGetVolumeStats volume does not exist scenario
Given a Isilon service
When I call Probe
And I call NodeGetVolumeStats with name "volume2=_=_=43=_=_=System=_=_=cluster1" and path ""
Then the error contains "no Volume Path found in request"

Scenario: Identity GetReplicationCapabilities call
Given a Isilon service
When I call GetReplicationCapabilities
Then a valid GetReplicationCapabilitiesResponse is returned

Scenario: Call Isilon Service with custom topology
Given a Isilon service with custom topology "blah" "controller"
When I call Probe
Then the error contains "probe of all isilon clusters failed"

Scenario: Call ProbeController
Given a Isilon service
When I call Probe
And I call ProbeController
Then the error contains "none"

Scenario Outline: Dynamic log config change
Given a Isilon service
When I call DynamicLogChange <file>
Then a valid DynamicLogChange occurs <file> <level>
Examples:
| file | level |
| "logLevelInfo.yaml" | "info" |
| "logConfigError.yaml" | "debug" |
Empty file.
1 change: 1 addition & 0 deletions service/mock/loglevel/logConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CSI_LOG_LEVEL: "Debug"
1 change: 1 addition & 0 deletions service/mock/loglevel/logConfigError.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CSI_LOG_LEVEL: "xyz"
1 change: 1 addition & 0 deletions service/mock/loglevel/logLevelInfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CSI_LOG_LEVEL: "INFO"
52 changes: 52 additions & 0 deletions service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ package service
import (
"errors"
"fmt"
"github.com/dell/csi-isilon/common/utils"
"log"
"net"
"net/http/httptest"
"os"
"runtime"
"strings"
"sync"
"time"

"github.com/dell/csi-isilon/common/constants"
"github.com/dell/csi-isilon/common/k8sutils"
csiext "github.com/dell/dell-csi-extensions/replication"
"google.golang.org/grpc"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"os/exec"

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/cucumber/godog"
commonext "github.com/dell/dell-csi-extensions/common"
podmon "github.com/dell/dell-csi-extensions/podmon"
"github.com/dell/gocsi"
"github.com/dell/gofsutil"
Expand Down Expand Up @@ -103,6 +107,8 @@ type feature struct {
getReplicationCapabilityRequest *csiext.GetReplicationCapabilityRequest
getReplicationCapabilityResponse *csiext.GetReplicationCapabilityResponse
validateVolumeHostConnectivityResp *podmon.ValidateVolumeHostConnectivityResponse
ProbeControllerRequest *commonext.ProbeControllerRequest
ProbeControllerResponse *commonext.ProbeControllerResponse
volumeIDList []string
snapshotIDList []string
groupIDList []string
Expand Down Expand Up @@ -247,6 +253,8 @@ func (f *feature) getService() *service {

svc.opts = opts
svc.mode = "controller"
server := grpc.NewServer()
svc.RegisterAdditionalServers(server)
f.service = svc
f.service.nodeID, _ = os.Hostname()
f.service.nodeIP = "127.0.0.1"
Expand Down Expand Up @@ -384,6 +392,10 @@ func FeatureContext(s *godog.Suite) {
s.Step(`^a valid GetReplicationCapabilitiesResponse is returned$`, f.aValidGetReplicationCapabilitiesResponseIsReturned)
s.Step(`^I call ValidateConnectivity$`, f.iCallValidateVolumeHostConnectivity)
s.Step(`^the ValidateConnectivity response message contains "([^"]*)"$`, f.theValidateConnectivityResponseMessageContains)
s.Step(`^I call ProbeController$`, f.iCallProbeController)
s.Step(`^I call DynamicLogChange "([^"]*)"$`, f.iCallDynamicLogChange)
s.Step(`^a valid DynamicLogChange occurs "([^"]*)" "([^"]*)"$`, f.aValidDynamicLogChangeOccurs)
s.Step(`^I set noProbeOnStart to "([^"]*)"$`, f.iSetNoProbeOnStart)
}

// GetPluginInfo
Expand Down Expand Up @@ -3057,3 +3069,43 @@ func (f *feature) theValidateConnectivityResponseMessageContains(expected string
}
return fmt.Errorf("Expected %s message in ValidateVolumeHostConnectivityResp but it wasn't there", expected)
}

func (f *feature) iCallProbeController() error {
header := metadata.New(map[string]string{"csi.requestid": "1"})
ctx := metadata.NewIncomingContext(context.Background(), header)
req := &commonext.ProbeControllerRequest{}
connect, err := f.service.ProbeController(ctx, req)
if err != nil {
f.err = errors.New(err.Error())
return nil
}
fmt.Printf("response is %v", connect)
return nil
}

func (f *feature) iCallDynamicLogChange(file string) error {
log.Printf("level before change: %s", utils.GetCurrentLogLevel())
DriverConfigParamsFile = "mock/loglevel/" + file
log.Printf("wait for config change %s", DriverConfigParamsFile)
f.iCallBeforeServe()
time.Sleep(10 * time.Second)
return nil
}

func (f *feature) aValidDynamicLogChangeOccurs(file, expectedLevel string) error {
log.Printf("level after change: %s", utils.GetCurrentLogLevel())
if utils.GetCurrentLogLevel().String() != expectedLevel {
err := fmt.Errorf("level was expected to be %s, but was %s instead", expectedLevel, utils.GetCurrentLogLevel().String())
return err
}
log.Printf("Reverting log changes made")
DriverConfigParamsFile = "mock/loglevel/logConfig.yaml"
f.iCallBeforeServe()
time.Sleep(10 * time.Second)
return nil
}

func (f *feature) iSetNoProbeOnStart(value string) error {
os.Setenv(constants.EnvNoProbeOnStart, value)
return nil
}