diff --git a/.github/workflows/aws-experiment-pipeline.yml b/.github/workflows/aws-experiment-pipeline.yml index 82ef56d8c..76897ab34 100644 --- a/.github/workflows/aws-experiment-pipeline.yml +++ b/.github/workflows/aws-experiment-pipeline.yml @@ -33,7 +33,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '1.14' + go-version: '1.16' - name: Create Kubernetes secret for aws experiment if: always() @@ -119,6 +119,28 @@ jobs: run: | aws ec2 terminate-instances --instance-ids ${{ env.INSTANCE_ONE }} ${{ env.INSTANCE_TWO }} + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh + AWS_EBS_Loss_By_ID_And_Tag: runs-on: ubuntu-latest needs: AWS_EC2_Terminate_By_ID_And_Tag @@ -138,7 +160,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '1.14' + go-version: '1.16' - name: Create Kubernetes secret for aws experiment if: always() @@ -260,3 +282,25 @@ jobs: if: always() run: | aws ec2 delete-volume --volume-id "${{ env.VOLUME_ID }}" --region ${{ secrets.REGION }} + + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh \ No newline at end of file diff --git a/.github/workflows/gcp-experiment-pipeline.yml b/.github/workflows/gcp-experiment-pipeline.yml new file mode 100644 index 000000000..a5c7aa767 --- /dev/null +++ b/.github/workflows/gcp-experiment-pipeline.yml @@ -0,0 +1,237 @@ +--- +name: GCP-Experiment-Pipeline +on: + workflow_dispatch: + inputs: + goExperimentImage: + default: "litmuschaos/go-runner:ci" + operatorImage: + default: "litmuschaos/chaos-operator:ci" + runnerImage: + default: "litmuschaos/chaos-runner:ci" + chaosNamespace: + default: "default" + experimentImagePullPolicy: + default: "Always" + +jobs: + GCP_VM_Instance_Stop: + runs-on: ubuntu-latest + steps: + + #Install and configure a k3s cluster + - name: Installing Prerequisites (K3S Cluster) + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + curl -sfL https://get.k3s.io | sh -s - --docker --write-kubeconfig-mode 664 + kubectl wait node --all --for condition=ready --timeout=90s + mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config + kubectl get nodes + + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + + - name: Create Kubernetes secret for gcp experiment + if: always() + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + cat < logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh + + GCP_VM_Disk_Loss: + runs-on: ubuntu-latest + needs: GCP_VM_Instance_Stop + steps: + + #Install and configure a k3s cluster + - name: Installing Prerequisites (K3S Cluster) + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + curl -sfL https://get.k3s.io | sh -s - --docker --write-kubeconfig-mode 664 + kubectl wait node --all --for condition=ready --timeout=90s + mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config + kubectl get nodes + + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + + - name: Create Kubernetes secret for gcp experiment + if: always() + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + cat < logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh \ No newline at end of file diff --git a/.github/workflows/node-level-pipeline.yml b/.github/workflows/node-level-pipeline.yml index f42fd891f..60090e6a6 100644 --- a/.github/workflows/node-level-pipeline.yml +++ b/.github/workflows/node-level-pipeline.yml @@ -126,6 +126,20 @@ jobs: - name: TCID-EC2-GENERIC-INFRA-NODE-SELECTOR if: always() run: make node-selector + + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt ### Runing Experiment Tunables Engine_Test: @@ -151,6 +165,20 @@ jobs: - name: TCID-EC2-GENERIC-INFRA-WITH-APP-INFO run: make with-app-info + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + ### App Cleanup App_Cleanup: needs: Engine_Test diff --git a/.github/workflows/scheduled-aws-experiment-pipeline.yml b/.github/workflows/scheduled-aws-experiment-pipeline.yml index d3d3d53ae..449f197e7 100644 --- a/.github/workflows/scheduled-aws-experiment-pipeline.yml +++ b/.github/workflows/scheduled-aws-experiment-pipeline.yml @@ -23,7 +23,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '1.14' + go-version: '1.16' - name: Create Kubernetes secret for aws experiment if: always() @@ -101,6 +101,28 @@ jobs: run: | aws ec2 terminate-instances --instance-ids ${{ env.INSTANCE_ONE }} ${{ env.INSTANCE_TWO }} --region ${{ secrets.REGION }} + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh + AWS_EBS_Loss: runs-on: ubuntu-latest needs: AWS_EC2_Test @@ -120,7 +142,7 @@ jobs: - uses: actions/setup-go@v2 with: - go-version: '1.14' + go-version: '1.16' - name: Create Kubernetes secret for aws experiment if: always() @@ -242,3 +264,25 @@ jobs: if: always() run: | aws ec2 delete-volume --volume-id "${{ env.VOLUME_ID }}" --region ${{ secrets.REGION }} + + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh diff --git a/.github/workflows/scheduled-gcp-experiment-pipeline.yml b/.github/workflows/scheduled-gcp-experiment-pipeline.yml new file mode 100644 index 000000000..e98ac4e54 --- /dev/null +++ b/.github/workflows/scheduled-gcp-experiment-pipeline.yml @@ -0,0 +1,218 @@ +--- +name: Scheduled-GCP-Experiment-Pipeline +on: + schedule: + - cron: "30 22 * * *" # Daily 02:30 AM in midnight + +jobs: + GCP_VM_Instance_Stop: + runs-on: ubuntu-latest + steps: + + #Install and configure a k3s cluster + - name: Installing Prerequisites (K3S Cluster) + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + curl -sfL https://get.k3s.io | sh -s - --docker --write-kubeconfig-mode 664 + kubectl wait node --all --for condition=ready --timeout=90s + mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config + kubectl get nodes + + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + + - name: Create Kubernetes secret for gcp experiment + if: always() + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + cat < logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh + + GCP_VM_Disk_Loss: + runs-on: ubuntu-latest + needs: GCP_VM_Instance_Stop + steps: + + #Install and configure a k3s cluster + - name: Installing Prerequisites (K3S Cluster) + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + curl -sfL https://get.k3s.io | sh -s - --docker --write-kubeconfig-mode 664 + kubectl wait node --all --for condition=ready --timeout=90s + mkdir -p $HOME/.kube && cat /etc/rancher/k3s/k3s.yaml > $HOME/.kube/config + kubectl get nodes + + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + + - name: Create Kubernetes secret for gcp experiment + if: always() + env: + KUBECONFIG: /etc/rancher/k3s/k3s.yaml + run: | + cat < logs.txt + cat logs.txt + + - name: Litmus Cleanup + if: ${{ always() }} + run: make litmus-cleanup + + - name: Deleting K3S cluster + if: always() + run: /usr/local/bin/k3s-uninstall.sh \ No newline at end of file diff --git a/.github/workflows/scheduled-node-level-pipeline.yml b/.github/workflows/scheduled-node-level-pipeline.yml index e9eea664e..c986373eb 100644 --- a/.github/workflows/scheduled-node-level-pipeline.yml +++ b/.github/workflows/scheduled-node-level-pipeline.yml @@ -100,6 +100,20 @@ jobs: if: always() run: make node-selector + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + ### Runing Experiment Tunables Engine_Test: needs: Node_Level_Test @@ -118,6 +132,20 @@ jobs: - name: TCID-EC2-GENERIC-INFRA-WITH-APP-INFO run: make with-app-info + - name: "[Debug]: check chaos resources" + if: ${{ failure() }} + continue-on-error: true + run: | + bash <(curl -s https://raw.githubusercontent.com/litmuschaos/litmus-e2e/master/build/debug.sh) + + - name: "[Debug]: check operator logs" + if: ${{ failure() }} + continue-on-error: true + run: | + operator_name=$(kubectl get pods -n litmus -l app.kubernetes.io/component=operator --no-headers | awk '{print$1}') + kubectl logs $operator_name -n litmus > logs.txt + cat logs.txt + ### App Cleanup App_Cleanup: needs: Engine_Test diff --git a/.master-plan.yml b/.master-plan.yml index 922f769bb..b6bde1d3d 100644 --- a/.master-plan.yml +++ b/.master-plan.yml @@ -230,6 +230,28 @@ spec: git/location: "" test/status: "Not Done" + # ------------------------------------------------- + # Kubernetes GCP chaos experiment BDD Tests + # ------------------------------------------------- + + - tcid: TCID-EC2-GCP-INFRA-VM-STOP + name: "TCID-EC2-GCP-INFRA-VM-STOP" + description: "Stop a GCP VM instance" + labels: + test/feature: "gcp" + test/tags: "gcp, vm stop" + git/location: "" + test/status: "Done" + + - tcid: TCID-EC2-GCP-INFRA-DISK-LOSS + name: "TCID-EC2-GCP-INFRA-DISK-LOSS" + description: "Detach a Disk Volume" + labels: + test/feature: "gcp" + test/tags: "gcp, disk loss" + git/location: "" + test/status: "Done" + # ---------------------------------------------------------- # LitmusChaos Ansible Experiments BDDs # ---------------------------------------------------------- diff --git a/Makefile b/Makefile index 4d6c63773..5d88aff04 100644 --- a/Makefile +++ b/Makefile @@ -225,6 +225,22 @@ ebs-loss-by-tag: @echo "------------------------------------------" @go test platform/aws/ebs-loss-by-tag_test.go -v -count=1 -timeout=20m +.PHONY: gcp-vm-instance-stop +gcp-vm-instance-stop: + + @echo "------------------------------------------" + @echo "Running gcp-vm-instance-stop experiment" + @echo "------------------------------------------" + @go test platform/gcp/gcp-vm-instance-stop_test.go -v -count=1 -timeout=20m + +.PHONY: gcp-vm-disk-loss +gcp-vm-disk-loss: + + @echo "------------------------------------------" + @echo "Running gcp-vm-disk-loss experiment" + @echo "------------------------------------------" + @go test platform/gcp/gcp-vm-disk-loss_test.go -v -count=1 -timeout=20m + .PHONY: operator-reconcile-resiliency-check operator-reconcile-resiliency-check: diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index b021f0b6b..70d83afc6 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -33,6 +33,12 @@ func GetENV(testDetails *types.TestDetails, expName, engineName string) { testDetails.InstanceTag = Getenv("EC2_INSTANCE_TAG", "") testDetails.EBSVolumeID = Getenv("EBS_VOLUME_ID", "") testDetails.EBSVolumeTag = Getenv("EBS_VOLUME_TAG", "") + testDetails.VMInstanceNames = Getenv("VM_INSTANCE_NAMES", "") + testDetails.GCPProjectID = Getenv("GCP_PROJECT_ID", "") + testDetails.InstanceZones = Getenv("INSTANCE_ZONES", "") + testDetails.DiskVolumeNames = Getenv("DISK_VOLUME_NAMES", "") + testDetails.DiskZones = Getenv("DISK_ZONES", "") + testDetails.DeviceNames = Getenv("DEVICE_NAMES", "") testDetails.Region = Getenv("REGION", "us-west-1") testDetails.UpdateWebsite = Getenv("UPDATE_WEBSITE", "false") testDetails.TargetNodes = Getenv("TARGET_NODES", "") diff --git a/pkg/install.go b/pkg/install.go index dd97b47ab..bb63ed95c 100644 --- a/pkg/install.go +++ b/pkg/install.go @@ -310,6 +310,15 @@ func setEngineVar(chaosEngine *v1alpha1.ChaosEngine, testsDetails *types.TestDet Name: "CHAOS_KILL_COMMAND", Value: testsDetails.MemoryKillCommand, }) + case "gcp-vm-instance-stop": + envDetails.SetEnv("GCP_PROJECT_ID", testsDetails.GCPProjectID). + SetEnv("VM_INSTANCE_NAMES", testsDetails.VMInstanceNames). + SetEnv("INSTANCE_ZONES", testsDetails.InstanceZones) + case "gcp-vm-disk-loss": + envDetails.SetEnv("GCP_PROJECT_ID", testsDetails.GCPProjectID). + SetEnv("DISK_VOLUME_NAMES", testsDetails.DiskVolumeNames). + SetEnv("DISK_ZONES", testsDetails.DiskZones). + SetEnv("DEVICE_NAMES", testsDetails.DeviceNames) } // for experiments like pod network latency diff --git a/pkg/types/types.go b/pkg/types/types.go index 1df8a8e59..860644447 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -42,6 +42,12 @@ type TestDetails struct { InstanceTag string EBSVolumeID string EBSVolumeTag string + VMInstanceNames string + GCPProjectID string + InstanceZones string + DiskVolumeNames string + DiskZones string + DeviceNames string Region string Lib string PodsAffectedPercentage string diff --git a/platform/gcp/gcp-vm-disk-loss_test.go b/platform/gcp/gcp-vm-disk-loss_test.go new file mode 100644 index 000000000..0113c19cf --- /dev/null +++ b/platform/gcp/gcp-vm-disk-loss_test.go @@ -0,0 +1,154 @@ +package tests + +import ( + "testing" + + "github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1" + "github.com/litmuschaos/litmus-e2e/pkg" + "github.com/litmuschaos/litmus-e2e/pkg/environment" + "github.com/litmuschaos/litmus-e2e/pkg/log" + "github.com/litmuschaos/litmus-e2e/pkg/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/klog" +) + +func TestGoGCPVMDiskLoss(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "BDD test") +} + +//BDD for testing experiment +var _ = Describe("BDD of gcp-vm-disk-loss experiment", func() { + + // BDD TEST CASE 1 - gcp-vm-disk-loss in parallel mode + Context("Check for gcp-vm-disk-loss experiment", func() { + + It("Should check for the gcp vm disk loss in parallel", func() { + + testsDetails := types.TestDetails{} + clients := environment.ClientSets{} + chaosExperiment := v1alpha1.ChaosExperiment{} + chaosEngine := v1alpha1.ChaosEngine{} + + //Getting kubeConfig and Generate ClientSets + By("[PreChaos]: Getting kubeconfig and generate clientset") + err := clients.GenerateClientSetFromKubeConfig() + Expect(err).To(BeNil(), "Unable to Get the kubeconfig, due to {%v}", err) + + //Fetching all the default ENV + By("[PreChaos]: Fetching all default ENVs") + klog.Infof("[PreReq]: Getting the ENVs for the %v test", testsDetails.ExperimentName) + environment.GetENV(&testsDetails, "gcp-vm-disk-loss", "gcp-disk-engine-par") + log.Infof("[Info]: The target disk volumes are: %v", testsDetails.DiskVolumeNames) + + testsDetails.RbacPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/rbac.yaml" + testsDetails.ExperimentPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/experiment.yaml" + testsDetails.EnginePath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/engine.yaml" + testsDetails.ChaosNamespace = "default" + testsDetails.AppNS = "default" + + // Checking the chaos operator running status + By("[Status]: Checking chaos operator status") + err = pkg.OperatorStatusCheck(&testsDetails, clients) + Expect(err).To(BeNil(), "Operator status check failed, due to {%v}", err) + + // Prepare Chaos Execution + By("[Prepare]: Prepare Chaos Execution") + err = pkg.PrepareChaos(&testsDetails, &chaosExperiment, &chaosEngine, clients, false) + Expect(err).To(BeNil(), "fail to prepare chaos, due to {%v}", err) + + //Checking runner pod running state + By("[Status]: Runner pod running status check") + err = pkg.RunnerPodStatus(&testsDetails, testsDetails.AppNS, clients) + Expect(err).To(BeNil(), "Runner pod status check failed, due to {%v}", err) + + //Chaos pod running status check + err = pkg.ChaosPodStatus(&testsDetails, clients) + Expect(err).To(BeNil(), "Chaos pod status check failed, due to {%v}", err) + + //Waiting for chaos pod to get completed + //And Print the logs of the chaos pod + By("[Status]: Wait for chaos pod completion and then print logs") + err = pkg.ChaosPodLogs(&testsDetails, clients) + Expect(err).To(BeNil(), "Fail to get the experiment chaos pod logs, due to {%v}", err) + + //Checking the chaosresult verdict + By("[Verdict]: Checking the chaosresult verdict") + err = pkg.ChaosResultVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChasoResult Verdict check failed, due to {%v}", err) + + //Checking chaosengine verdict + By("Checking the Verdict of Chaos Engine") + err = pkg.ChaosEngineVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChaosEngine Verdict check failed, due to {%v}", err) + + }) + }) + + // BDD TEST CASE 2 - gcp-vm-disk-loss in serial mode + Context("Check for gcp-vm-disk-loss experiment", func() { + + It("Should check for the gcp vm disk loss in serial", func() { + + testsDetails := types.TestDetails{} + clients := environment.ClientSets{} + chaosExperiment := v1alpha1.ChaosExperiment{} + chaosEngine := v1alpha1.ChaosEngine{} + + //Getting kubeConfig and Generate ClientSets + By("[PreChaos]: Getting kubeconfig and generate clientset") + err := clients.GenerateClientSetFromKubeConfig() + Expect(err).To(BeNil(), "Unable to Get the kubeconfig, due to {%v}", err) + + //Fetching all the default ENV + By("[PreChaos]: Fetching all default ENVs") + klog.Infof("[PreReq]: Getting the ENVs for the %v test", testsDetails.ExperimentName) + environment.GetENV(&testsDetails, "gcp-vm-disk-loss", "gcp-disk-engine-ser") + log.Infof("[Info]: The target disk volumes are: %v", testsDetails.DiskVolumeNames) + + testsDetails.RbacPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/rbac.yaml" + testsDetails.ExperimentPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/experiment.yaml" + testsDetails.EnginePath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-disk-loss/engine.yaml" + testsDetails.Sequence = "serial" + testsDetails.ChaosNamespace = "default" + testsDetails.AppNS = "default" + + // Checking the chaos operator running status + By("[Status]: Checking chaos operator status") + err = pkg.OperatorStatusCheck(&testsDetails, clients) + Expect(err).To(BeNil(), "Operator status check failed, due to {%v}", err) + + // Prepare Chaos Execution + By("[Prepare]: Prepare Chaos Execution") + err = pkg.PrepareChaos(&testsDetails, &chaosExperiment, &chaosEngine, clients, false) + Expect(err).To(BeNil(), "fail to prepare chaos, due to {%v}", err) + + //Checking runner pod running state + By("[Status]: Runner pod running status check") + err = pkg.RunnerPodStatus(&testsDetails, testsDetails.AppNS, clients) + Expect(err).To(BeNil(), "Runner pod status check failed, due to {%v}", err) + + //Chaos pod running status check + err = pkg.ChaosPodStatus(&testsDetails, clients) + Expect(err).To(BeNil(), "Chaos pod status check failed, due to {%v}", err) + + //Waiting for chaos pod to get completed + //And Print the logs of the chaos pod + By("[Status]: Wait for chaos pod completion and then print logs") + err = pkg.ChaosPodLogs(&testsDetails, clients) + Expect(err).To(BeNil(), "Fail to get the experiment chaos pod logs, due to {%v}", err) + + //Checking the chaosresult verdict + By("[Verdict]: Checking the chaosresult verdict") + err = pkg.ChaosResultVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChasoResult Verdict check failed, due to {%v}", err) + + //Checking chaosengine verdict + By("Checking the Verdict of Chaos Engine") + err = pkg.ChaosEngineVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChaosEngine Verdict check failed, due to {%v}", err) + + }) + }) +}) diff --git a/platform/gcp/gcp-vm-instance-stop_test.go b/platform/gcp/gcp-vm-instance-stop_test.go new file mode 100644 index 000000000..1cf46ff8c --- /dev/null +++ b/platform/gcp/gcp-vm-instance-stop_test.go @@ -0,0 +1,151 @@ +package tests + +import ( + "testing" + + "github.com/litmuschaos/chaos-operator/pkg/apis/litmuschaos/v1alpha1" + "github.com/litmuschaos/litmus-e2e/pkg" + "github.com/litmuschaos/litmus-e2e/pkg/environment" + "github.com/litmuschaos/litmus-e2e/pkg/log" + "github.com/litmuschaos/litmus-e2e/pkg/types" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "k8s.io/klog" +) + +func TestGoGCPVMInstanceStop(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "BDD test") +} + +var _ = Describe("BDD of gcp-vm-instance-stop experiment", func() { + + // BDD TEST CASE 1 - gcp-vm-instance-stop in parallel mode + Context("Check for gcp-vm-instance-stop experiment", func() { + It("Should check for the gcp vm instance stop in parallel", func() { + + testsDetails := types.TestDetails{} + clients := environment.ClientSets{} + chaosExperiment := v1alpha1.ChaosExperiment{} + chaosEngine := v1alpha1.ChaosEngine{} + + //Getting kubeConfig and Generate ClientSets + By("[PreChaos]: Getting kubeconfig and generate clientset") + err := clients.GenerateClientSetFromKubeConfig() + Expect(err).To(BeNil(), "Unable to Get the kubeconfig, due to {%v}", err) + + //Fetching all the default ENV + By("[PreChaos]: Fetching all default ENVs") + klog.Infof("[PreReq]: Getting the ENVs for the %v test", testsDetails.ExperimentName) + environment.GetENV(&testsDetails, "gcp-vm-instance-stop", "gcp-vm-engine-par") + log.Infof("[Info]: The target VM instances are: %v", testsDetails.VMInstanceNames) + + testsDetails.RbacPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/rbac.yaml" + testsDetails.ExperimentPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/experiment.yaml" + testsDetails.EnginePath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/engine.yaml" + testsDetails.ChaosNamespace = "default" + testsDetails.AppNS = "default" + + // Checking the chaos operator running status + By("[Status]: Checking chaos operator status") + err = pkg.OperatorStatusCheck(&testsDetails, clients) + Expect(err).To(BeNil(), "Operator status check failed, due to {%v}", err) + + // Prepare Chaos Execution + By("[Prepare]: Prepare Chaos Execution") + err = pkg.PrepareChaos(&testsDetails, &chaosExperiment, &chaosEngine, clients, false) + Expect(err).To(BeNil(), "fail to prepare chaos, due to {%v}", err) + + //Checking runner pod running state + By("[Status]: Runner pod running status check") + err = pkg.RunnerPodStatus(&testsDetails, testsDetails.AppNS, clients) + Expect(err).To(BeNil(), "Runner pod status check failed, due to {%v}", err) + + //Chaos pod running status check + err = pkg.ChaosPodStatus(&testsDetails, clients) + Expect(err).To(BeNil(), "Chaos pod status check failed, due to {%v}", err) + + //Waiting for chaos pod to get completed + //And Print the logs of the chaos pod + By("[Status]: Wait for chaos pod completion and then print logs") + err = pkg.ChaosPodLogs(&testsDetails, clients) + Expect(err).To(BeNil(), "Fail to get the experiment chaos pod logs, due to {%v}", err) + + //Checking the chaosresult verdict + By("[Verdict]: Checking the chaosresult verdict") + err = pkg.ChaosResultVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChasoResult Verdict check failed, due to {%v}", err) + + //Checking chaosengine verdict + By("Checking the Verdict of Chaos Engine") + err = pkg.ChaosEngineVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChaosEngine Verdict check failed, due to {%v}", err) + }) + }) + + // BDD TEST CASE 2 - gcp-vm-instance-stop in serial mode + Context("Check for gcp-vm-instance-stop experiment", func() { + + It("Should check for the gcp vm instance stop in serial", func() { + + testsDetails := types.TestDetails{} + clients := environment.ClientSets{} + chaosExperiment := v1alpha1.ChaosExperiment{} + chaosEngine := v1alpha1.ChaosEngine{} + + //Getting kubeConfig and Generate ClientSets + By("[PreChaos]: Getting kubeconfig and generate clientset") + err := clients.GenerateClientSetFromKubeConfig() + Expect(err).To(BeNil(), "Unable to Get the kubeconfig, due to {%v}", err) + + //Fetching all the default ENV + By("[PreChaos]: Fetching all default ENVs") + klog.Infof("[PreReq]: Getting the ENVs for the %v test", testsDetails.ExperimentName) + environment.GetENV(&testsDetails, "gcp-vm-instance-stop", "gcp-vm-engine-ser") + log.Infof("[Info]: The target VM instances are: %v", testsDetails.VMInstanceNames) + + testsDetails.RbacPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/rbac.yaml" + testsDetails.ExperimentPath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/experiment.yaml" + testsDetails.EnginePath = "https://hub.litmuschaos.io/api/chaos/master?file=charts/gcp/gcp-vm-instance-stop/engine.yaml" + testsDetails.Sequence = "serial" + testsDetails.ChaosNamespace = "default" + testsDetails.AppNS = "default" + + // Checking the chaos operator running status + By("[Status]: Checking chaos operator status") + err = pkg.OperatorStatusCheck(&testsDetails, clients) + Expect(err).To(BeNil(), "Operator status check failed, due to {%v}", err) + + // Prepare Chaos Execution + By("[Prepare]: Prepare Chaos Execution") + err = pkg.PrepareChaos(&testsDetails, &chaosExperiment, &chaosEngine, clients, false) + Expect(err).To(BeNil(), "fail to prepare chaos, due to {%v}", err) + + //Checking runner pod running state + By("[Status]: Runner pod running status check") + err = pkg.RunnerPodStatus(&testsDetails, testsDetails.AppNS, clients) + Expect(err).To(BeNil(), "Runner pod status check failed, due to {%v}", err) + + //Chaos pod running status check + err = pkg.ChaosPodStatus(&testsDetails, clients) + Expect(err).To(BeNil(), "Chaos pod status check failed, due to {%v}", err) + + //Waiting for chaos pod to get completed + //And Print the logs of the chaos pod + By("[Status]: Wait for chaos pod completion and then print logs") + err = pkg.ChaosPodLogs(&testsDetails, clients) + Expect(err).To(BeNil(), "Fail to get the experiment chaos pod logs, due to {%v}", err) + + //Checking the chaosresult verdict + By("[Verdict]: Checking the chaosresult verdict") + err = pkg.ChaosResultVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChasoResult Verdict check failed, due to {%v}", err) + + //Checking chaosengine verdict + By("Checking the Verdict of Chaos Engine") + err = pkg.ChaosEngineVerdict(&testsDetails, clients) + Expect(err).To(BeNil(), "ChaosEngine Verdict check failed, due to {%v}", err) + + }) + }) +})