Skip to content

Commit

Permalink
Cherry-Pick for 2.5.0 (#480)
Browse files Browse the repository at this point in the history
* Changed the failstep message in experiment template of litmus-sdk to follow the new convention (#475)

Signed-off-by: Akash Shrivastava <[email protected]>

* Chore(stress-chaos): Support stress-chaos experiment with custom experiment name (#474)

Signed-off-by: udit <[email protected]>

* Minor changes in Azure Experiments (#476)

* Removed AUT and app check from azure experiments

Signed-off-by: Akash Shrivastava <[email protected]>

* Changed azure status functions to accept string values rather than experimentType struct

Signed-off-by: Akash Shrivastava <[email protected]>

* Removed unused variables from test.yaml

Signed-off-by: Akash Shrivastava <[email protected]>

* Added AUT and Auxillary app check

Signed-off-by: Akash Shrivastava <[email protected]>

* Updated test.yaml

Signed-off-by: Akash Shrivastava <[email protected]>

* Chore(network-chaos): Add jitter in pod-network-latency experiment (#478)

Signed-off-by: uditgaurav <[email protected]>

Co-authored-by: Akash Shrivastava <[email protected]>
  • Loading branch information
uditgaurav and Akash Shrivastava authored Jan 15, 2022
1 parent a9e5f39 commit cf20ce5
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e-on-pr-commits.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: E2E
on:
pull_request:
branches: [master]
branches: [v2.5.x]
types: [opened, synchronize, reopened]
paths-ignore:
- '**.md'
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apk --update add \
# Packaging stage
# Image source: https://github.com/litmuschaos/test-tools/blob/master/custom/hardened-alpine/experiment/Dockerfile
# The base image is non-root (have litmus user) with default litmus directory.
FROM litmuschaos/experiment-alpine:2.4.0
FROM litmuschaos/experiment-alpine:2.5.0

LABEL maintainer="LitmusChaos"

Expand Down
2 changes: 1 addition & 1 deletion chaoslib/litmus/network-chaos/lib/latency/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import (
//PodNetworkLatencyChaos contains the steps to prepare and inject chaos
func PodNetworkLatencyChaos(experimentsDetails *experimentTypes.ExperimentDetails, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {

args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms"
args := "delay " + strconv.Itoa(experimentsDetails.NetworkLatency) + "ms " + strconv.Itoa(experimentsDetails.Jitter) + "ms"
return network_chaos.PrepareAndInjectChaos(experimentsDetails, clients, resultDetails, eventsDetails, chaosDetails, args)
}
7 changes: 4 additions & 3 deletions chaoslib/litmus/stress-chaos/helper/stress-helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,16 @@ func prepareStressor(experimentDetails *experimentTypes.ExperimentDetails) []str
strconv.Itoa(experimentDetails.ChaosDuration) + "s",
}

switch experimentDetails.ExperimentName {
case "pod-cpu-hog":
switch experimentDetails.StressType {
case "pod-cpu-stress":

log.InfoWithValues("[Info]: Details of Stressor:", logrus.Fields{
"CPU Core": experimentDetails.CPUcores,
"Timeout": experimentDetails.ChaosDuration,
})
stressArgs = append(stressArgs, "--cpu "+strconv.Itoa(experimentDetails.CPUcores))

case "pod-memory-hog":
case "pod-memory-stress":

log.InfoWithValues("[Info]: Details of Stressor:", logrus.Fields{
"Number of Workers": experimentDetails.NumberOfWorkers,
Expand Down Expand Up @@ -515,6 +515,7 @@ func getENV(experimentDetails *experimentTypes.ExperimentDetails) {
experimentDetails.NumberOfWorkers, _ = strconv.Atoi(types.Getenv("NUMBER_OF_WORKERS", ""))
experimentDetails.MemoryConsumption, _ = strconv.Atoi(types.Getenv("MEMORY_CONSUMPTION", ""))
experimentDetails.VolumeMountPath = types.Getenv("VOLUME_MOUNT_PATH", "")
experimentDetails.StressType = types.Getenv("STRESS_TYPE", "")
}

// abortWatcher continuously watch for the abort signals
Expand Down
1 change: 1 addition & 0 deletions chaoslib/litmus/stress-chaos/lib/stress-chaos.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func getPodEnv(experimentsDetails *experimentTypes.ExperimentDetails, podName st
SetEnv("NUMBER_OF_WORKERS", strconv.Itoa(experimentsDetails.NumberOfWorkers)).
SetEnv("MEMORY_CONSUMPTION", strconv.Itoa(experimentsDetails.MemoryConsumption)).
SetEnv("VOLUME_MOUNT_PATH", experimentsDetails.VolumeMountPath).
SetEnv("STRESS_TYPE", experimentsDetails.StressType).
SetEnv("INSTANCE_ID", experimentsDetails.InstanceID).
SetEnvFromDownwardAPI("v1", "metadata.name")

Expand Down
22 changes: 11 additions & 11 deletions contribute/developer-guide/templates/experiment.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Experiment(clients clients.ClientSets){
log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName)
if err := result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT");err != nil {
log.Errorf("Unable to Create the Chaos Result, err: %v", err)
failStep := "Updating the chaos result of pod-delete experiment (SOT)"
failStep := "[pre-chaos]: Failed to update the chaos result of pod-delete experiment (SOT), err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
Expand Down Expand Up @@ -78,7 +78,7 @@ func Experiment(clients clients.ClientSets){
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (pre-chaos)")
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "Verify that the AUT (Application Under Test) is running (pre-chaos)"
failStep := "[pre-chaos]: Failed to verify that the AUT (Application Under Test) is in running state, err: " + err.Error()
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT: Not Running", "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand All @@ -90,7 +90,7 @@ func Experiment(clients clients.ClientSets){
log.Info("[Status]: Verify that the Auxiliary Applications are running (pre-chaos)")
if err := status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients);err != nil {
log.Errorf("Auxiliary Application status check failed, err: %v", err)
failStep := "Verify that the Auxiliary Applications are running (pre-chaos)"
failStep := "[pre-chaos]: Failed to verify that the Auxiliary Applications are in running state, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
Expand All @@ -106,7 +106,7 @@ func Experiment(clients clients.ClientSets){

if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails);err != nil {
log.Errorf("Probe Failed, err: %v", err)
failStep := "Failed while running probes"
failStep := "[pre-chaos]: Failed while running probes, err: " + err.Error()
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
Expand All @@ -129,15 +129,15 @@ func Experiment(clients clients.ClientSets){
switch experimentsDetails.ChaosLib {
case "litmus":
if err := litmusLIB.PrepareChaos(&experimentsDetails, clients, &resultDetails, &eventsDetails, &chaosDetails); err != nil {
failStep := "failed in chaos injection phase"
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
log.Errorf("Chaos injection failed, err: %v", err)
failStep := "[chaos]: Failed inside the chaoslib, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
default:
failStep := "lib and container-runtime combination not supported!"
log.Error("[Invalid]: Please Provide the correct LIB")
failStep := "[chaos]: no match found for specified lib"
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
log.Error("lib and container-runtime combination not supported, provide the correct value of lib & container-runtime")
return
}

Expand All @@ -149,7 +149,7 @@ func Experiment(clients clients.ClientSets){
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (post-chaos)")
if err := status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "Verify that the AUT (Application Under Test) is running (post-chaos)"
failStep := "[post-chaos]: Failed to verify that the AUT (Application Under Test) is running, err: " + err.Error()
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT: Not Running", "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand All @@ -161,7 +161,7 @@ func Experiment(clients clients.ClientSets){
log.Info("[Status]: Verify that the Auxiliary Applications are running (post-chaos)")
if err := status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients);err != nil {
log.Errorf("Auxiliary Application status check failed, err: %v", err)
failStep := "Verify that the Auxiliary Applications are running (post-chaos)"
failStep := "[post-chaos]: Failed to verify that the Auxiliary Applications are running, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}
Expand All @@ -176,7 +176,7 @@ func Experiment(clients clients.ClientSets){
if len(resultDetails.ProbeDetails) != 0 {
if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails);err != nil {
log.Errorf("Probes Failed, err: %v", err)
failStep := "Failed while running probes"
failStep := "[post-chaos]: Failed while running probes, err: " + err.Error()
msg := "AUT: Running, Probes: Unsuccessful"
types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails)
events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine")
Expand Down
23 changes: 12 additions & 11 deletions experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func AzureDiskLoss(clients clients.ClientSets) {

//DISPLAY THE APP INFORMATION
log.InfoWithValues("The volume information is as follows", logrus.Fields{
"Chaos Duration": experimentsDetails.ChaosDuration,
"Disk Names": experimentsDetails.VirtualDiskNames,
"Resource Group": experimentsDetails.ResourceGroup,
"Sequence": experimentsDetails.Sequence,
Expand Down Expand Up @@ -104,7 +105,7 @@ func AzureDiskLoss(clients clients.ClientSets) {

// PRE-CHAOS VIRTUAL DISK STATUS CHECK
log.Info("[Status]: Verify that the virtual disk are attached to VM instance(pre-chaos)")
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails); err != nil {
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails.SubscriptionID, experimentsDetails.VirtualDiskNames, experimentsDetails.ResourceGroup); err != nil {
log.Errorf("Virtual disk status check failed, err: %v", err)
failStep := "[pre-chaos]: Failed to verify that the virtual disk are attached to VM instance, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand All @@ -118,7 +119,7 @@ func AzureDiskLoss(clients clients.ClientSets) {
// run the probes in the pre-chaos check
if len(resultDetails.ProbeDetails) != 0 {

if err := probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil {
if err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails); err != nil {
log.Errorf("Probe Failed, err: %v", err)
failStep := "[pre-chaos]: Failed while running probes, err: " + err.Error()
msg := "AUT: Running, Probes: Unsuccessful"
Expand Down Expand Up @@ -153,6 +154,15 @@ func AzureDiskLoss(clients clients.ClientSets) {
log.Infof("[Confirmation]: %v chaos has been injected successfully", experimentsDetails.ExperimentName)
resultDetails.Verdict = v1alpha1.ResultVerdictPassed

// POST-CHAOS VIRTUAL DISK STATUS CHECK
log.Info("[Status]: Verify that the virtual disk are attached to VM instance(post-chaos)")
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails.SubscriptionID, experimentsDetails.VirtualDiskNames, experimentsDetails.ResourceGroup); err != nil {
log.Errorf("Virtual disk status check failed, err: %v", err)
failStep := "[post-chaos]: Failed to verify that the virtual disk are attached to VM instance, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

//POST-CHAOS APPLICATION STATUS CHECK
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (post-chaos)")
if err = status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
Expand All @@ -173,15 +183,6 @@ func AzureDiskLoss(clients clients.ClientSets) {
}
}

// POST-CHAOS VIRTUAL DISK STATUS CHECK
log.Info("[Status]: Verify that the virtual disk are attached to VM instance(post-chaos)")
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails); err != nil {
log.Errorf("Virtual disk status check failed, err: %v", err)
failStep := "[post-chaos]: Failed to verify that the virtual disk are attached to VM instance, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
return
}

if experimentsDetails.EngineName != "" {
// marking AUT as running, as we already checked the status of application under test
msg := "AUT: Running"
Expand Down
35 changes: 15 additions & 20 deletions experiments/azure/azure-disk-loss/test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,33 @@ spec:
- sleep
- "3600"
env:
# provide application namespace
- name: APP_NAMESPACE
value: ''
value: 'default'

# provide application labels
- name: APP_LABEL
value: ''

# provide application kind
value: 'run=nginx'

- name: APP_KIND
value: ''
value: 'deployment'

- name: TOTAL_CHAOS_DURATION
value: ''

# provide auxiliary application details - namespace and labels of the applications
# sample input is - "ns1:app=percona,ns2:name=nginx"
- name: AUXILIARY_APPINFO
value: ''
value: '60'

- name: CHAOS_INTERVAL
value: '30'

## Period to wait before injection of chaos in sec
- name: RAMP_TIME
value: ''

## env var that describes the library used to execute the chaos
## default: litmus
- name: LIB
value: ''
value: 'litmus'

# provide the chaos namespace
- name: CHAOS_NAMESPACE
value: ''

# provide target container name
- name: TARGET_CONTAINER
value: ''
value: 'litmus'

# provide the resouce group of the instance
- name: RESOURCE_GROUP
Expand All @@ -72,7 +63,7 @@ spec:

# provide the sequence type for the run. Options: serial/parallel
- name: SEQUENCE
value: ''
value: 'parallel'

# provide the path to aks credentials mounted from secret
- name: AZURE_AUTH_LOCATION
Expand All @@ -88,4 +79,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.serviceAccountName

secrets:
- name: cloud-secret
mountPath: /tmp/

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
clients "github.com/litmuschaos/litmus-go/pkg/clients"
azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common"
azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance"
"github.com/litmuschaos/litmus-go/pkg/status"

"github.com/litmuschaos/litmus-go/pkg/events"
"github.com/litmuschaos/litmus-go/pkg/log"
"github.com/litmuschaos/litmus-go/pkg/probe"
"github.com/litmuschaos/litmus-go/pkg/result"
"github.com/litmuschaos/litmus-go/pkg/status"
"github.com/litmuschaos/litmus-go/pkg/types"
"github.com/litmuschaos/litmus-go/pkg/utils/common"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -64,16 +64,16 @@ func AzureInstanceStop(clients clients.ClientSets) {
go common.AbortWatcherWithoutExit(experimentsDetails.ExperimentName, clients, &resultDetails, &chaosDetails, &eventsDetails)

//DISPLAY THE APP INFORMATION
log.InfoWithValues("The application information is as follows", logrus.Fields{
log.InfoWithValues("The instance information is as follows", logrus.Fields{
"Chaos Duration": experimentsDetails.ChaosDuration,
"Resource Group": experimentsDetails.ResourceGroup,
"Instance Name": experimentsDetails.AzureInstanceName,
"Sequence": experimentsDetails.Sequence,
})

//PRE-CHAOS APPLICATION STATUS CHECK
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (pre-chaos)")
err = status.CheckApplicationStatus(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
if err != nil {
if err = status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "[pre-chaos]: Failed to verify that the AUT (Application Under Test) is in running state, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand All @@ -83,8 +83,7 @@ func AzureInstanceStop(clients clients.ClientSets) {
//PRE-CHAOS AUXILIARY APPLICATION STATUS CHECK
if experimentsDetails.AuxiliaryAppInfo != "" {
log.Info("[Status]: Verify that the Auxiliary Applications are running (pre-chaos)")
err = status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
if err != nil {
if err = status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
log.Errorf("Auxiliary Application status check failed, err: %v", err)
failStep := "[pre-chaos]: Failed to verify that the Auxiliary Applications are in running state, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand Down Expand Up @@ -130,7 +129,7 @@ func AzureInstanceStop(clients clients.ClientSets) {
}

//Verify the azure target instance is running (pre-chaos)
if err := azureStatus.InstanceStatusCheckByName(&experimentsDetails); err != nil {
if err = azureStatus.InstanceStatusCheckByName(experimentsDetails.AzureInstanceName, experimentsDetails.ScaleSet, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup); err != nil {
log.Errorf("failed to get the azure instance status, err: %v", err)
failStep := "[pre-chaos]: Failed to verify the azure instance status, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand Down Expand Up @@ -158,7 +157,7 @@ func AzureInstanceStop(clients clients.ClientSets) {
resultDetails.Verdict = v1alpha1.ResultVerdictPassed

//Verify the azure instance is running (post chaos)
if err = azureStatus.InstanceStatusCheckByName(&experimentsDetails); err != nil {
if err = azureStatus.InstanceStatusCheckByName(experimentsDetails.AzureInstanceName, experimentsDetails.ScaleSet, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup); err != nil {
log.Errorf("failed to get the azure instance status, err: %v", err)
failStep := "[pre-chaos]: Failed to update the azure instance status, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand All @@ -168,7 +167,7 @@ func AzureInstanceStop(clients clients.ClientSets) {

//POST-CHAOS APPLICATION STATUS CHECK
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (post-chaos)")
if err = status.CheckApplicationStatus(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
if err = status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
log.Errorf("Application status check failed, err: %v", err)
failStep := "[post-chaos]: Failed to verify that the AUT (Application Under Test) is running, err: " + err.Error()
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
Expand Down
Loading

0 comments on commit cf20ce5

Please sign in to comment.