Example #1
0
// Test using the updated interface
func TestStacksNewTemplateFormat(t *testing.T) {
	// Create a provider client for making the HTTP requests.
	// See common.go in this directory for more information.
	client := newClient(t)

	stackName1 := "gophercloud-test-stack-2"
	templateOpts := new(osStacks.Template)
	templateOpts.Bin = []byte(template)
	createOpts := osStacks.CreateOpts{
		Name:         stackName1,
		TemplateOpts: templateOpts,
		Timeout:      5,
	}
	stack, err := stacks.Create(client, createOpts).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created stack: %+v\n", stack)
	defer func() {
		err := stacks.Delete(client, stackName1, stack.ID).ExtractErr()
		th.AssertNoErr(t, err)
		t.Logf("Deleted stack (%s)", stackName1)
	}()
	err = gophercloud.WaitFor(60, func() (bool, error) {
		getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
		if err != nil {
			return false, err
		}
		if getStack.Status == "CREATE_COMPLETE" {
			return true, nil
		}
		return false, nil
	})

	updateOpts := osStacks.UpdateOpts{
		TemplateOpts: templateOpts,
		Timeout:      20,
	}
	err = stacks.Update(client, stackName1, stack.ID, updateOpts).ExtractErr()
	th.AssertNoErr(t, err)
	err = gophercloud.WaitFor(60, func() (bool, error) {
		getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
		if err != nil {
			return false, err
		}
		if getStack.Status == "UPDATE_COMPLETE" {
			return true, nil
		}
		return false, nil
	})

	t.Logf("Updated stack")

	err = stacks.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
		stackList, err := osStacks.ExtractStacks(page)
		th.AssertNoErr(t, err)

		t.Logf("Got stack list: %+v\n", stackList)

		return true, nil
	})
	th.AssertNoErr(t, err)

	getStack, err := stacks.Get(client, stackName1, stack.ID).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Got stack: %+v\n", getStack)

	abandonedStack, err := stacks.Abandon(client, stackName1, stack.ID).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Abandonded stack %+v\n", abandonedStack)
	th.AssertNoErr(t, err)
}
Example #2
0
func TestAdoptStackNewTemplateFormat(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	os.HandleCreateSuccessfully(t, CreateOutput)
	template := new(os.Template)
	template.Bin = []byte(`{
  "outputs": {
	"db_host": {
	  "value": {
		"get_attr": [
		"db",
		"hostname"
		]
	  }
	}
  },
  "heat_template_version": "2014-10-16",
  "description": "HEAT template for creating a Cloud Database.\n",
  "parameters": {
	"db_name": {
	  "default": "wordpress",
	  "type": "string",
	  "description": "the name for the database",
	  "constraints": [
	  {
		"length": {
		  "max": 64,
		  "min": 1
		},
		"description": "must be between 1 and 64 characters"
	  },
	  {
		"allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
		"description": "must begin with a letter and contain only alphanumeric characters."
	  }
	  ]
	},
	"db_instance_name": {
	  "default": "Cloud_DB",
	  "type": "string",
	  "description": "the database instance name"
	},
	"db_username": {
	  "default": "admin",
	  "hidden": true,
	  "type": "string",
	  "description": "database admin account username",
	  "constraints": [
	  {
		"length": {
		  "max": 16,
		  "min": 1
		},
		"description": "must be between 1 and 16 characters"
	  },
	  {
		"allowed_pattern": "[a-zA-Z][a-zA-Z0-9]*",
		"description": "must begin with a letter and contain only alphanumeric characters."
	  }
	  ]
	},
	"db_volume_size": {
	  "default": 30,
	  "type": "number",
	  "description": "database volume size (in GB)",
	  "constraints": [
	  {
		"range": {
		  "max": 1024,
		  "min": 1
		},
		"description": "must be between 1 and 1024 GB"
	  }
	  ]
	},
	"db_flavor": {
	  "default": "1GB Instance",
	  "type": "string",
	  "description": "database instance size",
	  "constraints": [
	  {
		"description": "must be a valid cloud database flavor",
		"allowed_values": [
		"1GB Instance",
		"2GB Instance",
		"4GB Instance",
		"8GB Instance",
		"16GB Instance"
		]
	  }
	  ]
	},
	"db_password": {
	  "default": "admin",
	  "hidden": true,
	  "type": "string",
	  "description": "database admin account password",
	  "constraints": [
	  {
		"length": {
		  "max": 41,
		  "min": 1
		},
		"description": "must be between 1 and 14 characters"
	  },
	  {
		"allowed_pattern": "[a-zA-Z0-9]*",
		"description": "must contain only alphanumeric characters."
	  }
	  ]
	}
  },
  "resources": {
	"db": {
	  "type": "OS::Trove::Instance",
	  "properties": {
		"flavor": {
		  "get_param": "db_flavor"
		},
		"size": {
		  "get_param": "db_volume_size"
		},
		"users": [
		{
		  "password": {
			"get_param": "db_password"
		  },
		  "name": {
			"get_param": "db_username"
		  },
		  "databases": [
		  {
			"get_param": "db_name"
		  }
		  ]
		}
		],
		"name": {
		  "get_param": "db_instance_name"
		},
		"databases": [
		{
		  "name": {
			"get_param": "db_name"
		  }
		}
		]
	  }
	}
  }
}`)

	adoptOpts := os.AdoptOpts{
		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},`,
		Name:            "stackadopted",
		Timeout:         60,
		TemplateOpts:    template,
		DisableRollback: os.Disable,
	}
	actual, err := Adopt(fake.ServiceClient(), adoptOpts).Extract()
	th.AssertNoErr(t, err)

	expected := CreateExpected
	th.AssertDeepEquals(t, expected, actual)
}