github.com/ranjib/nomad@v0.1.1-0.20160225204057-97751b02f70b/client/driver/qemu_test.go (about) 1 package driver 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/nomad/client/config" 8 "github.com/hashicorp/nomad/nomad/structs" 9 10 ctestutils "github.com/hashicorp/nomad/client/testutil" 11 ) 12 13 // The fingerprinter test should always pass, even if QEMU is not installed. 14 func TestQemuDriver_Fingerprint(t *testing.T) { 15 t.Parallel() 16 ctestutils.QemuCompatible(t) 17 driverCtx, _ := testDriverContexts(&structs.Task{Name: "foo"}) 18 d := NewQemuDriver(driverCtx) 19 node := &structs.Node{ 20 Attributes: make(map[string]string), 21 } 22 apply, err := d.Fingerprint(&config.Config{}, node) 23 if err != nil { 24 t.Fatalf("err: %v", err) 25 } 26 if !apply { 27 t.Fatalf("should apply") 28 } 29 if node.Attributes["driver.qemu"] == "" { 30 t.Fatalf("Missing Qemu driver") 31 } 32 if node.Attributes["driver.qemu.version"] == "" { 33 t.Fatalf("Missing Qemu driver version") 34 } 35 } 36 37 func TestQemuDriver_StartOpen_Wait(t *testing.T) { 38 t.Parallel() 39 ctestutils.QemuCompatible(t) 40 // TODO: use test server to load from a fixture 41 task := &structs.Task{ 42 Name: "linux", 43 Config: map[string]interface{}{ 44 "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", 45 "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", 46 "accelerator": "tcg", 47 "port_map": []map[string]int{{ 48 "main": 22, 49 "web": 8080, 50 }}, 51 }, 52 LogConfig: &structs.LogConfig{ 53 MaxFiles: 10, 54 MaxFileSizeMB: 10, 55 }, 56 Resources: &structs.Resources{ 57 CPU: 500, 58 MemoryMB: 512, 59 Networks: []*structs.NetworkResource{ 60 &structs.NetworkResource{ 61 ReservedPorts: []structs.Port{{"main", 22000}, {"web", 80}}, 62 }, 63 }, 64 }, 65 } 66 67 driverCtx, execCtx := testDriverContexts(task) 68 defer execCtx.AllocDir.Destroy() 69 d := NewQemuDriver(driverCtx) 70 71 handle, err := d.Start(execCtx, task) 72 if err != nil { 73 t.Fatalf("err: %v", err) 74 } 75 if handle == nil { 76 t.Fatalf("missing handle") 77 } 78 79 // Attempt to open 80 handle2, err := d.Open(execCtx, handle.ID()) 81 if err != nil { 82 t.Fatalf("err: %v", err) 83 } 84 if handle2 == nil { 85 t.Fatalf("missing handle") 86 } 87 88 // Clean up 89 if err := handle.Kill(); err != nil { 90 fmt.Printf("\nError killing Qemu test: %s", err) 91 } 92 } 93 94 func TestQemuDriver_RequiresMemory(t *testing.T) { 95 t.Parallel() 96 ctestutils.QemuCompatible(t) 97 // TODO: use test server to load from a fixture 98 task := &structs.Task{ 99 Name: "linux", 100 Config: map[string]interface{}{ 101 "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", 102 "accelerator": "tcg", 103 "host_port": "8080", 104 "guest_port": "8081", 105 "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", 106 // ssh u/p would be here 107 }, 108 LogConfig: &structs.LogConfig{ 109 MaxFiles: 10, 110 MaxFileSizeMB: 10, 111 }, 112 } 113 114 driverCtx, execCtx := testDriverContexts(task) 115 defer execCtx.AllocDir.Destroy() 116 d := NewQemuDriver(driverCtx) 117 118 _, err := d.Start(execCtx, task) 119 if err == nil { 120 t.Fatalf("Expected error when not specifying memory") 121 } 122 }