mirror of
https://github.com/kemko/nomad.git
synced 2026-01-07 02:45:42 +03:00
driver/qemu: Require a memory resource on the task
This commit is contained in:
@@ -81,6 +81,12 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
|
||||
return nil, fmt.Errorf("Missing source image Qemu driver")
|
||||
}
|
||||
|
||||
// Qemu defaults to 128M of RAM for a given VM. Instead, we force users to
|
||||
// supply a memory size in the tasks resources
|
||||
if task.Resources == nil || task.Resources.MemoryMB == 0 {
|
||||
return nil, fmt.Errorf("Missing required Task Resource: Memory")
|
||||
}
|
||||
|
||||
// Attempt to download the thing
|
||||
// Should be extracted to some kind of Http Fetcher
|
||||
// Right now, assume publicly accessible HTTP url
|
||||
|
||||
@@ -53,7 +53,6 @@ func TestQemuDriver_Start(t *testing.T) {
|
||||
task := &structs.Task{
|
||||
Config: map[string]string{
|
||||
"image_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
|
||||
"memory": "512M",
|
||||
"accelerator": "tcg",
|
||||
"host_port": "8080",
|
||||
"guest_port": "8081",
|
||||
@@ -61,6 +60,12 @@ func TestQemuDriver_Start(t *testing.T) {
|
||||
// ssh u/p would be here
|
||||
},
|
||||
}
|
||||
|
||||
// add requred memory resource
|
||||
task.Resources = &structs.Resources{
|
||||
MemoryMB: 512,
|
||||
}
|
||||
|
||||
handle, err := d.Start(ctx, task)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
@@ -83,3 +88,27 @@ func TestQemuDriver_Start(t *testing.T) {
|
||||
fmt.Printf("\nError killing Qemu test: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQemuDriver_RequiresMemory(t *testing.T) {
|
||||
ctx := NewExecContext()
|
||||
ctx.AllocDir = os.TempDir()
|
||||
d := NewQemuDriver(testLogger())
|
||||
|
||||
// TODO: use test server to load from a fixture
|
||||
task := &structs.Task{
|
||||
Config: map[string]string{
|
||||
"image_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
|
||||
"accelerator": "tcg",
|
||||
"host_port": "8080",
|
||||
"guest_port": "8081",
|
||||
"checksum": "a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
|
||||
// ssh u/p would be here
|
||||
},
|
||||
}
|
||||
|
||||
_, err := d.Start(ctx, task)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error when not specifying memory")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user