Skip to content

Commit

Permalink
update vcom test to use evetestkit package
Browse files Browse the repository at this point in the history
Signed-off-by: Shahriyar Jalayeri <[email protected]>
  • Loading branch information
shjala committed Aug 22, 2024
1 parent 4ebebba commit 06b9eac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 175 deletions.
149 changes: 0 additions & 149 deletions tests/vcom/base.go

This file was deleted.

55 changes: 29 additions & 26 deletions tests/vcom/vcom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,55 @@ import (
"testing"
"time"

tk "github.com/lf-edge/eden/pkg/evetestkit"
log "github.com/sirupsen/logrus"
)

var eveNode *tk.EveNode

const (
sshPort = "8027"
vmUser = "ubuntu"
vmPass = "passw0rd"
testScriptBasePath = "/home/ubuntu/"
cloudConfig = "#cloud-config\npassword: passw0rd\nchpasswd: { expire: False }\nssh_pwauth: True\n"
appLink = "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
sshPort = "8027"
appLink = "https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img"
)

func TestMain(m *testing.M) {
log.Println("VCOM Test started")
res := initilizeTest(m)
defer log.Println("VCOM Test finished")

node, err := tk.InitilizeTest(m, "vcomlink")
if err != nil {
log.Fatalf("Failed to initialize test: %v", err)
}

log.Println("VCOM Test finished")
eveNode = node
res := m.Run()
os.Exit(res)
}

func TestVcomLink(t *testing.T) {
log.Println("TestVcomLink started")
defer log.Println("TestVcomLink finished")

if !isTpmEnabled() {
if !eveNode.IsTpmEnabled() {
t.Skip("TPM is enabled, skipping test")
}

stat, err := rnode.RunEveCommand("eve exec pillar ss -l --vsock")
t.Log("Checking if vcomlink is running on EVE")
stat, err := eveNode.EveRunCommand("eve exec pillar ss -l --vsock")
// vcomlink listens on port 2000 and host cid is 2.
// this is hacky way to check it is running, but it works ¯\_(ツ)_/¯
if !strings.Contains(string(stat), "2:2000") {
t.Fatalf("vcomlink is not running %v", err)
}

appname = getAppName("vcom-")
publishedPorts := sshPort + ":22"
err = deployApp(appLink, appname, cloudConfig, []string{publishedPorts})
appName := tk.GetRandomAppName("vcom-")
pc := tk.GetDefaultVmConfig(appName, tk.DefaultCloudConfig, []string{sshPort + ":22"})
err = eveNode.DeployVm(appLink, pc)
if err != nil {
t.Fatalf("Failed to deploy app: %v", err)
}
defer func() {
err = rnode.StopAndRemoveApp(appname)
err = eveNode.StopAndRemoveApp(appName)
if err != nil {
log.Errorf("Failed to stop and remove app: %v", err)
}
Expand All @@ -58,35 +64,31 @@ func TestVcomLink(t *testing.T) {
time.Sleep(10 * time.Second)

// wait 5 minutes for the app to start
t.Logf("Waiting for app %s to start...", appname)
err = rnode.WaitForAppStart(appname, 60*5)
t.Logf("Waiting for app %s to start...", appName)
err = eveNode.WaitForAppRunningState(appName, 60*5)
if err != nil {
t.Fatalf("Failed to wait for app to start: %v", err)
}

rnode.SSHUser = vmUser
rnode.SSHPass = vmPass
rnode.SSHPort = sshPort
err = rnode.GetNodeIP()
if err != nil {
t.Fatalf("Failed to get node IP: %v", err)
}
// add app to the list so we can use it
eveNode.AddApp(appName, tk.DefaultSSHUser, tk.DefaultSSHPass, sshPort)

t.Logf("Waiting for ssh to be ready...")
err = rnode.WaitForSSH(60 * 5)
err = eveNode.WaitForSSH(appName, 60*5)
if err != nil {
t.Fatalf("Failed to wait for ssh: %v", err)
}
t.Logf("SSH connection established")

_, err = rnode.AppSSHExec("sudo apt-get -y install socat")
t.Log("Installing socat on the vm")
_, err = eveNode.SSHExec(appName, "sudo apt-get -y install socat")
if err != nil {
t.Fatalf("Failed install socat on the vm: %v", err)
}

// send a request to vcomlink via vsock to get the host's TPM EK
command := "echo '{\"channel\":2,\"request\":1}' | socat - VSOCK-CONNECT:2:2000"
out, err := rnode.AppSSHExec(command)
out, err := eveNode.SSHExec(appName, command)
if err != nil {
t.Fatalf("Failed to communicate with host via vsock: %v", err)
}
Expand All @@ -96,4 +98,5 @@ func TestVcomLink(t *testing.T) {
if strings.Contains(string(out), "error") {
t.Fatalf("Failed to communicate with host via vsock: %v", out)
}
t.Log("Successfully communicated from VM to vcomlink (host) via vsock")
}

0 comments on commit 06b9eac

Please sign in to comment.