| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 1 | package stackresources | 
|  | 2 |  | 
|  | 3 | import ( | 
|  | 4 | "fmt" | 
|  | 5 | "net/http" | 
|  | 6 | "testing" | 
|  | 7 | "time" | 
|  | 8 |  | 
|  | 9 | "github.com/rackspace/gophercloud" | 
|  | 10 | th "github.com/rackspace/gophercloud/testhelper" | 
|  | 11 | fake "github.com/rackspace/gophercloud/testhelper/client" | 
|  | 12 | ) | 
|  | 13 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 14 | // FindExpected represents the expected object from a Find request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 15 | var FindExpected = []Resource{ | 
|  | 16 | Resource{ | 
|  | 17 | Name: "hello_world", | 
|  | 18 | Links: []gophercloud.Link{ | 
|  | 19 | gophercloud.Link{ | 
|  | 20 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", | 
|  | 21 | Rel:  "self", | 
|  | 22 | }, | 
|  | 23 | gophercloud.Link{ | 
|  | 24 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", | 
|  | 25 | Rel:  "stack", | 
|  | 26 | }, | 
|  | 27 | }, | 
|  | 28 | LogicalID:    "hello_world", | 
|  | 29 | StatusReason: "state changed", | 
|  | 30 | UpdatedTime:  time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), | 
|  | 31 | RequiredBy:   []interface{}{}, | 
|  | 32 | Status:       "CREATE_IN_PROGRESS", | 
|  | 33 | PhysicalID:   "49181cd6-169a-4130-9455-31185bbfc5bf", | 
|  | 34 | Type:         "OS::Nova::Server", | 
|  | 35 | }, | 
|  | 36 | } | 
|  | 37 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 38 | // FindOutput represents the response body from a Find request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 39 | const FindOutput = ` | 
|  | 40 | { | 
|  | 41 | "resources": [ | 
|  | 42 | { | 
|  | 43 | "resource_name": "hello_world", | 
|  | 44 | "links": [ | 
|  | 45 | { | 
|  | 46 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", | 
|  | 47 | "rel": "self" | 
|  | 48 | }, | 
|  | 49 | { | 
|  | 50 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", | 
|  | 51 | "rel": "stack" | 
|  | 52 | } | 
|  | 53 | ], | 
|  | 54 | "logical_resource_id": "hello_world", | 
|  | 55 | "resource_status_reason": "state changed", | 
|  | 56 | "updated_time": "2015-02-05T21:33:11Z", | 
|  | 57 | "required_by": [], | 
|  | 58 | "resource_status": "CREATE_IN_PROGRESS", | 
|  | 59 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", | 
|  | 60 | "resource_type": "OS::Nova::Server" | 
|  | 61 | } | 
|  | 62 | ] | 
|  | 63 | }` | 
|  | 64 |  | 
|  | 65 | // HandleFindSuccessfully creates an HTTP handler at `/stacks/hello_world/resources` | 
|  | 66 | // on the test handler mux that responds with a `Find` response. | 
|  | 67 | func HandleFindSuccessfully(t *testing.T, output string) { | 
|  | 68 | th.Mux.HandleFunc("/stacks/hello_world/resources", func(w http.ResponseWriter, r *http.Request) { | 
|  | 69 | th.TestMethod(t, r, "GET") | 
|  | 70 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 71 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 72 |  | 
|  | 73 | w.Header().Set("Content-Type", "application/json") | 
|  | 74 | w.WriteHeader(http.StatusOK) | 
|  | 75 | fmt.Fprintf(w, output) | 
|  | 76 | }) | 
|  | 77 | } | 
|  | 78 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 79 | // ListExpected represents the expected object from a List request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 80 | var ListExpected = []Resource{ | 
|  | 81 | Resource{ | 
|  | 82 | Name: "hello_world", | 
|  | 83 | Links: []gophercloud.Link{ | 
|  | 84 | gophercloud.Link{ | 
|  | 85 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", | 
|  | 86 | Rel:  "self", | 
|  | 87 | }, | 
|  | 88 | gophercloud.Link{ | 
|  | 89 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", | 
|  | 90 | Rel:  "stack", | 
|  | 91 | }, | 
|  | 92 | }, | 
|  | 93 | LogicalID:    "hello_world", | 
|  | 94 | StatusReason: "state changed", | 
|  | 95 | UpdatedTime:  time.Date(2015, 2, 5, 21, 33, 11, 0, time.UTC), | 
|  | 96 | RequiredBy:   []interface{}{}, | 
|  | 97 | Status:       "CREATE_IN_PROGRESS", | 
|  | 98 | PhysicalID:   "49181cd6-169a-4130-9455-31185bbfc5bf", | 
|  | 99 | Type:         "OS::Nova::Server", | 
|  | 100 | }, | 
|  | 101 | } | 
|  | 102 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 103 | // ListOutput represents the response body from a List request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 104 | const ListOutput = `{ | 
|  | 105 | "resources": [ | 
|  | 106 | { | 
|  | 107 | "resource_name": "hello_world", | 
|  | 108 | "links": [ | 
|  | 109 | { | 
|  | 110 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b/resources/hello_world", | 
|  | 111 | "rel": "self" | 
|  | 112 | }, | 
|  | 113 | { | 
|  | 114 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/postman_stack/5f57cff9-93fc-424e-9f78-df0515e7f48b", | 
|  | 115 | "rel": "stack" | 
|  | 116 | } | 
|  | 117 | ], | 
|  | 118 | "logical_resource_id": "hello_world", | 
|  | 119 | "resource_status_reason": "state changed", | 
|  | 120 | "updated_time": "2015-02-05T21:33:11Z", | 
|  | 121 | "required_by": [], | 
|  | 122 | "resource_status": "CREATE_IN_PROGRESS", | 
|  | 123 | "physical_resource_id": "49181cd6-169a-4130-9455-31185bbfc5bf", | 
|  | 124 | "resource_type": "OS::Nova::Server" | 
|  | 125 | } | 
|  | 126 | ] | 
|  | 127 | }` | 
|  | 128 |  | 
|  | 129 | // HandleListSuccessfully creates an HTTP handler at `/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources` | 
|  | 130 | // on the test handler mux that responds with a `List` response. | 
|  | 131 | func HandleListSuccessfully(t *testing.T, output string) { | 
|  | 132 | th.Mux.HandleFunc("/stacks/hello_world/49181cd6-169a-4130-9455-31185bbfc5bf/resources", func(w http.ResponseWriter, r *http.Request) { | 
|  | 133 | th.TestMethod(t, r, "GET") | 
|  | 134 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 135 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 136 |  | 
|  | 137 | w.Header().Set("Content-Type", "application/json") | 
|  | 138 | r.ParseForm() | 
|  | 139 | marker := r.Form.Get("marker") | 
|  | 140 | switch marker { | 
|  | 141 | case "": | 
|  | 142 | fmt.Fprintf(w, output) | 
| Jon Perritt | 64f594d | 2015-02-08 21:24:33 -0700 | [diff] [blame] | 143 | case "49181cd6-169a-4130-9455-31185bbfc5bf": | 
|  | 144 | fmt.Fprintf(w, `{"resources":[]}`) | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 145 | default: | 
|  | 146 | t.Fatalf("Unexpected marker: [%s]", marker) | 
|  | 147 | } | 
|  | 148 | }) | 
|  | 149 | } | 
|  | 150 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 151 | // GetExpected represents the expected object from a Get request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 152 | var GetExpected = &Resource{ | 
|  | 153 | Name: "wordpress_instance", | 
|  | 154 | Links: []gophercloud.Link{ | 
|  | 155 | gophercloud.Link{ | 
|  | 156 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", | 
|  | 157 | Rel:  "self", | 
|  | 158 | }, | 
|  | 159 | gophercloud.Link{ | 
|  | 160 | Href: "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e", | 
|  | 161 | Rel:  "stack", | 
|  | 162 | }, | 
|  | 163 | }, | 
|  | 164 | LogicalID:    "wordpress_instance", | 
|  | 165 | StatusReason: "state changed", | 
|  | 166 | UpdatedTime:  time.Date(2014, 12, 10, 18, 34, 35, 0, time.UTC), | 
|  | 167 | RequiredBy:   []interface{}{}, | 
|  | 168 | Status:       "CREATE_COMPLETE", | 
|  | 169 | PhysicalID:   "00e3a2fe-c65d-403c-9483-4db9930dd194", | 
|  | 170 | Type:         "OS::Nova::Server", | 
|  | 171 | } | 
|  | 172 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 173 | // GetOutput represents the response body from a Get request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 174 | const GetOutput = ` | 
|  | 175 | { | 
|  | 176 | "resource": { | 
|  | 177 | "resource_name": "wordpress_instance", | 
|  | 178 | "description": "", | 
|  | 179 | "links": [ | 
|  | 180 | { | 
|  | 181 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", | 
|  | 182 | "rel": "self" | 
|  | 183 | }, | 
|  | 184 | { | 
|  | 185 | "href": "http://166.78.160.107:8004/v1/98606384f58d4ad0b3db7d0d779549ac/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e", | 
|  | 186 | "rel": "stack" | 
|  | 187 | } | 
|  | 188 | ], | 
|  | 189 | "logical_resource_id": "wordpress_instance", | 
|  | 190 | "resource_status": "CREATE_COMPLETE", | 
|  | 191 | "updated_time": "2014-12-10T18:34:35Z", | 
|  | 192 | "required_by": [], | 
|  | 193 | "resource_status_reason": "state changed", | 
|  | 194 | "physical_resource_id": "00e3a2fe-c65d-403c-9483-4db9930dd194", | 
|  | 195 | "resource_type": "OS::Nova::Server" | 
|  | 196 | } | 
|  | 197 | }` | 
|  | 198 |  | 
|  | 199 | // HandleGetSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance` | 
|  | 200 | // on the test handler mux that responds with a `Get` response. | 
|  | 201 | func HandleGetSuccessfully(t *testing.T, output string) { | 
|  | 202 | th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance", func(w http.ResponseWriter, r *http.Request) { | 
|  | 203 | th.TestMethod(t, r, "GET") | 
|  | 204 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 205 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 206 |  | 
|  | 207 | w.Header().Set("Content-Type", "application/json") | 
|  | 208 | w.WriteHeader(http.StatusOK) | 
|  | 209 | fmt.Fprintf(w, output) | 
|  | 210 | }) | 
|  | 211 | } | 
|  | 212 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 213 | // MetadataExpected represents the expected object from a Metadata request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 214 | var MetadataExpected = map[string]string{ | 
|  | 215 | "number": "7", | 
|  | 216 | "animal": "auk", | 
|  | 217 | } | 
|  | 218 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 219 | // MetadataOutput represents the response body from a Metadata request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 220 | const MetadataOutput = ` | 
|  | 221 | { | 
|  | 222 | "metadata": { | 
|  | 223 | "number": "7", | 
|  | 224 | "animal": "auk" | 
|  | 225 | } | 
|  | 226 | }` | 
|  | 227 |  | 
|  | 228 | // HandleMetadataSuccessfully creates an HTTP handler at `/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata` | 
|  | 229 | // on the test handler mux that responds with a `Metadata` response. | 
|  | 230 | func HandleMetadataSuccessfully(t *testing.T, output string) { | 
|  | 231 | th.Mux.HandleFunc("/stacks/teststack/0b1771bd-9336-4f2b-ae86-a80f971faf1e/resources/wordpress_instance/metadata", func(w http.ResponseWriter, r *http.Request) { | 
|  | 232 | th.TestMethod(t, r, "GET") | 
|  | 233 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 234 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 235 |  | 
|  | 236 | w.Header().Set("Content-Type", "application/json") | 
|  | 237 | w.WriteHeader(http.StatusOK) | 
|  | 238 | fmt.Fprintf(w, output) | 
|  | 239 | }) | 
|  | 240 | } | 
|  | 241 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 242 | // ListTypesExpected represents the expected object from a ListTypes request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 243 | var ListTypesExpected = []string{ | 
|  | 244 | "OS::Nova::Server", | 
|  | 245 | "OS::Heat::RandomString", | 
|  | 246 | "OS::Swift::Container", | 
|  | 247 | "OS::Trove::Instance", | 
|  | 248 | "OS::Nova::FloatingIPAssociation", | 
|  | 249 | "OS::Cinder::VolumeAttachment", | 
|  | 250 | "OS::Nova::FloatingIP", | 
|  | 251 | "OS::Nova::KeyPair", | 
|  | 252 | } | 
|  | 253 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 254 | // ListTypesOutput represents the response body from a ListTypes request. | 
| Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 255 | const ListTypesOutput = ` | 
|  | 256 | { | 
|  | 257 | "resource_types": [ | 
|  | 258 | "OS::Nova::Server", | 
|  | 259 | "OS::Heat::RandomString", | 
|  | 260 | "OS::Swift::Container", | 
|  | 261 | "OS::Trove::Instance", | 
|  | 262 | "OS::Nova::FloatingIPAssociation", | 
|  | 263 | "OS::Cinder::VolumeAttachment", | 
|  | 264 | "OS::Nova::FloatingIP", | 
|  | 265 | "OS::Nova::KeyPair" | 
|  | 266 | ] | 
|  | 267 | }` | 
|  | 268 |  | 
|  | 269 | // HandleListTypesSuccessfully creates an HTTP handler at `/resource_types` | 
|  | 270 | // on the test handler mux that responds with a `ListTypes` response. | 
|  | 271 | func HandleListTypesSuccessfully(t *testing.T, output string) { | 
|  | 272 | th.Mux.HandleFunc("/resource_types", func(w http.ResponseWriter, r *http.Request) { | 
|  | 273 | th.TestMethod(t, r, "GET") | 
|  | 274 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 275 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 276 |  | 
|  | 277 | w.Header().Set("Content-Type", "application/json") | 
|  | 278 | w.WriteHeader(http.StatusOK) | 
|  | 279 | fmt.Fprintf(w, output) | 
|  | 280 | }) | 
|  | 281 | } | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 282 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 283 | // GetSchemaExpected represents the expected object from a Schema request. | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 284 | var GetSchemaExpected = &TypeSchema{ | 
|  | 285 | Attributes: map[string]interface{}{ | 
|  | 286 | "an_attribute": map[string]interface{}{ | 
|  | 287 | "description": "An attribute description .", | 
|  | 288 | }, | 
|  | 289 | }, | 
|  | 290 | Properties: map[string]interface{}{ | 
|  | 291 | "a_property": map[string]interface{}{ | 
|  | 292 | "update_allowed": false, | 
|  | 293 | "required":       true, | 
|  | 294 | "type":           "string", | 
|  | 295 | "description":    "A resource description.", | 
|  | 296 | }, | 
|  | 297 | }, | 
|  | 298 | ResourceType: "OS::Heat::AResourceName", | 
|  | 299 | } | 
|  | 300 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 301 | // GetSchemaOutput represents the response body from a Schema request. | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 302 | const GetSchemaOutput = ` | 
|  | 303 | { | 
|  | 304 | "attributes": { | 
|  | 305 | "an_attribute": { | 
|  | 306 | "description": "An attribute description ." | 
|  | 307 | } | 
|  | 308 | }, | 
|  | 309 | "properties": { | 
|  | 310 | "a_property": { | 
|  | 311 | "update_allowed": false, | 
|  | 312 | "required": true, | 
|  | 313 | "type": "string", | 
|  | 314 | "description": "A resource description." | 
|  | 315 | } | 
|  | 316 | }, | 
|  | 317 | "resource_type": "OS::Heat::AResourceName" | 
|  | 318 | }` | 
|  | 319 |  | 
|  | 320 | // HandleGetSchemaSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName` | 
|  | 321 | // on the test handler mux that responds with a `Schema` response. | 
|  | 322 | func HandleGetSchemaSuccessfully(t *testing.T, output string) { | 
|  | 323 | th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName", func(w http.ResponseWriter, r *http.Request) { | 
|  | 324 | th.TestMethod(t, r, "GET") | 
|  | 325 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 326 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 327 |  | 
|  | 328 | w.Header().Set("Content-Type", "application/json") | 
|  | 329 | w.WriteHeader(http.StatusOK) | 
|  | 330 | fmt.Fprintf(w, output) | 
|  | 331 | }) | 
|  | 332 | } | 
|  | 333 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 334 | // GetTemplateExpected represents the expected object from a Template request. | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 335 | var GetTemplateExpected = &TypeTemplate{ | 
|  | 336 | HeatTemplateFormatVersion: "2012-12-12", | 
|  | 337 | Outputs: map[string]interface{}{ | 
|  | 338 | "private_key": map[string]interface{}{ | 
|  | 339 | "Description": "The private key if it has been saved.", | 
|  | 340 | "Value":       "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}", | 
|  | 341 | }, | 
|  | 342 | "public_key": map[string]interface{}{ | 
|  | 343 | "Description": "The public key.", | 
|  | 344 | "Value":       "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}", | 
|  | 345 | }, | 
|  | 346 | }, | 
|  | 347 | Parameters: map[string]interface{}{ | 
|  | 348 | "name": map[string]interface{}{ | 
|  | 349 | "Description": "The name of the key pair.", | 
|  | 350 | "Type":        "String", | 
|  | 351 | }, | 
|  | 352 | "public_key": map[string]interface{}{ | 
|  | 353 | "Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.", | 
|  | 354 | "Type":        "String", | 
|  | 355 | }, | 
|  | 356 | "save_private_key": map[string]interface{}{ | 
|  | 357 | "AllowedValues": []string{ | 
|  | 358 | "True", | 
|  | 359 | "true", | 
|  | 360 | "False", | 
|  | 361 | "false", | 
|  | 362 | }, | 
|  | 363 | "Default":     false, | 
|  | 364 | "Description": "True if the system should remember a generated private key; False otherwise.", | 
|  | 365 | "Type":        "String", | 
|  | 366 | }, | 
|  | 367 | }, | 
|  | 368 | Resources: map[string]interface{}{ | 
|  | 369 | "KeyPair": map[string]interface{}{ | 
|  | 370 | "Properties": map[string]interface{}{ | 
|  | 371 | "name": map[string]interface{}{ | 
|  | 372 | "Ref": "name", | 
|  | 373 | }, | 
|  | 374 | "public_key": map[string]interface{}{ | 
|  | 375 | "Ref": "public_key", | 
|  | 376 | }, | 
|  | 377 | "save_private_key": map[string]interface{}{ | 
|  | 378 | "Ref": "save_private_key", | 
|  | 379 | }, | 
|  | 380 | }, | 
|  | 381 | "Type": "OS::Nova::KeyPair", | 
|  | 382 | }, | 
|  | 383 | }, | 
|  | 384 | } | 
|  | 385 |  | 
| Jon Perritt | bba201b | 2015-02-08 21:12:38 -0700 | [diff] [blame] | 386 | // GetTemplateOutput represents the response body from a Template request. | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 387 | const GetTemplateOutput = ` | 
|  | 388 | { | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 389 | "HeatTemplateFormatVersion": "2012-12-12", | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 390 | "Outputs": { | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 391 | "private_key": { | 
|  | 392 | "Description": "The private key if it has been saved.", | 
|  | 393 | "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"private_key\"]}" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 394 | }, | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 395 | "public_key": { | 
|  | 396 | "Description": "The public key.", | 
|  | 397 | "Value": "{\"Fn::GetAtt\": [\"KeyPair\", \"public_key\"]}" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 398 | } | 
|  | 399 | }, | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 400 | "Parameters": { | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 401 | "name": { | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 402 | "Description": "The name of the key pair.", | 
|  | 403 | "Type": "String" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 404 | }, | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 405 | "public_key": { | 
|  | 406 | "Description": "The optional public key. This allows users to supply the public key from a pre-existing key pair. If not supplied, a new key pair will be generated.", | 
|  | 407 | "Type": "String" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 408 | }, | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 409 | "save_private_key": { | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 410 | "AllowedValues": [ | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 411 | "True", | 
|  | 412 | "true", | 
|  | 413 | "False", | 
|  | 414 | "false" | 
|  | 415 | ], | 
|  | 416 | "Default": false, | 
|  | 417 | "Description": "True if the system should remember a generated private key; False otherwise.", | 
|  | 418 | "Type": "String" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 419 | } | 
|  | 420 | }, | 
|  | 421 | "Resources": { | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 422 | "KeyPair": { | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 423 | "Properties": { | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 424 | "name": { | 
|  | 425 | "Ref": "name" | 
|  | 426 | }, | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 427 | "public_key": { | 
|  | 428 | "Ref": "public_key" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 429 | }, | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 430 | "save_private_key": { | 
|  | 431 | "Ref": "save_private_key" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 432 | } | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 433 | }, | 
|  | 434 | "Type": "OS::Nova::KeyPair" | 
| Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 435 | } | 
|  | 436 | } | 
|  | 437 | }` | 
| Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 438 |  | 
|  | 439 | // HandleGetTemplateSuccessfully creates an HTTP handler at `/resource_types/OS::Heat::AResourceName/template` | 
|  | 440 | // on the test handler mux that responds with a `Template` response. | 
|  | 441 | func HandleGetTemplateSuccessfully(t *testing.T, output string) { | 
|  | 442 | th.Mux.HandleFunc("/resource_types/OS::Heat::AResourceName/template", func(w http.ResponseWriter, r *http.Request) { | 
|  | 443 | th.TestMethod(t, r, "GET") | 
|  | 444 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 445 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 446 |  | 
|  | 447 | w.Header().Set("Content-Type", "application/json") | 
|  | 448 | w.WriteHeader(http.StatusOK) | 
|  | 449 | fmt.Fprintf(w, output) | 
|  | 450 | }) | 
|  | 451 | } |