Skip to content

Commit c8835bb

Browse files
committed
feat(aws-az-chaos): add an error message when using elbv2 in parallel mode as it can't work, boto3 enforces at least one subnet per load balancer. Also fix a missing ref in aws_az class.
Signed-off-by: Guillaume R 63466144+Guigui0812@users.noreply.github.com
1 parent 496be5f commit c8835bb

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

chaosLib/litmus/aws_az_chaos/lib/aws_az_chaos.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def PrepareAWSAZExperiment(experimentsDetails , resultDetails, eventsDetails, ch
2020
if err != None:
2121
return err
2222
elif experimentsDetails.Sequence.lower() == "parallel":
23-
err = injectChaosInParallelMode(experimentsDetails, chaosDetails, eventsDetails, resultDetails, clients, statusAws)
23+
if experimentsDetails.LoadBalancerVersion == "elb":
24+
err = injectChaosInParallelMode(experimentsDetails, chaosDetails, eventsDetails, resultDetails, clients, statusAws)
25+
elif experimentsDetails.LoadBalancerVersion == "elbv2":
26+
logging.info("[Sequence]: aws az chaos is not available in parallel mode with elbv2 as it requires at least one subnet per LoadBalancer")
27+
return ValueError("aws az chaos is not available in parallel mode with elbv2 as it requires at least one subnet per LoadBalancer")
2428
if err != None:
2529
return err
2630
else:
@@ -58,6 +62,10 @@ def injectChaosInSerialMode(experimentsDetails , chaosDetails , eventsDetails ,
5862
if err != None:
5963
return err
6064

65+
if targetSubnet is None:
66+
logging.error("[Error]: No subnet found for the zone %s", azone)
67+
return ValueError("No subnet found for the zone %s" % azone)
68+
6169
if experimentsDetails.LoadBalancerVersion == "elb":
6270
subnetList = list(targetSubnet.split(" "))
6371
logging.info("[Info]: Detaching the following subnet, %s", subnetList)

pkg/aws_az/environment/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ def GetENV(experimentDetails):
99
experimentDetails.ChaosNamespace = os.getenv("CHAOS_NAMESPACE", "")
1010
experimentDetails.EngineName = os.getenv("CHAOSENGINE", "")
1111
experimentDetails.ChaosDuration = maths.atoi(os.getenv("TOTAL_CHAOS_DURATION", "60"))
12-
experimentDetails.ChaosInterval = os.getenv("CHAOS_INTERVAL", "30")
12+
experimentDetails.ChaosInterval = os.getenv("CHAOS_INTERVAL", "60")
1313
experimentDetails.RampTime = maths.atoi(os.getenv("RAMP_TIME", ""))
1414
experimentDetails.ChaosLib = os.getenv("LIB", "litmus")
1515
experimentDetails.ChaosUID = os.getenv("CHAOS_UID", "")
1616
experimentDetails.InstanceID = os.getenv("INSTANCE_ID", "")
1717
experimentDetails.ChaosPodName = os.getenv("POD_NAME", "")
1818
experimentDetails.Delay = maths.atoi(os.getenv("STATUS_CHECK_DELAY", "2"))
1919
experimentDetails.Timeout = maths.atoi(os.getenv("STATUS_CHECK_TIMEOUT", "180"))
20-
experimentDetails.Sequence = os.getenv("SEQUENCE", "parallel")
20+
experimentDetails.Sequence = os.getenv("SEQUENCE", "serial")
2121
experimentDetails.AWSRegion = os.getenv("AWS_REGION", "")
2222
experimentDetails.LoadBalancerName = os.getenv("LOAD_BALANCER_NAME", "")
2323
experimentDetails.LoadBalancerZones = os.getenv("LOAD_BALANCER_ZONES", "")

pkg/aws_status/status.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, client=None):
1111
# CheckAWSStatus checks target load balancer availability
1212
def CheckAWSStatus(self, experimentsDetails):
1313

14-
self.clients = client.AWSClient().clientElb
14+
self.clients = client.AWSClient(experimentsDetails).clientElb
1515

1616
if experimentsDetails.LoadBalancerName == "" or experimentsDetails.LoadBalancerZones == "" :
1717
return ValueError("Provided LoadBalancer Name or LoadBalancerZoner are empty")
@@ -108,11 +108,16 @@ def detachSubnetv2(self, experimentsDetails, subnet):
108108
for az in response['LoadBalancers'][0]['AvailabilityZones']:
109109
if az['SubnetId'] not in subnet:
110110
subnetsToKeep.append(az['SubnetId'])
111-
112-
response = client.set_subnets(
113-
LoadBalancerArn=response['LoadBalancers'][0]['LoadBalancerArn'],
114-
Subnets=subnetsToKeep
115-
)
111+
if experimentsDetails.Sequence is "parallel":
112+
response = client.set_subnets(
113+
LoadBalancerArn=response['LoadBalancers'][0]['LoadBalancerArn'],
114+
Subnets=[""]
115+
)
116+
else:
117+
response = client.set_subnets(
118+
LoadBalancerArn=response['LoadBalancers'][0]['LoadBalancerArn'],
119+
Subnets=subnetsToKeep
120+
)
116121

117122
except (self.clients.exceptions.AccessPointNotFoundException, self.clients.exceptions.InvalidConfigurationRequestException) as exp:
118123
return ValueError(exp)

0 commit comments

Comments
 (0)