From 1685a28eea1e53362bd1c87468b10b303e2ba900 Mon Sep 17 00:00:00 2001 From: Anthony Lu <67125539+koln67@users.noreply.github.com> Date: Fri, 22 Sep 2023 09:13:33 -0700 Subject: [PATCH] Int64 fix (#801) --- imagetest/test_suites/hotattach/hot_attach_test.go | 2 +- imagetest/test_suites/hotattach/setup.go | 1 - imagetest/test_suites/storageperf/iops_read_test.go | 2 +- imagetest/test_suites/storageperf/iops_write_test.go | 2 +- .../test_suites/storageperf/storage_perf_utils.go | 2 -- imagetest/utils/test_utils.go | 12 ++++++++---- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/imagetest/test_suites/hotattach/hot_attach_test.go b/imagetest/test_suites/hotattach/hot_attach_test.go index bfb009907..5ff460fd0 100644 --- a/imagetest/test_suites/hotattach/hot_attach_test.go +++ b/imagetest/test_suites/hotattach/hot_attach_test.go @@ -43,7 +43,7 @@ func getProjectAndZone() (string, string, error) { func getLinuxMountPath(mountDiskSizeGB int, mountDiskName string) (string, error) { symlinkRealPath := "" - diskPartition, err := utils.GetMountDiskPartition(mountDiskSizeGB * bytesInGB) + diskPartition, err := utils.GetMountDiskPartition(mountDiskSizeGB) if err == nil { symlinkRealPath = "/dev/" + diskPartition } else { diff --git a/imagetest/test_suites/hotattach/setup.go b/imagetest/test_suites/hotattach/setup.go index 761aa9353..53e5fc5d7 100644 --- a/imagetest/test_suites/hotattach/setup.go +++ b/imagetest/test_suites/hotattach/setup.go @@ -14,7 +14,6 @@ const ( diskName = "hotattachMount" instanceName = "hotattachvm" - bytesInGB = 1073741824 bootDiskSizeGB = 10 mountDiskSizeGB = 30 diff --git a/imagetest/test_suites/storageperf/iops_read_test.go b/imagetest/test_suites/storageperf/iops_read_test.go index 8888f971f..1f651f69d 100644 --- a/imagetest/test_suites/storageperf/iops_read_test.go +++ b/imagetest/test_suites/storageperf/iops_read_test.go @@ -44,7 +44,7 @@ func RunFIOReadWindows(mode string) ([]byte, error) { func getLinuxSymlinkRead() (string, error) { symlinkRealPath := "" - diskPartition, err := utils.GetMountDiskPartition(hyperdiskSizeGB * bytesInGB) + diskPartition, err := utils.GetMountDiskPartition(hyperdiskSizeGB) if err == nil { symlinkRealPath = "/dev/" + diskPartition } else { diff --git a/imagetest/test_suites/storageperf/iops_write_test.go b/imagetest/test_suites/storageperf/iops_write_test.go index 1ce759be1..c5cce216c 100644 --- a/imagetest/test_suites/storageperf/iops_write_test.go +++ b/imagetest/test_suites/storageperf/iops_write_test.go @@ -44,7 +44,7 @@ func RunFIOWriteWindows(mode string) ([]byte, error) { func getLinuxSymlinkWrite() (string, error) { symlinkRealPath := "" - diskPartition, err := utils.GetMountDiskPartition(hyperdiskSizeGB * bytesInGB) + diskPartition, err := utils.GetMountDiskPartition(hyperdiskSizeGB) if err == nil { symlinkRealPath = "/dev/" + diskPartition } else { diff --git a/imagetest/test_suites/storageperf/storage_perf_utils.go b/imagetest/test_suites/storageperf/storage_perf_utils.go index 8974e8dee..bc4dedc9f 100644 --- a/imagetest/test_suites/storageperf/storage_perf_utils.go +++ b/imagetest/test_suites/storageperf/storage_perf_utils.go @@ -19,8 +19,6 @@ const ( vmName = "vm" // iopsErrorMargin allows for a small difference between iops found in the test and the iops value listed in public documentation. iopsErrorMargin = 0.95 - // hyperdiskSize in bytes is used to determine which partition is the mounted hyperdisk. - bytesInGB = 1073741824 hyperdiskSizeGB = 3500 bootdiskSizeGB = 50 mountDiskName = "hyperdisk" diff --git a/imagetest/utils/test_utils.go b/imagetest/utils/test_utils.go index 2559b94fe..08e8ff58f 100644 --- a/imagetest/utils/test_utils.go +++ b/imagetest/utils/test_utils.go @@ -23,7 +23,10 @@ import ( "golang.org/x/crypto/ssh" ) -const metadataURLPrefix = "http://metadata.google.internal/computeMetadata/v1/instance/" +const ( + metadataURLPrefix = "http://metadata.google.internal/computeMetadata/v1/instance/" + bytesInGB = 1073741824 +) var windowsClientImagePatterns = []string{ "windows-7-", @@ -40,7 +43,7 @@ type BlockDeviceList struct { // BlockDevice defines information about a single partition or disk in the output of lsblk. type BlockDevice struct { Name string `json:"name,omitempty"` - Size int `json:"size,omitempty"` + Size int64 `json:"size,omitempty"` Type string `json:"type,omitempty"` // Other fields are not currently used. X map[string]interface{} `json:"-"` @@ -399,7 +402,8 @@ func FailOnPowershellFail(command string, errorMsg string, t *testing.T) { // GetMountDiskPartition runs lsblk to get the partition of the mount disk on linux, assuming the // size of the mount disk is diskExpectedSizeGb. -func GetMountDiskPartition(diskExpectedSizeBytes int) (string, error) { +func GetMountDiskPartition(diskExpectedSizeGB int) (string, error) { + var diskExpectedSizeBytes int64 = int64(diskExpectedSizeGB) * int64(bytesInGB) lsblkCmd := "lsblk" if !CheckLinuxCmdExists(lsblkCmd) { return "", fmt.Errorf("could not find lsblk") @@ -422,7 +426,7 @@ func GetMountDiskPartition(diskExpectedSizeBytes int) (string, error) { } // we should have a slice of length 3, with fields name, size, type var blkname, blksize, blktype = linetokens[0], linetokens[1], linetokens[2] - blksizeInt, err := strconv.Atoi(blksize) + blksizeInt, err := strconv.ParseInt(blksize, 10, 64) if err != nil { return "", fmt.Errorf("did not find int in output of lsblk: string %s error %v", blksize, err) }