Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial powershell test for windows nodes #5635

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion e2e/scenario_win_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package e2e

import (
"context"
"fmt"
"strings"
"testing"

"github.com/Azure/agentbaker/e2e/config"
Expand All @@ -16,6 +19,9 @@ func Test_Windows2019Containerd(t *testing.T) {
VHD: config.VHDWindows2019Containerd,
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {},
BootstrapConfigMutator: func(configuration *datamodel.NodeBootstrappingConfiguration) {},
Validator: func(ctx context.Context, s *Scenario) {
ValidateFileHasContentWindows(ctx, s, "c:/k/kubelet", "--rotate-server-certificates=true")
},
},
})
}
Expand All @@ -42,7 +48,6 @@ func Test_Windows2022ContainerdGen2(t *testing.T) {
VHD: config.VHDWindows2022ContainerdGen2,
VMConfigMutator: func(vmss *armcompute.VirtualMachineScaleSet) {},
BootstrapConfigMutator: func(configuration *datamodel.NodeBootstrappingConfiguration) {

},
},
})
Expand Down Expand Up @@ -75,3 +80,31 @@ func Test_Windows23H2Gen2(t *testing.T) {
},
})
}

func makeExecutablePowershellCommand(steps []string) string {
stepsWithEchos := make([]string, len(steps)*2)

for i, s := range steps {
stepsWithEchos[i*2] = fmt.Sprintf("echo '%s'", cleanse(s))
stepsWithEchos[i*2+1] = s
}

// quote " quotes and $ vars
joinedCommand := strings.Join(stepsWithEchos, " && ")
quotedCommand := strings.Replace(joinedCommand, "'", "'\"'\"'", -1)

command := fmt.Sprintf("pwsh -C '%s'", quotedCommand)

return command
}

func ValidateFileHasContentWindows(ctx context.Context, s *Scenario, fileName string, contents string) {
steps := []string{
fmt.Sprintf("dir %[1]s", fileName),
fmt.Sprintf("Get-Content %[1]s", fileName),
fmt.Sprintf("if (Select-String -Path .%s -Pattern \"%s\" -SimpleMatch -Quiet) { return 1 } else { return 0 }", fileName, contents),
}

command := makeExecutablePowershellCommand(steps)
execOnVMForScenarioValidateExitCode(ctx, s, command, 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong")
}
8 changes: 4 additions & 4 deletions e2e/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, c
fmt.Sprintf("(sudo cat %[1]s | grep -q -F -e %[2]q)", fileName, contents),
}

command := makeExecutableCommand(steps)
command := makeExecutableBashCommand(steps)
execOnVMForScenarioValidateExitCode(ctx, s, command, 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong")
}

Expand All @@ -77,7 +77,7 @@ func ValidateFileExcludesContent(ctx context.Context, s *Scenario, fileName stri
fmt.Sprintf("sudo cat %[1]s", fileName),
fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents),
}
command := makeExecutableCommand(steps)
command := makeExecutableBashCommand(steps)
execOnVMForScenarioValidateExitCode(ctx, s, command, 0, "could not validate file excludes contents - might mean file does have contents, might mean something went wrong")
}

Expand All @@ -86,7 +86,7 @@ func cleanse(str string) string {
return strings.Replace(str, "'", "", -1)
}

func makeExecutableCommand(steps []string) string {
func makeExecutableBashCommand(steps []string) string {
stepsWithEchos := make([]string, len(steps)*2)

for i, s := range steps {
Expand Down Expand Up @@ -131,7 +131,7 @@ func ServiceCanRestartValidator(ctx context.Context, s *Scenario, serviceName st
"if [[ \"$INITIAL_PID\" == \"$POST_PID\" ]]; then echo PID did not change after restart, failing validator. ; exit 1; fi",
}

command := makeExecutableCommand(steps)
command := makeExecutableBashCommand(steps)
execOnVMForScenarioValidateExitCode(ctx, s, command, 0, "command to restart service failed")
}

Expand Down
Loading