diff --git a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go index 9ca7b8404..5a84ec8fa 100644 --- a/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go +++ b/chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go @@ -50,11 +50,11 @@ func PrepareAWSSSMChaosByID(experimentsDetails *experimentTypes.ExperimentDetail // watching for the abort signal and revert the chaos go lib.AbortWatcher(experimentsDetails, abort) - //get the instance id or list of instance ids - instanceIDList := strings.Split(experimentsDetails.EC2InstanceID, ",") - if len(instanceIDList) == 0 { + if experimentsDetails.EC2InstanceID == "" { return errors.Errorf("no instance id found for chaos injection") } + //get the instance id or list of instance ids + instanceIDList := strings.Split(strings.TrimSpace(experimentsDetails.EC2InstanceID), ",") switch strings.ToLower(experimentsDetails.Sequence) { case "serial": diff --git a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go index 867506603..8ea5f1576 100644 --- a/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go +++ b/chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go @@ -44,12 +44,11 @@ func PrepareChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime) common.WaitForDuration(experimentsDetails.RampTime) } - - //get the disk name or list of disk names - diskNameList := strings.Split(experimentsDetails.VirtualDiskNames, ",") - if len(diskNameList) == 0 { + if experimentsDetails.VirtualDiskNames == "" { return errors.Errorf("no volume names found to detach") } + //get the disk name or list of disk names + diskNameList := strings.Split(strings.TrimSpace(experimentsDetails.VirtualDiskNames), ",") instanceNamesWithDiskNames, err := diskStatus.GetInstanceNameForDisks(diskNameList, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup) if err != nil { diff --git a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go index f15330682..b52dbd223 100644 --- a/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go +++ b/chaoslib/litmus/azure-instance-stop/lib/azure-instance-stop.go @@ -42,11 +42,11 @@ func PrepareAzureStop(experimentsDetails *experimentTypes.ExperimentDetails, cli common.WaitForDuration(experimentsDetails.RampTime) } - // get the instance name or list of instance names - instanceNameList := strings.Split(experimentsDetails.AzureInstanceNames, ",") - if len(instanceNameList) == 0 { + if experimentsDetails.AzureInstanceNames == "" { return errors.Errorf("no instance name found to stop") } + // get the instance name or list of instance names + instanceNameList := strings.Split(strings.TrimSpace(experimentsDetails.AzureInstanceNames), ",") // watching for the abort signal and revert the chaos go abortWatcher(experimentsDetails, instanceNameList) diff --git a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go index a07c8aa5a..df2d38644 100644 --- a/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go +++ b/chaoslib/litmus/ebs-loss/lib/ebs-loss-by-id/lib/ebs-loss-by-id.go @@ -44,12 +44,11 @@ func PrepareEBSLossByID(experimentsDetails *experimentTypes.ExperimentDetails, c // stopping the chaos execution, if abort signal received os.Exit(0) default: - - //get the volume id or list of instance ids - volumeIDList := strings.Split(experimentsDetails.EBSVolumeID, ",") - if len(volumeIDList) == 0 { + if experimentsDetails.EBSVolumeID == "" { return errors.Errorf("no volume id found to detach") } + //get the volume id or list of instance ids + volumeIDList := strings.Split(strings.TrimSpace(experimentsDetails.EBSVolumeID), ",") // watching for the abort signal and revert the chaos go ebsloss.AbortWatcher(experimentsDetails, volumeIDList, abort, chaosDetails) diff --git a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go index 62c76a2e3..bfc7344c5 100644 --- a/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go +++ b/chaoslib/litmus/ec2-terminate-by-id/lib/ec2-terminate-by-id.go @@ -41,12 +41,11 @@ func PrepareEC2TerminateByID(experimentsDetails *experimentTypes.ExperimentDetai log.Infof("[Ramp]: Waiting for the %vs ramp time before injecting chaos", experimentsDetails.RampTime) common.WaitForDuration(experimentsDetails.RampTime) } - - //get the instance id or list of instance ids - instanceIDList := strings.Split(experimentsDetails.Ec2InstanceID, ",") - if len(instanceIDList) == 0 { + if experimentsDetails.Ec2InstanceID == "" { return errors.Errorf("no instance id found to terminate") } + //get the instance id or list of instance ids + instanceIDList := strings.Split(strings.TrimSpace(experimentsDetails.Ec2InstanceID), ",") // watching for the abort signal and revert the chaos go abortWatcher(experimentsDetails, instanceIDList, chaosDetails) diff --git a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go index 454dbabb2..ab5e0bd6f 100644 --- a/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go +++ b/chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go @@ -43,11 +43,20 @@ func PrepareVMStop(computeService *compute.Service, experimentsDetails *experime common.WaitForDuration(experimentsDetails.RampTime) } + if experimentsDetails.VMInstanceName == "" { + return errors.Errorf("no instance name found to stop") + } // get the instance name or list of instance names - instanceNamesList := strings.Split(experimentsDetails.VMInstanceName, ",") - + instanceNamesList := strings.Split(strings.TrimSpace(experimentsDetails.VMInstanceName), ",") + if experimentsDetails.Zones == "" { + return errors.Errorf("no corresponding zones found for the instances") + } // get the zone name or list of corresponding zones for the instances - instanceZonesList := strings.Split(experimentsDetails.Zones, ",") + instanceZonesList := strings.Split(strings.TrimSpace(experimentsDetails.Zones), ",") + + if len(instanceNamesList) != len(instanceZonesList) { + return errors.Errorf("number of instances is not equal to the number of zones") + } go abortWatcher(computeService, experimentsDetails, instanceNamesList, instanceZonesList, chaosDetails) diff --git a/pkg/cloud/aws/ebs/ebs-volume-state.go b/pkg/cloud/aws/ebs/ebs-volume-state.go index d49bd307b..124eb6500 100644 --- a/pkg/cloud/aws/ebs/ebs-volume-state.go +++ b/pkg/cloud/aws/ebs/ebs-volume-state.go @@ -101,11 +101,10 @@ func GetEBSStatus(ebsVolumeID, ec2InstanceID, region string) (string, error) { //EBSStateCheckByID will check the attachment state of the given volume func EBSStateCheckByID(volumeIDs, region string) error { - - volumeIDList := strings.Split(volumeIDs, ",") - if len(volumeIDList) == 0 { + if volumeIDs == "" { return errors.Errorf("no volumeID provided, please provide a volume to detach") } + volumeIDList := strings.Split(strings.TrimSpace(volumeIDs), ",") for _, id := range volumeIDList { instanceID, _, err := GetVolumeAttachmentDetails(id, "", region) if err != nil { diff --git a/pkg/cloud/aws/ec2/ec2-instance-status.go b/pkg/cloud/aws/ec2/ec2-instance-status.go index b0f9b051f..d35e1e403 100644 --- a/pkg/cloud/aws/ec2/ec2-instance-status.go +++ b/pkg/cloud/aws/ec2/ec2-instance-status.go @@ -41,11 +41,10 @@ func GetEC2InstanceStatus(instanceID, region string) (string, error) { //InstanceStatusCheckByID is used to check the instance status of all the instance under chaos. func InstanceStatusCheckByID(instanceID, region string) error { - - instanceIDList := strings.Split(instanceID, ",") - if len(instanceIDList) == 0 { + if instanceID == "" { return errors.Errorf("no instance id found to terminate") } + instanceIDList := strings.Split(strings.TrimSpace(instanceID), ",") log.Infof("[Info]: The instances under chaos(IUC) are: %v", instanceIDList) return InstanceStatusCheck(instanceIDList, region) } diff --git a/pkg/cloud/azure/instance/instance-status.go b/pkg/cloud/azure/instance/instance-status.go index b3039ddb1..d04946e61 100644 --- a/pkg/cloud/azure/instance/instance-status.go +++ b/pkg/cloud/azure/instance/instance-status.go @@ -71,10 +71,10 @@ func GetAzureScaleSetInstanceStatus(subscriptionID, resourceGroup, virtualMachin // InstanceStatusCheckByName is used to check the instance status of all the instance under chaos func InstanceStatusCheckByName(azureInstanceNames, scaleSet, subscriptionID, resourceGroup string) error { - instanceNameList := strings.Split(azureInstanceNames, ",") - if len(instanceNameList) == 0 { + if azureInstanceNames == "" { return errors.Errorf("no instance found to check the status") } + instanceNameList := strings.Split(strings.TrimSpace(azureInstanceNames), ",") log.Infof("[Info]: The instance under chaos(IUC) are: %v", instanceNameList) switch scaleSet { case "enable": diff --git a/pkg/cloud/gcp/disk-volume-status.go b/pkg/cloud/gcp/disk-volume-status.go index 4c1ecabd9..1961e70cc 100644 --- a/pkg/cloud/gcp/disk-volume-status.go +++ b/pkg/cloud/gcp/disk-volume-status.go @@ -103,16 +103,17 @@ func DiskVolumeStateCheck(computeService *compute.Service, experimentsDetails *e return errors.Errorf("no gcp project id provided, please provide the project id") } - diskNamesList := strings.Split(experimentsDetails.DiskVolumeNames, ",") - if len(diskNamesList) == 0 { + if experimentsDetails.DiskVolumeNames == "" { return errors.Errorf("no disk name provided, please provide the name of the disk") } - zonesList := strings.Split(experimentsDetails.Zones, ",") - if len(zonesList) == 0 { + diskNamesList := strings.Split(strings.TrimSpace(experimentsDetails.DiskVolumeNames), ",") + if experimentsDetails.Zones == "" { return errors.Errorf("no zone provided, please provide the zone of the disk") } + zonesList := strings.Split(strings.TrimSpace(experimentsDetails.Zones), ",") + if len(diskNamesList) != len(zonesList) { return errors.Errorf("unequal number of disk names and zones found, please verify the input details") } diff --git a/pkg/cloud/gcp/vm-instance-status.go b/pkg/cloud/gcp/vm-instance-status.go index bcf091cb6..5975ead96 100644 --- a/pkg/cloud/gcp/vm-instance-status.go +++ b/pkg/cloud/gcp/vm-instance-status.go @@ -26,18 +26,20 @@ func GetVMInstanceStatus(computeService *compute.Service, instanceName string, g // InstanceStatusCheckByName is used to check the status of all the VM instances under chaos func InstanceStatusCheckByName(computeService *compute.Service, managedInstanceGroup string, delay, timeout int, check string, instanceNames string, gcpProjectId string, instanceZones string) error { - instanceNamesList := strings.Split(instanceNames, ",") + if instanceNames == "" { + return errors.Errorf("no vm instance name found to stop") + } + instanceNamesList := strings.Split(strings.TrimSpace(instanceNames), ",") - instanceZonesList := strings.Split(instanceZones, ",") + if instanceZones == "" { + return errors.Errorf("no corresponding zones found for the instances") + } + instanceZonesList := strings.Split(strings.TrimSpace(instanceZones), ",") if managedInstanceGroup != "enable" && managedInstanceGroup != "disable" { return errors.Errorf("invalid value for MANAGED_INSTANCE_GROUP: %v", managedInstanceGroup) } - if len(instanceNamesList) == 0 { - return errors.Errorf("no vm instance name found to stop") - } - if len(instanceNamesList) != len(instanceZonesList) { return errors.Errorf("the number of vm instance names and the number of regions are not equal") } diff --git a/pkg/cloud/vmware/vm-status.go b/pkg/cloud/vmware/vm-status.go index 0a98b4eee..46683804b 100644 --- a/pkg/cloud/vmware/vm-status.go +++ b/pkg/cloud/vmware/vm-status.go @@ -58,11 +58,10 @@ func GetVMStatus(vcenterServer, vmId, cookie string) (string, error) { //VMStatusCheck validates the steady state for the given vm ids func VMStatusCheck(vcenterServer, vmIds, cookie string) error { - - vmIdList := strings.Split(vmIds, ",") - if len(vmIdList) == 0 { + if vmIds == "" { return errors.Errorf("no vm received, please input the target VMMoids") } + vmIdList := strings.Split(strings.TrimSpace(vmIds), ",") for _, vmId := range vmIdList {