Skip to content

Commit b4c083e

Browse files
committed
Fixed the Logic for comma-separated splitting
Signed-off-by: chinmaym07 <[email protected]>
1 parent f804136 commit b4c083e

File tree

12 files changed

+39
-44
lines changed

12 files changed

+39
-44
lines changed

Diff for: chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail
5050
// watching for the abort signal and revert the chaos
5151
go lib.AbortWatcher(experimentsDetails, abort)
5252

53-
//get the instance id or list of instance ids
54-
instanceIDList := strings.Split(experimentsDetails.EC2InstanceID, ",")
55-
if len(instanceIDList) == 0 {
53+
if experimentsDetails.EC2InstanceID == "" {
5654
return errors.Errorf("no instance id found for chaos injection")
5755
}
56+
//get the instance id or list of instance ids
57+
instanceIDList := strings.Split(experimentsDetails.EC2InstanceID, ",")
5858

5959
switch strings.ToLower(experimentsDetails.Sequence) {
6060
case "serial":

Diff for: chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients
4444
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4545
common.WaitForDuration(experimentsDetails.RampTime)
4646
}
47-
48-
//get the disk name or list of disk names
49-
diskNameList := strings.Split(experimentsDetails.VirtualDiskNames, ",")
50-
if len(diskNameList) == 0 {
47+
if experimentsDetails.VirtualDiskNames == "" {
5148
return errors.Errorf("no volume names found to detach")
5249
}
50+
//get the disk name or list of disk names
51+
diskNameList := strings.Split(experimentsDetails.VirtualDiskNames, ",")
5352
instanceNamesWithDiskNames, err := diskStatus.GetInstanceNameForDisks(diskNameList, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup)
5453

5554
if err != nil {

Diff for: chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, cli
4141
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4242
common.WaitForDuration(experimentsDetails.RampTime)
4343
}
44-
45-
// get the instance name or list of instance names
46-
instanceNameList := strings.Split(experimentsDetails.AzureInstanceName, ",")
47-
if len(instanceNameList) == 0 {
44+
if experimentsDetails.AzureInstanceName == "" {
4845
return errors.Errorf("no instance name found to stop")
4946
}
47+
// get the instance name or list of instance names
48+
instanceNameList := strings.Split(experimentsDetails.AzureInstanceName, ",")
5049

5150
// watching for the abort signal and revert the chaos
5251
go abortWatcher(experimentsDetails, instanceNameList)

Diff for: chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, c
4444
// stopping the chaos execution, if abort signal received
4545
os.Exit(0)
4646
default:
47-
48-
//get the volume id or list of instance ids
49-
volumeIDList := strings.Split(experimentsDetails.EBSVolumeID, ",")
50-
if len(volumeIDList) == 0 {
47+
if experimentsDetails.EBSVolumeID == "" {
5148
return errors.Errorf("no volume id found to detach")
5249
}
50+
//get the volume id or list of instance ids
51+
volumeIDList := strings.Split(experimentsDetails.EBSVolumeID, ",")
5352
// watching for the abort signal and revert the chaos
5453
go ebsloss.AbortWatcher(experimentsDetails, volumeIDList, abort, chaosDetails)
5554

Diff for: chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetai
4141
log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime)
4242
common.WaitForDuration(experimentsDetails.RampTime)
4343
}
44-
45-
//get the instance id or list of instance ids
46-
instanceIDList := strings.Split(experimentsDetails.Ec2InstanceID, ",")
47-
if len(instanceIDList) == 0 {
44+
if experimentsDetails.Ec2InstanceID == "" {
4845
return errors.Errorf("no instance id found to terminate")
4946
}
47+
//get the instance id or list of instance ids
48+
instanceIDList := strings.Split(experimentsDetails.Ec2InstanceID, ",")
5049

5150
// watching for the abort signal and revert the chaos
5251
go abortWatcher(experimentsDetails, instanceIDList, chaosDetails)

Diff for: chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ func PrepareVMStop(computeService *compute.Service, experimentsDetails *experime
4343
common.WaitForDuration(experimentsDetails.RampTime)
4444
}
4545

46+
if experimentsDetails.VMInstanceName == "" {
47+
return errors.Errorf("no instance name found to stop")
48+
}
4649
// get the instance name or list of instance names
4750
instanceNamesList := strings.Split(experimentsDetails.VMInstanceName, ",")
48-
if len(instanceNamesList) == 0 {
49-
return errors.Errorf("no instance name found to stop")
51+
if experimentsDetails.InstanceZone == "" {
52+
return errors.Errorf("no corresponding zones found for the instances")
5053
}
51-
5254
// get the zone name or list of corresponding zones for the instances
5355
instanceZonesList := strings.Split(experimentsDetails.InstanceZone, ",")
54-
if len(instanceZonesList) == 0 {
55-
return errors.Errorf("no corresponding zones found for the instances")
56-
}
5756

5857
if len(instanceNamesList) != len(instanceZonesList) {
5958
return errors.Errorf("number of instances is not equal to the number of zones")

Diff for: pkg/cloud/aws/ebs/ebs-volume-state.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,10 @@ func GetEBSStatus(ebsVolumeID, ec2InstanceID, region string) (string, error) {
101101

102102
//EBSStateCheckByID will check the attachment state of the given volume
103103
func EBSStateCheckByID(volumeIDs, region string) error {
104-
105-
volumeIDList := strings.Split(volumeIDs, ",")
106-
if len(volumeIDList) == 0 {
104+
if volumeIDs == "" {
107105
return errors.Errorf("no volumeID provided, please provide a volume to detach")
108106
}
107+
volumeIDList := strings.Split(volumeIDs, ",")
109108
for _, id := range volumeIDList {
110109
instanceID, _, err := GetVolumeAttachmentDetails(id, "", region)
111110
if err != nil {

Diff for: pkg/cloud/aws/ec2/ec2-instance-status.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ func GetEC2InstanceStatus(instanceID, region string) (string, error) {
4141

4242
//InstanceStatusCheckByID is used to check the instance status of all the instance under chaos.
4343
func InstanceStatusCheckByID(instanceID, region string) error {
44-
45-
instanceIDList := strings.Split(instanceID, ",")
46-
if len(instanceIDList) == 0 {
44+
if instanceID == "" {
4745
return errors.Errorf("no instance id found to terminate")
4846
}
47+
instanceIDList := strings.Split(instanceID, ",")
4948
log.Infof("[Info]: The instances under chaos(IUC) are: %v", instanceIDList)
5049
return InstanceStatusCheck(instanceIDList, region)
5150
}

Diff for: pkg/cloud/azure/instance/instance-status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func GetAzureScaleSetInstanceStatus(subscriptionID, resourceGroup, virtualMachin
7171

7272
// InstanceStatusCheckByName is used to check the instance status of all the instance under chaos
7373
func InstanceStatusCheckByName(azureInstanceNames, scaleSet, subscriptionID, resourceGroup string) error {
74-
instanceNameList := strings.Split(azureInstanceNames, ",")
75-
if len(instanceNameList) == 0 {
74+
if azureInstanceNames == "" {
7675
return errors.Errorf("no instance found to check the status")
7776
}
77+
instanceNameList := strings.Split(azureInstanceNames, ",")
7878
log.Infof("[Info]: The instance under chaos(IUC) are: %v", instanceNameList)
7979
switch scaleSet {
8080
case "enable":

Diff for: pkg/cloud/gcp/disk-volume-status.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,17 @@ func DiskVolumeStateCheck(computeService *compute.Service, experimentsDetails *e
103103
return errors.Errorf("no gcp project id provided, please provide the project id")
104104
}
105105

106-
diskNamesList := strings.Split(experimentsDetails.DiskVolumeNames, ",")
107-
if len(diskNamesList) == 0 {
106+
if experimentsDetails.DiskVolumeNames == "" {
108107
return errors.Errorf("no disk name provided, please provide the name of the disk")
109108
}
110109

111-
zonesList := strings.Split(experimentsDetails.DiskZones, ",")
112-
if len(zonesList) == 0 {
110+
diskNamesList := strings.Split(experimentsDetails.DiskVolumeNames, ",")
111+
if experimentsDetails.DiskZones == "" {
113112
return errors.Errorf("no zone provided, please provide the zone of the disk")
114113
}
115114

115+
zonesList := strings.Split(experimentsDetails.DiskZones, ",")
116+
116117
if len(diskNamesList) != len(zonesList) {
117118
return errors.Errorf("unequal number of disk names and zones found, please verify the input details")
118119
}

Diff for: pkg/cloud/gcp/vm-instance-status.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ func GetVMInstanceStatus(computeService *compute.Service, instanceName string, g
2626
//InstanceStatusCheckByName is used to check the status of all the VM instances under chaos
2727
func InstanceStatusCheckByName(computeService *compute.Service, managedInstanceGroup string, delay, timeout int, check string, instanceNames string, gcpProjectId string, instanceZones string) error {
2828

29+
if instanceNames == "" {
30+
return errors.Errorf("no vm instance name found to stop")
31+
}
2932
instanceNamesList := strings.Split(instanceNames, ",")
3033

34+
if instanceZones == "" {
35+
return errors.Errorf("no corresponding zones found for the instances")
36+
}
3137
instanceZonesList := strings.Split(instanceZones, ",")
3238

3339
if managedInstanceGroup != "enable" && managedInstanceGroup != "disable" {
3440
return errors.Errorf("invalid value for MANAGED_INSTANCE_GROUP: %v", managedInstanceGroup)
3541
}
3642

37-
if len(instanceNamesList) == 0 {
38-
return errors.Errorf("no vm instance name found to stop")
39-
}
40-
4143
if len(instanceNamesList) != len(instanceZonesList) {
4244
return errors.Errorf("the number of vm instance names and the number of regions are not equal")
4345
}

Diff for: pkg/cloud/vmware/vm-status.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,10 @@ func GetVMStatus(vcenterServer, vmId, cookie string) (string, error) {
5858

5959
//VMStatusCheck validates the steady state for the given vm ids
6060
func VMStatusCheck(vcenterServer, vmIds, cookie string) error {
61-
62-
vmIdList := strings.Split(vmIds, ",")
63-
if len(vmIdList) == 0 {
61+
if vmIds == "" {
6462
return errors.Errorf("no vm received, please input the target VMMoids")
6563
}
64+
vmIdList := strings.Split(vmIds, ",")
6665

6766
for _, vmId := range vmIdList {
6867

0 commit comments

Comments
 (0)