Joe Topjian | 27a6243 | 2015-04-18 01:48:50 +0000 | [diff] [blame] | 1 | package schedulerhints |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 7 | th "github.com/rackspace/gophercloud/testhelper" |
| 8 | ) |
| 9 | |
| 10 | func 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 | }, |
Joe Topjian | 7d6989c | 2015-05-05 20:38:08 +0000 | [diff] [blame] | 27 | Query: []interface{}{">=", "$free_ram_mb", "1024"}, |
Joe Topjian | 27a6243 | 2015-04-18 01:48:50 +0000 | [diff] [blame] | 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", |
Jon Perritt | ad5f1cb | 2015-05-20 10:38:13 -0600 | [diff] [blame] | 42 | "flavorRef": "performance1-1", |
| 43 | "flavorName": "", |
| 44 | "imageName": "" |
Joe Topjian | 27a6243 | 2015-04-18 01:48:50 +0000 | [diff] [blame] | 45 | }, |
| 46 | "os:scheduler_hints": { |
| 47 | "group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba", |
| 48 | "different_host": [ |
| 49 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 50 | "8c19174f-4220-44f0-824a-cd1eeef10287" |
| 51 | ], |
| 52 | "same_host": [ |
| 53 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 54 | "8c19174f-4220-44f0-824a-cd1eeef10287" |
| 55 | ], |
| 56 | "query": [ |
| 57 | ">=", "$free_ram_mb", "1024" |
| 58 | ], |
| 59 | "target_cell": "foobar", |
| 60 | "build_near_host_ip": "192.168.1.1", |
| 61 | "cidr": "/24" |
| 62 | } |
| 63 | } |
| 64 | ` |
| 65 | actual, err := ext.ToServerCreateMap() |
| 66 | th.AssertNoErr(t, err) |
| 67 | th.CheckJSONEquals(t, expected, actual) |
| 68 | } |
Joe Topjian | 7d6989c | 2015-05-05 20:38:08 +0000 | [diff] [blame] | 69 | |
| 70 | func TestCreateOptsWithComplexQuery(t *testing.T) { |
| 71 | base := servers.CreateOpts{ |
| 72 | Name: "createdserver", |
| 73 | ImageRef: "asdfasdfasdf", |
| 74 | FlavorRef: "performance1-1", |
| 75 | } |
| 76 | |
| 77 | schedulerHints := SchedulerHints{ |
| 78 | Group: "101aed42-22d9-4a3e-9ba1-21103b0d1aba", |
| 79 | DifferentHost: []string{ |
| 80 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 81 | "8c19174f-4220-44f0-824a-cd1eeef10287", |
| 82 | }, |
| 83 | SameHost: []string{ |
| 84 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 85 | "8c19174f-4220-44f0-824a-cd1eeef10287", |
| 86 | }, |
| 87 | Query: []interface{}{"and", []string{">=", "$free_ram_mb", "1024"}, []string{">=", "$free_disk_mb", "204800"}}, |
| 88 | TargetCell: "foobar", |
| 89 | BuildNearHostIP: "192.168.1.1/24", |
| 90 | } |
| 91 | |
| 92 | ext := CreateOptsExt{ |
| 93 | CreateOptsBuilder: base, |
| 94 | SchedulerHints: schedulerHints, |
| 95 | } |
| 96 | |
| 97 | expected := ` |
| 98 | { |
| 99 | "server": { |
| 100 | "name": "createdserver", |
| 101 | "imageRef": "asdfasdfasdf", |
Jon Perritt | ad5f1cb | 2015-05-20 10:38:13 -0600 | [diff] [blame] | 102 | "flavorRef": "performance1-1", |
| 103 | "flavorName": "", |
| 104 | "imageName": "" |
Joe Topjian | 7d6989c | 2015-05-05 20:38:08 +0000 | [diff] [blame] | 105 | }, |
| 106 | "os:scheduler_hints": { |
| 107 | "group": "101aed42-22d9-4a3e-9ba1-21103b0d1aba", |
| 108 | "different_host": [ |
| 109 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 110 | "8c19174f-4220-44f0-824a-cd1eeef10287" |
| 111 | ], |
| 112 | "same_host": [ |
| 113 | "a0cf03a5-d921-4877-bb5c-86d26cf818e1", |
| 114 | "8c19174f-4220-44f0-824a-cd1eeef10287" |
| 115 | ], |
| 116 | "query": [ |
| 117 | "and", |
| 118 | [">=", "$free_ram_mb", "1024"], |
| 119 | [">=", "$free_disk_mb", "204800"] |
| 120 | ], |
| 121 | "target_cell": "foobar", |
| 122 | "build_near_host_ip": "192.168.1.1", |
| 123 | "cidr": "/24" |
| 124 | } |
| 125 | } |
| 126 | ` |
| 127 | actual, err := ext.ToServerCreateMap() |
| 128 | th.AssertNoErr(t, err) |
| 129 | th.CheckJSONEquals(t, expected, actual) |
| 130 | } |