Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ jobs:
push: true
file: Dockerfile
platforms: linux/amd64,linux/arm64
tags: litmuschaos/py-runner:ci
tags: litmuschaos/py-runner:ci
24 changes: 0 additions & 24 deletions build/go-multiarch-build.sh

This file was deleted.

33 changes: 21 additions & 12 deletions chaosLib/litmus/aws_az_chaos/lib/aws_az_chaos.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ def injectChaosInSerialMode(experimentsDetails , chaosDetails , eventsDetails ,
# Detaching the target zones from loa balancer
for azone in targetZones:

logging.info("[Info]: Detaching the following zone(s), Zone Name : %s", azone)
err = statusAws.detachAZfromLB(experimentsDetails, azone)
logging.info("[Info]: Detaching the following zone, Zone Name %s", azone)
targetSubnet, err = statusAws.getTargetSubnet(experimentsDetails, azone)
subnetList = list(targetSubnet.split(" "))
if err != None:
return err
logging.info("[Info]: Detaching the following subnet, %s", subnetList)
err = statusAws.detachSubnet(experimentsDetails, subnetList)
if err != None:
return err

if chaosDetails.Randomness:
err = common.RandomInterval(experimentsDetails.ChaosInterval)
if err != None:
Expand All @@ -85,19 +91,17 @@ def injectChaosInSerialMode(experimentsDetails , chaosDetails , eventsDetails ,
duration = (datetime.now() - ChaosStartTimeStamp).seconds

logging.info("[Completion]: %s chaos is done",(experimentsDetails.ExperimentName))

return None

# injectChaosInParallelMode disable the target available zone from loadbalancer in parallel mode (all at once)
def injectChaosInParallelMode(experimentsDetails , chaosDetails , eventsDetails , resultDetails, clients, statusAws):


#ChaosStartTimeStamp contains the start timestamp, when the chaos injection begin
ChaosStartTimeStamp = datetime.now()
duration = (datetime.now() - ChaosStartTimeStamp).seconds

subnet = []

while duration < experimentsDetails.ChaosDuration:

# Get the target available zone details for the chaos execution
targetZones = experimentsDetails.LoadBalancerZones.split(",")
logging.info("[Info]: Target available zone list, %s", targetZones)
Expand All @@ -107,12 +111,17 @@ def injectChaosInParallelMode(experimentsDetails , chaosDetails , eventsDetails
types.SetEngineEventAttributes(eventsDetails, types.ChaosInject, msg, "Normal", chaosDetails)
events.GenerateEvents(eventsDetails, chaosDetails, "ChaosEngine",clients)

# Detaching the target zones from loa balancer
# Detaching the target zones from load balancer
for azone in targetZones:
logging.info("[Info]: Detaching the following zone(s), Zone Name %s", azone)
err = statusAws.detachAZfromLB(experimentsDetails, azone)
logging.info("[Info]: Detaching the following zone, Zone Name %s", azone)
targetSubnet, err = statusAws.getTargetSubnet(experimentsDetails, azone)
subnet.append(targetSubnet)
if err != None:
return err
return err
logging.info("[Info]: Detaching the following subnet(s), %s", subnet)
err = statusAws.detachSubnet(experimentsDetails,subnet)
if err != None:
return err

if chaosDetails.Randomness:
err = common.RandomInterval(experimentsDetails.ChaosInterval)
Expand All @@ -128,10 +137,10 @@ def injectChaosInParallelMode(experimentsDetails , chaosDetails , eventsDetails
# Attaching the target available zone after the chaos injection
logging.info("[Status]: Attach the available zone back to load balancer")
for azone in targetZones:
err = statusAws.attachAZtoLB(experimentsDetails, azone)
err = statusAws.attachSubnet(experimentsDetails, subnet)
if err != None:
return err
#Verify the status of available zone after the chaos injection
logging.info("[Status]: Checking AWS load balancer's AZ status")
err = statusAws.CheckAWSStatus(experimentsDetails)
Expand Down
6 changes: 3 additions & 3 deletions pkg/aws_az/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def GetENV(experimentDetails):
experimentDetails.ExperimentName = os.getenv("EXPERIMENT_NAME", "aws-az-chaos")
experimentDetails.ChaosNamespace = os.getenv("CHAOS_NAMESPACE", "")
experimentDetails.EngineName = os.getenv("CHAOSENGINE", "")
experimentDetails.ChaosDuration = maths.atoi(os.getenv("TOTAL_CHAOS_DURATION", ""))
experimentDetails.ChaosInterval = os.getenv("CHAOS_INTERVAL", "")
experimentDetails.ChaosDuration = maths.atoi(os.getenv("TOTAL_CHAOS_DURATION", "60"))
experimentDetails.ChaosInterval = os.getenv("CHAOS_INTERVAL", "30")
experimentDetails.RampTime = maths.atoi(os.getenv("RAMP_TIME", ""))
experimentDetails.ChaosLib = os.getenv("LIB", "litmus")
experimentDetails.ChaosUID = os.getenv("CHAOS_UID", "")
Expand All @@ -22,7 +22,7 @@ def GetENV(experimentDetails):
experimentDetails.LoadBalancerName = os.getenv("LOAD_BALANCER_NAME", "")
experimentDetails.LoadBalancerZones = os.getenv("LOAD_BALANCER_ZONES", "")
experimentDetails.LoadBalancerNameARN = os.getenv("LOAD_BALANCERNAME_ARN", "na")

#InitialiseChaosVariables initialise all the global variables
def InitialiseChaosVariables(chaosDetails, experimentDetails):
appDetails = types.AppDetails()
Expand Down
3 changes: 1 addition & 2 deletions pkg/aws_az/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class ExperimentDetails(object):
def __init__(self, ExperimentName=None, EngineName=None, ChaosDuration=None, ChaosInterval=None, RampTime=None, Force=None, ChaosLib=None,
AWSZones=None, AWSRegion=None, AppNS=None, AppLabel=None, AppKind=None, InstanceID=None, ChaosNamespace=None, ChaosPodName=None, Timeout=None,
Delay=None, LoadBalancerName= None, LIBImagePullPolicy=None, LoadBalancerNameARN=None, LoadBalancerZones=None, UID=None):
Delay=None, LoadBalancerName= None, LIBImagePullPolicy=None, LoadBalancerNameARN=None, LoadBalancerZones=None, UID=None, VPCType=None):
self.ExperimentName = ExperimentName
self.EngineName = EngineName
self.ChaosDuration = ChaosDuration
Expand All @@ -23,4 +23,3 @@ def __init__(self, ExperimentName=None, EngineName=None, ChaosDuration=None, Cha
self.LoadBalancerName = LoadBalancerName
self.LoadBalancerZones = LoadBalancerZones
self.LoadBalancerNameARN = LoadBalancerNameARN

59 changes: 44 additions & 15 deletions pkg/aws_status/status.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from distutils.log import error
from re import subn
import boto3, logging
import pkg.utils.client.client as client

Expand All @@ -20,29 +22,56 @@ def CheckAWSStatus(self, experimentsDetails):
return ValueError(exp)
logging.info("[Info]: LoadBalancer and Availablity of zone has been checked")

# detachAZfromLB detaching availablity zone from load balancer
def detachAZfromLB(self, experimentsDetails, zone):
self.clients = client.AWSClient().clientElb
def getSubnetFromVPC(self, experimentsDetails):
client = boto3.client('elb')
try:
self.clients.disable_availability_zones_for_load_balancer(
LoadBalancerName=experimentsDetails.LoadBalancerName,
AvailabilityZones=[
zone,
response = client.describe_load_balancers(
LoadBalancerNames=[
experimentsDetails.LoadBalancerName,
]
)
return (response['LoadBalancerDescriptions'][0]['Subnets'])
except (self.clients.exceptions.AccessPointNotFoundException, self.clients.exceptions.InvalidConfigurationRequestException) as exp:
return ValueError(exp)

def getTargetSubnet(self, experimentsDetails, zone):
client = boto3.client('ec2')
try:
lst=self.getSubnetFromVPC(experimentsDetails)
i=0
for i in range(len(lst)):
response = client.describe_subnets(
SubnetIds=[
lst[i],
],
)
if(response['Subnets'][0]['AvailabilityZone']) == zone:
return lst[i], None
except (self.clients.exceptions.AccessPointNotFoundException, self.clients.exceptions.InvalidConfigurationRequestException) as exp:
return lst[i], ValueError(exp)


def detachSubnet(self, experimentsDetails, subnet):
client = boto3.client('elb')
try:
response = client.detach_load_balancer_from_subnets(
LoadBalancerName=experimentsDetails.LoadBalancerName,
Subnets=subnet
)
if (response['ResponseMetadata']['HTTPStatusCode']) != "200":
ValueError("[Error]: Fail to detach the target subnet %s", subnet)
except (self.clients.exceptions.AccessPointNotFoundException, self.clients.exceptions.InvalidConfigurationRequestException) as exp:
return ValueError(exp)

# attachAZtoLB attaching availablity zone from load balancer
def attachAZtoLB(self, experimentsDetails, zone):
self.clients = client.AWSClient().clientElb

def attachSubnet(self, experimentsDetails, subnet):
client = boto3.client('elb')
try:
self.clients.enable_availability_zones_for_load_balancer(
response = client.attach_load_balancer_to_subnets(
LoadBalancerName=experimentsDetails.LoadBalancerName,
AvailabilityZones=[
zone,
]
Subnets=subnet
)
if (response['ResponseMetadata']['HTTPStatusCode']) != "200":
ValueError("[Error]: Fail to attach the target subnet %s", subnet)
except (self.clients.exceptions.AccessPointNotFoundException, self.clients.exceptions.InvalidConfigurationRequestException) as exp:
return ValueError(exp)