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

Fixed the Logic for comma-separated splitting #564

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
ispeakc0de marked this conversation as resolved.
Show resolved Hide resolved
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":
Expand Down
7 changes: 3 additions & 4 deletions chaoslib/litmus/azure-disk-loss/lib/azure-disk-loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions pkg/cloud/aws/ebs/ebs-volume-state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions pkg/cloud/aws/ec2/ec2-instance-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/azure/instance/instance-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 5 additions & 4 deletions pkg/cloud/gcp/disk-volume-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/cloud/gcp/vm-instance-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/cloud/vmware/vm-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down