From cb1480335c12961e891945b8bf0df9be97e827a0 Mon Sep 17 00:00:00 2001 From: Shubham Chaudhary Date: Fri, 14 Aug 2020 09:40:42 +0530 Subject: [PATCH] chore(probe): Adding probes in all go experiments (#80) Signed-off-by: shubhamchaudhary --- .../developer-guide/templates/experiment.tmpl | 43 +++++++++++++++++-- .../generic/container-kill/container-kill.go | 40 ++++++++++++++++- experiments/generic/disk-fill/disk-fill.go | 39 ++++++++++++++++- .../kubelet-service-kill.go | 39 ++++++++++++++++- .../generic/node-cpu-hog/node-cpu-hog.go | 39 ++++++++++++++++- experiments/generic/node-drain/node-drain.go | 39 ++++++++++++++++- .../node-memory-hog/node-memory-hog.go | 39 ++++++++++++++++- experiments/generic/node-taint/node-taint.go | 39 ++++++++++++++++- .../generic/pod-cpu-hog/pod-cpu-hog.go | 39 ++++++++++++++++- experiments/generic/pod-delete/pod-delete.go | 1 + .../generic/pod-memory-hog/pod-memory-hog.go | 39 ++++++++++++++++- .../pod-network-corruption.go | 40 ++++++++++++++++- .../pod-network-duplication.go | 40 ++++++++++++++++- .../pod-network-latency.go | 40 ++++++++++++++++- .../pod-network-loss/pod-network-loss.go | 40 ++++++++++++++++- .../container-kill/environment/environment.go | 3 +- .../disk-fill/environment/environment.go | 3 +- .../environment/environment.go | 3 +- .../network-chaos/environment/environment.go | 3 +- .../node-cpu-hog/environment/environment.go | 3 +- .../node-drain/environment/environment.go | 3 +- .../environment/environment.go | 3 +- .../node-taint/environment/environment.go | 3 +- .../pod-cpu-hog/environment/environment.go | 3 +- .../pod-memory-hog/environment/environment.go | 3 +- 25 files changed, 546 insertions(+), 40 deletions(-) diff --git a/contribute/developer-guide/templates/experiment.tmpl b/contribute/developer-guide/templates/experiment.tmpl index d2e330371..54ab29c8b 100644 --- a/contribute/developer-guide/templates/experiment.tmpl +++ b/contribute/developer-guide/templates/experiment.tmpl @@ -6,6 +6,7 @@ import ( "github.com/litmuschaos/litmus-go/pkg/log" experimentEnv "github.com/litmuschaos/litmus-go/pkg/{{ .Category }}/{{ .Name }}/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/{{ .Category }}/{{ .Name }}/types" + "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" @@ -39,11 +40,14 @@ func main() { log.Infof("[PreReq]: Getting the ENV for the %v experiment", experimentsDetails.ExperimentName) experimentEnv.GetENV(&experimentsDetails, "{{ .Name }}") + // Intialise the chaos attributes + experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails) + // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, experimentsDetails.EngineName, experimentsDetails.ExperimentName) - // Intialise the chaos attributes - experimentEnv.InitialiseChaosVariables(&chaosDetails, &experimentsDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) @@ -92,7 +96,22 @@ func main() { {{- end }} if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -145,10 +164,26 @@ func main() { {{- end }} if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } + //Updating the chaosResult in the end of experiment log.Infof("[The End]: Updating the chaos result of %v experiment (EOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "EOT") diff --git a/experiments/generic/container-kill/container-kill.go b/experiments/generic/container-kill/container-kill.go index f52b78f46..2c20f96b5 100644 --- a/experiments/generic/container-kill/container-kill.go +++ b/experiments/generic/container-kill/container-kill.go @@ -8,6 +8,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/container-kill/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -76,8 +80,24 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -112,8 +132,24 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/disk-fill/disk-fill.go b/experiments/generic/disk-fill/disk-fill.go index 910475980..d9f994691 100644 --- a/experiments/generic/disk-fill/disk-fill.go +++ b/experiments/generic/disk-fill/disk-fill.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/disk-fill/types" "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" @@ -46,6 +47,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -89,7 +93,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -134,7 +154,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/kubelet-service-kill/kubelet-service-kill.go b/experiments/generic/kubelet-service-kill/kubelet-service-kill.go index d53034bb3..04b9cab38 100644 --- a/experiments/generic/kubelet-service-kill/kubelet-service-kill.go +++ b/experiments/generic/kubelet-service-kill/kubelet-service-kill.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/kubelet-service-kill/types" "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" @@ -46,6 +47,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -89,7 +93,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -134,7 +154,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/node-cpu-hog/node-cpu-hog.go b/experiments/generic/node-cpu-hog/node-cpu-hog.go index 28002ca5a..59cf7a7ae 100644 --- a/experiments/generic/node-cpu-hog/node-cpu-hog.go +++ b/experiments/generic/node-cpu-hog/node-cpu-hog.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-cpu-hog/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -91,7 +95,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -136,7 +156,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/node-drain/node-drain.go b/experiments/generic/node-drain/node-drain.go index 55f96adfb..a143227e6 100644 --- a/experiments/generic/node-drain/node-drain.go +++ b/experiments/generic/node-drain/node-drain.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-drain/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-drain/types" "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" @@ -46,6 +47,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -90,7 +94,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -135,7 +155,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/node-memory-hog/node-memory-hog.go b/experiments/generic/node-memory-hog/node-memory-hog.go index 515181878..3b650671b 100644 --- a/experiments/generic/node-memory-hog/node-memory-hog.go +++ b/experiments/generic/node-memory-hog/node-memory-hog.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-memory-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-memory-hog/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -80,7 +84,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -113,7 +133,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/node-taint/node-taint.go b/experiments/generic/node-taint/node-taint.go index 1cca77c05..77c93f0f6 100644 --- a/experiments/generic/node-taint/node-taint.go +++ b/experiments/generic/node-taint/node-taint.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/node-taint/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/node-taint/types" "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" @@ -46,6 +47,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -89,7 +93,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -134,7 +154,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-cpu-hog/pod-cpu-hog.go b/experiments/generic/pod-cpu-hog/pod-cpu-hog.go index a61e1cdb4..43a93bf55 100644 --- a/experiments/generic/pod-cpu-hog/pod-cpu-hog.go +++ b/experiments/generic/pod-cpu-hog/pod-cpu-hog.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-cpu-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-cpu-hog/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -79,7 +83,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -112,7 +132,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-delete/pod-delete.go b/experiments/generic/pod-delete/pod-delete.go index c942f48c8..088873faa 100644 --- a/experiments/generic/pod-delete/pod-delete.go +++ b/experiments/generic/pod-delete/pod-delete.go @@ -128,6 +128,7 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { // run the probes in the post-chaos check diff --git a/experiments/generic/pod-memory-hog/pod-memory-hog.go b/experiments/generic/pod-memory-hog/pod-memory-hog.go index 571313dc0..b8ce26f5f 100644 --- a/experiments/generic/pod-memory-hog/pod-memory-hog.go +++ b/experiments/generic/pod-memory-hog/pod-memory-hog.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/pod-memory-hog/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/pod-memory-hog/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -80,7 +84,23 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -113,7 +133,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-network-corruption/pod-network-corruption.go b/experiments/generic/pod-network-corruption/pod-network-corruption.go index 8a9647a6a..2f5d9da43 100644 --- a/experiments/generic/pod-network-corruption/pod-network-corruption.go +++ b/experiments/generic/pod-network-corruption/pod-network-corruption.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -76,8 +80,25 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -110,7 +131,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-network-duplication/pod-network-duplication.go b/experiments/generic/pod-network-duplication/pod-network-duplication.go index f62c88c7c..b4c3645bc 100644 --- a/experiments/generic/pod-network-duplication/pod-network-duplication.go +++ b/experiments/generic/pod-network-duplication/pod-network-duplication.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -76,8 +80,25 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -110,7 +131,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-network-latency/pod-network-latency.go b/experiments/generic/pod-network-latency/pod-network-latency.go index a18d7d55f..60c0e305f 100644 --- a/experiments/generic/pod-network-latency/pod-network-latency.go +++ b/experiments/generic/pod-network-latency/pod-network-latency.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginning of experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -76,8 +80,25 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -110,7 +131,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/experiments/generic/pod-network-loss/pod-network-loss.go b/experiments/generic/pod-network-loss/pod-network-loss.go index 7383afb84..525d23e55 100644 --- a/experiments/generic/pod-network-loss/pod-network-loss.go +++ b/experiments/generic/pod-network-loss/pod-network-loss.go @@ -7,6 +7,7 @@ import ( experimentEnv "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/environment" experimentTypes "github.com/litmuschaos/litmus-go/pkg/generic/network-chaos/types" "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" @@ -47,6 +48,9 @@ func main() { // Intialise Chaos Result Parameters types.SetResultAttributes(&resultDetails, chaosDetails) + // Intialise the probe details + probe.InitializeProbesInChaosResultDetails(&chaosDetails, clients, &resultDetails) + //Updating the chaos result in the beginningo f experiment log.Infof("[PreReq]: Updating the chaos result of %v experiment (SOT)", experimentsDetails.ExperimentName) err = result.ChaosResult(&chaosDetails, clients, &resultDetails, "SOT") @@ -76,8 +80,25 @@ func main() { result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) return } + if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the pre-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PreChaos", &eventsDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + if err != nil { + log.Errorf("Probe failed, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating pre chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PreChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } @@ -110,7 +131,22 @@ func main() { } if experimentsDetails.EngineName != "" { - types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, "AUT is Running successfully", "Normal", &chaosDetails) + + // run the probes in the post-chaos check + err = probe.RunProbes(&chaosDetails, clients, &resultDetails, "PostChaos", &eventsDetails) + if err != nil { + log.Errorf("Unable to Add the probes, due to err: %v", err) + failStep := "Failed while adding probe" + msg := "AUT: Running, Probes: Unsuccessful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Warning", &chaosDetails) + events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") + result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails) + return + } + + // generating post chaos event + msg := "AUT: Running, Probes: Successful" + types.SetEngineEventAttributes(&eventsDetails, types.PostChaosCheck, msg, "Normal", &chaosDetails) events.GenerateEvents(&eventsDetails, clients, &chaosDetails, "ChaosEngine") } diff --git a/pkg/generic/container-kill/environment/environment.go b/pkg/generic/container-kill/environment/environment.go index 45b48dd3d..d9ce217aa 100644 --- a/pkg/generic/container-kill/environment/environment.go +++ b/pkg/generic/container-kill/environment/environment.go @@ -51,5 +51,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/disk-fill/environment/environment.go b/pkg/generic/disk-fill/environment/environment.go index 5375e81c1..e8ec01962 100644 --- a/pkg/generic/disk-fill/environment/environment.go +++ b/pkg/generic/disk-fill/environment/environment.go @@ -51,5 +51,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/kubelet-service-kill/environment/environment.go b/pkg/generic/kubelet-service-kill/environment/environment.go index 9827049ac..0b01039b3 100644 --- a/pkg/generic/kubelet-service-kill/environment/environment.go +++ b/pkg/generic/kubelet-service-kill/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/network-chaos/environment/environment.go b/pkg/generic/network-chaos/environment/environment.go index f00e6b3ee..600b5cf75 100644 --- a/pkg/generic/network-chaos/environment/environment.go +++ b/pkg/generic/network-chaos/environment/environment.go @@ -54,5 +54,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/node-cpu-hog/environment/environment.go b/pkg/generic/node-cpu-hog/environment/environment.go index 2db014cd1..04aea4686 100644 --- a/pkg/generic/node-cpu-hog/environment/environment.go +++ b/pkg/generic/node-cpu-hog/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/node-drain/environment/environment.go b/pkg/generic/node-drain/environment/environment.go index b21864942..4dad667c8 100644 --- a/pkg/generic/node-drain/environment/environment.go +++ b/pkg/generic/node-drain/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/node-memory-hog/environment/environment.go b/pkg/generic/node-memory-hog/environment/environment.go index dac3a3a0d..d46a3c128 100644 --- a/pkg/generic/node-memory-hog/environment/environment.go +++ b/pkg/generic/node-memory-hog/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/node-taint/environment/environment.go b/pkg/generic/node-taint/environment/environment.go index cc2e9642e..84d0ca12a 100644 --- a/pkg/generic/node-taint/environment/environment.go +++ b/pkg/generic/node-taint/environment/environment.go @@ -49,5 +49,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/pod-cpu-hog/environment/environment.go b/pkg/generic/pod-cpu-hog/environment/environment.go index db1362d97..e0359ad6e 100644 --- a/pkg/generic/pod-cpu-hog/environment/environment.go +++ b/pkg/generic/pod-cpu-hog/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay } diff --git a/pkg/generic/pod-memory-hog/environment/environment.go b/pkg/generic/pod-memory-hog/environment/environment.go index 514b297a2..86f9e13f0 100644 --- a/pkg/generic/pod-memory-hog/environment/environment.go +++ b/pkg/generic/pod-memory-hog/environment/environment.go @@ -48,5 +48,6 @@ func InitialiseChaosVariables(chaosDetails *types.ChaosDetails, experimentDetail chaosDetails.EngineName = experimentDetails.EngineName chaosDetails.ExperimentName = experimentDetails.ExperimentName chaosDetails.InstanceID = experimentDetails.InstanceID - + chaosDetails.Timeout = experimentDetails.Timeout + chaosDetails.Delay = experimentDetails.Delay }