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

draft: add file and test for file #5995

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .pipelines/.vsts-vhd-builder-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,4 +1334,5 @@ stages:
- template: ./templates/e2e-template.yaml
parameters:
name: All Linux
IgnoreScenariosWithMissingVhd: true

2 changes: 2 additions & 0 deletions .pipelines/.vsts-vhd-builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ stages:
VHD_BUILD_ID: $(Build.BuildId)
jobs:
- template: ./templates/e2e-template.yaml
parameters:
IgnoreScenariosWithMissingVhd: true

1 change: 1 addition & 0 deletions .pipelines/e2e-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ jobs:
- template: ./templates/e2e-template.yaml
parameters:
name: Windows Tests
IgnoreScenariosWithMissingVhd: false
1 change: 1 addition & 0 deletions .pipelines/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ jobs:
- template: ./templates/e2e-template.yaml
parameters:
name: Linux Tests
IgnoreScenariosWithMissingVhd: false
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ stages:
- template: ./e2e-template.yaml
parameters:
name: For image ${{ parameters.imageName }}
IgnoreScenariosWithMissingVhd: false

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ steps:

make -f packer.mk test-building-vhd
displayName: Run VHD cache test
enabled: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder: re-enable this step.

env:
SUBSCRIPTION_ID: $(AZURE_BUILD_SUBSCRIPTION_ID)
AZURE_RESOURCE_GROUP_NAME: $(AZURE_BUILD_RESOURCE_GROUP_NAME)
Expand Down
19 changes: 16 additions & 3 deletions .pipelines/templates/e2e-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ parameters:
type: string
displayName: Additional name for the pipeline step
default: ""
- name: IgnoreScenariosWithMissingVhd
type: boolean
displayName: Ignore tests where the VHD can't be loaded

jobs:
- job: e2e
Expand All @@ -14,6 +17,13 @@ jobs:
timeoutInMinutes: 90
displayName: Run AgentBaker E2E ${{parameters.name}}
steps:
- checkout: self
# s is the default path for repositories - if we don't set this when using multiple repsositories, then it is the repo name
# "s/AgentBaker", but most of the pipeline variables still refer to "s" and many of the scripts below fail.
path: s
fetchTags: false
fetchDepth: 1

- bash: |
set -ex
az login --identity --username $(E2E_AGENT_IDENTITY_ID)
Expand All @@ -28,16 +38,18 @@ jobs:
echo "##vso[task.setvariable variable=LOGGING_DIR]$LOGGING_DIR"
displayName: Set logging directory
- bash: |
set -ex
set -e
export PATH="/usr/local/go/bin:$PATH"
go version

echo "VHD_BUILD_ID=$VHD_BUILD_ID"

echo "IGNORE_SCENARIOS_WITH_MISSING_VHD: $IGNORE_SCENARIOS_WITH_MISSING_VHD"
echo "LOGGING_DIR: $LOGGING_DIR"

if [ -n "${VHD_BUILD_ID}" ]; then
echo "VHD_BUILD_ID is specified (${VHD_BUILD_ID}). Running tests using VHDs from that build"
export SIG_VERSION_TAG_NAME=buildId
export SIG_VERSION_TAG_VALUE=$VHD_BUILD_ID
export IGNORE_SCENARIOS_WITH_MISSING_VHD=true
else
echo "VHD_BUILD_ID is not specified. Running tests with default SIG version tag selectors."
fi
Expand All @@ -50,6 +62,7 @@ jobs:
env:
VHD_BUILD_ID: $(VHD_BUILD_ID)
LOGGING_DIR: $(LOGGING_DIR)
IGNORE_SCENARIOS_WITH_MISSING_VHD: ${{parameters.IgnoreScenariosWithMissingVhd}}
# Without this step next step may fail on successful run
- bash: |
set -ex
Expand Down
14 changes: 3 additions & 11 deletions e2e/config/vhd.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ var (
OS: "windows",
Arch: "amd64",
Distro: datamodel.AKSWindows2019Containerd,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -153,7 +152,6 @@ var (
OS: "windows",
Arch: "amd64",
Distro: datamodel.AKSWindows2022Containerd,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -162,7 +160,6 @@ var (
OS: OSWindows,
Arch: "amd64",
Distro: datamodel.AKSWindows2022ContainerdGen2,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -171,7 +168,6 @@ var (
OS: OSWindows,
Arch: "amd64",
Distro: datamodel.AKSWindows23H2,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -180,7 +176,6 @@ var (
OS: OSWindows,
Arch: "amd64",
Distro: datamodel.AKSWindows23H2Gen2,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -189,7 +184,6 @@ var (
OS: OSWindows,
Arch: "amd64",
Distro: datamodel.AKSWindows2025,
Latest: true,
Gallery: windowsGallery,
}

Expand All @@ -198,7 +192,6 @@ var (
OS: OSWindows,
Arch: "amd64",
Distro: datamodel.AKSWindows2025Gen2,
Latest: true,
Gallery: windowsGallery,
}
)
Expand All @@ -212,7 +205,6 @@ type Image struct {
OS OS
Version string
Gallery *Gallery
Latest bool // a hack to get the latest version of the image for windows, currently windows images are not tagged

vhd VHDResourceID
vhdOnce sync.Once
Expand All @@ -227,16 +219,16 @@ func (i *Image) String() string {
func (i *Image) VHDResourceID(ctx context.Context, t *testing.T) (VHDResourceID, error) {
i.vhdOnce.Do(func() {
switch {
case i.Latest:
i.vhd, i.vhdErr = Azure.LatestSIGImageVersionByTag(ctx, i, "", "")
case i.Version != "":
i.vhd, i.vhdErr = Azure.EnsureSIGImageVersion(ctx, i)
t.Logf("got version vid %s: %s", i.Version, i.vhd)
default:
i.vhd, i.vhdErr = Azure.LatestSIGImageVersionByTag(ctx, i, Config.SIGVersionTagName, Config.SIGVersionTagValue)
t.Logf("got version by tag %s=%s: %s", Config.SIGVersionTagName, Config.SIGVersionTagValue, i.vhd)
}
if i.vhdErr != nil {
i.vhdErr = fmt.Errorf("img: %s, tag %s=%s, err %w", i.Name, Config.SIGVersionTagName, Config.SIGVersionTagValue, i.vhdErr)
t.Logf("failed to find the latest image version for %s", i.vhdErr)
t.Logf("failed to find the image sub=%s rg=%s gallary=%s version for with id %s", i.Gallery.SubscriptionID, i.Gallery.ResourceGroupName, i.Gallery.Name, i.vhdErr)
}
})
return i.vhd, i.vhdErr
Expand Down
1 change: 1 addition & 0 deletions e2e/scenario_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func RunScenario(t *testing.T, s *Scenario) {
s.T = t
t.Parallel()
ctx := newTestCtx(t)

maybeSkipScenario(ctx, t, s)
cluster, err := s.Config.Cluster(ctx, s.T)
require.NoError(s.T, err)
Expand Down
5 changes: 5 additions & 0 deletions e2e/scenario_win_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Test_Windows2019Containerd(t *testing.T) {
ValidateFileHasContent(ctx, s, "/k/kubeletstart.ps1", "--container-runtime=remote")
ValidateWindowsProcessHasCliArguments(ctx, s, "kubelet.exe", []string{"--rotate-certificates=true", "--client-ca-file=c:\\k\\ca.crt"})
ValidateCiliumIsNotRunningWindows(ctx, s)
ValidateFileHasContent(ctx, s, "/k/test.txt", "this is a test file")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are currently here to check the e2e tests are being run with the right VHD version. They will be removed before I merge the PR.

},
},
})
Expand All @@ -48,6 +49,7 @@ func Test_Windows2022Containerd(t *testing.T) {
ValidateFileHasContent(ctx, s, "/k/kubeletstart.ps1", "--container-runtime=remote")
ValidateWindowsProcessHasCliArguments(ctx, s, "kubelet.exe", []string{"--rotate-certificates=true", "--client-ca-file=c:\\k\\ca.crt"})
ValidateCiliumIsNotRunningWindows(ctx, s)
ValidateFileHasContent(ctx, s, "/k/test.txt", "this is a test file")
},
},
})
Expand All @@ -68,6 +70,7 @@ func Test_Windows2022ContainerdGen2(t *testing.T) {
ValidateFileHasContent(ctx, s, "/k/kubeletstart.ps1", "--container-runtime=remote")
ValidateWindowsProcessHasCliArguments(ctx, s, "kubelet.exe", []string{"--rotate-certificates=true", "--client-ca-file=c:\\k\\ca.crt"})
ValidateCiliumIsNotRunningWindows(ctx, s)
ValidateFileHasContent(ctx, s, "/k/test.txt", "this is a test file")
},
},
})
Expand All @@ -88,6 +91,7 @@ func Test_Windows23H2(t *testing.T) {
ValidateFileHasContent(ctx, s, "/k/kubeletstart.ps1", "--container-runtime=remote")
ValidateWindowsProcessHasCliArguments(ctx, s, "kubelet.exe", []string{"--rotate-certificates=true", "--client-ca-file=c:\\k\\ca.crt"})
ValidateCiliumIsNotRunningWindows(ctx, s)
ValidateFileHasContent(ctx, s, "/k/test.txt", "this is a test file")
},
},
})
Expand All @@ -108,6 +112,7 @@ func Test_Windows23H2Gen2(t *testing.T) {
ValidateFileHasContent(ctx, s, "/k/kubeletstart.ps1", "--container-runtime=remote")
ValidateWindowsProcessHasCliArguments(ctx, s, "kubelet.exe", []string{"--rotate-certificates=true", "--client-ca-file=c:\\k\\ca.crt"})
ValidateCiliumIsNotRunningWindows(ctx, s)
ValidateFileHasContent(ctx, s, "/k/test.txt", "this is a test file")
},
},
})
Expand Down
2 changes: 2 additions & 0 deletions e2e/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func (s *Scenario) PrepareVMSSModel(ctx context.Context, t *testing.T, vmss *arm
require.NotNil(t, vmss, "input VirtualMachineScaleSet")
require.NotNil(t, vmss.Properties, "input VirtualMachineScaleSet.Properties")

s.T.Logf("got vhd resource id %s", resourceID)

if s.VMConfigMutator != nil {
s.VMConfigMutator(vmss)
}
Expand Down
30 changes: 22 additions & 8 deletions e2e/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func ValidateNonEmptyDirectory(ctx context.Context, s *Scenario, dirName string)
func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, contents string) {
if s.VHD.OS == config.OSWindows {
steps := []string{
"$ErrorActionPreference = \"Stop\"",
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),
fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName),
fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 0 } else { exit 1 }", fileName, contents),
}

execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong")
Expand All @@ -102,14 +104,26 @@ func ValidateFileHasContent(ctx context.Context, s *Scenario, fileName string, c
func ValidateFileExcludesContent(ctx context.Context, s *Scenario, fileName string, contents string) {
require.NotEqual(s.T, "", contents, "Test setup failure: Can't validate that a file excludes an empty string. Filename: %s", fileName)

steps := []string{
"set -ex",
fmt.Sprintf("test -f %[1]s || exit 0", fileName),
fmt.Sprintf("ls -la %[1]s", fileName),
fmt.Sprintf("sudo cat %[1]s", fileName),
fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents),
if s.VHD.OS == config.OSWindows {
steps := []string{
"$ErrorActionPreference = \"Stop\"",
fmt.Sprintf("dir %[1]s", fileName),
fmt.Sprintf("Get-Content %[1]s", fileName),
fmt.Sprintf("if ( -not ( Test-Path -Path %s ) ) { exit 2 }", fileName),
fmt.Sprintf("if (Select-String -Path %s -Pattern \"%s\" -SimpleMatch -Quiet) { exit 1 } else { exit 0 }", fileName, contents),
}

execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file has contents - might mean file does not have contents, might mean something went wrong")
} else {
steps := []string{
"set -ex",
fmt.Sprintf("test -f %[1]s || exit 0", fileName),
fmt.Sprintf("ls -la %[1]s", fileName),
fmt.Sprintf("sudo cat %[1]s", fileName),
fmt.Sprintf("(sudo cat %[1]s | grep -q -v -F -e %[2]q)", fileName, contents),
}
execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file excludes contents - might mean file does have contents, might mean something went wrong")
}
execScriptOnVMForScenarioValidateExitCode(ctx, s, strings.Join(steps, "\n"), 0, "could not validate file excludes contents - might mean file does have contents, might mean something went wrong")
}

func ServiceCanRestartValidator(ctx context.Context, s *Scenario, serviceName string, restartTimeoutInSeconds int) {
Expand Down
10 changes: 10 additions & 0 deletions e2e/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ func createVMSS(ctx context.Context, s *Scenario) *armcompute.VirtualMachineScal
customData = nodeBootstrapping.CustomData
}

if nodeBootstrapping != nil && nodeBootstrapping.SigImageConfig != nil {
s.T.Logf("vhd sub id %s", nodeBootstrapping.SigImageConfig.SubscriptionID)
s.T.Logf("vhd rgr id %s", nodeBootstrapping.SigImageConfig.ResourceGroup)
s.T.Logf("vhd galler %s", nodeBootstrapping.SigImageConfig.Gallery)
s.T.Logf("vhd versio %s", nodeBootstrapping.SigImageConfig.Version)
s.T.Logf("vhd defini %s", nodeBootstrapping.SigImageConfig.Definition)
} else {
s.T.Logf("nbc or sigimageconfig is nil")
}

model := getBaseVMSSModel(s, customData, cse)
if s.Tags.NonAnonymousACR {
// add acr pull identity
Expand Down
3 changes: 3 additions & 0 deletions vhdbuilder/packer/windows/configure-windows-vhd.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ try
Clear-TempFolder
Log-VHDFreeSize
Test-AzureExtensions

Write-Output "creating test.txt file"
Write-Output "this is a test file" > "c:\k\test.txt"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to Tim: I have to remove this once I've tested the e2e tests are running against the right VHDs.

}
default {
Write-Log "Unable to determine provisiong phase... exiting"
Expand Down
7 changes: 6 additions & 1 deletion vhdbuilder/packer/windows/windows-vhd-builder-sig.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@
"SkipASMAzSecPack": "True",
"SkipASMAV": "True",
"SkipCIExtensionAudit": "True",
"SkipCIEmergency": "True"
"SkipCIEmergency": "True",
"buildDefinitionName": "{{user `build_definition_name`}}",
"buildNumber": "{{user `build_number`}}",
"buildId": "{{user `build_id`}}",
"image_sku": "{{user `img_sku`}}",
"branch": "{{user `branch`}}"
},
"virtual_network_resource_group_name": "{{user `vnet_resource_group_name`}}",
"virtual_network_name": "{{user `vnet_name`}}",
Expand Down
Loading