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

Approve sdc by Guid #156

Merged
merged 11 commits into from
Feb 7, 2023
4 changes: 4 additions & 0 deletions helm/csi-vxflexos/templates/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ spec:
- name: X_CSI_HEALTH_MONITOR_ENABLED
value: "{{ .Values.node.healthMonitor.enabled }}"
{{- end }}
{{- if hasKey .Values.node "approveSDC" }}
- name: X_CSI_APPROVE_SDC_ENABLED
value: "{{ .Values.node.approveSDC.enabled }}"
{{- end }}
{{- if hasKey .Values.node "renameSDC" }}
- name: X_CSI_RENAME_SDC_ENABLED
value: "{{ .Values.node.renameSDC.enabled }}"
Expand Down
10 changes: 10 additions & 0 deletions helm/csi-vxflexos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ node:
# Default value: none
# Examples: "rhel-sdc", "sdc-test"
prefix: "sdc-test"

# "approveSDC" defines the approve operation for SDC
# Default value: None
approveSDC:
# enabled: Enable/Disable SDC approval
JacobGros marked this conversation as resolved.
Show resolved Hide resolved
#Allowed values:
# true: Driver will attempt to approve restricted SDC by GUID during setup
# false: Driver will not attempt to approve restricted SDC by GUID during setup
# Default value: false
enabled: false

# monitoring pod details
# These options control the running of the monitoring container
Expand Down
4 changes: 4 additions & 0 deletions service/envvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ const (
// EnvSDCPrefix is the name of the environment variable used to set the prefix for SDC name. This is only used by
// the Node Service.
EnvSDCPrefix = "X_CSI_RENAME_SDC_PREFIX"

// EnvIsApproveSDCEnabled is the name of the environment variable that specifies if the SDC approval is to be
// carried out or not.
EnvIsApproveSDCEnabled = "X_CSI_APPROVE_SDC_ENABLED"
)
2 changes: 1 addition & 1 deletion service/features/get_sdc_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"versionInfo": null,
"perfProfile": "Default",
"sdcApproved": true,
"sdcApproved": false,
"osType": "Linux",
"mdmConnectionState": "Connected",
"memoryAllocationFailure": null,
Expand Down
4 changes: 2 additions & 2 deletions service/features/get_system_instances.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
"swid": "",
"defaultIsVolumeObfuscated": false,
"daysInstalled": 6,
"restrictedSdcModeEnabled": false,
"restrictedSdcMode": "None",
"restrictedSdcModeEnabled": true,
VamsiSiddu-7 marked this conversation as resolved.
Show resolved Hide resolved
"restrictedSdcMode": "Guid",
"maxCapacityInGb": "Unlimited",
"capacityTimeLeftInDays": "Unlimited",
"enterpriseFeaturesEnabled": true,
Expand Down
17 changes: 17 additions & 0 deletions service/features/service.feature
Original file line number Diff line number Diff line change
Expand Up @@ -972,3 +972,20 @@ Feature: VxFlex OS CSI interface
And I call Probe
When I call Node Probe
Then the error contains "induced error"

Scenario: Call Probe for approving sdc
Given a VxFlexOS service
And I set approveSDC with approveSDCEnabled "true"
And I call Probe
When I call Node Probe
Then the error contains "none"

Scenario: Call Probe for approving sdc, invalid guid
Given a VxFlexOS service
And I induce error "ApproveSdcError"
And I set approveSDC with approveSDCEnabled "true"
And I call Probe
When I call Node Probe
Then the error contains "The given GUID is invalid"


48 changes: 48 additions & 0 deletions service/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,14 @@ func (s *service) nodeProbe(ctx context.Context) error {
}
}

// support for pre-approved guid
if s.opts.IsApproveSDCEnabled {
Log.Infof("Approve SDC enabled")
if err := s.approveSDC(s.opts); err != nil {
return err
}
}

// get all the system names and IDs.
s.getSystemName(ctx, connectedSystemID)

Expand All @@ -420,6 +428,46 @@ func (s *service) nodeProbe(ctx context.Context) error {
return nil
}

func (s *service) approveSDC(opts Opts) error {

for _, systemID := range connectedSystemID {
system := s.systems[systemID]

if system == nil {
continue
}

//fetch SDC details
sdc, err := s.systems[systemID].FindSdc("SdcGUID", opts.SdcGUID)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "%s", err)
}

//fetch the restrictedSdcMode
if system.System.RestrictedSdcMode == "Guid" {
if !sdc.Sdc.SdcApproved {
resp, err := system.ApproveSdcByGUID(sdc.Sdc.SdcGUID)
if err != nil {
return status.Errorf(codes.FailedPrecondition, "%s", err)
}
Log.Infof("SDC Approved, SDC Id: %s and SDC GUID: %s", resp.SdcID, sdc.Sdc.SdcGUID)
} else {
Log.Infof("SDC already approved, SDC GUID: %s", sdc.Sdc.SdcGUID)
}
} else {
if !sdc.Sdc.SdcApproved {
return status.Errorf(codes.FailedPrecondition, "Array RestrictedSdcMode is %s, driver only supports GUID RestrictedSdcMode cannot approve SDC %s",
system.System.RestrictedSdcMode, sdc.Sdc.SdcGUID)
JacobGros marked this conversation as resolved.
Show resolved Hide resolved
}
Log.Warnf("Array RestrictedSdcMode is %s, driver only supports GUID RestrictedSdcMode If SDC becomes restricted again, driver will not be able to approve",
system.System.RestrictedSdcMode)

}

}
return nil
}

func (s *service) renameSDC(opts Opts) error {
// fetch hostname
hostName, ok := os.LookupEnv("HOSTNAME")
Expand Down
8 changes: 8 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type Opts struct {
IsHealthMonitorEnabled bool // allow driver to make use of the alpha feature gate, CSIVolumeHealth
IsSdcRenameEnabled bool // allow driver to enable renaming SDC
SdcPrefix string // prefix to be set for SDC name
IsApproveSDCEnabled bool
}

type service struct {
Expand Down Expand Up @@ -325,6 +326,7 @@ func (s *service) BeforeServe(
"IsHealthMonitorEnabled": s.opts.IsHealthMonitorEnabled,
"IsSdcRenameEnabled": s.opts.IsSdcRenameEnabled,
"sdcPrefix": s.opts.SdcPrefix,
"IsApproveSDCEnabled": s.opts.IsApproveSDCEnabled,
}

Log.WithFields(fields).Infof("configured %s", Name)
Expand Down Expand Up @@ -388,6 +390,12 @@ func (s *service) BeforeServe(
if sdcPrefix, ok := csictx.LookupEnv(ctx, EnvSDCPrefix); ok {
opts.SdcPrefix = sdcPrefix
}
if approveSDC, ok := csictx.LookupEnv(ctx, EnvIsApproveSDCEnabled); ok {
VamsiSiddu-7 marked this conversation as resolved.
Show resolved Hide resolved
if approveSDC == "true" {
opts.IsApproveSDCEnabled = true
}
}

if s.privDir == "" {
s.privDir = defaultPrivDir
}
Expand Down
9 changes: 9 additions & 0 deletions service/step_defs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ func (f *feature) iInduceError(errtype string) error {
stepHandlersErrors.NoVolIDSDCError = true
case "SetSdcNameError":
stepHandlersErrors.SetSdcNameError = true
case "ApproveSdcError":
stepHandlersErrors.ApproveSdcError = true
case "NoVolError":
stepHandlersErrors.NoVolError = true
case "SetVolumeSizeError":
Expand Down Expand Up @@ -3378,6 +3380,12 @@ func (f *feature) iSetRenameSdcEnabledWithPrefix(renameEnabled string, prefix st
f.service.opts.SdcPrefix = prefix
return nil
}
func (f *feature) iSetApproveSdcEnabled(approveSDCEnabled string) error {
if approveSDCEnabled == "true" {
f.service.opts.IsApproveSDCEnabled = true
}
return nil
}

func FeatureContext(s *godog.ScenarioContext) {
f := &feature{}
Expand Down Expand Up @@ -3539,6 +3547,7 @@ func FeatureContext(s *godog.ScenarioContext) {
s.Step(`^I call GetReplicationCapabilities$`, f.iCallGetReplicationCapabilities)
s.Step(`^a "([^"]*)" replication capabilities structure is returned$`, f.aReplicationCapabilitiesStructureIsReturned)
s.Step(`^I set renameSDC with renameEnabled "([^"]*)" prefix "([^"]*)"$`, f.iSetRenameSdcEnabledWithPrefix)
s.Step(`^I set approveSDC with approveSDCEnabled "([^"]*)"`, f.iSetApproveSdcEnabled)

s.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if f.server != nil {
Expand Down
20 changes: 20 additions & 0 deletions service/step_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
GetSystemSdcError bool
GetSdcInstancesError bool
MapSdcError bool
ApproveSdcError bool
RemoveMappedSdcError bool
SDCLimitsError bool
SIOGatewayVolumeNotFoundError bool
Expand Down Expand Up @@ -170,6 +171,7 @@ func getHandler() http.Handler {
stepHandlersErrors.NoVolIDSDCError = false
stepHandlersErrors.NoVolError = false
stepHandlersErrors.SetSdcNameError = false
stepHandlersErrors.ApproveSdcError = false
sdcMappings = sdcMappings[:0]
sdcMappingsID = ""
return handler
Expand Down Expand Up @@ -421,6 +423,24 @@ func handleAction(w http.ResponseWriter, r *http.Request) {

setSdcNameSuccess = true

case "approveSdc":
errMsg := "The given GUID is invalid.Please specify GUID in the following format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
if stepHandlersErrors.ApproveSdcError {
writeError(w, errMsg, http.StatusInternalServerError, codes.Internal)
}
req := types.ApproveSdcParam{}
decoder := json.NewDecoder(r.Body)
err := decoder.Decode(&req)
if err != nil {
log.Printf("error decoding json: %s\n", err.Error())
}
resp := types.ApproveSdcByGUIDResponse{SdcID: "d0f055a700000000"}
encoder := json.NewEncoder(w)
err = encoder.Encode(resp)
if err != nil {
log.Printf("error encoding json: %s\n", err.Error())
}

case "addMappedSdc":
if stepHandlersErrors.MapSdcError {
writeError(w, "induced error", http.StatusRequestTimeout, codes.Internal)
Expand Down