blob: c494fda4aa72550797a5aa29dfb471591c359a0a [file] [log] [blame]
Joe Topjian27a62432015-04-18 01:48:50 +00001package schedulerhints
2
3import (
4 "testing"
5
6 "github.com/rackspace/gophercloud/openstack/compute/v2/servers"
7 th "github.com/rackspace/gophercloud/testhelper"
8)
9
10func TestCreateOpts(t *testing.T) {
11 base := servers.CreateOpts{
12 Name: "createdserver",
13 ImageRef: "asdfasdfasdf",
14 FlavorRef: "performance1-1",
15 }
16
17 schedulerHints := SchedulerHints{
18 Group: "101aed42-22d9-4a3e-9ba1-21103b0d1aba",
19 DifferentHost: []string{
20 "a0cf03a5-d921-4877-bb5c-86d26cf818e1",
21 "8c19174f-4220-44f0-824a-cd1eeef10287",
22 },
23 SameHost: []string{
24 "a0cf03a5-d921-4877-bb5c-86d26cf818e1",
25 "8c19174f-4220-44f0-824a-cd1eeef10287",
26 },
27 Query: []string{">=", "$free_ram_mb", "1024"},
28 TargetCell: "foobar",
29 BuildNearHostIP: "192.168.1.1/24",
30 }
31
32 ext := CreateOptsExt{
33 CreateOptsBuilder: base,
34 SchedulerHints: schedulerHints,
35 }
36
37 expected := `
38 {
39 "server": {
40 "name": "createdserver",
41 "imageRef": "asdfasdfasdf",
42 "flavorRef": "performance1-1"
43 },
44 "os:scheduler_hints": {
45 "group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba",
46 "different_host": [
47 "a0cf03a5-d921-4877-bb5c-86d26cf818e1",
48 "8c19174f-4220-44f0-824a-cd1eeef10287"
49 ],
50 "same_host": [
51 "a0cf03a5-d921-4877-bb5c-86d26cf818e1",
52 "8c19174f-4220-44f0-824a-cd1eeef10287"
53 ],
54 "query": [
55 ">=", "$free_ram_mb", "1024"
56 ],
57 "target_cell": "foobar",
58 "build_near_host_ip": "192.168.1.1",
59 "cidr": "/24"
60 }
61 }
62 `
63 actual, err := ext.ToServerCreateMap()
64 th.AssertNoErr(t, err)
65 th.CheckJSONEquals(t, expected, actual)
66}