Skip to content

Commit e9fd9db

Browse files
committed
test (e2e) : add step for setting persistent-volume-size config option (#4186)
Add step for `persistent-volume-size` config option in story_microshift.feature Signed-off-by: Rohan Kumar <[email protected]>
1 parent 0224cc2 commit e9fd9db

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

test/e2e/features/config.feature

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Feature: Test configuration settings
2222
| memory | 10753 | 4096 |
2323
| nameserver | 120.0.0.1 | 999.999.999.999 |
2424
| pull-secret-file | /etc | /nonexistent-file |
25+
| persistent-volume-size | 20 | 5 |
2526

2627
@linux
2728
Examples: Config settings on Linux
@@ -30,6 +31,7 @@ Feature: Test configuration settings
3031
| memory | 10753 | 4096 |
3132
| nameserver | 120.0.0.1 | 999.999.999.999 |
3233
| pull-secret-file | /etc | /nonexistent-file |
34+
| persistent-volume-size | 20 | 5 |
3335

3436
@windows
3537
Examples: Config settings on Windows
@@ -38,6 +40,7 @@ Feature: Test configuration settings
3840
| memory | 10753 | 4096 |
3941
| nameserver | 120.0.0.1 | 999.999.999.999 |
4042
| pull-secret-file | /Users | /nonexistent-file |
43+
| persistent-volume-size | 20 | 5 |
4144

4245
@linux @darwin @windows
4346
Scenario: CRC config checks (bundle version)

test/e2e/features/story_microshift.feature

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ Feature: Microshift test stories
33

44
Background:
55
Given setting config property "preset" to value "microshift" succeeds
6+
And setting config property "disk-size" to value "41" succeeds
7+
And setting config property "persistent-volume-size" to value "20" succeeds
68
And ensuring network mode user
79
And executing single crc setup command succeeds
810
And starting CRC with default bundle succeeds
911
And ensuring oc command is available
1012
And ensuring microshift cluster is fully operational
11-
13+
And executing "crc status" succeeds
14+
And stdout should contain "Persistent Volume Usage:"
15+
And persistent volume of size "20"GB exists
16+
1217
# End-to-end health check
1318

1419
@microshift @testdata @linux @windows @darwin @cleanup

test/e2e/testsuite/testsuite.go

+81
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import (
1010
"os/user"
1111
"path/filepath"
1212
"runtime"
13+
"slices"
14+
"strconv"
1315
"strings"
1416
"time"
1517

18+
"github.com/crc-org/crc/v2/pkg/crc/ssh"
19+
1620
"github.com/crc-org/crc/v2/pkg/crc/constants"
1721
"github.com/crc-org/crc/v2/pkg/crc/machine"
1822
"github.com/crc-org/crc/v2/pkg/crc/preset"
@@ -555,6 +559,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
555559
EnsureKubeConfigIsCleanedUp)
556560
s.Step(`^crc version has expected output$`,
557561
EnsureCrcVersionIsCorrect)
562+
s.Step(`^persistent volume of size "([^"]*)"GB exists$`,
563+
EnsureVMPartitionSizeCorrect)
558564

559565
s.After(func(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
560566

@@ -1128,3 +1134,78 @@ func EnsureMicroshiftClusterIsOperational() error {
11281134

11291135
return nil
11301136
}
1137+
1138+
func EnsureVMPartitionSizeCorrect(expectedPVSizeStr string) error {
1139+
expectedPVSize, err := strconv.Atoi(expectedPVSizeStr)
1140+
if err != nil {
1141+
return fmt.Errorf("invalid expected persistent volume size provided in test input")
1142+
}
1143+
err = util.ExecuteCommand("crc ip")
1144+
if err != nil {
1145+
return fmt.Errorf("error in determining crc vm's ip address: %v", err)
1146+
}
1147+
crcIP := util.GetLastCommandOutput("stdout")
1148+
runner, err := ssh.CreateRunner(crcIP, 2222, filepath.Join(util.CRCHome, "machines", "crc", "id_ed25519"))
1149+
if err != nil {
1150+
return fmt.Errorf("error creating ssh runner: %v", err)
1151+
}
1152+
out, _, err := runner.Run("lsblk -oTYPE,SIZE -n")
1153+
if err != nil {
1154+
return fmt.Errorf("error in executing command in crc vm: %v", err)
1155+
}
1156+
1157+
actualPVSize, err := deserializeListBlockDeviceCommandOutputToExtractPVSize(out)
1158+
if err != nil {
1159+
return err
1160+
}
1161+
if actualPVSize != expectedPVSize {
1162+
return fmt.Errorf("expecting persistent volume size to be %d, got %d", expectedPVSize, actualPVSize)
1163+
}
1164+
return nil
1165+
}
1166+
1167+
func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string) (int, error) {
1168+
type BlockDevice struct {
1169+
DeviceType string
1170+
Size string
1171+
}
1172+
blockDevices := make([]BlockDevice, 0)
1173+
lines := strings.Split(lsblkOutput, "\n")
1174+
1175+
for _, line := range lines {
1176+
fields := strings.Fields(line)
1177+
if len(fields) < 2 {
1178+
continue
1179+
}
1180+
1181+
blockDevices = append(blockDevices, BlockDevice{
1182+
DeviceType: fields[0],
1183+
Size: fields[1],
1184+
})
1185+
}
1186+
1187+
var lvmSize int
1188+
lvmBlockDeviceIndex := slices.IndexFunc(blockDevices, func(b BlockDevice) bool {
1189+
return b.DeviceType == "lvm"
1190+
})
1191+
if lvmBlockDeviceIndex == -1 {
1192+
return -1, fmt.Errorf("expecting lsblk output to contain a lvm device, got no device with type lvm")
1193+
}
1194+
_, err := fmt.Sscanf(blockDevices[lvmBlockDeviceIndex].Size, "%dG", &lvmSize)
1195+
if err != nil {
1196+
return -1, fmt.Errorf("error in scanning lvm device size: %v", err)
1197+
}
1198+
1199+
var diskSize int
1200+
diskDeviceIndex := slices.IndexFunc(blockDevices, func(b BlockDevice) bool {
1201+
return b.DeviceType == "disk"
1202+
})
1203+
if diskDeviceIndex == -1 {
1204+
return -1, fmt.Errorf("expecting lsblk output to contain a disk device, got no device with type disk")
1205+
}
1206+
_, err = fmt.Sscanf(blockDevices[diskDeviceIndex].Size, "%dG", &diskSize)
1207+
if err != nil {
1208+
return -1, fmt.Errorf("error in scanning disk device size: %v", err)
1209+
}
1210+
return diskSize - (lvmSize + 1), nil
1211+
}

0 commit comments

Comments
 (0)