Skip to content

Commit

Permalink
Merge pull request #724 from pablochacin/fix-pts-console-test
Browse files Browse the repository at this point in the history
Fix pts dev not found in console test
  • Loading branch information
MalloZup authored Apr 6, 2020
2 parents 8cbe9ad + 0cf9e4d commit 883978b
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions libvirt/resource_libvirt_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"testing"
"unsafe"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
Expand Down Expand Up @@ -626,7 +628,7 @@ func TestAccLibvirtDomain_NetworkInterface(t *testing.T) {
Steps: []resource.TestStep{
{
Config: config,
ExpectNonEmptyPlan: false,
ExpectNonEmptyPlan: false,
Check: resource.ComposeTestCheckFunc(
testAccCheckLibvirtDomainExists("libvirt_domain."+randomDomainName, &domain),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -989,24 +991,54 @@ func TestAccLibvirtDomain_Filesystems(t *testing.T) {
})
}

func createPts() (string, error) {

var ptsNumber int

fd, err := syscall.Open("/dev/ptmx", int(syscall.O_RDWR), 0)
if err != nil {
fmt.Printf("Error creating pts %v", err)
}

_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(syscall.TIOCGPTN), uintptr(unsafe.Pointer(&ptsNumber)))

if ep != 0 {
return "", syscall.Errno(ep)
}

return fmt.Sprintf("/dev/pts/%d", ptsNumber), nil

}

func TestAccLibvirtDomain_Consoles(t *testing.T) {
skipIfPrivilegedDisabled(t)

var domain libvirt.Domain
randomDomainName := acctest.RandStringFromCharSet(10, acctest.CharSetAlpha)

pts1, err := createPts()
if err != nil {
t.Errorf("error creating pts %v", err)
}

pts2, err := createPts()
if err != nil {
t.Errorf("error creating pts %v", err)
}

var config = fmt.Sprintf(`
resource "libvirt_domain" "%s" {
name = "%s"
console {
type = "pty"
target_port = "0"
source_path = "/dev/pts/1"
source_path = "%s"
}
console {
type = "pty"
target_port = "0"
target_type = "virtio"
source_path = "/dev/pts/2"
source_path = "%s"
}
console {
type = "tcp"
Expand All @@ -1015,7 +1047,7 @@ func TestAccLibvirtDomain_Consoles(t *testing.T) {
source_host = "127.0.1.1"
source_service = "cisco-sccp"
}
}`, randomDomainName, randomDomainName)
}`, randomDomainName, randomDomainName, pts1, pts2)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -1031,15 +1063,15 @@ func TestAccLibvirtDomain_Consoles(t *testing.T) {
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.0.target_port", "0"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.0.source_path", "/dev/pts/1"),
"libvirt_domain."+randomDomainName, "console.0.source_path", pts1),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.1.type", "pty"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.1.target_port", "0"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.1.target_type", "virtio"),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.1.source_path", "/dev/pts/2"),
"libvirt_domain."+randomDomainName, "console.1.source_path", pts2),
resource.TestCheckResourceAttr(
"libvirt_domain."+randomDomainName, "console.2.type", "tcp"),
resource.TestCheckResourceAttr(
Expand Down

0 comments on commit 883978b

Please sign in to comment.