@@ -10,9 +10,13 @@ import (
10
10
"os/user"
11
11
"path/filepath"
12
12
"runtime"
13
+ "slices"
14
+ "strconv"
13
15
"strings"
14
16
"time"
15
17
18
+ "github.com/crc-org/crc/v2/pkg/crc/ssh"
19
+
16
20
"github.com/crc-org/crc/v2/pkg/crc/constants"
17
21
"github.com/crc-org/crc/v2/pkg/crc/machine"
18
22
"github.com/crc-org/crc/v2/pkg/crc/preset"
@@ -555,6 +559,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
555
559
EnsureKubeConfigIsCleanedUp )
556
560
s .Step (`^crc version has expected output$` ,
557
561
EnsureCrcVersionIsCorrect )
562
+ s .Step (`^persistent volume of size "([^"]*)"GB exists$` ,
563
+ EnsureVMPartitionSizeCorrect )
558
564
559
565
s .After (func (ctx context.Context , _ * godog.Scenario , err error ) (context.Context , error ) {
560
566
@@ -1128,3 +1134,78 @@ func EnsureMicroshiftClusterIsOperational() error {
1128
1134
1129
1135
return nil
1130
1136
}
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