Skip to content

Commit d73b15d

Browse files
redbeamanjannath
authored andcommitted
9p: add e2e feature test
1 parent 3f6e5fa commit d73b15d

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

test/e2e/features/9pfs.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@story_9pfs @windows
2+
Feature: Verify 9pfs mount works
3+
4+
Verify 9pfs mount of user's home directory is mounted, accessible
5+
and that basic file operations work. Only relevant on Windows.
6+
7+
Scenario: Test mounted home directory functionality
8+
Given home directory mount exists in VM
9+
And filesystem is mounted
10+
Then listing files in mounted home directory should succeed
11+
And basic file operations in mounted home directory should succeed
12+
And basic directory operations in mounted home directory should succeed

test/e2e/testsuite/testsuite.go

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
"net/http"
1111
"os"
1212
"os/user"
13+
"path"
1314
"path/filepath"
1415
"runtime"
1516
"slices"
1617
"strconv"
1718
"strings"
1819
"time"
1920

21+
"github.com/crc-org/crc/v2/pkg/crc/machine/libhvee"
2022
"github.com/crc-org/crc/v2/pkg/crc/ssh"
2123
"github.com/spf13/cast"
2224
"go.podman.io/common/pkg/strongunits"
@@ -599,6 +601,19 @@ func InitializeScenario(s *godog.ScenarioContext) {
599601
s.Step(`^get memory data "([^"]*)"`,
600602
getMemoryData)
601603

604+
// 9P file sharing checks
605+
mountedHomeDir := libhvee.ConvertToUnixPath(constants.GetHomeDir())
606+
s.Step(`^home directory mount exists in VM$`,
607+
func() error { return directoryExistInVM(mountedHomeDir) })
608+
s.Step(`^filesystem is mounted$`,
609+
filesystemIsMounted)
610+
s.Step(`^listing files in mounted home directory should succeed$`,
611+
func() error { return listingFilesInDirectoryShouldSucceed(mountedHomeDir) })
612+
s.Step(`^basic file operations in mounted home directory should succeed$`,
613+
func() error { return basicFileOperationsInDirectoryShouldSucceed(mountedHomeDir) })
614+
s.Step(`^basic directory operations in mounted home directory should succeed$`,
615+
func() error { return basicDirectoryOperationsInDirectoryShouldSucceed(mountedHomeDir) })
616+
602617
s.After(func(ctx context.Context, _ *godog.Scenario, err error) (context.Context, error) {
603618

604619
if usingPreexistingCluster() {
@@ -1363,3 +1378,115 @@ func getTimestamp(content string) error {
13631378
file := filepath.Join(wd, "../test-results/time-stamp.txt")
13641379
return util.WriteToFile(data, file)
13651380
}
1381+
1382+
func directoryExistInVM(dirName string) error {
1383+
_, err := util.SendCommandToVM(fmt.Sprintf("stat %s", dirName))
1384+
if err != nil {
1385+
return fmt.Errorf("directory '%s' does not exist: %v", dirName, err)
1386+
}
1387+
return nil
1388+
}
1389+
1390+
func filesystemIsMounted() error {
1391+
out, err := util.SendCommandToVM("mount")
1392+
if err != nil {
1393+
return fmt.Errorf("error running mount: %v", err)
1394+
}
1395+
if !strings.Contains(out, "fuse.9pfs") {
1396+
return fmt.Errorf("filesystem is not mounted")
1397+
}
1398+
return nil
1399+
}
1400+
1401+
func listingFilesInDirectoryShouldSucceed(dirName string) error {
1402+
_, err := util.SendCommandToVM(fmt.Sprintf("ls -l %s", dirName))
1403+
if err != nil {
1404+
return fmt.Errorf("cannot list files: %v", err)
1405+
}
1406+
return nil
1407+
}
1408+
1409+
func basicFileOperationsInDirectoryShouldSucceed(dirName string) error {
1410+
filename := path.Join(dirName, "story_9pfs_test_file")
1411+
content := "test content"
1412+
1413+
// Create
1414+
_, err := util.SendCommandToVM(fmt.Sprintf("> %s", filename))
1415+
if err != nil {
1416+
return fmt.Errorf("cannot create file in 9p mounted directory: %v", err)
1417+
}
1418+
1419+
// Write
1420+
_, err = util.SendCommandToVM(fmt.Sprintf("echo \"%s\" > %s", content, filename))
1421+
if err != nil {
1422+
return fmt.Errorf("cannot write to file in 9p mounted directory: %v", err)
1423+
}
1424+
1425+
// Read
1426+
out, err := util.SendCommandToVM(fmt.Sprintf("cat %s", filename))
1427+
if err != nil {
1428+
return fmt.Errorf("cannot read file in 9p mounted directory: %v", err)
1429+
}
1430+
if strings.TrimSpace(out) != content {
1431+
return fmt.Errorf("file content mismatch in 9p mounted directory: got '%s', should have '%s'", out, content)
1432+
}
1433+
1434+
// Update
1435+
newContent := "updated content"
1436+
_, err = util.SendCommandToVM(fmt.Sprintf("echo \"%s\" > %s", newContent, filename))
1437+
if err != nil {
1438+
return fmt.Errorf("cannot update file in 9p mounted directory: %v", err)
1439+
}
1440+
out, err = util.SendCommandToVM(fmt.Sprintf("cat %s", filename))
1441+
if err != nil {
1442+
return fmt.Errorf("cannot read updated file in 9p mounted directory: %v", err)
1443+
}
1444+
if strings.TrimSpace(out) != newContent {
1445+
return fmt.Errorf("file content mismatch in 9p mounted directory: got '%s', should have '%s'", out, newContent)
1446+
}
1447+
1448+
// Change permissions
1449+
_, err = util.SendCommandToVM(fmt.Sprintf("chmod 777 %s", filename))
1450+
if err != nil {
1451+
return fmt.Errorf("cannot chmod file in 9p mounted directory: %v", err)
1452+
}
1453+
1454+
// Rename
1455+
newFilename := path.Join(dirName, "story_9pfs_test_file_renamed")
1456+
_, err = util.SendCommandToVM(fmt.Sprintf("mv %s %s", filename, newFilename))
1457+
if err != nil {
1458+
return fmt.Errorf("cannot rename file in 9p mounted directory: %v", err)
1459+
}
1460+
1461+
// Delete
1462+
_, err = util.SendCommandToVM(fmt.Sprintf("rm %s", newFilename))
1463+
if err != nil {
1464+
return fmt.Errorf("cannot delete file in 9p mounted directory: %v", err)
1465+
}
1466+
1467+
return nil
1468+
}
1469+
1470+
func basicDirectoryOperationsInDirectoryShouldSucceed(dirName string) error {
1471+
testDirName := path.Join(dirName, "story_9pfs_test_dir")
1472+
1473+
// Create
1474+
_, err := util.SendCommandToVM(fmt.Sprintf("mkdir %s", testDirName))
1475+
if err != nil {
1476+
return fmt.Errorf("cannot create subdirectory in 9p mounted directory: %v", err)
1477+
}
1478+
1479+
// List
1480+
_, err = util.SendCommandToVM(fmt.Sprintf("ls %s", testDirName))
1481+
if err != nil {
1482+
return fmt.Errorf("cannot list subdirectory in 9p mounted directory: %v", err)
1483+
}
1484+
1485+
// Delete
1486+
_, err = util.SendCommandToVM(fmt.Sprintf("rmdir %s", testDirName))
1487+
if err != nil {
1488+
return fmt.Errorf("cannot delete subdirectory in 9p mounted directory: %v", err)
1489+
}
1490+
1491+
return nil
1492+
}

0 commit comments

Comments
 (0)