Skip to content

Commit

Permalink
Fix json unmarshal error (#807)
Browse files Browse the repository at this point in the history
* Fix json unmarshal error

* Change print item formatting

* Print integer in formatting correctly

* fix presubmit
  • Loading branch information
koln67 authored Sep 27, 2023
1 parent 3037dc6 commit fb9f1f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 4 additions & 4 deletions imagetest/test_suites/storageperf/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSetup(t *imagetest.TestWorkflow) error {
// {"machineType": "c3d-standard-180", "zone": "us-east4-c", "diskType": imagetest.HyperdiskExtreme},
{"machineType": "n2-standard-80", "diskType": imagetest.HyperdiskExtreme},
{"machineType": "c3-standard-88", "diskType": imagetest.PdBalanced},
// {"machineType": "c3d-standard-180", "zone": "us-east4-c", "diskType": imagetest.PdBalanced},
{"machineType": "c3d-standard-180", "zone": "us-east4-c", "diskType": imagetest.PdBalanced},
}
testVMs := []*imagetest.TestVM{}
for _, paramMap := range paramMaps {
Expand All @@ -45,9 +45,9 @@ func TestSetup(t *imagetest.TestWorkflow) error {
if diskTypeParam, foundKey := paramMap["diskType"]; foundKey {
diskType = diskTypeParam
}
//if strings.HasPrefix(machineType, "c3d") && (strings.Contains(t.Image, "windows-2012") || strings.Contains(t.Image, "windows-2016")) {
// continue
//}
if strings.HasPrefix(machineType, "c3d") && (strings.Contains(t.Image, "windows-2012") || strings.Contains(t.Image, "windows-2016")) {
continue
}
bootDisk := compute.Disk{Name: vmName + machineType + diskType, Type: imagetest.PdBalanced, SizeGb: bootdiskSizeGB}
mountDisk := compute.Disk{Name: mountDiskName + machineType + diskType, Type: diskType, SizeGb: mountdiskSizeGB}
bootDisk.Zone = paramMap["zone"]
Expand Down
15 changes: 11 additions & 4 deletions imagetest/utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ 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 int64 `json:"size,omitempty"`
Type string `json:"type,omitempty"`
// on some OSes, size is a string, and on some OSes, size is a number.
// This allows both to be parsed
Size json.Number `json:"size,omitempty"`
Type string `json:"type,omitempty"`
// Other fields are not currently used.
X map[string]interface{} `json:"-"`
}
Expand Down Expand Up @@ -439,10 +441,15 @@ func GetMountDiskPartition(diskExpectedSizeGB int) (string, error) {

var blockDevices BlockDeviceList
if err := json.Unmarshal(lsblkout, &blockDevices); err != nil {
return "", fmt.Errorf("failed to unmarshal lsblk output with error: %v", err)
return "", fmt.Errorf("failed to unmarshal lsblk output %s with error: %v", lsblkout, err)
}
for _, blockDev := range blockDevices.BlockDevices {
if strings.ToLower(blockDev.Type) == diskType && blockDev.Size == diskExpectedSizeBytes {
// deal with the case where the unmarshalled size field can be a number with or without quotes on different operating systems.
blockDevSizeInt, err := blockDev.Size.Int64()
if err != nil {
return "", fmt.Errorf("block dev size %s was not an int: error %v", blockDev.Size.String(), err)
}
if strings.ToLower(blockDev.Type) == diskType && blockDevSizeInt == diskExpectedSizeBytes {
return blockDev.Name, nil
}
}
Expand Down

0 comments on commit fb9f1f6

Please sign in to comment.