func waitForStatus(client *gophercloud.ServiceClient, server *servers.Server, status string) error { return tools.WaitFor(func() (bool, error) { latest, err := servers.Get(client, server.ID).Extract() if err != nil { return false, err } if latest.Status == status { // Success! return true, nil } return false, nil }) }
func TestUpdateServer(t *testing.T) { client, err := newClient() if err != nil { t.Fatalf("Unable to create a compute client: %v", err) } choices, err := ComputeChoicesFromEnv() if err != nil { t.Fatal(err) } server, err := createServer(t, client, choices) if err != nil { t.Fatal(err) } defer servers.Delete(client, server.ID) if err = waitForStatus(client, server, "ACTIVE"); err != nil { t.Fatal(err) } alternateName := tools.RandomString("ACPTTEST", 16) for alternateName == server.Name { alternateName = tools.RandomString("ACPTTEST", 16) } t.Logf("Attempting to rename the server to %s.", alternateName) updated, err := servers.Update(client, server.ID, servers.UpdateOpts{Name: alternateName}).Extract() if err != nil { t.Fatalf("Unable to rename server: %v", err) } if updated.ID != server.ID { t.Errorf("Updated server ID [%s] didn't match original server ID [%s]!", updated.ID, server.ID) } err = tools.WaitFor(func() (bool, error) { latest, err := servers.Get(client, updated.ID).Extract() if err != nil { return false, err } return latest.Name == alternateName, nil }) }