diff options
Diffstat (limited to 'libvirt/utils_libvirt_test.go')
-rw-r--r-- | libvirt/utils_libvirt_test.go | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/libvirt/utils_libvirt_test.go b/libvirt/utils_libvirt_test.go index fa76cd84..38d90136 100644 --- a/libvirt/utils_libvirt_test.go +++ b/libvirt/utils_libvirt_test.go @@ -3,8 +3,11 @@ package libvirt import ( "encoding/xml" "testing" + "time" + libvirt "github.com/libvirt/libvirt-go" "github.com/libvirt/libvirt-go-xml" + "os" ) func TestGetHostXMLDesc(t *testing.T) { @@ -32,3 +35,96 @@ func TestGetHostXMLDesc(t *testing.T) { t.Errorf("expected name %s, got %s", name, dd.Name) } } + +func connect(t *testing.T) *libvirt.Connect { + conn, err := libvirt.NewConnect(os.Getenv("LIBVIRT_DEFAULT_URI")) + if err != nil { + t.Fatal(err) + } + + return conn +} + +func TestGetHostArchitecture(t *testing.T) { + + conn := connect(t) + defer conn.Close() + + arch, err := getHostArchitecture(conn) + + if err != nil { + t.Errorf("error %v", err) + } + + t.Logf("[DEBUG] arch - %s", arch) + + if arch == "" { + t.Errorf("arch is blank.") + } +} + +func TestGetCanonicalMachineName(t *testing.T) { + + conn := connect(t) + defer conn.Close() + arch := "x86_64" + virttype := "hvm" + machine := "pc" + + caps,err := getHostCapabilities(conn) + if err != nil { + t.Error(err) + } + + name, err := getCanonicalMachineName(caps, arch, virttype, machine) + + if err != nil { + t.Errorf("Could not get canonical name for %s/%s", arch, machine) + return + } + + t.Logf("Canonical name for %s/%s = %s", arch, machine, name) +} + +func TestGetOriginalMachineName(t *testing.T) { + conn := connect(t) + defer conn.Close() + arch := "x86_64" + virttype := "hvm" + machine := "pc" + + caps,err := getHostCapabilities(conn) + if err != nil { + t.Error(err) + } + + canonname, err := getCanonicalMachineName(caps, arch, virttype, machine) + if err != nil { + t.Error(err) + } + reversename, err := getOriginalMachineName(caps, arch, virttype, canonname) + if err != nil { + t.Error(err) + } + if reversename != machine { + t.Errorf("Cannot reverse canonical machine lookup") + } + + t.Logf("Reverse canonical lookup for %s is %s which matches %s", canonname, reversename, machine) +} + +func TestGetHostCapabilties(t *testing.T) { + start := time.Now() + conn := connect(t) + defer conn.Close() + caps,err := getHostCapabilities(conn) + if err != nil { + t.Errorf("Can't get host capabilties") + } + if caps.Host.UUID == "" { + t.Errorf("Host has no UUID!") + } + + elapsed := time.Since(start) + t.Logf("[DEBUG] Get host capabilites took %s", elapsed) +} |