Jon Perritt | 034ef07 | 2015-02-03 13:14:44 -0700 | [diff] [blame] | 1 | package stacks |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | os "github.com/rackspace/gophercloud/openstack/orchestration/v1/stacks" |
Jon Perritt | 2870e04 | 2015-02-04 15:50:08 -0700 | [diff] [blame] | 7 | "github.com/rackspace/gophercloud/pagination" |
Jon Perritt | 034ef07 | 2015-02-03 13:14:44 -0700 | [diff] [blame] | 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
| 12 | func TestCreateStack(t *testing.T) { |
| 13 | th.SetupHTTP() |
| 14 | defer th.TeardownHTTP() |
| 15 | os.HandleCreateSuccessfully(t, CreateOutput) |
| 16 | |
| 17 | createOpts := os.CreateOpts{ |
| 18 | Name: "stackcreated", |
| 19 | Timeout: 60, |
| 20 | Template: `{ |
| 21 | "outputs": { |
| 22 | "db_host": { |
| 23 | "value": { |
| 24 | "get_attr": [ |
| 25 | "db", |
| 26 | "hostname" |
| 27 | ] |
| 28 | } |
| 29 | } |
| 30 | }, |
| 31 | "heat_template_version": "2014-10-16", |
| 32 | "description": "HEAT template for creating a Cloud Database.\n", |
| 33 | "parameters": { |
| 34 | "db_name": { |
| 35 | "default": "wordpress", |
| 36 | "type": "string", |
| 37 | "description": "the name for the database", |
| 38 | "constraints": [ |
| 39 | { |
| 40 | "length": { |
| 41 | "max": 64, |
| 42 | "min": 1 |
| 43 | }, |
| 44 | "description": "must be between 1 and 64 characters" |
| 45 | }, |
| 46 | { |
| 47 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 48 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 49 | } |
| 50 | ] |
| 51 | }, |
| 52 | "db_instance_name": { |
| 53 | "default": "Cloud_DB", |
| 54 | "type": "string", |
| 55 | "description": "the database instance name" |
| 56 | }, |
| 57 | "db_username": { |
| 58 | "default": "admin", |
| 59 | "hidden": true, |
| 60 | "type": "string", |
| 61 | "description": "database admin account username", |
| 62 | "constraints": [ |
| 63 | { |
| 64 | "length": { |
| 65 | "max": 16, |
| 66 | "min": 1 |
| 67 | }, |
| 68 | "description": "must be between 1 and 16 characters" |
| 69 | }, |
| 70 | { |
| 71 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 72 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 73 | } |
| 74 | ] |
| 75 | }, |
| 76 | "db_volume_size": { |
| 77 | "default": 30, |
| 78 | "type": "number", |
| 79 | "description": "database volume size (in GB)", |
| 80 | "constraints": [ |
| 81 | { |
| 82 | "range": { |
| 83 | "max": 1024, |
| 84 | "min": 1 |
| 85 | }, |
| 86 | "description": "must be between 1 and 1024 GB" |
| 87 | } |
| 88 | ] |
| 89 | }, |
| 90 | "db_flavor": { |
| 91 | "default": "1GB Instance", |
| 92 | "type": "string", |
| 93 | "description": "database instance size", |
| 94 | "constraints": [ |
| 95 | { |
| 96 | "description": "must be a valid cloud database flavor", |
| 97 | "allowed_values": [ |
| 98 | "1GB Instance", |
| 99 | "2GB Instance", |
| 100 | "4GB Instance", |
| 101 | "8GB Instance", |
| 102 | "16GB Instance" |
| 103 | ] |
| 104 | } |
| 105 | ] |
| 106 | }, |
| 107 | "db_password": { |
| 108 | "default": "admin", |
| 109 | "hidden": true, |
| 110 | "type": "string", |
| 111 | "description": "database admin account password", |
| 112 | "constraints": [ |
| 113 | { |
| 114 | "length": { |
| 115 | "max": 41, |
| 116 | "min": 1 |
| 117 | }, |
| 118 | "description": "must be between 1 and 14 characters" |
| 119 | }, |
| 120 | { |
| 121 | "allowed_pattern": "[a-zA-Z0-9]*", |
| 122 | "description": "must contain only alphanumeric characters." |
| 123 | } |
| 124 | ] |
| 125 | } |
| 126 | }, |
| 127 | "resources": { |
| 128 | "db": { |
| 129 | "type": "OS::Trove::Instance", |
| 130 | "properties": { |
| 131 | "flavor": { |
| 132 | "get_param": "db_flavor" |
| 133 | }, |
| 134 | "size": { |
| 135 | "get_param": "db_volume_size" |
| 136 | }, |
| 137 | "users": [ |
| 138 | { |
| 139 | "password": { |
| 140 | "get_param": "db_password" |
| 141 | }, |
| 142 | "name": { |
| 143 | "get_param": "db_username" |
| 144 | }, |
| 145 | "databases": [ |
| 146 | { |
| 147 | "get_param": "db_name" |
| 148 | } |
| 149 | ] |
| 150 | } |
| 151 | ], |
| 152 | "name": { |
| 153 | "get_param": "db_instance_name" |
| 154 | }, |
| 155 | "databases": [ |
| 156 | { |
| 157 | "name": { |
| 158 | "get_param": "db_name" |
| 159 | } |
| 160 | } |
| 161 | ] |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | }`, |
| 166 | DisableRollback: os.Disable, |
| 167 | } |
| 168 | actual, err := Create(fake.ServiceClient(), createOpts).Extract() |
| 169 | th.AssertNoErr(t, err) |
| 170 | |
| 171 | expected := CreateExpected |
| 172 | th.AssertDeepEquals(t, expected, actual) |
| 173 | } |
Jon Perritt | 1d3bc4b | 2015-02-04 12:06:19 -0700 | [diff] [blame] | 174 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 175 | func TestCreateStackNewTemplateFormat(t *testing.T) { |
| 176 | th.SetupHTTP() |
| 177 | defer th.TeardownHTTP() |
| 178 | os.HandleCreateSuccessfully(t, CreateOutput) |
| 179 | |
| 180 | createOpts := os.CreateOpts{ |
| 181 | Name: "stackcreated", |
| 182 | Timeout: 60, |
| 183 | TemplateOpts: new(os.Template), |
| 184 | DisableRollback: os.Disable, |
| 185 | } |
| 186 | createOpts.TemplateOpts.Bin = []byte(`{ |
| 187 | "outputs": { |
| 188 | "db_host": { |
| 189 | "value": { |
| 190 | "get_attr": [ |
| 191 | "db", |
| 192 | "hostname" |
| 193 | ] |
| 194 | } |
| 195 | } |
| 196 | }, |
| 197 | "heat_template_version": "2014-10-16", |
| 198 | "description": "HEAT template for creating a Cloud Database.\n", |
| 199 | "parameters": { |
| 200 | "db_name": { |
| 201 | "default": "wordpress", |
| 202 | "type": "string", |
| 203 | "description": "the name for the database", |
| 204 | "constraints": [ |
| 205 | { |
| 206 | "length": { |
| 207 | "max": 64, |
| 208 | "min": 1 |
| 209 | }, |
| 210 | "description": "must be between 1 and 64 characters" |
| 211 | }, |
| 212 | { |
| 213 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 214 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 215 | } |
| 216 | ] |
| 217 | }, |
| 218 | "db_instance_name": { |
| 219 | "default": "Cloud_DB", |
| 220 | "type": "string", |
| 221 | "description": "the database instance name" |
| 222 | }, |
| 223 | "db_username": { |
| 224 | "default": "admin", |
| 225 | "hidden": true, |
| 226 | "type": "string", |
| 227 | "description": "database admin account username", |
| 228 | "constraints": [ |
| 229 | { |
| 230 | "length": { |
| 231 | "max": 16, |
| 232 | "min": 1 |
| 233 | }, |
| 234 | "description": "must be between 1 and 16 characters" |
| 235 | }, |
| 236 | { |
| 237 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 238 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 239 | } |
| 240 | ] |
| 241 | }, |
| 242 | "db_volume_size": { |
| 243 | "default": 30, |
| 244 | "type": "number", |
| 245 | "description": "database volume size (in GB)", |
| 246 | "constraints": [ |
| 247 | { |
| 248 | "range": { |
| 249 | "max": 1024, |
| 250 | "min": 1 |
| 251 | }, |
| 252 | "description": "must be between 1 and 1024 GB" |
| 253 | } |
| 254 | ] |
| 255 | }, |
| 256 | "db_flavor": { |
| 257 | "default": "1GB Instance", |
| 258 | "type": "string", |
| 259 | "description": "database instance size", |
| 260 | "constraints": [ |
| 261 | { |
| 262 | "description": "must be a valid cloud database flavor", |
| 263 | "allowed_values": [ |
| 264 | "1GB Instance", |
| 265 | "2GB Instance", |
| 266 | "4GB Instance", |
| 267 | "8GB Instance", |
| 268 | "16GB Instance" |
| 269 | ] |
| 270 | } |
| 271 | ] |
| 272 | }, |
| 273 | "db_password": { |
| 274 | "default": "admin", |
| 275 | "hidden": true, |
| 276 | "type": "string", |
| 277 | "description": "database admin account password", |
| 278 | "constraints": [ |
| 279 | { |
| 280 | "length": { |
| 281 | "max": 41, |
| 282 | "min": 1 |
| 283 | }, |
| 284 | "description": "must be between 1 and 14 characters" |
| 285 | }, |
| 286 | { |
| 287 | "allowed_pattern": "[a-zA-Z0-9]*", |
| 288 | "description": "must contain only alphanumeric characters." |
| 289 | } |
| 290 | ] |
| 291 | } |
| 292 | }, |
| 293 | "resources": { |
| 294 | "db": { |
| 295 | "type": "OS::Trove::Instance", |
| 296 | "properties": { |
| 297 | "flavor": { |
| 298 | "get_param": "db_flavor" |
| 299 | }, |
| 300 | "size": { |
| 301 | "get_param": "db_volume_size" |
| 302 | }, |
| 303 | "users": [ |
| 304 | { |
| 305 | "password": { |
| 306 | "get_param": "db_password" |
| 307 | }, |
| 308 | "name": { |
| 309 | "get_param": "db_username" |
| 310 | }, |
| 311 | "databases": [ |
| 312 | { |
| 313 | "get_param": "db_name" |
| 314 | } |
| 315 | ] |
| 316 | } |
| 317 | ], |
| 318 | "name": { |
| 319 | "get_param": "db_instance_name" |
| 320 | }, |
| 321 | "databases": [ |
| 322 | { |
| 323 | "name": { |
| 324 | "get_param": "db_name" |
| 325 | } |
| 326 | } |
| 327 | ] |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | }`) |
| 332 | actual, err := Create(fake.ServiceClient(), createOpts).Extract() |
| 333 | th.AssertNoErr(t, err) |
| 334 | |
| 335 | expected := CreateExpected |
| 336 | th.AssertDeepEquals(t, expected, actual) |
| 337 | } |
| 338 | |
Jon Perritt | 1d3bc4b | 2015-02-04 12:06:19 -0700 | [diff] [blame] | 339 | func TestAdoptStack(t *testing.T) { |
| 340 | th.SetupHTTP() |
| 341 | defer th.TeardownHTTP() |
| 342 | os.HandleCreateSuccessfully(t, CreateOutput) |
| 343 | |
| 344 | adoptOpts := os.AdoptOpts{ |
| 345 | AdoptStackData: `{\"environment\":{\"parameters\":{}}, \"status\":\"COMPLETE\",\"name\": \"trovestack\",\n \"template\": {\n \"outputs\": {\n \"db_host\": {\n \"value\": {\n \"get_attr\": [\n \"db\",\n \"hostname\"\n ]\n }\n }\n },\n \"heat_template_version\": \"2014-10-16\",\n \"description\": \"HEAT template for creating a Cloud Database.\\n\",\n \"parameters\": {\n \"db_instance_name\": {\n \"default\": \"Cloud_DB\",\n \"type\": \"string\",\n \"description\": \"the database instance name\"\n },\n \"db_flavor\": {\n \"default\": \"1GB Instance\",\n \"type\": \"string\",\n \"description\": \"database instance size\",\n \"constraints\": [\n {\n \"description\": \"must be a valid cloud database flavor\",\n \"allowed_values\": [\n \"1GB Instance\",\n \"2GB Instance\",\n \"4GB Instance\",\n \"8GB Instance\",\n \"16GB Instance\"\n ]\n }\n ]\n },\n \"db_password\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account password\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 41,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 14 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z0-9]*\",\n \"description\": \"must contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_name\": {\n \"default\": \"wordpress\",\n \"type\": \"string\",\n \"description\": \"the name for the database\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 64,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 64 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_username\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account username\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 16,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 16 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_volume_size\": {\n \"default\": 30,\n \"type\": \"number\",\n \"description\": \"database volume size (in GB)\",\n \"constraints\": [\n {\n \"range\": {\n \"max\": 1024,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 1024 GB\"\n }\n ]\n }\n },\n \"resources\": {\n \"db\": {\n \"type\": \"OS::Trove::Instance\",\n \"properties\": {\n \"flavor\": {\n \"get_param\": \"db_flavor\"\n },\n \"databases\": [\n {\n \"name\": {\n \"get_param\": \"db_name\"\n }\n }\n ],\n \"users\": [\n {\n \"password\": {\n \"get_param\": \"db_password\"\n },\n \"name\": {\n \"get_param\": \"db_username\"\n },\n \"databases\": [\n {\n \"get_param\": \"db_name\"\n }\n ]\n }\n ],\n \"name\": {\n \"get_param\": \"db_instance_name\"\n },\n \"size\": {\n \"get_param\": \"db_volume_size\"\n }\n }\n }\n }\n },\n \"action\": \"CREATE\",\n \"id\": \"exxxxd-7xx5-4xxb-bxx2-cxxxxxx5\",\n \"resources\": {\n \"db\": {\n \"status\": \"COMPLETE\",\n \"name\": \"db\",\n \"resource_data\": {},\n \"resource_id\": \"exxxx2-9xx0-4xxxb-bxx2-dxxxxxx4\",\n \"action\": \"CREATE\",\n \"type\": \"OS::Trove::Instance\",\n \"metadata\": {}\n }\n }\n},`, |
| 346 | Name: "stackadopted", |
| 347 | Timeout: 60, |
| 348 | Template: `{ |
| 349 | "outputs": { |
| 350 | "db_host": { |
| 351 | "value": { |
| 352 | "get_attr": [ |
| 353 | "db", |
| 354 | "hostname" |
| 355 | ] |
| 356 | } |
| 357 | } |
| 358 | }, |
| 359 | "heat_template_version": "2014-10-16", |
| 360 | "description": "HEAT template for creating a Cloud Database.\n", |
| 361 | "parameters": { |
| 362 | "db_name": { |
| 363 | "default": "wordpress", |
| 364 | "type": "string", |
| 365 | "description": "the name for the database", |
| 366 | "constraints": [ |
| 367 | { |
| 368 | "length": { |
| 369 | "max": 64, |
| 370 | "min": 1 |
| 371 | }, |
| 372 | "description": "must be between 1 and 64 characters" |
| 373 | }, |
| 374 | { |
| 375 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 376 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 377 | } |
| 378 | ] |
| 379 | }, |
| 380 | "db_instance_name": { |
| 381 | "default": "Cloud_DB", |
| 382 | "type": "string", |
| 383 | "description": "the database instance name" |
| 384 | }, |
| 385 | "db_username": { |
| 386 | "default": "admin", |
| 387 | "hidden": true, |
| 388 | "type": "string", |
| 389 | "description": "database admin account username", |
| 390 | "constraints": [ |
| 391 | { |
| 392 | "length": { |
| 393 | "max": 16, |
| 394 | "min": 1 |
| 395 | }, |
| 396 | "description": "must be between 1 and 16 characters" |
| 397 | }, |
| 398 | { |
| 399 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 400 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 401 | } |
| 402 | ] |
| 403 | }, |
| 404 | "db_volume_size": { |
| 405 | "default": 30, |
| 406 | "type": "number", |
| 407 | "description": "database volume size (in GB)", |
| 408 | "constraints": [ |
| 409 | { |
| 410 | "range": { |
| 411 | "max": 1024, |
| 412 | "min": 1 |
| 413 | }, |
| 414 | "description": "must be between 1 and 1024 GB" |
| 415 | } |
| 416 | ] |
| 417 | }, |
| 418 | "db_flavor": { |
| 419 | "default": "1GB Instance", |
| 420 | "type": "string", |
| 421 | "description": "database instance size", |
| 422 | "constraints": [ |
| 423 | { |
| 424 | "description": "must be a valid cloud database flavor", |
| 425 | "allowed_values": [ |
| 426 | "1GB Instance", |
| 427 | "2GB Instance", |
| 428 | "4GB Instance", |
| 429 | "8GB Instance", |
| 430 | "16GB Instance" |
| 431 | ] |
| 432 | } |
| 433 | ] |
| 434 | }, |
| 435 | "db_password": { |
| 436 | "default": "admin", |
| 437 | "hidden": true, |
| 438 | "type": "string", |
| 439 | "description": "database admin account password", |
| 440 | "constraints": [ |
| 441 | { |
| 442 | "length": { |
| 443 | "max": 41, |
| 444 | "min": 1 |
| 445 | }, |
| 446 | "description": "must be between 1 and 14 characters" |
| 447 | }, |
| 448 | { |
| 449 | "allowed_pattern": "[a-zA-Z0-9]*", |
| 450 | "description": "must contain only alphanumeric characters." |
| 451 | } |
| 452 | ] |
| 453 | } |
| 454 | }, |
| 455 | "resources": { |
| 456 | "db": { |
| 457 | "type": "OS::Trove::Instance", |
| 458 | "properties": { |
| 459 | "flavor": { |
| 460 | "get_param": "db_flavor" |
| 461 | }, |
| 462 | "size": { |
| 463 | "get_param": "db_volume_size" |
| 464 | }, |
| 465 | "users": [ |
| 466 | { |
| 467 | "password": { |
| 468 | "get_param": "db_password" |
| 469 | }, |
| 470 | "name": { |
| 471 | "get_param": "db_username" |
| 472 | }, |
| 473 | "databases": [ |
| 474 | { |
| 475 | "get_param": "db_name" |
| 476 | } |
| 477 | ] |
| 478 | } |
| 479 | ], |
| 480 | "name": { |
| 481 | "get_param": "db_instance_name" |
| 482 | }, |
| 483 | "databases": [ |
| 484 | { |
| 485 | "name": { |
| 486 | "get_param": "db_name" |
| 487 | } |
| 488 | } |
| 489 | ] |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | }`, |
| 494 | DisableRollback: os.Disable, |
| 495 | } |
| 496 | actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract() |
| 497 | th.AssertNoErr(t, err) |
| 498 | |
| 499 | expected := CreateExpected |
| 500 | th.AssertDeepEquals(t, expected, actual) |
| 501 | } |
Jon Perritt | 2870e04 | 2015-02-04 15:50:08 -0700 | [diff] [blame] | 502 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 503 | func TestAdoptStackNewTemplateFormat(t *testing.T) { |
| 504 | th.SetupHTTP() |
| 505 | defer th.TeardownHTTP() |
| 506 | os.HandleCreateSuccessfully(t, CreateOutput) |
| 507 | template := new(os.Template) |
| 508 | template.Bin = []byte(`{ |
| 509 | "outputs": { |
| 510 | "db_host": { |
| 511 | "value": { |
| 512 | "get_attr": [ |
| 513 | "db", |
| 514 | "hostname" |
| 515 | ] |
| 516 | } |
| 517 | } |
| 518 | }, |
| 519 | "heat_template_version": "2014-10-16", |
| 520 | "description": "HEAT template for creating a Cloud Database.\n", |
| 521 | "parameters": { |
| 522 | "db_name": { |
| 523 | "default": "wordpress", |
| 524 | "type": "string", |
| 525 | "description": "the name for the database", |
| 526 | "constraints": [ |
| 527 | { |
| 528 | "length": { |
| 529 | "max": 64, |
| 530 | "min": 1 |
| 531 | }, |
| 532 | "description": "must be between 1 and 64 characters" |
| 533 | }, |
| 534 | { |
| 535 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 536 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 537 | } |
| 538 | ] |
| 539 | }, |
| 540 | "db_instance_name": { |
| 541 | "default": "Cloud_DB", |
| 542 | "type": "string", |
| 543 | "description": "the database instance name" |
| 544 | }, |
| 545 | "db_username": { |
| 546 | "default": "admin", |
| 547 | "hidden": true, |
| 548 | "type": "string", |
| 549 | "description": "database admin account username", |
| 550 | "constraints": [ |
| 551 | { |
| 552 | "length": { |
| 553 | "max": 16, |
| 554 | "min": 1 |
| 555 | }, |
| 556 | "description": "must be between 1 and 16 characters" |
| 557 | }, |
| 558 | { |
| 559 | "allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*", |
| 560 | "description": "must begin with a letter and contain only alphanumeric characters." |
| 561 | } |
| 562 | ] |
| 563 | }, |
| 564 | "db_volume_size": { |
| 565 | "default": 30, |
| 566 | "type": "number", |
| 567 | "description": "database volume size (in GB)", |
| 568 | "constraints": [ |
| 569 | { |
| 570 | "range": { |
| 571 | "max": 1024, |
| 572 | "min": 1 |
| 573 | }, |
| 574 | "description": "must be between 1 and 1024 GB" |
| 575 | } |
| 576 | ] |
| 577 | }, |
| 578 | "db_flavor": { |
| 579 | "default": "1GB Instance", |
| 580 | "type": "string", |
| 581 | "description": "database instance size", |
| 582 | "constraints": [ |
| 583 | { |
| 584 | "description": "must be a valid cloud database flavor", |
| 585 | "allowed_values": [ |
| 586 | "1GB Instance", |
| 587 | "2GB Instance", |
| 588 | "4GB Instance", |
| 589 | "8GB Instance", |
| 590 | "16GB Instance" |
| 591 | ] |
| 592 | } |
| 593 | ] |
| 594 | }, |
| 595 | "db_password": { |
| 596 | "default": "admin", |
| 597 | "hidden": true, |
| 598 | "type": "string", |
| 599 | "description": "database admin account password", |
| 600 | "constraints": [ |
| 601 | { |
| 602 | "length": { |
| 603 | "max": 41, |
| 604 | "min": 1 |
| 605 | }, |
| 606 | "description": "must be between 1 and 14 characters" |
| 607 | }, |
| 608 | { |
| 609 | "allowed_pattern": "[a-zA-Z0-9]*", |
| 610 | "description": "must contain only alphanumeric characters." |
| 611 | } |
| 612 | ] |
| 613 | } |
| 614 | }, |
| 615 | "resources": { |
| 616 | "db": { |
| 617 | "type": "OS::Trove::Instance", |
| 618 | "properties": { |
| 619 | "flavor": { |
| 620 | "get_param": "db_flavor" |
| 621 | }, |
| 622 | "size": { |
| 623 | "get_param": "db_volume_size" |
| 624 | }, |
| 625 | "users": [ |
| 626 | { |
| 627 | "password": { |
| 628 | "get_param": "db_password" |
| 629 | }, |
| 630 | "name": { |
| 631 | "get_param": "db_username" |
| 632 | }, |
| 633 | "databases": [ |
| 634 | { |
| 635 | "get_param": "db_name" |
| 636 | } |
| 637 | ] |
| 638 | } |
| 639 | ], |
| 640 | "name": { |
| 641 | "get_param": "db_instance_name" |
| 642 | }, |
| 643 | "databases": [ |
| 644 | { |
| 645 | "name": { |
| 646 | "get_param": "db_name" |
| 647 | } |
| 648 | } |
| 649 | ] |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | }`) |
| 654 | |
| 655 | adoptOpts := os.AdoptOpts{ |
| 656 | AdoptStackData: `{\"environment\":{\"parameters\":{}}, \"status\":\"COMPLETE\",\"name\": \"trovestack\",\n \"template\": {\n \"outputs\": {\n \"db_host\": {\n \"value\": {\n \"get_attr\": [\n \"db\",\n \"hostname\"\n ]\n }\n }\n },\n \"heat_template_version\": \"2014-10-16\",\n \"description\": \"HEAT template for creating a Cloud Database.\\n\",\n \"parameters\": {\n \"db_instance_name\": {\n \"default\": \"Cloud_DB\",\n \"type\": \"string\",\n \"description\": \"the database instance name\"\n },\n \"db_flavor\": {\n \"default\": \"1GB Instance\",\n \"type\": \"string\",\n \"description\": \"database instance size\",\n \"constraints\": [\n {\n \"description\": \"must be a valid cloud database flavor\",\n \"allowed_values\": [\n \"1GB Instance\",\n \"2GB Instance\",\n \"4GB Instance\",\n \"8GB Instance\",\n \"16GB Instance\"\n ]\n }\n ]\n },\n \"db_password\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account password\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 41,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 14 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z0-9]*\",\n \"description\": \"must contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_name\": {\n \"default\": \"wordpress\",\n \"type\": \"string\",\n \"description\": \"the name for the database\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 64,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 64 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_username\": {\n \"default\": \"admin\",\n \"hidden\": true,\n \"type\": \"string\",\n \"description\": \"database admin account username\",\n \"constraints\": [\n {\n \"length\": {\n \"max\": 16,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 16 characters\"\n },\n {\n \"allowed_pattern\": \"[a-zA-Z][a-zA-Z0-9]*\",\n \"description\": \"must begin with a letter and contain only alphanumeric characters.\"\n }\n ]\n },\n \"db_volume_size\": {\n \"default\": 30,\n \"type\": \"number\",\n \"description\": \"database volume size (in GB)\",\n \"constraints\": [\n {\n \"range\": {\n \"max\": 1024,\n \"min\": 1\n },\n \"description\": \"must be between 1 and 1024 GB\"\n }\n ]\n }\n },\n \"resources\": {\n \"db\": {\n \"type\": \"OS::Trove::Instance\",\n \"properties\": {\n \"flavor\": {\n \"get_param\": \"db_flavor\"\n },\n \"databases\": [\n {\n \"name\": {\n \"get_param\": \"db_name\"\n }\n }\n ],\n \"users\": [\n {\n \"password\": {\n \"get_param\": \"db_password\"\n },\n \"name\": {\n \"get_param\": \"db_username\"\n },\n \"databases\": [\n {\n \"get_param\": \"db_name\"\n }\n ]\n }\n ],\n \"name\": {\n \"get_param\": \"db_instance_name\"\n },\n \"size\": {\n \"get_param\": \"db_volume_size\"\n }\n }\n }\n }\n },\n \"action\": \"CREATE\",\n \"id\": \"exxxxd-7xx5-4xxb-bxx2-cxxxxxx5\",\n \"resources\": {\n \"db\": {\n \"status\": \"COMPLETE\",\n \"name\": \"db\",\n \"resource_data\": {},\n \"resource_id\": \"exxxx2-9xx0-4xxxb-bxx2-dxxxxxx4\",\n \"action\": \"CREATE\",\n \"type\": \"OS::Trove::Instance\",\n \"metadata\": {}\n }\n }\n},`, |
| 657 | Name: "stackadopted", |
| 658 | Timeout: 60, |
| 659 | TemplateOpts: template, |
| 660 | DisableRollback: os.Disable, |
| 661 | } |
| 662 | actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract() |
| 663 | th.AssertNoErr(t, err) |
| 664 | |
| 665 | expected := CreateExpected |
| 666 | th.AssertDeepEquals(t, expected, actual) |
| 667 | } |
| 668 | |
Jon Perritt | 2870e04 | 2015-02-04 15:50:08 -0700 | [diff] [blame] | 669 | func TestListStack(t *testing.T) { |
| 670 | th.SetupHTTP() |
| 671 | defer th.TeardownHTTP() |
| 672 | os.HandleListSuccessfully(t, os.FullListOutput) |
| 673 | |
| 674 | count := 0 |
| 675 | err := List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) { |
| 676 | count++ |
| 677 | actual, err := os.ExtractStacks(page) |
| 678 | th.AssertNoErr(t, err) |
| 679 | |
| 680 | th.CheckDeepEquals(t, os.ListExpected, actual) |
| 681 | |
| 682 | return true, nil |
| 683 | }) |
| 684 | th.AssertNoErr(t, err) |
| 685 | th.CheckEquals(t, count, 1) |
| 686 | } |
Jon Perritt | a6346d9 | 2015-02-04 17:54:52 -0700 | [diff] [blame] | 687 | |
| 688 | func TestUpdateStack(t *testing.T) { |
| 689 | th.SetupHTTP() |
| 690 | defer th.TeardownHTTP() |
| 691 | os.HandleUpdateSuccessfully(t) |
| 692 | |
| 693 | updateOpts := os.UpdateOpts{ |
| 694 | Template: ` |
| 695 | { |
| 696 | "heat_template_version": "2013-05-23", |
| 697 | "description": "Simple template to test heat commands", |
| 698 | "parameters": { |
| 699 | "flavor": { |
| 700 | "default": "m1.tiny", |
| 701 | "type": "string" |
| 702 | } |
| 703 | }, |
| 704 | "resources": { |
| 705 | "hello_world": { |
| 706 | "type":"OS::Nova::Server", |
| 707 | "properties": { |
| 708 | "key_name": "heat_key", |
| 709 | "flavor": { |
| 710 | "get_param": "flavor" |
| 711 | }, |
| 712 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 713 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | }`, |
| 718 | } |
| 719 | err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() |
| 720 | th.AssertNoErr(t, err) |
| 721 | } |
Jon Perritt | 27a0b3e | 2015-02-04 18:04:35 -0700 | [diff] [blame] | 722 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 723 | func TestUpdateStackNewTemplateFormat(t *testing.T) { |
| 724 | th.SetupHTTP() |
| 725 | defer th.TeardownHTTP() |
| 726 | os.HandleUpdateSuccessfully(t) |
| 727 | |
| 728 | updateOpts := os.UpdateOpts{ |
| 729 | TemplateOpts: new(os.Template), |
| 730 | } |
| 731 | updateOpts.TemplateOpts.Bin = []byte(` |
| 732 | { |
| 733 | "stack_name": "postman_stack", |
| 734 | "template": { |
| 735 | "heat_template_version": "2013-05-23", |
| 736 | "description": "Simple template to test heat commands", |
| 737 | "parameters": { |
| 738 | "flavor": { |
| 739 | "default": "m1.tiny", |
| 740 | "type": "string" |
| 741 | } |
| 742 | }, |
| 743 | "resources": { |
| 744 | "hello_world": { |
| 745 | "type": "OS::Nova::Server", |
| 746 | "properties": { |
| 747 | "key_name": "heat_key", |
| 748 | "flavor": { |
| 749 | "get_param": "flavor" |
| 750 | }, |
| 751 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 752 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | }`) |
| 758 | err := Update(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada", updateOpts).ExtractErr() |
| 759 | th.AssertNoErr(t, err) |
| 760 | } |
| 761 | |
Jon Perritt | 27a0b3e | 2015-02-04 18:04:35 -0700 | [diff] [blame] | 762 | func TestDeleteStack(t *testing.T) { |
| 763 | th.SetupHTTP() |
| 764 | defer th.TeardownHTTP() |
| 765 | os.HandleDeleteSuccessfully(t) |
| 766 | |
| 767 | err := Delete(fake.ServiceClient(), "gophercloud-test-stack-2", "db6977b2-27aa-4775-9ae7-6213212d4ada").ExtractErr() |
| 768 | th.AssertNoErr(t, err) |
| 769 | } |
Jon Perritt | 68c2717 | 2015-02-04 18:55:38 -0700 | [diff] [blame] | 770 | |
| 771 | func TestPreviewStack(t *testing.T) { |
| 772 | th.SetupHTTP() |
| 773 | defer th.TeardownHTTP() |
| 774 | os.HandlePreviewSuccessfully(t, os.GetOutput) |
| 775 | |
| 776 | previewOpts := os.PreviewOpts{ |
| 777 | Name: "stackcreated", |
| 778 | Timeout: 60, |
| 779 | Template: ` |
| 780 | { |
| 781 | "stack_name": "postman_stack", |
| 782 | "template": { |
| 783 | "heat_template_version": "2013-05-23", |
| 784 | "description": "Simple template to test heat commands", |
| 785 | "parameters": { |
| 786 | "flavor": { |
| 787 | "default": "m1.tiny", |
| 788 | "type": "string" |
| 789 | } |
| 790 | }, |
| 791 | "resources": { |
| 792 | "hello_world": { |
| 793 | "type":"OS::Nova::Server", |
| 794 | "properties": { |
| 795 | "key_name": "heat_key", |
| 796 | "flavor": { |
| 797 | "get_param": "flavor" |
| 798 | }, |
| 799 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 800 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | }`, |
| 806 | DisableRollback: os.Disable, |
| 807 | } |
| 808 | actual, err := Preview(fake.ServiceClient(), previewOpts).Extract() |
| 809 | th.AssertNoErr(t, err) |
| 810 | |
| 811 | expected := os.PreviewExpected |
| 812 | th.AssertDeepEquals(t, expected, actual) |
| 813 | } |
Jon Perritt | 9b81b8c | 2015-02-05 12:55:53 -0700 | [diff] [blame] | 814 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 815 | func TestPreviewStackNewTemplateFormat(t *testing.T) { |
| 816 | th.SetupHTTP() |
| 817 | defer th.TeardownHTTP() |
| 818 | os.HandlePreviewSuccessfully(t, os.GetOutput) |
| 819 | |
| 820 | previewOpts := os.PreviewOpts{ |
| 821 | Name: "stackcreated", |
| 822 | Timeout: 60, |
| 823 | TemplateOpts: new(os.Template), |
| 824 | DisableRollback: os.Disable, |
| 825 | } |
| 826 | previewOpts.TemplateOpts.Bin = []byte(` |
| 827 | { |
| 828 | "stack_name": "postman_stack", |
| 829 | "template": { |
| 830 | "heat_template_version": "2013-05-23", |
| 831 | "description": "Simple template to test heat commands", |
| 832 | "parameters": { |
| 833 | "flavor": { |
| 834 | "default": "m1.tiny", |
| 835 | "type": "string" |
| 836 | } |
| 837 | }, |
| 838 | "resources": { |
| 839 | "hello_world": { |
| 840 | "type": "OS::Nova::Server", |
| 841 | "properties": { |
| 842 | "key_name": "heat_key", |
| 843 | "flavor": { |
| 844 | "get_param": "flavor" |
| 845 | }, |
| 846 | "image": "ad091b52-742f-469e-8f3c-fd81cadf0743", |
| 847 | "user_data": "#!/bin/bash -xv\necho \"hello world\" > /root/hello-world.txt\n" |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | } |
| 852 | }`) |
| 853 | actual, err := Preview(fake.ServiceClient(), previewOpts).Extract() |
| 854 | th.AssertNoErr(t, err) |
| 855 | |
| 856 | expected := os.PreviewExpected |
| 857 | th.AssertDeepEquals(t, expected, actual) |
| 858 | } |
| 859 | |
Jon Perritt | 9b81b8c | 2015-02-05 12:55:53 -0700 | [diff] [blame] | 860 | func TestAbandonStack(t *testing.T) { |
| 861 | th.SetupHTTP() |
| 862 | defer th.TeardownHTTP() |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 863 | os.HandleAbandonSuccessfully(t, os.AbandonOutput) |
Jon Perritt | 9b81b8c | 2015-02-05 12:55:53 -0700 | [diff] [blame] | 864 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 865 | actual, err := Abandon(fake.ServiceClient(), "postman_stack", "16ef0584-4458-41eb-87c8-0dc8d5f66c8").Extract() |
| 866 | th.AssertNoErr(t, err) |
Jon Perritt | 9b81b8c | 2015-02-05 12:55:53 -0700 | [diff] [blame] | 867 | |
Pratik Mallya | 5fddb2a | 2015-09-14 14:04:49 -0500 | [diff] [blame] | 868 | expected := os.AbandonExpected |
| 869 | th.AssertDeepEquals(t, expected, actual) |
Jon Perritt | 9b81b8c | 2015-02-05 12:55:53 -0700 | [diff] [blame] | 870 | } |