Skip to content

Commit db95990

Browse files
author
Akash Shrivastava
authored
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]>
1 parent 57fef3d commit db95990

File tree

10 files changed

+96
-99
lines changed

10 files changed

+96
-99
lines changed

experiments/azure/azure-disk-loss/experiment/azure-disk-loss.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func AzureDiskLoss(clients clients.ClientSets) {
6969

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

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

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

157+
// POST-CHAOS VIRTUAL DISK STATUS CHECK
158+
log.Info("[Status]: Verify that the virtual disk are attached to VM instance(post-chaos)")
159+
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails.SubscriptionID, experimentsDetails.VirtualDiskNames, experimentsDetails.ResourceGroup); err != nil {
160+
log.Errorf("Virtual disk status check failed, err: %v", err)
161+
failStep := "[post-chaos]: Failed to verify that the virtual disk are attached to VM instance, err: " + err.Error()
162+
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
163+
return
164+
}
165+
156166
//POST-CHAOS APPLICATION STATUS CHECK
157167
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (post-chaos)")
158168
if err = status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
@@ -173,15 +183,6 @@ func AzureDiskLoss(clients clients.ClientSets) {
173183
}
174184
}
175185

176-
// POST-CHAOS VIRTUAL DISK STATUS CHECK
177-
log.Info("[Status]: Verify that the virtual disk are attached to VM instance(post-chaos)")
178-
if err = azureStatus.CheckVirtualDiskWithInstance(experimentsDetails); err != nil {
179-
log.Errorf("Virtual disk status check failed, err: %v", err)
180-
failStep := "[post-chaos]: Failed to verify that the virtual disk are attached to VM instance, err: " + err.Error()
181-
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
182-
return
183-
}
184-
185186
if experimentsDetails.EngineName != "" {
186187
// marking AUT as running, as we already checked the status of application under test
187188
msg := "AUT: Running"

experiments/azure/azure-disk-loss/test/test.yml

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,33 @@ spec:
2121
- sleep
2222
- "3600"
2323
env:
24-
# provide application namespace
2524
- name: APP_NAMESPACE
26-
value: ''
25+
value: 'default'
2726

28-
# provide application labels
2927
- name: APP_LABEL
30-
value: ''
31-
32-
# provide application kind
28+
value: 'run=nginx'
29+
3330
- name: APP_KIND
34-
value: ''
31+
value: 'deployment'
3532

3633
- name: TOTAL_CHAOS_DURATION
37-
value: ''
38-
39-
# provide auxiliary application details - namespace and labels of the applications
40-
# sample input is - "ns1:app=percona,ns2:name=nginx"
41-
- name: AUXILIARY_APPINFO
42-
value: ''
34+
value: '60'
4335

36+
- name: CHAOS_INTERVAL
37+
value: '30'
38+
4439
## Period to wait before injection of chaos in sec
4540
- name: RAMP_TIME
4641
value: ''
4742

4843
## env var that describes the library used to execute the chaos
4944
## default: litmus
5045
- name: LIB
51-
value: ''
46+
value: 'litmus'
5247

5348
# provide the chaos namespace
5449
- name: CHAOS_NAMESPACE
55-
value: ''
56-
57-
# provide target container name
58-
- name: TARGET_CONTAINER
59-
value: ''
50+
value: 'litmus'
6051

6152
# provide the resouce group of the instance
6253
- name: RESOURCE_GROUP
@@ -72,7 +63,7 @@ spec:
7263

7364
# provide the sequence type for the run. Options: serial/parallel
7465
- name: SEQUENCE
75-
value: ''
66+
value: 'parallel'
7667

7768
# provide the path to aks credentials mounted from secret
7869
- name: AZURE_AUTH_LOCATION
@@ -88,4 +79,8 @@ spec:
8879
valueFrom:
8980
fieldRef:
9081
fieldPath: spec.serviceAccountName
82+
83+
secrets:
84+
- name: cloud-secret
85+
mountPath: /tmp/
9186

experiments/azure/instance-stop/experiment/azure-instance-stop.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
clients "github.com/litmuschaos/litmus-go/pkg/clients"
1111
azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common"
1212
azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance"
13+
"github.com/litmuschaos/litmus-go/pkg/status"
1314

1415
"github.com/litmuschaos/litmus-go/pkg/events"
1516
"github.com/litmuschaos/litmus-go/pkg/log"
1617
"github.com/litmuschaos/litmus-go/pkg/probe"
1718
"github.com/litmuschaos/litmus-go/pkg/result"
18-
"github.com/litmuschaos/litmus-go/pkg/status"
1919
"github.com/litmuschaos/litmus-go/pkg/types"
2020
"github.com/litmuschaos/litmus-go/pkg/utils/common"
2121
"github.com/sirupsen/logrus"
@@ -64,16 +64,16 @@ func AzureInstanceStop(clients clients.ClientSets) {
6464
go common.AbortWatcherWithoutExit(experimentsDetails.ExperimentName, clients, &resultDetails, &chaosDetails, &eventsDetails)
6565

6666
//DISPLAY THE APP INFORMATION
67-
log.InfoWithValues("The application information is as follows", logrus.Fields{
67+
log.InfoWithValues("The instance information is as follows", logrus.Fields{
6868
"Chaos Duration": experimentsDetails.ChaosDuration,
6969
"Resource Group": experimentsDetails.ResourceGroup,
7070
"Instance Name": experimentsDetails.AzureInstanceName,
71+
"Sequence": experimentsDetails.Sequence,
7172
})
7273

7374
//PRE-CHAOS APPLICATION STATUS CHECK
7475
log.Info("[Status]: Verify that the AUT (Application Under Test) is running (pre-chaos)")
75-
err = status.CheckApplicationStatus(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
76-
if err != nil {
76+
if err = status.AUTStatusCheck(experimentsDetails.AppNS, experimentsDetails.AppLabel, experimentsDetails.TargetContainer, experimentsDetails.Timeout, experimentsDetails.Delay, clients, &chaosDetails); err != nil {
7777
log.Errorf("Application status check failed, err: %v", err)
7878
failStep := "[pre-chaos]: Failed to verify that the AUT (Application Under Test) is in running state, err: " + err.Error()
7979
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
@@ -83,8 +83,7 @@ func AzureInstanceStop(clients clients.ClientSets) {
8383
//PRE-CHAOS AUXILIARY APPLICATION STATUS CHECK
8484
if experimentsDetails.AuxiliaryAppInfo != "" {
8585
log.Info("[Status]: Verify that the Auxiliary Applications are running (pre-chaos)")
86-
err = status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients)
87-
if err != nil {
86+
if err = status.CheckAuxiliaryApplicationStatus(experimentsDetails.AuxiliaryAppInfo, experimentsDetails.Timeout, experimentsDetails.Delay, clients); err != nil {
8887
log.Errorf("Auxiliary Application status check failed, err: %v", err)
8988
failStep := "[pre-chaos]: Failed to verify that the Auxiliary Applications are in running state, err: " + err.Error()
9089
result.RecordAfterFailure(&chaosDetails, &resultDetails, failStep, clients, &eventsDetails)
@@ -130,7 +129,7 @@ func AzureInstanceStop(clients clients.ClientSets) {
130129
}
131130

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

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

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

experiments/azure/instance-stop/test/test.yml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,61 @@ spec:
2121
- sleep
2222
- "3600"
2323
env:
24-
- name: LIB
25-
value: 'litmus'
2624

27-
- name: AZURE_INSTANCE_NAME
25+
- name: APP_NAMESPACE
26+
value: 'default'
27+
28+
- name: APP_LABEL
29+
value: 'run=nginx'
30+
31+
- name: APP_KIND
32+
value: 'deployment'
33+
34+
- name: RAMP_TIME
2835
value: ''
36+
37+
- name: TOTAL_CHAOS_DURATION
38+
value: '60'
39+
40+
- name: CHAOS_INTERVAL
41+
value: '30'
2942

43+
- name: LIB
44+
value: 'litmus'
45+
3046
- name: CHAOS_NAMESPACE
31-
value: 'default'
47+
value: 'litmus'
3248

33-
- name: RESOURCE_GROUP
49+
# provide the instance names (comma seperated if multiple)
50+
- name: AZURE_INSTANCE_NAME
3451
value: ''
35-
36-
- name: RAMP_TIME
52+
53+
# provide the resouce group of the instance
54+
- name: RESOURCE_GROUP
3755
value: ''
3856

57+
# whether the disk is attached to scale instance or not, accepted values are disable, enable
58+
- name: SCALE_SET
59+
value: 'disable'
60+
61+
# provide the sequence type for the run. Options: serial/parallel
3962
- name: SEQUENCE
4063
value: 'parallel'
4164

42-
- name: CHAOS_INTERVAL
43-
value: '30'
65+
# provide the path to aks credentials mounted from secret
66+
- name: AZURE_AUTH_LOCATION
67+
value: '/tmp/azure.auth'
4468

4569
- name: POD_NAME
4670
valueFrom:
4771
fieldRef:
48-
fieldPath: metadata.name
72+
fieldPath: metadata.name
73+
74+
- name: CHAOS_SERVICE_ACCOUNT
75+
valueFrom:
76+
fieldRef:
77+
fieldPath: spec.serviceAccountName
78+
79+
secrets:
80+
- name: cloud-secret
81+
mountPath: /tmp/

pkg/azure/disk-loss/environment/environment.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
1414
experimentDetails.ExperimentName = types.Getenv("EXPERIMENT_NAME", "azure-disk-loss")
1515
experimentDetails.ChaosNamespace = types.Getenv("CHAOS_NAMESPACE", "litmus")
1616
experimentDetails.EngineName = types.Getenv("CHAOSENGINE", "")
17-
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
18-
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "30"))
19-
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))
20-
experimentDetails.ChaosLib = types.Getenv("LIB", "litmus")
2117
experimentDetails.AppNS = types.Getenv("APP_NAMESPACE", "")
2218
experimentDetails.AppLabel = types.Getenv("APP_LABEL", "")
2319
experimentDetails.AppKind = types.Getenv("APP_KIND", "")
2420
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")
21+
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
22+
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
23+
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "30"))
24+
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))
25+
experimentDetails.ChaosLib = types.Getenv("LIB", "litmus")
2526
experimentDetails.ChaosUID = clientTypes.UID(types.Getenv("CHAOS_UID", ""))
2627
experimentDetails.InstanceID = types.Getenv("INSTANCE_ID", "")
2728
experimentDetails.ChaosPodName = types.Getenv("POD_NAME", "")
2829
experimentDetails.Delay, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_DELAY", "2"))
2930
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
30-
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
3131
experimentDetails.ScaleSet = types.Getenv("SCALE_SET", "disable")
3232
experimentDetails.ResourceGroup = types.Getenv("RESOURCE_GROUP", "")
3333
experimentDetails.VirtualDiskNames = types.Getenv("VIRTUAL_DISK_NAMES", "")
34-
experimentDetails.SubscriptionID = types.Getenv("SUBSCRIPTION_ID", "")
3534
experimentDetails.Sequence = types.Getenv("SEQUENCE", "parallel")
3635
}

pkg/azure/disk-loss/types/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ type ExperimentDetails struct {
1111
ChaosDuration int
1212
ChaosInterval int
1313
RampTime int
14-
ChaosLib string
1514
AppNS string
1615
AppLabel string
1716
AppKind string
1817
AuxiliaryAppInfo string
18+
ChaosLib string
1919
ChaosUID clientTypes.UID
2020
InstanceID string
2121
ChaosNamespace string
2222
ChaosPodName string
23+
TargetContainer string
2324
Timeout int
2425
Delay int
2526
LIBImagePullPolicy string
26-
TargetContainer string
2727
ScaleSet string
2828
ResourceGroup string
2929
SubscriptionID string

pkg/azure/instance-stop/environment/environment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
1818
experimentDetails.AppLabel = types.Getenv("APP_LABEL", "")
1919
experimentDetails.AppKind = types.Getenv("APP_KIND", "")
2020
experimentDetails.AuxiliaryAppInfo = types.Getenv("AUXILIARY_APPINFO", "")
21+
experimentDetails.TargetContainer = types.Getenv("TARGET_CONTAINER", "")
2122
experimentDetails.ChaosDuration, _ = strconv.Atoi(types.Getenv("TOTAL_CHAOS_DURATION", "30"))
2223
experimentDetails.ChaosInterval, _ = strconv.Atoi(types.Getenv("CHAOS_INTERVAL", "30"))
2324
experimentDetails.RampTime, _ = strconv.Atoi(types.Getenv("RAMP_TIME", "0"))

pkg/azure/instance-stop/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ExperimentDetails struct {
2020
InstanceID string
2121
ChaosNamespace string
2222
ChaosPodName string
23+
TargetContainer string
2324
Timeout int
2425
Delay int
2526
AzureInstanceName string

pkg/cloud/azure/disk/disk-status.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/Azure/go-autorest/autorest/azure/auth"
1111
"github.com/litmuschaos/litmus-go/pkg/cloud/azure/common"
1212

13-
experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/disk-loss/types"
1413
"github.com/pkg/errors"
1514
)
1615

@@ -80,10 +79,10 @@ func GetDiskStatus(subscriptionID, resourceGroup, diskName string) (compute.Disk
8079
}
8180

8281
// CheckVirtualDiskWithInstance checks whether the given list of disk are attached to the provided VM instance
83-
func CheckVirtualDiskWithInstance(experimentsDetails experimentTypes.ExperimentDetails) error {
82+
func CheckVirtualDiskWithInstance(subscriptionID, virtualDiskNames, resourceGroup string) error {
8483

8584
// Setup and authorize disk client
86-
diskClient := compute.NewDisksClient(experimentsDetails.SubscriptionID)
85+
diskClient := compute.NewDisksClient(subscriptionID)
8786
authorizer, err := auth.NewAuthorizerFromFile(azure.PublicCloud.ResourceManagerEndpoint)
8887

8988
if err != nil {
@@ -92,10 +91,10 @@ func CheckVirtualDiskWithInstance(experimentsDetails experimentTypes.ExperimentD
9291
diskClient.Authorizer = authorizer
9392

9493
// Creating an array of the name of the attached disks
95-
diskNameList := strings.Split(experimentsDetails.VirtualDiskNames, ",")
94+
diskNameList := strings.Split(virtualDiskNames, ",")
9695

9796
for _, diskName := range diskNameList {
98-
disk, err := diskClient.Get(context.Background(), experimentsDetails.ResourceGroup, diskName)
97+
disk, err := diskClient.Get(context.Background(), resourceGroup, diskName)
9998
if err != nil {
10099
return errors.Errorf("failed to get disk: %v, err: %v", diskName, err)
101100
}

0 commit comments

Comments
 (0)