Skip to content

Commit

Permalink
test (e2e) : add step for setting persistent-volume-size config opt…
Browse files Browse the repository at this point in the history
…ion (#4186)

Add step for `persistent-volume-size` config option in story_microshift.feature

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Feb 18, 2025
1 parent 457b653 commit 5f1bbae
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions test/e2e/features/config.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Feature: Test configuration settings
| memory | 10753 | 4096 |
| nameserver | 120.0.0.1 | 999.999.999.999 |
| pull-secret-file | /etc | /nonexistent-file |
| persistent-volume-size | 20 | 5 |

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

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

@linux @darwin @windows
Scenario: CRC config checks (bundle version)
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/features/story_microshift.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ Feature: Microshift test stories

Background:
Given setting config property "preset" to value "microshift" succeeds
And setting config property "disk-size" to value "41" succeeds
And setting config property "persistent-volume-size" to value "20" succeeds
And ensuring network mode user
And executing single crc setup command succeeds
And starting CRC with default bundle succeeds
And ensuring oc command is available
And ensuring microshift cluster is fully operational

And executing "crc status" succeeds
And stdout should contain "Persistent Volume Usage:"
And persistent volume of size "20"GB exists

# End-to-end health check

@microshift @testdata @linux @windows @darwin @cleanup
Expand Down
79 changes: 79 additions & 0 deletions test/e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ package testsuite
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"net/http"
"os"
"os/user"
"path/filepath"
"runtime"
"slices"
"strconv"
"strings"
"time"

"github.com/crc-org/crc/v2/pkg/crc/ssh"

"github.com/crc-org/crc/v2/pkg/crc/constants"
"github.com/crc-org/crc/v2/pkg/crc/machine"
"github.com/crc-org/crc/v2/pkg/crc/preset"
Expand Down Expand Up @@ -554,6 +559,8 @@ func InitializeScenario(s *godog.ScenarioContext) {
EnsureMicroshiftClusterIsOperational)
s.Step(`^kubeconfig is cleaned up$`,
EnsureKubeConfigIsCleanedUp)
s.Step(`^persistent volume of size "([^"]*)"GB exists$`,
EnsureVMPartitionSizeCorrect)

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

Expand Down Expand Up @@ -1101,3 +1108,75 @@ func EnsureMicroshiftClusterIsOperational() error {

return nil
}

func EnsureVMPartitionSizeCorrect(expectedPVSizeStr string) error {
expectedPVSize, err := strconv.Atoi(expectedPVSizeStr)
if err != nil {
return fmt.Errorf("invalid expected persistent volume size provided in test input")
}
err = util.ExecuteCommand("crc ip")
if err != nil {
return fmt.Errorf("error in determining crc vm's ip address: %v", err)
}
crcIP := util.GetLastCommandOutput("stdout")
runner, err := ssh.CreateRunner(crcIP, 2222, filepath.Join(util.CRCHome, "machines", "crc", "id_ed25519"))
if err != nil {
return fmt.Errorf("error creating ssh runner: %v", err)
}
out, _, err := runner.Run("lsblk --json -oTYPE,SIZE")
if err != nil {
return fmt.Errorf("error in executing command in crc vm: %v", err)
}

actualPVSize, err := deserializeListBlockDeviceCommandOutputToExtractPVSize(out)
if err != nil {
return err
}
if actualPVSize != expectedPVSize {
return fmt.Errorf("expecting persistent volume size to be %d, got %d", expectedPVSize, actualPVSize)
}
return nil
}

func deserializeListBlockDeviceCommandOutputToExtractPVSize(lsblkOutput string) (int, error) {
type BlockDevice struct {
DeviceType string `json:"type"`
Size string `json:"size"`
}
type Root struct {
BlockDevices []BlockDevice
}
var deviceRoot Root
err := json.Unmarshal([]byte(lsblkOutput), &deviceRoot)
if err != nil {
return -1, fmt.Errorf("error in unmarshalling lsblk output json: %v", err)
}
if len(deviceRoot.BlockDevices) == 0 {
return -1, fmt.Errorf("expecting lsblk output to contain a device, got empty list")
}

var lvmSize int
lvmBlockDeviceIndex := slices.IndexFunc(deviceRoot.BlockDevices, func(b BlockDevice) bool {
return b.DeviceType == "lvm"
})
if lvmBlockDeviceIndex == -1 {
return -1, fmt.Errorf("expecting lsblk output to contain a lvm device, got no device with type lvm")
}
_, err = fmt.Sscanf(deviceRoot.BlockDevices[lvmBlockDeviceIndex].Size, "%dG", &lvmSize)
if err != nil {
return -1, fmt.Errorf("error in scanning lvm device size: %v", err)
}

var diskSize int
diskDeviceIndex := slices.IndexFunc(deviceRoot.BlockDevices, func(b BlockDevice) bool {
return b.DeviceType == "disk"
})
if diskDeviceIndex == -1 {
return -1, fmt.Errorf("expecting lsblk output to contain a disk device, got no device with type disk")
}
_, err = fmt.Sscanf(deviceRoot.BlockDevices[diskDeviceIndex].Size, "%dG", &diskSize)
if err != nil {
return -1, fmt.Errorf("error in scanning disk device size: %v", err)
}
return diskSize - (lvmSize + 1), nil
}

0 comments on commit 5f1bbae

Please sign in to comment.