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

chore: replace endpoint in Mooncake in the test #5924

Open
wants to merge 3 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
4 changes: 2 additions & 2 deletions vhdbuilder/packer/test/linux-vhd-content-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ testPackagesInstalled() {
echo $test "[INFO] File ${downloadedPackage} exists and has the correct size ${fileSizeDownloaded} bytes"
# Validate whether package exists in Azure China cloud
if [[ $downloadURL == https://acs-mirror.azureedge.net/* ]]; then
mcURL="${downloadURL/https:\/\/acs-mirror.azureedge.net/https:\/\/kubernetesartifacts.blob.core.chinacloudapi.cn}"
mcURL="${downloadURL/https:\/\/acs-mirror.azureedge.net/https:\/\/mirror.azk8s.cn}"
echo "Validating: $mcURL"
isExist=$(curl -sLI "$mcURL" | grep -i "404 The specified blob does not exist." | awk '{print $2}')
if [[ "$isExist" == "404" ]]; then
err "$mcURL is invalid"
continue
fi

fileSizeInMC=$(curl -sLI $mcURL | grep -i Content-Length | tail -n1 | awk '{print $2}' | tr -d '\r')
fileSizeInMC=$(wget -S $mcURL --start-pos=500G 2>&1 | grep -i Content-Length | tail -n1 | awk '{print $2}' | tr -d '\r')
if [[ "$fileSizeInMC" != "$fileSizeDownloaded" ]]; then
err "$mcURL is valid but the file size is different. Expected file size: ${fileSizeDownloaded} - downloaded file size: ${fileSizeInMC}"
continue
Expand Down
14 changes: 11 additions & 3 deletions vhdbuilder/packer/test/windows-files-check.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,17 @@ function Test-CompareSingleDir {
}

if ($URL.StartsWith("https://acs-mirror.azureedge.net/")) {
$mcURL = $URL.replace("https://acs-mirror.azureedge.net/", "https://kubernetesartifacts.blob.core.chinacloudapi.cn/")

$mooncakeFileSize = (Invoke-WebRequest $mcURL -UseBasicParsing -Method Head).Headers.'Content-Length'
$mcURL = $URL.replace("https://acs-mirror.azureedge.net/", "https://mirror.azk8s.cn/")

Write-Output "Getting the size of the file: $mcURL"
$webRequest = [System.Net.HttpWebRequest]::Create($mcURL)
# Set the 'Range' header using the AddRange method
$webRequest.AddRange(0, 1023)
Retry-Command -ScriptBlock {
# Get the response
$global:response = $webRequest.GetResponse()
} -ErrorMessage "Failed to get the size ofthe file: $mcURL"
$mooncakeFileSize = $global:response.Headers["Content-Range"] -split "/" | Select-Object -Last 1

if ($globalFileSize -ne $mooncakeFileSize) {
$MisMatchFiles[$URL]=$mcURL
Expand Down
58 changes: 56 additions & 2 deletions vhdbuilder/packer/test/windows-vhd-content-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,50 @@ function DownloadFileWithRetry
}
}

function Retry-Command {
[CmdletBinding()]
Param(
[Parameter(Position=0, Mandatory=$true)]
[scriptblock]$ScriptBlock,

[Parameter(Position=1, Mandatory=$true)]
[string]$ErrorMessage,

[Parameter(Position=2, Mandatory=$false)]
[int]$Maximum = 5,

[Parameter(Position=3, Mandatory=$false)]
[int]$Delay = 10
)

Begin {
$cnt = 0
}

Process {
do {
$cnt++
try {
$ScriptBlock.Invoke()
if ($LASTEXITCODE) {
throw "Retry $cnt : $ErrorMessage"
}
return
} catch {
Write-ErrorWithTimestamp $_.Exception.InnerException.Message -ErrorAction Continue
if ($_.Exception.InnerException.Message.Contains("There is not enough space on the disk. (0x70)")) {
throw "Exit retry since there is not enough space on the disk"
}
Start-Sleep $Delay
}
} while ($cnt -lt $Maximum)

# Throw an error after $Maximum unsuccessful invocations. Doesn't need
# a condition, since the function returns upon successful invocation.
throw 'All retries failed. $ErrorMessage'
}
}

function Test-FilesToCacheOnVHD
{
$invalidFiles = @()
Expand Down Expand Up @@ -167,12 +211,22 @@ function Test-FilesToCacheOnVHD

if ( $URL.StartsWith("https://acs-mirror.azureedge.net/"))
{
$mcURL = $URL.replace("https://acs-mirror.azureedge.net/", "https://kubernetesartifacts.blob.core.chinacloudapi.cn/")
$mcURL = $URL.replace("https://acs-mirror.azureedge.net/", "https://mirror.azk8s.cn/")
try
{
# It's too slow to download the file from the China Cloud. So we only compare the file size.
$localFileSize = (Get-Item $dest).length
$remoteFileSize = (Invoke-WebRequest $mcURL -UseBasicParsing -Method Head).Headers.'Content-Length'

Write-Output "Getting the size of the file: $mcURL"
$webRequest = [System.Net.HttpWebRequest]::Create($mcURL)
# Set the 'Range' header using the AddRange method
$webRequest.AddRange(0, 1023)
Retry-Command -ScriptBlock {
# Get the response
$global:response = $webRequest.GetResponse()
} -ErrorMessage "Failed to get the size ofthe file: $mcURL"
$mooncakeFileSize = $global:response.Headers["Content-Range"] -split "/" | Select-Object -Last 1
$remoteFileSize = $response.Headers["Content-Range"] -split "/" | Select-Object -Last 1
if ($localFileSize -ne $remoteFileSize)
{
$isIgnore = $False
Expand Down
Loading