Skip to content

Commit dd65f6f

Browse files
committed
Fix some reference issues
1 parent a95fc81 commit dd65f6f

File tree

5 files changed

+69
-49
lines changed

5 files changed

+69
-49
lines changed

chaoslib/litmus/azure-instance-runscript/azure-instance-runscript.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"syscall"
1010
"time"
1111

12+
instanceRunScript "pkg/azure/instance-runscript"
13+
1214
experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/instance-runscript/types"
1315
"github.com/litmuschaos/litmus-go/pkg/cerrors"
1416
"github.com/litmuschaos/litmus-go/pkg/clients"
15-
azureCommon "github.com/litmuschaos/litmus-go/pkg/cloud/azure/common"
16-
azureStatus "github.com/litmuschaos/litmus-go/pkg/cloud/azure/instance"
1717
"github.com/litmuschaos/litmus-go/pkg/events"
1818
"github.com/litmuschaos/litmus-go/pkg/log"
1919
"github.com/litmuschaos/litmus-go/pkg/probe"
@@ -109,9 +109,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
109109
//Running start Script the Azure instance
110110
log.Infof("[Chaos]:Running Script the Azure instance: %v", vmName)
111111
if experimentsDetails.ScaleSet == "enable" {
112-
return notImplementedError("scale set instance run script not implemented")
112+
// Yet to implement
113113
} else {
114-
if err := azureStatus.AzureInstanceRunScript(experimentsDetails.Timeout, experimentsDetails.Delay, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup, vmName, experimentDetails.PowershellChaosStartBase64OrPsFilePath, experimentDetails.IsBase64, experimentDetails.PowershellChaosStartParams); err != nil {
114+
if err := instanceRunScript.AzureInstanceRunScript(experimentsDetails.Timeout, experimentsDetails.Delay, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup, vmName, experimentDetails.PowershellChaosStartBase64OrPsFilePath, experimentDetails.IsBase64, experimentDetails.PowershellChaosStartParamNames, experimentDetails.PowershellChaosStartParamValues); err != nil {
115115
return stacktrace.Propagate(err, "unable to run script in the Azure instance")
116116
}
117117
}
@@ -131,9 +131,9 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
131131
// Running the end PS Script in the Azure instance
132132
log.Info("[Chaos]: Starting back the Azure instance")
133133
if experimentsDetails.ScaleSet == "enable" {
134-
return notImplementedError("scale set instance run script not implemented")
134+
//scale set instance run script not implemented
135135
} else {
136-
if err := azureStatus.AzureInstanceRunScript(experimentsDetails.Timeout, experimentsDetails.Delay, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup, vmName, experimentDetails.PowershellChaosEndBase64OrPsFilePath, experimentDetails.IsBase64, experimentDetails.PowershellChaosEndParams); err != nil {
136+
if err := instanceRunScript.AzureInstanceRunScript(experimentsDetails.Timeout, experimentsDetails.Delay, experimentsDetails.SubscriptionID, experimentsDetails.ResourceGroup, vmName, experimentDetails.PowershellChaosEndBase64OrPsFilePath, experimentDetails.IsBase64, experimentDetails.PowershellChaosEndParamNames, experimentDetails.PowershellChaosEndParamValues); err != nil {
137137
return stacktrace.Propagate(err, "unable to run the script in the Azure instance")
138138
}
139139
}
@@ -148,12 +148,12 @@ func injectChaosInSerialMode(ctx context.Context, experimentsDetails *experiment
148148
func injectChaosInParallelMode(ctx context.Context, experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string, clients clients.ClientSets, resultDetails *types.ResultDetails, eventsDetails *types.EventDetails, chaosDetails *types.ChaosDetails) error {
149149
ctx, span := otel.Tracer(telemetry.TracerName).Start(ctx, "InjectAzureInstanceRunScriptFaultInParallelMode")
150150
defer span.End()
151-
return notImplementedError("scale set instance run script not implemented so parallel mode run script also not implemented.")
151+
//scale set instance run script not implemented so parallel mode run script also not implemented
152152
}
153153

154154
// watching for the abort signal and revert the chaos
155155
func abortWatcher(experimentsDetails *experimentTypes.ExperimentDetails, instanceNameList []string) {
156156
<-abort
157157

158-
return notImplementedError("Abort run script not implemented")
158+
//Abort run script not implemented
159159
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,24 @@ spec:
5555
- name: SCALE_SET
5656
value: 'disable'
5757

58-
# provide the Powershell params for Chaos Start powershell script
59-
- name: PowershellChaosStartParams
58+
# provide the Powershell paramNames for Chaos Start powershell script
59+
- name: PowershellChaosStartParamNames
60+
value: ''
61+
62+
# provide the Powershell paramValues for Chaos Start powershell script
63+
- name: PowershellChaosStartParamValues
6064
value: ''
6165

6266
# provide the Powershell script file path or script itself as a Base64 string for Chaos Start powershell script
6367
- name: PowershellChaosStartBase64OrPsFilePath
6468
value: ''
6569

66-
# provide the Powershell params for Chaos End powershell script
67-
- name: PowershellChaosEndParams
70+
# provide the Powershell paramNames for Chaos End powershell script
71+
- name: PowershellChaosEndParamNames
72+
value: ''
73+
74+
# provide the Powershell paramValues for Chaos End powershell script
75+
- name: PowershellChaosEndParamValues
6876
value: ''
6977

7078
# provide the Powershell script file path or script itself as a Base64 string for Chaos End powershell script

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66

77
clientTypes "k8s.io/apimachinery/pkg/types"
88

9-
experimentTypes "github.com/litmuschaos/litmus-go/pkg/azure/instance-runscript/types"
9+
experimentTypes "pkg/azure/instance-runscript/types"
10+
1011
"github.com/litmuschaos/litmus-go/pkg/types"
1112
)
1213

@@ -25,9 +26,12 @@ func GetENV(experimentDetails *experimentTypes.ExperimentDetails) {
2526
experimentDetails.Timeout, _ = strconv.Atoi(types.Getenv("STATUS_CHECK_TIMEOUT", "180"))
2627
experimentDetails.AzureInstanceNames = strings.TrimSpace(types.Getenv("AZURE_INSTANCE_NAMES", ""))
2728
experimentDetails.ResourceGroup = types.Getenv("RESOURCE_GROUP", "")
28-
experimentDetails.IsBase64 = strconv.ParseBool(isBase64Str)
29-
experimentDetails.PowershellChaosStartParams = strings.Split(types.Getenv("POWERSHELL_CHAOS_START_PARAMS", ""))
30-
experimentDetails.PowershellChaosEndParams = strings.Split(types.Getenv("POWERSHELL_CHAOS_END_PARAMS", ""))
29+
isBase64Str := types.Getenv("IS_BASE64", "false")
30+
experimentDetails.IsBase64, _ = strconv.ParseBool(isBase64Str)
31+
experimentDetails.PowershellChaosStartParamNames = strings.Split(types.Getenv("POWERSHELL_CHAOS_START_PARAMNAMES", ""))
32+
experimentDetails.PowershellChaosEndParamNames = strings.Split(types.Getenv("POWERSHELL_CHAOS_END_PARAMNAMES", ""))
33+
experimentDetails.PowershellChaosStartParamValues = strings.Split(types.Getenv("POWERSHELL_CHAOS_START_PARAMVALUES", ""))
34+
experimentDetails.PowershellChaosEndParamValues = strings.Split(types.Getenv("POWERSHELL_CHAOS_END_PARAMVALUES", ""))
3135
experimentDetails.PowershellChaosStartBase64OrPsFilePath = types.Getenv("POWERSHELL_CHAOS_START_SCRIPT_BASE64_STR_OR_PS_FILE_PATH", "")
3236
experimentDetails.PowershellChaosEndBase64OrPsFilePath = types.Getenv("POWERSHELL_CHAOS_END_SCRIPT_BASE64_STR_OR_PS_FILE_PATH", "")
3337
experimentDetails.ScaleSet = types.Getenv("SCALE_SET", "disable")

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ import (
66

77
// ExperimentDetails is for collecting all the experiment-related details
88
type ExperimentDetails struct {
9-
ExperimentName string
10-
EngineName string
11-
RampTime int
12-
ChaosDuration int
13-
ChaosInterval int
14-
ChaosUID clientTypes.UID
15-
InstanceID string
16-
ChaosNamespace string
17-
ChaosPodName string
18-
Timeout int
19-
Delay int
20-
AzureInstanceNames string
21-
ResourceGroup string
22-
PowershellChaosStartParams []string
23-
PowershellChaosEndParams []string
9+
ExperimentName string
10+
EngineName string
11+
RampTime int
12+
ChaosDuration int
13+
ChaosInterval int
14+
ChaosUID clientTypes.UID
15+
InstanceID string
16+
ChaosNamespace string
17+
ChaosPodName string
18+
Timeout int
19+
Delay int
20+
AzureInstanceNames string
21+
ResourceGroup string
22+
PowershellChaosStartParamNames []string
23+
PowershellChaosStartParamValues []string
24+
PowershellChaosEndParamNames []string
25+
PowershellChaosEndParamValues []string
2426
PowershellChaosStartBase64OrPsFilePath string
25-
PowershellChaosEndBase64OrPsFilePath string
26-
IsBase64 bool
27-
SubscriptionID string
28-
ScaleSet string
29-
Sequence string
27+
PowershellChaosEndBase64OrPsFilePath string
28+
IsBase64 bool
29+
SubscriptionID string
30+
ScaleSet string
31+
Sequence string
3032
}

pkg/cloud/azure/instance/instance-operations.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package azure
22

33
import (
44
"context"
5+
"encoding/base64"
56
"fmt"
67
"time"
7-
"os"
8-
"strings"
9-
"encoding/base64"
108

119
"github.com/Azure/azure-sdk-for-go/profiles/latest/compute/mgmt/compute"
1210
"github.com/Azure/go-autorest/autorest/azure"
@@ -196,11 +194,11 @@ func WaitForAzureComputeUp(timeout, delay int, scaleSet, subscriptionID, resourc
196194
}
197195
}
198196
return nil
199-
})
197+
})
200198
}
201199

202200
// AzureInstanceRunPowershell runs a PowerShell script on the target instance
203-
func AzureInstanceRunPowershell(subscriptionID, resourceGroup, azureInstanceName, scriptContent string, isBase64 bool, scriptParams []string) error {
201+
func AzureInstanceRunPowershell(subscriptionID, resourceGroup, azureInstanceName, scriptContent string, isBase64 bool, scriptParamNames []string, scriptParamValues []string) error {
204202
vmClient := compute.NewVirtualMachinesClient(subscriptionID)
205203

206204
authorizer, err := auth.NewAuthorizerFromFile(azure.PublicCloud.ResourceManagerEndpoint)
@@ -229,15 +227,23 @@ func AzureInstanceRunPowershell(subscriptionID, resourceGroup, azureInstanceName
229227
script = scriptContent
230228
}
231229

230+
scriptId := "RunPowerShellScript"
231+
params := make([]compute.RunCommandInputParameter, len(scriptParamNames))
232+
for i, name := range scriptParamNames {
233+
value := ""
234+
if i < len(scriptParamValues) {
235+
value = scriptParamValues[i]
236+
}
237+
params[i] = compute.RunCommandInputParameter{
238+
Name: &name,
239+
Value: &value,
240+
}
241+
}
242+
232243
runCommandParameters := compute.RunCommandInput{
233-
CommandID: "RunPowerShellScript",
234-
Script: []string{script},
235-
Parameters: &[]compute.RunCommandInputParameter{
236-
{
237-
Name: "params",
238-
Value: strings.Join(scriptParams, " "),
239-
},
240-
},
244+
CommandID: &scriptId,
245+
Script: &[]string{script},
246+
Parameters: &params,
241247
}
242248

243249
log.Info("[Info]: Running PowerShell script on the instance")

0 commit comments

Comments
 (0)