driver/qemu: Require a memory resource on the task

This commit is contained in:
Clint Shryock
2015-09-09 14:28:16 -05:00
parent 58d9e437d5
commit db5b3e7e12
2 changed files with 36 additions and 1 deletions

View File

@@ -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

View File

@@ -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")
}
}