blob: 0250e81448f7589fdb09ff9b703f490aff765a31 [file] [log] [blame]
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package crostini
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
"chromiumos/tast/local/crostini"
"chromiumos/tast/local/cryptohome"
"chromiumos/tast/local/vm"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: SSHFSMount,
Desc: "Checks crostini SSHFS mount",
Contacts: []string{"joelhockey@chromium.org", "cros-containers-dev@google.com"},
Attr: []string{"group:mainline"},
Vars: []string{"keepState"},
VarDeps: []string{"ui.gaiaPoolDefault"},
SoftwareDeps: []string{"chrome", "vm_host"},
Params: []testing.Param{
// Parameters generated by params_test.go. DO NOT EDIT.
{
Name: "stretch_stable",
ExtraData: []string{crostini.GetContainerMetadataArtifact("stretch", false), crostini.GetContainerRootfsArtifact("stretch", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcStretch(),
Timeout: 7 * time.Minute,
}, {
Name: "stretch_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("stretch", false), crostini.GetContainerRootfsArtifact("stretch", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcStretch(),
Timeout: 7 * time.Minute,
}, {
Name: "buster_stable",
ExtraData: []string{crostini.GetContainerMetadataArtifact("buster", false), crostini.GetContainerRootfsArtifact("buster", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcBuster(),
Timeout: 7 * time.Minute,
}, {
Name: "buster_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("buster", false), crostini.GetContainerRootfsArtifact("buster", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcBuster(),
Timeout: 7 * time.Minute,
}, {
Name: "bullseye_stable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("bullseye", false), crostini.GetContainerRootfsArtifact("bullseye", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniStable,
Pre: crostini.StartedByDlcBullseye(),
Timeout: 7 * time.Minute,
}, {
Name: "bullseye_unstable",
ExtraAttr: []string{"informational"},
ExtraData: []string{crostini.GetContainerMetadataArtifact("bullseye", false), crostini.GetContainerRootfsArtifact("bullseye", false)},
ExtraSoftwareDeps: []string{"dlc"},
ExtraHardwareDeps: crostini.CrostiniUnstable,
Pre: crostini.StartedByDlcBullseye(),
Timeout: 7 * time.Minute,
},
},
})
}
func SSHFSMount(ctx context.Context, s *testing.State) {
pre := s.PreValue().(crostini.PreData)
cr := pre.Chrome
cont := s.PreValue().(crostini.PreData).Container
defer crostini.RunCrostiniPostTest(ctx, s.PreValue().(crostini.PreData))
ownerID, err := cryptohome.UserHash(ctx, cr.NormalizedUser())
if err != nil {
s.Fatal("Failed to get user hash: ", err)
}
sshfsMountDir := fmt.Sprintf("/media/fuse/crostini_%s_%s_%s", ownerID, vm.DefaultVMName, vm.DefaultContainerName)
if stat, err := os.Stat(sshfsMountDir); err != nil {
s.Fatalf("Didn't find sshfs mount %v: %v", sshfsMountDir, err)
} else if !stat.IsDir() {
s.Fatal("Didn't get directory for sshfs mount ", sshfsMountDir)
}
// Verify mount works for writing a file.
const (
testFileName = "SshfsMount.txt"
testFileContent = "SshfsMount"
)
crosFileName := filepath.Join(sshfsMountDir, testFileName)
if err := ioutil.WriteFile(crosFileName, []byte(testFileContent), 0644); err != nil {
s.Fatalf("Failed writing file %v: %v", crosFileName, err)
}
defer os.Remove(crosFileName)
// Verify that test file is in the container.
if err := cont.CheckFileContent(ctx, testFileName, testFileContent); err != nil {
s.Fatalf("Wrong file content for %v: %v", testFileName, err)
}
}