Skip to content

Commit 97bb639

Browse files
committed
CI: azstemcell - parameterize os version validation
1 parent 30972b6 commit 97bb639

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

ci/azstemcell/main.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"path"
1818
"path/filepath"
1919
"regexp"
20+
"slices"
2021
"strings"
2122
"time"
2223
)
@@ -316,25 +317,25 @@ func DownloadVHD(dirname string) (string, error) {
316317
return destinationFile, nil
317318
}
318319

319-
// Main and flag validation
320-
320+
// Main and flag validation - add env keys first so that flags take precedence
321321
var (
322-
// Add env keys first so that flags take precedence
323322
VhdURL = os.Getenv("AZURE_VHD_URL") // vhd
324323
VhdURLFile = os.Getenv("AZURE_VHD_URL_FILE") // vhdfile
325324
Version = os.Getenv("AZURE_VERSION") // version
326325
VersionFile = os.Getenv("AZURE_VERSION_FILE") // versionfile
327326
WindowsOS = os.Getenv("AZURE_WINDOWS_OS") // os
328327
Destination = os.Getenv("AZURE_DESTINATION") // dest
329328
WorkDir = os.Getenv("AZURE_TEMP_DIR") // temp
329+
330+
supportedWindowsVersions = []string{"2019"}
330331
)
331332

332333
func parseFlags() error {
333334
flag.StringVar(&VhdURL, "vhd", "", "URL to VHD with SAS token, env: AZURE_VHD_URL")
334335
flag.StringVar(&VhdURLFile, "vhdfile", "", "File containing the VHD URL with SAS token, env: AZURE_VHD_URL_FILE")
335336
flag.StringVar(&Version, "version", "", "Stemcell version, env: AZURE_VERSION")
336337
flag.StringVar(&VersionFile, "versionfile", "", "File containing the stemcell version, env: AZURE_VERSION_FILE")
337-
flag.StringVar(&WindowsOS, "os", "", "Windows version (2019), env: AZURE_WINDOWS_OS")
338+
flag.StringVar(&WindowsOS, "os", "", "Windows version (e.g 2135), env: AZURE_WINDOWS_OS")
338339
flag.StringVar(&Destination, "dest", "", "Destination directory if not provided the current working directory will be used, env: AZURE_DESTINATION")
339340
flag.StringVar(&WorkDir, "temp", "", "Temporary directory (must be capable of storing +130GB of data), env: AZURE_TEMP_DIR")
340341

@@ -401,14 +402,12 @@ func validateFlags() []error {
401402
if WindowsOS == "" {
402403
add(errors.New("missing required argument: [os]"))
403404
}
404-
switch strings.ToLower(WindowsOS) {
405-
case "2019":
406-
// Ok
407-
case "windows2019":
408-
WindowsOS = strings.TrimPrefix(WindowsOS, "windows")
409-
default:
410-
add(fmt.Errorf("OS version must be 2019 have: %s", WindowsOS))
405+
406+
WindowsOS = strings.TrimPrefix(WindowsOS, "windows")
407+
if !slices.Contains(supportedWindowsVersions, WindowsOS) {
408+
add(fmt.Errorf("OS version must be one of %v, got: %s", supportedWindowsVersions, WindowsOS))
411409
}
410+
412411
if Destination == "" {
413412
add(errors.New("missing required argument: [dest]"))
414413
}

ci/azstemcell/main_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"io/ioutil"
54
"os"
65
"path/filepath"
76
"testing"
@@ -14,7 +13,7 @@ func TestCreateManifest(t *testing.T) {
1413
const expected = `---
1514
name: bosh-azure-hyperv-windows2019-go_agent
1615
version: '10.0.17763.410'
17-
bosh_protocol: 1
16+
api_version: 3
1817
sha1: 478da1732dba66e67e6a657fdf03b5614c513b04
1918
operating_system: windows2019
2019
cloud_properties:
@@ -31,7 +30,7 @@ cloud_properties:
3130
root_device_name: "/dev/sda1"
3231
`
3332

34-
tmpdir, err := ioutil.TempDir("", "")
33+
tmpdir, err := os.MkdirTemp("", "")
3534
if err != nil {
3635
t.Fatal(err)
3736
}

0 commit comments

Comments
 (0)