Skip to content

Commit

Permalink
Fixed the Logic for comma-separated splitting
Browse files Browse the repository at this point in the history
Signed-off-by: chinmaym07 <[email protected]>
  • Loading branch information
chinmaym07 authored and chinmaym07 committed Oct 30, 2022
1 parent 920c62d commit 8cbcece
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 38 deletions.
6 changes: 3 additions & 3 deletions chaoslib/litmus/aws-ssm-chaos/lib/ssm/aws-ssm-chaos-by-id.go
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 == "" {
return errors.Errorf("no instance id found for chaos injection")
}
//get the instance id or list of instance ids
instanceIDList := strings.Split(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(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(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(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(experimentsDetails.Ec2InstanceID, ",")

// watching for the abort signal and revert the chaos
go abortWatcher(experimentsDetails, instanceIDList, chaosDetails)
Expand Down
11 changes: 10 additions & 1 deletion chaoslib/litmus/gcp-vm-instance-stop/lib/gcp-vm-instance-stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,21 @@ 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, ",")

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, ",")

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)

switch strings.ToLower(experimentsDetails.Sequence) {
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(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(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(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(experimentsDetails.DiskVolumeNames, ",")
if experimentsDetails.Zones == "" {
return errors.Errorf("no zone provided, please provide the zone of the disk")
}

zonesList := strings.Split(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
10 changes: 6 additions & 4 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 {

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

if instanceZones == "" {
return errors.Errorf("no corresponding zones found for the instances")
}
instanceZonesList := strings.Split(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(vmIds, ",")

for _, vmId := range vmIdList {

Expand Down

0 comments on commit 8cbcece

Please sign in to comment.