More technical debt payoff.
Applied refactoring across the entire acceptance test code base.
diff --git a/acceptance/09-resize-server.go b/acceptance/09-resize-server.go
index 558b2cf..b12ef4b 100644
--- a/acceptance/09-resize-server.go
+++ b/acceptance/09-resize-server.go
@@ -10,43 +10,26 @@
var quiet = flag.Bool("quiet", false, "Quiet mode, for acceptance testing. $? still indicates errors though.")
func main() {
- provider, username, password := getCredentials()
flag.Parse()
- acc, err := gophercloud.Authenticate(
- provider,
- gophercloud.AuthOptions{
- Username: username,
- Password: password,
- },
- )
- if err != nil {
- panic(err)
- }
+ withIdentity(false, func(acc gophercloud.AccessProvider) {
+ withServerApi(acc, func(api gophercloud.CloudServersProvider) {
+ // These tests are going to take some time to complete.
+ // So, we'll do two tests at the same time to help amortize test time.
+ done := make(chan bool)
+ go resizeRejectTest(api, done)
+ go resizeAcceptTest(api, done)
+ _ = <- done
+ _ = <- done
- api, err := gophercloud.ServersApi(acc, gophercloud.ApiCriteria{
- Name: "cloudServersOpenStack",
- Region: "DFW",
- VersionId: "2",
- UrlChoice: gophercloud.PublicURL,
+ if !*quiet {
+ fmt.Println("Done.")
+ }
+ })
})
- if err != nil {
- panic(err)
- }
-
- // These tests are going to take some time to complete.
- // So, we'll do two tests at the same time to help amortize test time.
- done := make(chan bool)
- go resizeRejectTest(api, done)
- go resizeAcceptTest(api, done)
- _ = <- done
- _ = <- done
-
- if !*quiet {
- fmt.Println("Done.")
- }
}
+// Perform the resize test, but reject the resize request.
func resizeRejectTest(api gophercloud.CloudServersProvider, done chan bool) {
withServer(api, func(id string) {
newFlavorId := findAlternativeFlavor()
@@ -55,7 +38,7 @@
panic(err)
}
- waitForVerifyResize(api, id)
+ waitForServerState(api, id, "VERIFY_RESIZE")
err = api.RevertResize(id)
if err != nil {
@@ -65,6 +48,7 @@
done <- true
}
+// Perform the resize test, but accept the resize request.
func resizeAcceptTest(api gophercloud.CloudServersProvider, done chan bool) {
withServer(api, func(id string) {
newFlavorId := findAlternativeFlavor()
@@ -73,7 +57,7 @@
panic(err)
}
- waitForVerifyResize(api, id)
+ waitForServerState(api, id, "VERIFY_RESIZE")
err = api.ConfirmResize(id)
if err != nil {
@@ -83,19 +67,6 @@
done <- true
}
-func waitForVerifyResize(api gophercloud.CloudServersProvider, id string) {
- for {
- s, err := api.ServerById(id)
- if err != nil {
- panic(err)
- }
- if s.Status == "VERIFY_RESIZE" {
- break
- }
- time.Sleep(10 * time.Second)
- }
-}
-
func withServer(api gophercloud.CloudServersProvider, f func(string)) {
id, err := createServer(api, "", "", "", "")
if err != nil {
@@ -115,6 +86,13 @@
f(id)
+ // I've learned that resizing an instance can fail if a delete request
+ // comes in prior to its completion. This ends up leaving the server
+ // in an error state, and neither the resize NOR the delete complete.
+ // This is a bug in OpenStack, as far as I'm concerned, but thankfully,
+ // there's an easy work-around -- just wait for your server to return to
+ // active state first!
+ waitForServerState(api, id, "ACTIVE")
err = api.DeleteServerById(id)
if err != nil {
panic(err)